blob: 67827e397431abe8b55955d9cc6497cbf680c054 [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 Smartd080abe2017-02-12 13:52:39 -08004 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Smartd6de08c2015-12-16 18:11:53 -0500861 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
862 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
863 lpfc_unregister_fcf_prep(phba);
864
865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VFI_REGISTERED;
867 spin_unlock_irq(shost->host_lock);
868 phba->fc_topology_changed = 0;
869 }
870
James Smart2e0fef82007-06-17 19:56:36 -0500871 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500872 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400873
dea31012005-04-17 16:05:31 -0500874 if (rc >= 0) {
875 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500876 spin_lock_irq(shost->host_lock);
877 vport->fc_flag |= FC_PT2PT_PLOGI;
878 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500879
880 /*
James Smartd6de08c2015-12-16 18:11:53 -0500881 * N_Port ID cannot be 0, set our Id to LocalID
882 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500883 */
884
885 /* not equal */
886 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500887 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500888
James Smarte47c9092008-02-08 18:49:26 -0500889 /* Decrement ndlp reference count indicating that ndlp can be
890 * safely released when other references to it are done.
891 */
James Smart329f9bc2007-04-25 09:53:01 -0400892 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500893
James Smart2e0fef82007-06-17 19:56:36 -0500894 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500895 if (!ndlp) {
896 /*
897 * Cannot find existing Fabric ndlp, so allocate a
898 * new one
899 */
James Smart9d3d3402017-04-21 16:05:00 -0700900 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500901 if (!ndlp)
902 goto fail;
James Smarte47c9092008-02-08 18:49:26 -0500903 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
904 ndlp = lpfc_enable_node(vport, ndlp,
905 NLP_STE_UNUSED_NODE);
906 if(!ndlp)
907 goto fail;
dea31012005-04-17 16:05:31 -0500908 }
909
910 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500911 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500912 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500913 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500914 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500915 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
916 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500917 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500918 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500919 } else
920 /* This side will wait for the PLOGI, decrement ndlp reference
921 * count indicating that ndlp can be released when other
922 * references to it are done.
923 */
James Smart329f9bc2007-04-25 09:53:01 -0400924 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500925
James Smart09372822008-01-11 01:52:54 -0500926 /* If we are pt2pt with another NPort, force NPIV off! */
927 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
928
James Smartd6de08c2015-12-16 18:11:53 -0500929 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
930 if (!mbox)
931 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400932
James Smartd6de08c2015-12-16 18:11:53 -0500933 lpfc_config_link(phba, mbox);
934
935 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
936 mbox->vport = vport;
937 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
938 if (rc == MBX_NOT_FINISHED) {
939 mempool_free(mbox, phba->mbox_mem_pool);
940 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400941 }
dea31012005-04-17 16:05:31 -0500942
dea31012005-04-17 16:05:31 -0500943 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500944fail:
dea31012005-04-17 16:05:31 -0500945 return -ENXIO;
946}
947
James Smarte59058c2008-08-24 21:49:00 -0400948/**
James Smart3621a712009-04-06 18:47:14 -0400949 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400950 * @phba: pointer to lpfc hba data structure.
951 * @cmdiocb: pointer to lpfc command iocb data structure.
952 * @rspiocb: pointer to lpfc response iocb data structure.
953 *
954 * This routine is the top-level completion callback function for issuing
955 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
956 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
957 * retry has been made (either immediately or delayed with lpfc_els_retry()
958 * returning 1), the command IOCB will be released and function returned.
959 * If the retry attempt has been given up (possibly reach the maximum
960 * number of retries), one additional decrement of ndlp reference shall be
961 * invoked before going out after releasing the command IOCB. This will
962 * actually release the remote node (Note, lpfc_els_free_iocb() will also
963 * invoke one decrement of ndlp reference count). If no error reported in
964 * the IOCB status, the command Port ID field is used to determine whether
965 * this is a point-to-point topology or a fabric topology: if the Port ID
966 * field is assigned, it is a fabric topology; otherwise, it is a
967 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
968 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
969 * specific topology completion conditions.
970 **/
dea31012005-04-17 16:05:31 -0500971static void
James Smart329f9bc2007-04-25 09:53:01 -0400972lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
973 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500974{
James Smart2e0fef82007-06-17 19:56:36 -0500975 struct lpfc_vport *vport = cmdiocb->vport;
976 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500977 IOCB_t *irsp = &rspiocb->iocb;
978 struct lpfc_nodelist *ndlp = cmdiocb->context1;
979 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
980 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500981 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500982 int rc;
983
984 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500985 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500986 /* One additional decrement on node reference count to
987 * trigger the release of the node
988 */
James Smart329f9bc2007-04-25 09:53:01 -0400989 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500990 goto out;
991 }
992
James Smart858c9f62007-06-17 19:56:39 -0500993 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
994 "FLOGI cmpl: status:x%x/x%x state:x%x",
995 irsp->ulpStatus, irsp->un.ulpWord[4],
996 vport->port_state);
997
dea31012005-04-17 16:05:31 -0500998 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500999 /*
James Smarta93ff372010-10-22 11:06:08 -04001000 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05001001 * due to new FCF discovery
1002 */
1003 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001004 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1005 if (phba->link_state < LPFC_LINK_UP)
1006 goto stop_rr_fcf_flogi;
1007 if ((phba->fcoe_cvl_eventtag_attn ==
1008 phba->fcoe_cvl_eventtag) &&
1009 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001010 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1011 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001012 goto stop_rr_fcf_flogi;
1013 else
1014 phba->fcoe_cvl_eventtag_attn =
1015 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001016 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001017 "2611 FLOGI failed on FCF (x%x), "
1018 "status:x%x/x%x, tmo:x%x, perform "
1019 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001020 phba->fcf.current_rec.fcf_indx,
1021 irsp->ulpStatus, irsp->un.ulpWord[4],
1022 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001023 lpfc_sli4_set_fcf_flogi_fail(phba,
1024 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001025 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001026 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1027 if (rc)
1028 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001029 }
1030
James Smart80c17842012-03-01 22:35:45 -05001031stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001032 /* FLOGI failure */
1033 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart8fe5c162015-08-31 16:48:19 -04001034 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1035 "Data x%x x%x\n",
James Smart38b92ef2010-08-04 16:11:39 -04001036 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart8fe5c162015-08-31 16:48:19 -04001037 irsp->ulpTimeout, phba->hba_flag,
1038 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001039
dea31012005-04-17 16:05:31 -05001040 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001041 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001042 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001043
James Smart76a95d72010-11-20 23:11:48 -05001044 /* FLOGI failure */
1045 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1046 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1047 irsp->ulpStatus, irsp->un.ulpWord[4],
1048 irsp->ulpTimeout);
1049
dea31012005-04-17 16:05:31 -05001050 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001051 spin_lock_irq(shost->host_lock);
1052 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1053 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001054
James Smart329f9bc2007-04-25 09:53:01 -04001055 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001056 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1057 * alpa map would take too long otherwise.
1058 */
James Smart1b511972011-12-13 13:23:09 -05001059 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001060 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001061 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1062 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001063 (vport->fc_prevDID != vport->fc_myDID) ||
1064 phba->fc_topology_changed)) {
1065 if (vport->fc_flag & FC_VFI_REGISTERED) {
1066 if (phba->fc_topology_changed) {
1067 lpfc_unregister_fcf_prep(phba);
1068 spin_lock_irq(shost->host_lock);
1069 vport->fc_flag &= ~FC_VFI_REGISTERED;
1070 spin_unlock_irq(shost->host_lock);
1071 phba->fc_topology_changed = 0;
1072 } else {
1073 lpfc_sli4_unreg_all_rpis(vport);
1074 }
1075 }
James Smart342b59c2016-03-31 14:12:31 -07001076
1077 /* Do not register VFI if the driver aborted FLOGI */
1078 if (!lpfc_error_lost_link(irsp))
1079 lpfc_issue_reg_vfi(vport);
James Smartff78d8f2011-12-13 13:21:35 -05001080 lpfc_nlp_put(ndlp);
1081 goto out;
dea31012005-04-17 16:05:31 -05001082 }
dea31012005-04-17 16:05:31 -05001083 goto flogifail;
1084 }
James Smart695a8142010-01-26 23:08:03 -05001085 spin_lock_irq(shost->host_lock);
1086 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001087 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001088 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001089
1090 /*
1091 * The FLogI succeeded. Sync the data for the CPU before
1092 * accessing it.
1093 */
1094 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001095 if (!prsp)
1096 goto out;
dea31012005-04-17 16:05:31 -05001097 sp = prsp->virt + sizeof(uint32_t);
1098
1099 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001100 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001101 "0101 FLOGI completes successfully, I/O tag:x%x, "
1102 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001103 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001104 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1105 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001106
James Smart2e0fef82007-06-17 19:56:36 -05001107 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001108 /*
1109 * If Common Service Parameters indicate Nport
1110 * we are point to point, if Fport we are Fabric.
1111 */
1112 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001113 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001114 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001115 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001116 else {
1117 lpfc_printf_vlog(vport, KERN_ERR,
1118 LOG_FIP | LOG_ELS,
1119 "2831 FLOGI response with cleared Fabric "
1120 "bit fcf_index 0x%x "
1121 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1122 "Fabric Name "
1123 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1124 phba->fcf.current_rec.fcf_indx,
1125 phba->fcf.current_rec.switch_name[0],
1126 phba->fcf.current_rec.switch_name[1],
1127 phba->fcf.current_rec.switch_name[2],
1128 phba->fcf.current_rec.switch_name[3],
1129 phba->fcf.current_rec.switch_name[4],
1130 phba->fcf.current_rec.switch_name[5],
1131 phba->fcf.current_rec.switch_name[6],
1132 phba->fcf.current_rec.switch_name[7],
1133 phba->fcf.current_rec.fabric_name[0],
1134 phba->fcf.current_rec.fabric_name[1],
1135 phba->fcf.current_rec.fabric_name[2],
1136 phba->fcf.current_rec.fabric_name[3],
1137 phba->fcf.current_rec.fabric_name[4],
1138 phba->fcf.current_rec.fabric_name[5],
1139 phba->fcf.current_rec.fabric_name[6],
1140 phba->fcf.current_rec.fabric_name[7]);
1141 lpfc_nlp_put(ndlp);
1142 spin_lock_irq(&phba->hbalock);
1143 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001144 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001145 spin_unlock_irq(&phba->hbalock);
1146 goto out;
1147 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001148 if (!rc) {
1149 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001150 if (phba->hba_flag & HBA_FIP_SUPPORT)
1151 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1152 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001153 "2769 FLOGI to FCF (x%x) "
1154 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001155 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001156 spin_lock_irq(&phba->hbalock);
1157 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001158 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001159 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001160 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001161 }
dea31012005-04-17 16:05:31 -05001162 }
1163
1164flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001165 spin_lock_irq(&phba->hbalock);
1166 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1167 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001168
James Smart329f9bc2007-04-25 09:53:01 -04001169 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001170
James Smart858c9f62007-06-17 19:56:39 -05001171 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001172 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001173 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001174
1175 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001176 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001177 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001178 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1179 IOERR_SLI_ABORTED) &&
1180 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1181 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001182 (phba->link_state != LPFC_CLEAR_LA)) {
1183 /* If FLOGI failed enable link interrupt. */
1184 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001185 }
dea31012005-04-17 16:05:31 -05001186out:
1187 lpfc_els_free_iocb(phba, cmdiocb);
1188}
1189
James Smarte59058c2008-08-24 21:49:00 -04001190/**
James Smart3621a712009-04-06 18:47:14 -04001191 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001192 * @vport: pointer to a host virtual N_Port data structure.
1193 * @ndlp: pointer to a node-list data structure.
1194 * @retry: number of retries to the command IOCB.
1195 *
1196 * This routine issues a Fabric Login (FLOGI) Request ELS command
1197 * for a @vport. The initiator service parameters are put into the payload
1198 * of the FLOGI Request IOCB and the top-level callback function pointer
1199 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1200 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1201 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1202 *
1203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1205 * will be stored into the context1 field of the IOCB for the completion
1206 * callback function to the FLOGI ELS command.
1207 *
1208 * Return code
1209 * 0 - successfully issued flogi iocb for @vport
1210 * 1 - failed to issue flogi iocb for @vport
1211 **/
dea31012005-04-17 16:05:31 -05001212static int
James Smart2e0fef82007-06-17 19:56:36 -05001213lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001214 uint8_t retry)
1215{
James Smart2e0fef82007-06-17 19:56:36 -05001216 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001217 struct serv_parm *sp;
1218 IOCB_t *icmd;
1219 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001220 uint8_t *pcmd;
1221 uint16_t cmdsize;
1222 uint32_t tmo;
1223 int rc;
1224
James Smart92d7f7b2007-06-17 19:56:38 -05001225 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001226 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1227 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001228
James Smart488d1462006-03-07 15:02:37 -05001229 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001230 return 1;
dea31012005-04-17 16:05:31 -05001231
1232 icmd = &elsiocb->iocb;
1233 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1234
1235 /* For FLOGI request, remainder of payload is service parameters */
1236 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001237 pcmd += sizeof(uint32_t);
1238 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001239 sp = (struct serv_parm *) pcmd;
1240
1241 /* Setup CSPs accordingly for Fabric */
1242 sp->cmn.e_d_tov = 0;
1243 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001244 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001245 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001246 if (sp->cmn.fcphLow < FC_PH3)
1247 sp->cmn.fcphLow = FC_PH3;
1248 if (sp->cmn.fcphHigh < FC_PH3)
1249 sp->cmn.fcphHigh = FC_PH3;
1250
James Smartc31098c2011-04-16 11:03:33 -04001251 if (phba->sli_rev == LPFC_SLI_REV4) {
1252 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1253 LPFC_SLI_INTF_IF_TYPE_0) {
1254 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1255 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1256 /* FLOGI needs to be 3 for WQE FCFI */
1257 /* Set the fcfi to the fcfi we registered with */
1258 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1259 }
James Smart0f378872012-10-31 14:45:01 -04001260 /* Can't do SLI4 class2 without support sequence coalescing */
1261 sp->cls2.classValid = 0;
1262 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001263 } else {
James Smart0f378872012-10-31 14:45:01 -04001264 /* Historical, setting sequential-delivery bit for SLI3 */
1265 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1266 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001267 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1268 sp->cmn.request_multiple_Nport = 1;
1269 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1270 icmd->ulpCt_h = 1;
1271 icmd->ulpCt_l = 0;
1272 } else
1273 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001274 }
1275
James Smart76a95d72010-11-20 23:11:48 -05001276 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001277 icmd->un.elsreq64.myID = 0;
1278 icmd->un.elsreq64.fl = 1;
1279 }
1280
dea31012005-04-17 16:05:31 -05001281 tmo = phba->fc_ratov;
1282 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001283 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001284 phba->fc_ratov = tmo;
1285
1286 phba->fc_stat.elsXmitFLOGI++;
1287 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001288
1289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1290 "Issue FLOGI: opt:x%x",
1291 phba->sli3_options, 0, 0);
1292
James Smart92d7f7b2007-06-17 19:56:38 -05001293 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001294 if (rc == IOCB_ERROR) {
1295 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001296 return 1;
dea31012005-04-17 16:05:31 -05001297 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001298 return 0;
dea31012005-04-17 16:05:31 -05001299}
1300
James Smarte59058c2008-08-24 21:49:00 -04001301/**
James Smart3621a712009-04-06 18:47:14 -04001302 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001303 * @phba: pointer to lpfc hba data structure.
1304 *
1305 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1306 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1307 * list and issues an abort IOCB commond on each outstanding IOCB that
1308 * contains a active Fabric_DID ndlp. Note that this function is to issue
1309 * the abort IOCB command on all the outstanding IOCBs, thus when this
1310 * function returns, it does not guarantee all the IOCBs are actually aborted.
1311 *
1312 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001313 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001314 **/
dea31012005-04-17 16:05:31 -05001315int
James Smart2e0fef82007-06-17 19:56:36 -05001316lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001317{
1318 struct lpfc_sli_ring *pring;
1319 struct lpfc_iocbq *iocb, *next_iocb;
1320 struct lpfc_nodelist *ndlp;
1321 IOCB_t *icmd;
1322
1323 /* Abort outstanding I/O on NPort <nlp_DID> */
1324 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001325 "0201 Abort outstanding I/O on NPort x%x\n",
1326 Fabric_DID);
dea31012005-04-17 16:05:31 -05001327
James Smart895427b2017-02-12 13:52:30 -08001328 pring = lpfc_phba_elsring(phba);
dea31012005-04-17 16:05:31 -05001329
1330 /*
1331 * Check the txcmplq for an iocb that matches the nport the driver is
1332 * searching for.
1333 */
James Smart2e0fef82007-06-17 19:56:36 -05001334 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001335 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1336 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001337 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001338 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001339 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1340 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001341 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001342 }
1343 }
James Smart2e0fef82007-06-17 19:56:36 -05001344 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001345
1346 return 0;
1347}
1348
James Smarte59058c2008-08-24 21:49:00 -04001349/**
James Smart3621a712009-04-06 18:47:14 -04001350 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001351 * @vport: pointer to a host virtual N_Port data structure.
1352 *
1353 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1354 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1355 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1356 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1357 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1358 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1359 * @vport.
1360 *
1361 * Return code
1362 * 0 - failed to issue initial flogi for @vport
1363 * 1 - successfully issued initial flogi for @vport
1364 **/
dea31012005-04-17 16:05:31 -05001365int
James Smart2e0fef82007-06-17 19:56:36 -05001366lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001367{
1368 struct lpfc_nodelist *ndlp;
1369
James Smart98c9ea52007-10-27 13:37:33 -04001370 vport->port_state = LPFC_FLOGI;
1371 lpfc_set_disctmo(vport);
1372
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001373 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001374 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001375 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001376 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001377 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001378 if (!ndlp)
1379 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001380 /* Set the node type */
1381 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001382 /* Put ndlp onto node list */
1383 lpfc_enqueue_node(vport, ndlp);
1384 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1385 /* re-setup ndlp without removing from node list */
1386 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1387 if (!ndlp)
1388 return 0;
dea31012005-04-17 16:05:31 -05001389 }
James Smart87af33f2007-10-27 13:37:43 -04001390
James Smart5ac6b302010-10-22 11:05:36 -04001391 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001392 /* This decrement of reference count to node shall kick off
1393 * the release of the node.
1394 */
James Smart329f9bc2007-04-25 09:53:01 -04001395 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001396 return 0;
1397 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return 1;
dea31012005-04-17 16:05:31 -05001399}
1400
James Smarte59058c2008-08-24 21:49:00 -04001401/**
James Smart3621a712009-04-06 18:47:14 -04001402 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001403 * @vport: pointer to a host virtual N_Port data structure.
1404 *
1405 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1406 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1407 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1408 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1409 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1410 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1411 * @vport.
1412 *
1413 * Return code
1414 * 0 - failed to issue initial fdisc for @vport
1415 * 1 - successfully issued initial fdisc for @vport
1416 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001417int
1418lpfc_initial_fdisc(struct lpfc_vport *vport)
1419{
James Smart92d7f7b2007-06-17 19:56:38 -05001420 struct lpfc_nodelist *ndlp;
1421
1422 /* First look for the Fabric ndlp */
1423 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1424 if (!ndlp) {
1425 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001426 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001427 if (!ndlp)
1428 return 0;
James Smarte47c9092008-02-08 18:49:26 -05001429 /* Put ndlp onto node list */
1430 lpfc_enqueue_node(vport, ndlp);
1431 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1432 /* re-setup ndlp without removing from node list */
1433 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1434 if (!ndlp)
1435 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001436 }
James Smarte47c9092008-02-08 18:49:26 -05001437
James Smart92d7f7b2007-06-17 19:56:38 -05001438 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001439 /* decrement node reference count to trigger the release of
1440 * the node.
1441 */
James Smart92d7f7b2007-06-17 19:56:38 -05001442 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001443 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001444 }
1445 return 1;
1446}
James Smart87af33f2007-10-27 13:37:43 -04001447
James Smarte59058c2008-08-24 21:49:00 -04001448/**
James Smart3621a712009-04-06 18:47:14 -04001449 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001450 * @vport: pointer to a host virtual N_Port data structure.
1451 *
1452 * This routine checks whether there are more remaining Port Logins
1453 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1454 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1455 * to issue ELS PLOGIs up to the configured discover threads with the
1456 * @vport (@vport->cfg_discovery_threads). The function also decrement
1457 * the @vport's num_disc_node by 1 if it is not already 0.
1458 **/
James Smart87af33f2007-10-27 13:37:43 -04001459void
James Smart2e0fef82007-06-17 19:56:36 -05001460lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001461{
James Smart2e0fef82007-06-17 19:56:36 -05001462 if (vport->num_disc_nodes)
1463 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001464
1465 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001466 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1467 "0232 Continue discovery with %d PLOGIs to go "
1468 "Data: x%x x%x x%x\n",
1469 vport->num_disc_nodes, vport->fc_plogi_cnt,
1470 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001471 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001472 if (vport->fc_flag & FC_NLP_MORE)
1473 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001474 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001475
dea31012005-04-17 16:05:31 -05001476 return;
1477}
1478
James Smarte59058c2008-08-24 21:49:00 -04001479/**
James Smart3621a712009-04-06 18:47:14 -04001480 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001481 * @phba: pointer to lpfc hba data structure.
1482 * @prsp: pointer to response IOCB payload.
1483 * @ndlp: pointer to a node-list data structure.
1484 *
1485 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1486 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1487 * The following cases are considered N_Port confirmed:
1488 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1489 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1490 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1491 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1492 * 1) if there is a node on vport list other than the @ndlp with the same
1493 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1494 * on that node to release the RPI associated with the node; 2) if there is
1495 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1496 * into, a new node shall be allocated (or activated). In either case, the
1497 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1498 * be released and the new_ndlp shall be put on to the vport node list and
1499 * its pointer returned as the confirmed node.
1500 *
1501 * Note that before the @ndlp got "released", the keepDID from not-matching
1502 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1503 * of the @ndlp. This is because the release of @ndlp is actually to put it
1504 * into an inactive state on the vport node list and the vport node list
1505 * management algorithm does not allow two node with a same DID.
1506 *
1507 * Return code
1508 * pointer to the PLOGI N_Port @ndlp
1509 **/
James Smart488d1462006-03-07 15:02:37 -05001510static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001511lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001512 struct lpfc_nodelist *ndlp)
1513{
James Smarta0f2d3e2017-02-12 13:52:31 -08001514 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001516 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001517 struct lpfc_rport_data *rdata;
1518 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001519 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001520 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001521 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001522 uint16_t keep_nlp_state;
James Smart38b92ef2010-08-04 16:11:39 -04001523 int put_node;
1524 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001525 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001526
James Smart2fb9bd82006-12-02 13:33:57 -05001527 /* Fabric nodes can have the same WWPN so we don't bother searching
1528 * by WWPN. Just return the ndlp that was given to us.
1529 */
1530 if (ndlp->nlp_type & NLP_FABRIC)
1531 return ndlp;
1532
James Smart92d7f7b2007-06-17 19:56:38 -05001533 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001534 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001535
James Smart685f0bf2007-04-25 09:53:08 -04001536 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001537 * we have for that ndlp. If not, we have some work to do.
1538 */
James Smart2e0fef82007-06-17 19:56:36 -05001539 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001540
James Smarte47c9092008-02-08 18:49:26 -05001541 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001542 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001543 if (phba->sli_rev == LPFC_SLI_REV4) {
1544 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1545 GFP_KERNEL);
1546 if (active_rrqs_xri_bitmap)
1547 memset(active_rrqs_xri_bitmap, 0,
1548 phba->cfg_rrq_xri_bitmap_sz);
1549 }
James Smart488d1462006-03-07 15:02:37 -05001550
James Smart34f5ad82012-08-03 12:35:03 -04001551 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1552 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1553 ndlp, ndlp->nlp_DID, new_ndlp);
1554
James Smart488d1462006-03-07 15:02:37 -05001555 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001556 rc = memcmp(&ndlp->nlp_portname, name,
1557 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001558 if (!rc) {
1559 if (active_rrqs_xri_bitmap)
1560 mempool_free(active_rrqs_xri_bitmap,
1561 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001562 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001563 }
James Smart9d3d3402017-04-21 16:05:00 -07001564 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
James Smartcff261f2013-12-17 20:29:47 -05001565 if (!new_ndlp) {
1566 if (active_rrqs_xri_bitmap)
1567 mempool_free(active_rrqs_xri_bitmap,
1568 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001569 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001570 }
James Smarte47c9092008-02-08 18:49:26 -05001571 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001572 rc = memcmp(&ndlp->nlp_portname, name,
1573 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001574 if (!rc) {
1575 if (active_rrqs_xri_bitmap)
1576 mempool_free(active_rrqs_xri_bitmap,
1577 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001578 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001579 }
James Smarte47c9092008-02-08 18:49:26 -05001580 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1581 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001582 if (!new_ndlp) {
1583 if (active_rrqs_xri_bitmap)
1584 mempool_free(active_rrqs_xri_bitmap,
1585 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001586 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001587 }
James Smart58da1ff2008-04-07 10:15:56 -04001588 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001589 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1590 memcpy(active_rrqs_xri_bitmap,
1591 new_ndlp->active_rrqs_xri_bitmap,
1592 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001593 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001594 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001595 if (phba->sli_rev == LPFC_SLI_REV4 &&
1596 active_rrqs_xri_bitmap)
1597 memcpy(active_rrqs_xri_bitmap,
1598 new_ndlp->active_rrqs_xri_bitmap,
1599 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001600 }
James Smart488d1462006-03-07 15:02:37 -05001601
James Smart2e0fef82007-06-17 19:56:36 -05001602 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001603 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001604 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001605 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001606 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1607 ndlp->active_rrqs_xri_bitmap,
1608 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001609
James Smart953ceed2015-05-22 10:42:37 -04001610 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001611 keep_nlp_flag = new_ndlp->nlp_flag;
1612 new_ndlp->nlp_flag = ndlp->nlp_flag;
1613 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001614 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001615
James Smart953ceed2015-05-22 10:42:37 -04001616 /* Set nlp_states accordingly */
1617 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001618 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001619
James Smart2e0fef82007-06-17 19:56:36 -05001620 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001621 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1622 /* The new_ndlp is replacing ndlp totally, so we need
1623 * to put ndlp on UNUSED list and try to free it.
1624 */
James Smart34f5ad82012-08-03 12:35:03 -04001625 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1626 "3179 PLOGI confirm NEW: %x %x\n",
1627 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001628
1629 /* Fix up the rport accordingly */
1630 rport = ndlp->rport;
1631 if (rport) {
1632 rdata = rport->dd_data;
1633 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001634 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001635 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001636 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001637 rdata->pnode = lpfc_nlp_get(new_ndlp);
1638 new_ndlp->rport = rport;
1639 }
1640 new_ndlp->nlp_type = ndlp->nlp_type;
1641 }
James Smart58da1ff2008-04-07 10:15:56 -04001642 /* We shall actually free the ndlp with both nlp_DID and
1643 * nlp_portname fields equals 0 to avoid any ndlp on the
1644 * nodelist never to be used.
1645 */
1646 if (ndlp->nlp_DID == 0) {
1647 spin_lock_irq(&phba->ndlp_lock);
1648 NLP_SET_FREE_REQ(ndlp);
1649 spin_unlock_irq(&phba->ndlp_lock);
1650 }
James Smart0ff10d42008-01-11 01:52:36 -05001651
James Smart58da1ff2008-04-07 10:15:56 -04001652 /* Two ndlps cannot have the same did on the nodelist */
1653 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001654 if (phba->sli_rev == LPFC_SLI_REV4 &&
1655 active_rrqs_xri_bitmap)
1656 memcpy(ndlp->active_rrqs_xri_bitmap,
1657 active_rrqs_xri_bitmap,
1658 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001659
1660 if (!NLP_CHK_NODE_ACT(ndlp))
1661 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001662 }
James Smart92795652006-07-06 15:50:02 -04001663 else {
James Smart34f5ad82012-08-03 12:35:03 -04001664 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1665 "3180 PLOGI confirm SWAP: %x %x\n",
1666 new_ndlp->nlp_DID, keepDID);
1667
James Smart2e0fef82007-06-17 19:56:36 -05001668 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001669
James Smart58da1ff2008-04-07 10:15:56 -04001670 /* Two ndlps cannot have the same did */
1671 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001672 if (phba->sli_rev == LPFC_SLI_REV4 &&
1673 active_rrqs_xri_bitmap)
1674 memcpy(ndlp->active_rrqs_xri_bitmap,
1675 active_rrqs_xri_bitmap,
1676 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001677
James Smart953ceed2015-05-22 10:42:37 -04001678 /* Since we are switching over to the new_ndlp,
1679 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001680 */
1681 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1682 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001683 keep_nlp_state = NLP_STE_NPR_NODE;
1684 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001685
James Smart38b92ef2010-08-04 16:11:39 -04001686 /* Fix up the rport accordingly */
1687 rport = ndlp->rport;
1688 if (rport) {
1689 rdata = rport->dd_data;
1690 put_node = rdata->pnode != NULL;
1691 put_rport = ndlp->rport != NULL;
1692 rdata->pnode = NULL;
1693 ndlp->rport = NULL;
1694 if (put_node)
1695 lpfc_nlp_put(ndlp);
1696 if (put_rport)
1697 put_device(&rport->dev);
1698 }
James Smart92795652006-07-06 15:50:02 -04001699 }
James Smartcff261f2013-12-17 20:29:47 -05001700 if (phba->sli_rev == LPFC_SLI_REV4 &&
1701 active_rrqs_xri_bitmap)
1702 mempool_free(active_rrqs_xri_bitmap,
1703 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001704 return new_ndlp;
1705}
1706
James Smarte59058c2008-08-24 21:49:00 -04001707/**
James Smart3621a712009-04-06 18:47:14 -04001708 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001709 * @vport: pointer to a host virtual N_Port data structure.
1710 *
1711 * This routine checks whether more Registration State Change
1712 * Notifications (RSCNs) came in while the discovery state machine was in
1713 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1714 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1715 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1716 * handling the RSCNs.
1717 **/
James Smart87af33f2007-10-27 13:37:43 -04001718void
1719lpfc_end_rscn(struct lpfc_vport *vport)
1720{
1721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1722
1723 if (vport->fc_flag & FC_RSCN_MODE) {
1724 /*
1725 * Check to see if more RSCNs came in while we were
1726 * processing this one.
1727 */
1728 if (vport->fc_rscn_id_cnt ||
1729 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1730 lpfc_els_handle_rscn(vport);
1731 else {
1732 spin_lock_irq(shost->host_lock);
1733 vport->fc_flag &= ~FC_RSCN_MODE;
1734 spin_unlock_irq(shost->host_lock);
1735 }
1736 }
1737}
1738
James Smarte59058c2008-08-24 21:49:00 -04001739/**
James Smart19ca7602010-11-20 23:11:55 -05001740 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1741 * @phba: pointer to lpfc hba data structure.
1742 * @cmdiocb: pointer to lpfc command iocb data structure.
1743 * @rspiocb: pointer to lpfc response iocb data structure.
1744 *
1745 * This routine will call the clear rrq function to free the rrq and
1746 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1747 * exist then the clear_rrq is still called because the rrq needs to
1748 * be freed.
1749 **/
1750
1751static void
1752lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1753 struct lpfc_iocbq *rspiocb)
1754{
1755 struct lpfc_vport *vport = cmdiocb->vport;
1756 IOCB_t *irsp;
1757 struct lpfc_nodelist *ndlp;
1758 struct lpfc_node_rrq *rrq;
1759
1760 /* we pass cmdiocb to state machine which needs rspiocb as well */
1761 rrq = cmdiocb->context_un.rrq;
1762 cmdiocb->context_un.rsp_iocb = rspiocb;
1763
1764 irsp = &rspiocb->iocb;
1765 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1766 "RRQ cmpl: status:x%x/x%x did:x%x",
1767 irsp->ulpStatus, irsp->un.ulpWord[4],
1768 irsp->un.elsreq64.remoteID);
1769
1770 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1771 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1773 "2882 RRQ completes to NPort x%x "
1774 "with no ndlp. Data: x%x x%x x%x\n",
1775 irsp->un.elsreq64.remoteID,
1776 irsp->ulpStatus, irsp->un.ulpWord[4],
1777 irsp->ulpIoTag);
1778 goto out;
1779 }
1780
1781 /* rrq completes to NPort <nlp_DID> */
1782 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1783 "2880 RRQ completes to NPort x%x "
1784 "Data: x%x x%x x%x x%x x%x\n",
1785 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1786 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1787
1788 if (irsp->ulpStatus) {
1789 /* Check for retry */
1790 /* RRQ failed Don't print the vport to vport rjts */
1791 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1792 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1793 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1794 (phba)->pport->cfg_log_verbose & LOG_ELS)
1795 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1796 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1797 ndlp->nlp_DID, irsp->ulpStatus,
1798 irsp->un.ulpWord[4]);
1799 }
1800out:
1801 if (rrq)
1802 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1803 lpfc_els_free_iocb(phba, cmdiocb);
1804 return;
1805}
1806/**
James Smart3621a712009-04-06 18:47:14 -04001807 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001808 * @phba: pointer to lpfc hba data structure.
1809 * @cmdiocb: pointer to lpfc command iocb data structure.
1810 * @rspiocb: pointer to lpfc response iocb data structure.
1811 *
1812 * This routine is the completion callback function for issuing the Port
1813 * Login (PLOGI) command. For PLOGI completion, there must be an active
1814 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001815 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001816 * ignored and command IOCB released. The PLOGI response IOCB status is
1817 * checked for error conditons. If there is error status reported, PLOGI
1818 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1819 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1820 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1821 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1822 * there are additional N_Port nodes with the vport that need to perform
1823 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1824 * PLOGIs.
1825 **/
dea31012005-04-17 16:05:31 -05001826static void
James Smart2e0fef82007-06-17 19:56:36 -05001827lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1828 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001829{
James Smart2e0fef82007-06-17 19:56:36 -05001830 struct lpfc_vport *vport = cmdiocb->vport;
1831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001832 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001833 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001834 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001835 int disc, rc;
dea31012005-04-17 16:05:31 -05001836
dea31012005-04-17 16:05:31 -05001837 /* we pass cmdiocb to state machine which needs rspiocb as well */
1838 cmdiocb->context_un.rsp_iocb = rspiocb;
1839
1840 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1842 "PLOGI cmpl: status:x%x/x%x did:x%x",
1843 irsp->ulpStatus, irsp->un.ulpWord[4],
1844 irsp->un.elsreq64.remoteID);
1845
James Smart2e0fef82007-06-17 19:56:36 -05001846 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001847 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001848 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1849 "0136 PLOGI completes to NPort x%x "
1850 "with no ndlp. Data: x%x x%x x%x\n",
1851 irsp->un.elsreq64.remoteID,
1852 irsp->ulpStatus, irsp->un.ulpWord[4],
1853 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001854 goto out;
James Smarted957682007-06-17 19:56:37 -05001855 }
dea31012005-04-17 16:05:31 -05001856
1857 /* Since ndlp can be freed in the disc state machine, note if this node
1858 * is being used during discovery.
1859 */
James Smart2e0fef82007-06-17 19:56:36 -05001860 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001861 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001862 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001864 rc = 0;
1865
1866 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001867 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08001868 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04001869 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08001870 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1871 irsp->ulpStatus, irsp->un.ulpWord[4],
1872 disc, vport->num_disc_nodes);
1873
dea31012005-04-17 16:05:31 -05001874 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001875 if (lpfc_els_chk_latt(vport)) {
1876 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001877 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001878 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001879 goto out;
1880 }
1881
dea31012005-04-17 16:05:31 -05001882 if (irsp->ulpStatus) {
1883 /* Check for retry */
1884 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1885 /* ELS command is being retried */
1886 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001887 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001888 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001889 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001890 }
1891 goto out;
1892 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001893 /* PLOGI failed Don't print the vport to vport rjts */
1894 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1895 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1896 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1897 (phba)->pport->cfg_log_verbose & LOG_ELS)
1898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001899 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1900 ndlp->nlp_DID, irsp->ulpStatus,
1901 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001902 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001903 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001904 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001905 else
James Smart2e0fef82007-06-17 19:56:36 -05001906 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001907 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001908 } else {
1909 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001910 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001911 cmdiocb->context2)->list.next,
1912 struct lpfc_dmabuf, list);
1913 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001914 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001915 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001916 }
1917
James Smart2e0fef82007-06-17 19:56:36 -05001918 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001919 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001920 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001921
James Smart2e0fef82007-06-17 19:56:36 -05001922 if (vport->num_disc_nodes == 0) {
1923 spin_lock_irq(shost->host_lock);
1924 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1925 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001926
James Smart2e0fef82007-06-17 19:56:36 -05001927 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001928 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001929 }
1930 }
1931
1932out:
1933 lpfc_els_free_iocb(phba, cmdiocb);
1934 return;
1935}
1936
James Smarte59058c2008-08-24 21:49:00 -04001937/**
James Smart3621a712009-04-06 18:47:14 -04001938 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001939 * @vport: pointer to a host virtual N_Port data structure.
1940 * @did: destination port identifier.
1941 * @retry: number of retries to the command IOCB.
1942 *
1943 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1944 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1945 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1946 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1947 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1948 *
1949 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1950 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1951 * will be stored into the context1 field of the IOCB for the completion
1952 * callback function to the PLOGI ELS command.
1953 *
1954 * Return code
1955 * 0 - Successfully issued a plogi for @vport
1956 * 1 - failed to issue a plogi for @vport
1957 **/
dea31012005-04-17 16:05:31 -05001958int
James Smart2e0fef82007-06-17 19:56:36 -05001959lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001960{
James Smart2e0fef82007-06-17 19:56:36 -05001961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001962 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04001963 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001964 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001965 uint8_t *pcmd;
1966 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001967 int ret;
dea31012005-04-17 16:05:31 -05001968
James Smart98c9ea52007-10-27 13:37:33 -04001969 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001970 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1971 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001972
James Smarte47c9092008-02-08 18:49:26 -05001973 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001974 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001975 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001976 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001977 if (!elsiocb)
1978 return 1;
dea31012005-04-17 16:05:31 -05001979
dea31012005-04-17 16:05:31 -05001980 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1981
1982 /* For PLOGI request, remainder of payload is service parameters */
1983 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001984 pcmd += sizeof(uint32_t);
1985 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001986 sp = (struct serv_parm *) pcmd;
1987
James Smart5ac6b302010-10-22 11:05:36 -04001988 /*
1989 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1990 * to device on remote loops work.
1991 */
1992 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1993 sp->cmn.altBbCredit = 1;
1994
dea31012005-04-17 16:05:31 -05001995 if (sp->cmn.fcphLow < FC_PH_4_3)
1996 sp->cmn.fcphLow = FC_PH_4_3;
1997
1998 if (sp->cmn.fcphHigh < FC_PH3)
1999 sp->cmn.fcphHigh = FC_PH3;
2000
James Smarte0165f22016-12-19 15:07:20 -08002001 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002002 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smarte0165f22016-12-19 15:07:20 -08002003
James Smart858c9f62007-06-17 19:56:39 -05002004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2005 "Issue PLOGI: did:x%x",
2006 did, 0, 0);
2007
James Smart8c258642017-02-12 13:52:36 -08002008 /* If our firmware supports this feature, convey that
2009 * information to the target using the vendor specific field.
2010 */
2011 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2012 sp->cmn.valid_vendor_ver_level = 1;
2013 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2014 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2015 }
2016
dea31012005-04-17 16:05:31 -05002017 phba->fc_stat.elsXmitPLOGI++;
2018 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002019 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002020
2021 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002022 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002023 return 1;
dea31012005-04-17 16:05:31 -05002024 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002025 return 0;
dea31012005-04-17 16:05:31 -05002026}
2027
James Smarte59058c2008-08-24 21:49:00 -04002028/**
James Smart3621a712009-04-06 18:47:14 -04002029 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002030 * @phba: pointer to lpfc hba data structure.
2031 * @cmdiocb: pointer to lpfc command iocb data structure.
2032 * @rspiocb: pointer to lpfc response iocb data structure.
2033 *
2034 * This routine is the completion callback function for a Process Login
2035 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2036 * status. If there is error status reported, PRLI retry shall be attempted
2037 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2038 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2039 * ndlp to mark the PRLI completion.
2040 **/
dea31012005-04-17 16:05:31 -05002041static void
James Smart2e0fef82007-06-17 19:56:36 -05002042lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2043 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002044{
James Smart2e0fef82007-06-17 19:56:36 -05002045 struct lpfc_vport *vport = cmdiocb->vport;
2046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002047 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002048 struct lpfc_nodelist *ndlp;
2049
dea31012005-04-17 16:05:31 -05002050 /* we pass cmdiocb to state machine which needs rspiocb as well */
2051 cmdiocb->context_un.rsp_iocb = rspiocb;
2052
2053 irsp = &(rspiocb->iocb);
2054 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002055 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002056 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002057 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002058
James Smart858c9f62007-06-17 19:56:39 -05002059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2060 "PRLI cmpl: status:x%x/x%x did:x%x",
2061 irsp->ulpStatus, irsp->un.ulpWord[4],
2062 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002063
2064 /* Ddriver supports multiple FC4 types. Counters matter. */
2065 vport->fc_prli_sent--;
2066
dea31012005-04-17 16:05:31 -05002067 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002069 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002070 "Data: x%x x%x x%x x%x\n",
2071 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002072 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002073
dea31012005-04-17 16:05:31 -05002074 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002075 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002076 goto out;
2077
2078 if (irsp->ulpStatus) {
2079 /* Check for retry */
2080 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2081 /* ELS command is being retried */
James Smarta0f2d3e2017-02-12 13:52:31 -08002082 ndlp->fc4_prli_sent--;
dea31012005-04-17 16:05:31 -05002083 goto out;
2084 }
2085 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2087 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2088 ndlp->nlp_DID, irsp->ulpStatus,
2089 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002090 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002091 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002092 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002093 else
James Smart2e0fef82007-06-17 19:56:36 -05002094 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002095 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002096 } else
James Smarta0f2d3e2017-02-12 13:52:31 -08002097 /* Good status, call state machine. However, if another
2098 * PRLI is outstanding, don't call the state machine
2099 * because final disposition to Mapped or Unmapped is
2100 * completed there.
2101 */
James Smart2e0fef82007-06-17 19:56:36 -05002102 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002103 NLP_EVT_CMPL_PRLI);
James Smarta0f2d3e2017-02-12 13:52:31 -08002104
dea31012005-04-17 16:05:31 -05002105out:
2106 lpfc_els_free_iocb(phba, cmdiocb);
2107 return;
2108}
2109
James Smarte59058c2008-08-24 21:49:00 -04002110/**
James Smart3621a712009-04-06 18:47:14 -04002111 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002112 * @vport: pointer to a host virtual N_Port data structure.
2113 * @ndlp: pointer to a node-list data structure.
2114 * @retry: number of retries to the command IOCB.
2115 *
2116 * This routine issues a Process Login (PRLI) ELS command for the
2117 * @vport. The PRLI service parameters are set up in the payload of the
2118 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2119 * is put to the IOCB completion callback func field before invoking the
2120 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2121 *
2122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2124 * will be stored into the context1 field of the IOCB for the completion
2125 * callback function to the PRLI ELS command.
2126 *
2127 * Return code
2128 * 0 - successfully issued prli iocb command for @vport
2129 * 1 - failed to issue prli iocb command for @vport
2130 **/
dea31012005-04-17 16:05:31 -05002131int
James Smart2e0fef82007-06-17 19:56:36 -05002132lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002133 uint8_t retry)
2134{
James Smart2e0fef82007-06-17 19:56:36 -05002135 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2136 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002137 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002138 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002139 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002140 uint8_t *pcmd;
2141 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002142 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002143
James Smarta0f2d3e2017-02-12 13:52:31 -08002144 local_nlp_type = ndlp->nlp_fc4_type;
2145
2146 send_next_prli:
2147 if (local_nlp_type & NLP_FC4_FCP) {
2148 /* Payload is 4 + 16 = 20 x14 bytes. */
2149 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2150 elscmd = ELS_CMD_PRLI;
2151 } else if (local_nlp_type & NLP_FC4_NVME) {
2152 /* Payload is 4 + 20 = 24 x18 bytes. */
2153 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2154 elscmd = ELS_CMD_NVMEPRLI;
2155 } else {
2156 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2157 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2158 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2159 return 1;
2160 }
James Smart2e0fef82007-06-17 19:56:36 -05002161 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002162 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002163 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002164 return 1;
dea31012005-04-17 16:05:31 -05002165
dea31012005-04-17 16:05:31 -05002166 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2167
2168 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002169 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002170
James Smarta0f2d3e2017-02-12 13:52:31 -08002171 if (local_nlp_type & NLP_FC4_FCP) {
2172 /* Remainder of payload is FCP PRLI parameter page.
2173 * Note: this data structure is defined as
2174 * BE/LE in the structure definition so no
2175 * byte swap call is made.
2176 */
2177 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2178 pcmd += sizeof(uint32_t);
2179 npr = (PRLI *)pcmd;
2180
2181 /*
2182 * If our firmware version is 3.20 or later,
2183 * set the following bits for FC-TAPE support.
2184 */
2185 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2186 npr->ConfmComplAllowed = 1;
2187 npr->Retry = 1;
2188 npr->TaskRetryIdReq = 1;
2189 }
2190 npr->estabImagePair = 1;
2191 npr->readXferRdyDis = 1;
2192 if (vport->cfg_first_burst_size)
2193 npr->writeXferRdyDis = 1;
2194
2195 /* For FCP support */
2196 npr->prliType = PRLI_FCP_TYPE;
2197 npr->initiatorFunc = 1;
2198 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2199
2200 /* Remove FCP type - processed. */
2201 local_nlp_type &= ~NLP_FC4_FCP;
2202 } else if (local_nlp_type & NLP_FC4_NVME) {
2203 /* Remainder of payload is NVME PRLI parameter page.
2204 * This data structure is the newer definition that
2205 * uses bf macros so a byte swap is required.
2206 */
2207 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2208 pcmd += sizeof(uint32_t);
2209 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2210 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2211 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2212
2213 /* Only initiators request first burst. */
2214 if ((phba->cfg_nvme_enable_fb) &&
2215 !phba->nvmet_support)
2216 bf_set(prli_fba, npr_nvme, 1);
2217
James Smart8c258642017-02-12 13:52:36 -08002218 if (phba->nvmet_support) {
2219 bf_set(prli_tgt, npr_nvme, 1);
2220 bf_set(prli_disc, npr_nvme, 1);
2221
2222 } else {
2223 bf_set(prli_init, npr_nvme, 1);
2224 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002225 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2226 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2227 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2228
2229 /* Remove NVME type - processed. */
2230 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002231 }
dea31012005-04-17 16:05:31 -05002232
James Smart858c9f62007-06-17 19:56:39 -05002233 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2234 "Issue PRLI: did:x%x",
2235 ndlp->nlp_DID, 0, 0);
2236
dea31012005-04-17 16:05:31 -05002237 phba->fc_stat.elsXmitPRLI++;
2238 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002239 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002240 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002241 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002242 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2243 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002244 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002245 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002246 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002247 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002248 return 1;
dea31012005-04-17 16:05:31 -05002249 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002250
2251 /* The vport counters are used for lpfc_scan_finished, but
2252 * the ndlp is used to track outstanding PRLIs for different
2253 * FC4 types.
2254 */
James Smart2e0fef82007-06-17 19:56:36 -05002255 vport->fc_prli_sent++;
James Smarta0f2d3e2017-02-12 13:52:31 -08002256 ndlp->fc4_prli_sent++;
2257
2258 /* The driver supports 2 FC4 types. Make sure
2259 * a PRLI is issued for all types before exiting.
2260 */
2261 if (local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2262 goto send_next_prli;
2263
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002264 return 0;
dea31012005-04-17 16:05:31 -05002265}
2266
James Smarte59058c2008-08-24 21:49:00 -04002267/**
James Smart3621a712009-04-06 18:47:14 -04002268 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002269 * @vport: pointer to a host virtual N_Port data structure.
2270 *
2271 * This routine performs Registration State Change Notification (RSCN)
2272 * discovery for a @vport. If the @vport's node port recovery count is not
2273 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2274 * the nodes that need recovery. If none of the PLOGI were needed through
2275 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2276 * invoked to check and handle possible more RSCN came in during the period
2277 * of processing the current ones.
2278 **/
2279static void
2280lpfc_rscn_disc(struct lpfc_vport *vport)
2281{
2282 lpfc_can_disctmo(vport);
2283
2284 /* RSCN discovery */
2285 /* go thru NPR nodes and issue ELS PLOGIs */
2286 if (vport->fc_npr_cnt)
2287 if (lpfc_els_disc_plogi(vport))
2288 return;
2289
2290 lpfc_end_rscn(vport);
2291}
2292
2293/**
James Smart3621a712009-04-06 18:47:14 -04002294 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002295 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2296 *
2297 * This function is called when the final ADISC is completed during discovery.
2298 * This function handles clearing link attention or issuing reg_vpi depending
2299 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2300 * discovery.
2301 * This function is called with no locks held.
2302 **/
2303static void
2304lpfc_adisc_done(struct lpfc_vport *vport)
2305{
2306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2307 struct lpfc_hba *phba = vport->phba;
2308
2309 /*
2310 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2311 * and continue discovery.
2312 */
2313 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002314 !(vport->fc_flag & FC_RSCN_MODE) &&
2315 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002316 /* The ADISCs are complete. Doesn't matter if they
2317 * succeeded or failed because the ADISC completion
2318 * routine guarantees to call the state machine and
2319 * the RPI is either unregistered (failed ADISC response)
2320 * or the RPI is still valid and the node is marked
2321 * mapped for a target. The exchanges should be in the
2322 * correct state. This code is specific to SLI3.
2323 */
2324 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002325 lpfc_issue_reg_vpi(phba, vport);
2326 return;
2327 }
2328 /*
2329 * For SLI2, we need to set port_state to READY
2330 * and continue discovery.
2331 */
2332 if (vport->port_state < LPFC_VPORT_READY) {
2333 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002334 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002335 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2336 vport->num_disc_nodes = 0;
2337 /* go thru NPR list, issue ELS PLOGIs */
2338 if (vport->fc_npr_cnt)
2339 lpfc_els_disc_plogi(vport);
2340 if (!vport->num_disc_nodes) {
2341 spin_lock_irq(shost->host_lock);
2342 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2343 spin_unlock_irq(shost->host_lock);
2344 lpfc_can_disctmo(vport);
2345 lpfc_end_rscn(vport);
2346 }
2347 }
2348 vport->port_state = LPFC_VPORT_READY;
2349 } else
2350 lpfc_rscn_disc(vport);
2351}
2352
2353/**
James Smart3621a712009-04-06 18:47:14 -04002354 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002355 * @vport: pointer to a host virtual N_Port data structure.
2356 *
2357 * This routine determines whether there are more ndlps on a @vport
2358 * node list need to have Address Discover (ADISC) issued. If so, it will
2359 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2360 * remaining nodes which need to have ADISC sent.
2361 **/
James Smart0ff10d42008-01-11 01:52:36 -05002362void
James Smart2e0fef82007-06-17 19:56:36 -05002363lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002364{
James Smart2e0fef82007-06-17 19:56:36 -05002365 if (vport->num_disc_nodes)
2366 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002367 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002368 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2369 "0210 Continue discovery with %d ADISCs to go "
2370 "Data: x%x x%x x%x\n",
2371 vport->num_disc_nodes, vport->fc_adisc_cnt,
2372 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002373 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002374 if (vport->fc_flag & FC_NLP_MORE) {
2375 lpfc_set_disctmo(vport);
2376 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002377 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002378 }
James Smart90160e02008-08-24 21:49:45 -04002379 if (!vport->num_disc_nodes)
2380 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002381 return;
2382}
2383
James Smarte59058c2008-08-24 21:49:00 -04002384/**
James Smart3621a712009-04-06 18:47:14 -04002385 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002386 * @phba: pointer to lpfc hba data structure.
2387 * @cmdiocb: pointer to lpfc command iocb data structure.
2388 * @rspiocb: pointer to lpfc response iocb data structure.
2389 *
2390 * This routine is the completion function for issuing the Address Discover
2391 * (ADISC) command. It first checks to see whether link went down during
2392 * the discovery process. If so, the node will be marked as node port
2393 * recovery for issuing discover IOCB by the link attention handler and
2394 * exit. Otherwise, the response status is checked. If error was reported
2395 * in the response status, the ADISC command shall be retried by invoking
2396 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2397 * the response status, the state machine is invoked to set transition
2398 * with respect to NLP_EVT_CMPL_ADISC event.
2399 **/
dea31012005-04-17 16:05:31 -05002400static void
James Smart2e0fef82007-06-17 19:56:36 -05002401lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2402 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002403{
James Smart2e0fef82007-06-17 19:56:36 -05002404 struct lpfc_vport *vport = cmdiocb->vport;
2405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002406 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002407 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002408 int disc;
dea31012005-04-17 16:05:31 -05002409
2410 /* we pass cmdiocb to state machine which needs rspiocb as well */
2411 cmdiocb->context_un.rsp_iocb = rspiocb;
2412
2413 irsp = &(rspiocb->iocb);
2414 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002415
James Smart858c9f62007-06-17 19:56:39 -05002416 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2417 "ADISC cmpl: status:x%x/x%x did:x%x",
2418 irsp->ulpStatus, irsp->un.ulpWord[4],
2419 ndlp->nlp_DID);
2420
dea31012005-04-17 16:05:31 -05002421 /* Since ndlp can be freed in the disc state machine, note if this node
2422 * is being used during discovery.
2423 */
James Smart2e0fef82007-06-17 19:56:36 -05002424 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002425 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002426 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002427 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002428 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2430 "0104 ADISC completes to NPort x%x "
2431 "Data: x%x x%x x%x x%x x%x\n",
2432 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2433 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002434 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002435 if (lpfc_els_chk_latt(vport)) {
2436 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002437 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002438 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002439 goto out;
2440 }
2441
2442 if (irsp->ulpStatus) {
2443 /* Check for retry */
2444 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2445 /* ELS command is being retried */
2446 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002447 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002448 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002449 spin_unlock_irq(shost->host_lock);
2450 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002451 }
2452 goto out;
2453 }
2454 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002455 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2456 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2457 ndlp->nlp_DID, irsp->ulpStatus,
2458 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002459 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002460 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002461 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002462 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002463 } else
dea31012005-04-17 16:05:31 -05002464 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002465 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002466 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002467
James Smart90160e02008-08-24 21:49:45 -04002468 /* Check to see if there are more ADISCs to be sent */
2469 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002470 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002471out:
2472 lpfc_els_free_iocb(phba, cmdiocb);
2473 return;
2474}
2475
James Smarte59058c2008-08-24 21:49:00 -04002476/**
James Smart3621a712009-04-06 18:47:14 -04002477 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002478 * @vport: pointer to a virtual N_Port data structure.
2479 * @ndlp: pointer to a node-list data structure.
2480 * @retry: number of retries to the command IOCB.
2481 *
2482 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2483 * @vport. It prepares the payload of the ADISC ELS command, updates the
2484 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2485 * to issue the ADISC ELS command.
2486 *
2487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2489 * will be stored into the context1 field of the IOCB for the completion
2490 * callback function to the ADISC ELS command.
2491 *
2492 * Return code
2493 * 0 - successfully issued adisc
2494 * 1 - failed to issue adisc
2495 **/
dea31012005-04-17 16:05:31 -05002496int
James Smart2e0fef82007-06-17 19:56:36 -05002497lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002498 uint8_t retry)
2499{
James Smart2e0fef82007-06-17 19:56:36 -05002500 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2501 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002502 ADISC *ap;
dea31012005-04-17 16:05:31 -05002503 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002504 uint8_t *pcmd;
2505 uint16_t cmdsize;
2506
James Smart92d7f7b2007-06-17 19:56:38 -05002507 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002508 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2509 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002510 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002511 return 1;
dea31012005-04-17 16:05:31 -05002512
dea31012005-04-17 16:05:31 -05002513 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2514
2515 /* For ADISC request, remainder of payload is service parameters */
2516 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002517 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002518
2519 /* Fill in ADISC payload */
2520 ap = (ADISC *) pcmd;
2521 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002522 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2523 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002524 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002525
James Smart858c9f62007-06-17 19:56:39 -05002526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2527 "Issue ADISC: did:x%x",
2528 ndlp->nlp_DID, 0, 0);
2529
dea31012005-04-17 16:05:31 -05002530 phba->fc_stat.elsXmitADISC++;
2531 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002532 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002533 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002534 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002535 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2536 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002537 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002538 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002539 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002540 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002541 return 1;
dea31012005-04-17 16:05:31 -05002542 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002543 return 0;
dea31012005-04-17 16:05:31 -05002544}
2545
James Smarte59058c2008-08-24 21:49:00 -04002546/**
James Smart3621a712009-04-06 18:47:14 -04002547 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002548 * @phba: pointer to lpfc hba data structure.
2549 * @cmdiocb: pointer to lpfc command iocb data structure.
2550 * @rspiocb: pointer to lpfc response iocb data structure.
2551 *
2552 * This routine is the completion function for issuing the ELS Logout (LOGO)
2553 * command. If no error status was reported from the LOGO response, the
2554 * state machine of the associated ndlp shall be invoked for transition with
2555 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2556 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2557 **/
dea31012005-04-17 16:05:31 -05002558static void
James Smart2e0fef82007-06-17 19:56:36 -05002559lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2560 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002561{
James Smart2e0fef82007-06-17 19:56:36 -05002562 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2563 struct lpfc_vport *vport = ndlp->vport;
2564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002565 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002566 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002567 unsigned long flags;
2568 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002569
dea31012005-04-17 16:05:31 -05002570 /* we pass cmdiocb to state machine which needs rspiocb as well */
2571 cmdiocb->context_un.rsp_iocb = rspiocb;
2572
2573 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002574 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002575 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002576 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002577
James Smart858c9f62007-06-17 19:56:39 -05002578 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2579 "LOGO cmpl: status:x%x/x%x did:x%x",
2580 irsp->ulpStatus, irsp->un.ulpWord[4],
2581 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002582
dea31012005-04-17 16:05:31 -05002583 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002584 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2585 "0105 LOGO completes to NPort x%x "
2586 "Data: x%x x%x x%x x%x\n",
2587 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2588 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002589
James Smart086a3452012-08-14 14:25:21 -04002590 if (lpfc_els_chk_latt(vport)) {
2591 skip_recovery = 1;
2592 goto out;
2593 }
2594
2595 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002596 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2597 /* NLP_EVT_DEVICE_RM should unregister the RPI
2598 * which should abort all outstanding IOs.
2599 */
2600 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2601 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002602 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002603 goto out;
2604 }
2605
dea31012005-04-17 16:05:31 -05002606 if (irsp->ulpStatus) {
2607 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002608 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002609 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002610 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002611 goto out;
James Smart086a3452012-08-14 14:25:21 -04002612 }
dea31012005-04-17 16:05:31 -05002613 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002614 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2615 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2616 ndlp->nlp_DID, irsp->ulpStatus,
2617 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002618 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002619 if (lpfc_error_lost_link(irsp)) {
2620 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002621 goto out;
James Smart086a3452012-08-14 14:25:21 -04002622 }
2623 }
2624
2625 /* Call state machine. This will unregister the rpi if needed. */
2626 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2627
dea31012005-04-17 16:05:31 -05002628out:
2629 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002630 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2631 if ((vport->fc_flag & FC_PT2PT) &&
2632 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2633 phba->pport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002634
James Smart01649562017-02-12 13:52:32 -08002635 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -08002636 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08002637 if (phba->nvmet_support)
2638 lpfc_nvmet_update_targetport(phba);
2639 else
James Smart8c258642017-02-12 13:52:36 -08002640 lpfc_nvme_update_localport(phba->pport);
James Smart8c258642017-02-12 13:52:36 -08002641 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002642
James Smart92494142011-02-16 12:39:44 -05002643 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2644 if (mbox) {
2645 lpfc_config_link(phba, mbox);
2646 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2647 mbox->vport = vport;
2648 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2649 MBX_NOT_FINISHED) {
2650 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002651 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002652 }
2653 }
2654 }
James Smart086a3452012-08-14 14:25:21 -04002655
2656 /*
2657 * If the node is a target, the handling attempts to recover the port.
2658 * For any other port type, the rpi is unregistered as an implicit
2659 * LOGO.
2660 */
2661 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2662 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2663 spin_lock_irqsave(shost->host_lock, flags);
2664 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2665 spin_unlock_irqrestore(shost->host_lock, flags);
2666
2667 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2668 "3187 LOGO completes to NPort x%x: Start "
2669 "Recovery Data: x%x x%x x%x x%x\n",
2670 ndlp->nlp_DID, irsp->ulpStatus,
2671 irsp->un.ulpWord[4], irsp->ulpTimeout,
2672 vport->num_disc_nodes);
2673 lpfc_disc_start(vport);
2674 }
dea31012005-04-17 16:05:31 -05002675 return;
2676}
2677
James Smarte59058c2008-08-24 21:49:00 -04002678/**
James Smart3621a712009-04-06 18:47:14 -04002679 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002680 * @vport: pointer to a virtual N_Port data structure.
2681 * @ndlp: pointer to a node-list data structure.
2682 * @retry: number of retries to the command IOCB.
2683 *
2684 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2685 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2686 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2687 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2688 *
2689 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2690 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2691 * will be stored into the context1 field of the IOCB for the completion
2692 * callback function to the LOGO ELS command.
2693 *
2694 * Return code
2695 * 0 - successfully issued logo
2696 * 1 - failed to issue logo
2697 **/
dea31012005-04-17 16:05:31 -05002698int
James Smart2e0fef82007-06-17 19:56:36 -05002699lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002700 uint8_t retry)
2701{
James Smart2e0fef82007-06-17 19:56:36 -05002702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2703 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002704 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002705 uint8_t *pcmd;
2706 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002707 int rc;
dea31012005-04-17 16:05:31 -05002708
James Smart98c9ea52007-10-27 13:37:33 -04002709 spin_lock_irq(shost->host_lock);
2710 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2711 spin_unlock_irq(shost->host_lock);
2712 return 0;
2713 }
2714 spin_unlock_irq(shost->host_lock);
2715
James Smart92d7f7b2007-06-17 19:56:38 -05002716 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002717 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2718 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002719 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002720 return 1;
dea31012005-04-17 16:05:31 -05002721
dea31012005-04-17 16:05:31 -05002722 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2723 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002724 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002725
2726 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002727 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002728 pcmd += sizeof(uint32_t);
2729 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002730
James Smart858c9f62007-06-17 19:56:39 -05002731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2732 "Issue LOGO: did:x%x",
2733 ndlp->nlp_DID, 0, 0);
2734
James Smart086a3452012-08-14 14:25:21 -04002735 /*
2736 * If we are issuing a LOGO, we may try to recover the remote NPort
2737 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2738 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2739 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2740 * for that ELS cmd. To avoid this situation, lets get rid of the
2741 * RPI right now, before any ELS cmds are sent.
2742 */
2743 spin_lock_irq(shost->host_lock);
2744 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2745 spin_unlock_irq(shost->host_lock);
2746 if (lpfc_unreg_rpi(vport, ndlp)) {
2747 lpfc_els_free_iocb(phba, elsiocb);
2748 return 0;
2749 }
2750
dea31012005-04-17 16:05:31 -05002751 phba->fc_stat.elsXmitLOGO++;
2752 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002753 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002754 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002755 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002756 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002757 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002758
2759 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002760 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002761 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002762 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002763 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002764 return 1;
dea31012005-04-17 16:05:31 -05002765 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002766 return 0;
dea31012005-04-17 16:05:31 -05002767}
2768
James Smarte59058c2008-08-24 21:49:00 -04002769/**
James Smart3621a712009-04-06 18:47:14 -04002770 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002771 * @phba: pointer to lpfc hba data structure.
2772 * @cmdiocb: pointer to lpfc command iocb data structure.
2773 * @rspiocb: pointer to lpfc response iocb data structure.
2774 *
2775 * This routine is a generic completion callback function for ELS commands.
2776 * Specifically, it is the callback function which does not need to perform
2777 * any command specific operations. It is currently used by the ELS command
2778 * issuing routines for the ELS State Change Request (SCR),
2779 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2780 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2781 * certain debug loggings, this callback function simply invokes the
2782 * lpfc_els_chk_latt() routine to check whether link went down during the
2783 * discovery process.
2784 **/
dea31012005-04-17 16:05:31 -05002785static void
James Smart2e0fef82007-06-17 19:56:36 -05002786lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2787 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002788{
James Smart2e0fef82007-06-17 19:56:36 -05002789 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002790 IOCB_t *irsp;
2791
2792 irsp = &rspiocb->iocb;
2793
James Smart858c9f62007-06-17 19:56:39 -05002794 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2795 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2796 irsp->ulpStatus, irsp->un.ulpWord[4],
2797 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002798 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002799 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2800 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2801 irsp->ulpIoTag, irsp->ulpStatus,
2802 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002803 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002804 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002805 lpfc_els_free_iocb(phba, cmdiocb);
2806 return;
2807}
2808
James Smarte59058c2008-08-24 21:49:00 -04002809/**
James Smart3621a712009-04-06 18:47:14 -04002810 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002811 * @vport: pointer to a host virtual N_Port data structure.
2812 * @nportid: N_Port identifier to the remote node.
2813 * @retry: number of retries to the command IOCB.
2814 *
2815 * This routine issues a State Change Request (SCR) to a fabric node
2816 * on a @vport. The remote node @nportid is passed into the function. It
2817 * first search the @vport node list to find the matching ndlp. If no such
2818 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2819 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2820 * routine is invoked to send the SCR IOCB.
2821 *
2822 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2823 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2824 * will be stored into the context1 field of the IOCB for the completion
2825 * callback function to the SCR ELS command.
2826 *
2827 * Return code
2828 * 0 - Successfully issued scr command
2829 * 1 - Failed to issue scr command
2830 **/
dea31012005-04-17 16:05:31 -05002831int
James Smart2e0fef82007-06-17 19:56:36 -05002832lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002833{
James Smart2e0fef82007-06-17 19:56:36 -05002834 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002835 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002836 uint8_t *pcmd;
2837 uint16_t cmdsize;
2838 struct lpfc_nodelist *ndlp;
2839
James Smart92d7f7b2007-06-17 19:56:38 -05002840 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002841
James Smarte47c9092008-02-08 18:49:26 -05002842 ndlp = lpfc_findnode_did(vport, nportid);
2843 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07002844 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002845 if (!ndlp)
2846 return 1;
James Smarte47c9092008-02-08 18:49:26 -05002847 lpfc_enqueue_node(vport, ndlp);
2848 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2849 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2850 if (!ndlp)
2851 return 1;
2852 }
dea31012005-04-17 16:05:31 -05002853
James Smart2e0fef82007-06-17 19:56:36 -05002854 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2855 ndlp->nlp_DID, ELS_CMD_SCR);
2856
James Smart488d1462006-03-07 15:02:37 -05002857 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002858 /* This will trigger the release of the node just
2859 * allocated
2860 */
James Smart329f9bc2007-04-25 09:53:01 -04002861 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002862 return 1;
dea31012005-04-17 16:05:31 -05002863 }
2864
dea31012005-04-17 16:05:31 -05002865 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2866
2867 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002868 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002869
2870 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002871 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002872 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2873
James Smart858c9f62007-06-17 19:56:39 -05002874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2875 "Issue SCR: did:x%x",
2876 ndlp->nlp_DID, 0, 0);
2877
dea31012005-04-17 16:05:31 -05002878 phba->fc_stat.elsXmitSCR++;
2879 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002880 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2881 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002882 /* The additional lpfc_nlp_put will cause the following
2883 * lpfc_els_free_iocb routine to trigger the rlease of
2884 * the node.
2885 */
James Smart329f9bc2007-04-25 09:53:01 -04002886 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002887 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002888 return 1;
dea31012005-04-17 16:05:31 -05002889 }
James Smartfa4066b2008-01-11 01:53:27 -05002890 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2891 * trigger the release of node.
2892 */
James Smartcff261f2013-12-17 20:29:47 -05002893
James Smart329f9bc2007-04-25 09:53:01 -04002894 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002895 return 0;
dea31012005-04-17 16:05:31 -05002896}
2897
James Smarte59058c2008-08-24 21:49:00 -04002898/**
James Smart3621a712009-04-06 18:47:14 -04002899 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002900 * @vport: pointer to a host virtual N_Port data structure.
2901 * @nportid: N_Port identifier to the remote node.
2902 * @retry: number of retries to the command IOCB.
2903 *
2904 * This routine issues a Fibre Channel Address Resolution Response
2905 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2906 * is passed into the function. It first search the @vport node list to find
2907 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2908 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2909 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2910 *
2911 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2912 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2913 * will be stored into the context1 field of the IOCB for the completion
2914 * callback function to the PARPR ELS command.
2915 *
2916 * Return code
2917 * 0 - Successfully issued farpr command
2918 * 1 - Failed to issue farpr command
2919 **/
dea31012005-04-17 16:05:31 -05002920static int
James Smart2e0fef82007-06-17 19:56:36 -05002921lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002922{
James Smart2e0fef82007-06-17 19:56:36 -05002923 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002924 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002925 FARP *fp;
2926 uint8_t *pcmd;
2927 uint32_t *lp;
2928 uint16_t cmdsize;
2929 struct lpfc_nodelist *ondlp;
2930 struct lpfc_nodelist *ndlp;
2931
James Smart92d7f7b2007-06-17 19:56:38 -05002932 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002933
James Smarte47c9092008-02-08 18:49:26 -05002934 ndlp = lpfc_findnode_did(vport, nportid);
2935 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07002936 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002937 if (!ndlp)
2938 return 1;
James Smarte47c9092008-02-08 18:49:26 -05002939 lpfc_enqueue_node(vport, ndlp);
2940 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2941 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2942 if (!ndlp)
2943 return 1;
2944 }
James Smart2e0fef82007-06-17 19:56:36 -05002945
2946 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2947 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002948 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002949 /* This will trigger the release of the node just
2950 * allocated
2951 */
James Smart329f9bc2007-04-25 09:53:01 -04002952 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002953 return 1;
dea31012005-04-17 16:05:31 -05002954 }
2955
dea31012005-04-17 16:05:31 -05002956 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2957
2958 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002959 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002960
2961 /* Fill in FARPR payload */
2962 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002963 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002964 lp = (uint32_t *) pcmd;
2965 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002966 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002967 fp->Rflags = 0;
2968 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2969
James Smart92d7f7b2007-06-17 19:56:38 -05002970 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2971 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002972 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002973 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002974 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002975 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002976 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002977 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002978 }
2979
James Smart858c9f62007-06-17 19:56:39 -05002980 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2981 "Issue FARPR: did:x%x",
2982 ndlp->nlp_DID, 0, 0);
2983
dea31012005-04-17 16:05:31 -05002984 phba->fc_stat.elsXmitFARPR++;
2985 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002986 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2987 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002988 /* The additional lpfc_nlp_put will cause the following
2989 * lpfc_els_free_iocb routine to trigger the release of
2990 * the node.
2991 */
James Smart329f9bc2007-04-25 09:53:01 -04002992 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002993 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002994 return 1;
dea31012005-04-17 16:05:31 -05002995 }
James Smartfa4066b2008-01-11 01:53:27 -05002996 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2997 * trigger the release of the node.
2998 */
James Smart329f9bc2007-04-25 09:53:01 -04002999 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003000 return 0;
dea31012005-04-17 16:05:31 -05003001}
3002
James Smarte59058c2008-08-24 21:49:00 -04003003/**
James Smart3621a712009-04-06 18:47:14 -04003004 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04003005 * @vport: pointer to a host virtual N_Port data structure.
3006 * @nlp: pointer to a node-list data structure.
3007 *
3008 * This routine cancels the timer with a delayed IOCB-command retry for
3009 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3010 * removes the ELS retry event if it presents. In addition, if the
3011 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3012 * commands are sent for the @vport's nodes that require issuing discovery
3013 * ADISC.
3014 **/
dea31012005-04-17 16:05:31 -05003015void
James Smart2e0fef82007-06-17 19:56:36 -05003016lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05003017{
James Smart2e0fef82007-06-17 19:56:36 -05003018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05003019 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05003020
James Smart0d2b6b82008-06-14 22:52:47 -04003021 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3022 return;
James Smart2e0fef82007-06-17 19:56:36 -05003023 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003024 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003025 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003026 del_timer_sync(&nlp->nlp_delayfunc);
3027 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05003028 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05003029 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05003030 /* Decrement nlp reference count held for the delayed retry */
3031 evtp = &nlp->els_retry_evt;
3032 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3033 }
James Smartfdcebe22006-03-07 15:04:01 -05003034 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05003035 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003036 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05003037 spin_unlock_irq(shost->host_lock);
3038 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04003039 if (vport->port_state < LPFC_VPORT_READY) {
3040 /* Check if there are more ADISCs to be sent */
3041 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003042 } else {
3043 /* Check if there are more PLOGIs to be sent */
3044 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04003045 if (vport->num_disc_nodes == 0) {
3046 spin_lock_irq(shost->host_lock);
3047 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3048 spin_unlock_irq(shost->host_lock);
3049 lpfc_can_disctmo(vport);
3050 lpfc_end_rscn(vport);
3051 }
James Smartfdcebe22006-03-07 15:04:01 -05003052 }
3053 }
3054 }
3055 return;
3056}
3057
James Smarte59058c2008-08-24 21:49:00 -04003058/**
James Smart3621a712009-04-06 18:47:14 -04003059 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04003060 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3061 *
3062 * This routine is invoked by the ndlp delayed-function timer to check
3063 * whether there is any pending ELS retry event(s) with the node. If not, it
3064 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3065 * adds the delayed events to the HBA work list and invokes the
3066 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3067 * event. Note that lpfc_nlp_get() is called before posting the event to
3068 * the work list to hold reference count of ndlp so that it guarantees the
3069 * reference to ndlp will still be available when the worker thread gets
3070 * to the event associated with the ndlp.
3071 **/
James Smartfdcebe22006-03-07 15:04:01 -05003072void
dea31012005-04-17 16:05:31 -05003073lpfc_els_retry_delay(unsigned long ptr)
3074{
James Smart2e0fef82007-06-17 19:56:36 -05003075 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
3076 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003077 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05003078 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05003079 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003080
James Smart92d7f7b2007-06-17 19:56:38 -05003081 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003082 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003083 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003084 return;
3085 }
3086
James Smartfa4066b2008-01-11 01:53:27 -05003087 /* We need to hold the node by incrementing the reference
3088 * count until the queued work is done
3089 */
3090 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003091 if (evtp->evt_arg1) {
3092 evtp->evt = LPFC_EVT_ELS_RETRY;
3093 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003094 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003095 }
James Smart92d7f7b2007-06-17 19:56:38 -05003096 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003097 return;
3098}
3099
James Smarte59058c2008-08-24 21:49:00 -04003100/**
James Smart3621a712009-04-06 18:47:14 -04003101 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003102 * @ndlp: pointer to a node-list data structure.
3103 *
3104 * This routine is the worker-thread handler for processing the @ndlp delayed
3105 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3106 * the last ELS command from the associated ndlp and invokes the proper ELS
3107 * function according to the delayed ELS command to retry the command.
3108 **/
dea31012005-04-17 16:05:31 -05003109void
3110lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3111{
James Smart2e0fef82007-06-17 19:56:36 -05003112 struct lpfc_vport *vport = ndlp->vport;
3113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003114 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003115
James Smart2e0fef82007-06-17 19:56:36 -05003116 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003117 cmd = ndlp->nlp_last_elscmd;
3118 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003119
3120 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003121 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003122 return;
3123 }
3124
3125 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003126 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003127 /*
3128 * If a discovery event readded nlp_delayfunc after timer
3129 * firing and before processing the timer, cancel the
3130 * nlp_delayfunc.
3131 */
3132 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003133 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003134 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003135
3136 switch (cmd) {
3137 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003138 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003139 break;
3140 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003141 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003142 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003144 }
dea31012005-04-17 16:05:31 -05003145 break;
3146 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003147 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003148 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003149 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003150 }
dea31012005-04-17 16:05:31 -05003151 break;
3152 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003153 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003154 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003155 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003157 }
dea31012005-04-17 16:05:31 -05003158 break;
3159 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003160 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003161 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003163 }
dea31012005-04-17 16:05:31 -05003164 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003165 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003166 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3167 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003168 break;
dea31012005-04-17 16:05:31 -05003169 }
3170 return;
3171}
3172
James Smarte59058c2008-08-24 21:49:00 -04003173/**
James Smart3621a712009-04-06 18:47:14 -04003174 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003175 * @phba: pointer to lpfc hba data structure.
3176 * @cmdiocb: pointer to lpfc command iocb data structure.
3177 * @rspiocb: pointer to lpfc response iocb data structure.
3178 *
3179 * This routine makes a retry decision on an ELS command IOCB, which has
3180 * failed. The following ELS IOCBs use this function for retrying the command
3181 * when previously issued command responsed with error status: FLOGI, PLOGI,
3182 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3183 * returned error status, it makes the decision whether a retry shall be
3184 * issued for the command, and whether a retry shall be made immediately or
3185 * delayed. In the former case, the corresponding ELS command issuing-function
3186 * is called to retry the command. In the later case, the ELS command shall
3187 * be posted to the ndlp delayed event and delayed function timer set to the
3188 * ndlp for the delayed command issusing.
3189 *
3190 * Return code
3191 * 0 - No retry of els command is made
3192 * 1 - Immediate or delayed retry of els command is made
3193 **/
dea31012005-04-17 16:05:31 -05003194static int
James Smart2e0fef82007-06-17 19:56:36 -05003195lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3196 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003197{
James Smart2e0fef82007-06-17 19:56:36 -05003198 struct lpfc_vport *vport = cmdiocb->vport;
3199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3200 IOCB_t *irsp = &rspiocb->iocb;
3201 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3202 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003203 uint32_t *elscmd;
3204 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003205 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003206 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003207 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003208 uint32_t did;
dea31012005-04-17 16:05:31 -05003209
James Smart488d1462006-03-07 15:02:37 -05003210
dea31012005-04-17 16:05:31 -05003211 /* Note: context2 may be 0 for internal driver abort
3212 * of delays ELS command.
3213 */
3214
3215 if (pcmd && pcmd->virt) {
3216 elscmd = (uint32_t *) (pcmd->virt);
3217 cmd = *elscmd++;
3218 }
3219
James Smarte47c9092008-02-08 18:49:26 -05003220 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003221 did = ndlp->nlp_DID;
3222 else {
3223 /* We should only hit this case for retrying PLOGI */
3224 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003225 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003226 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3227 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003228 return 1;
3229 }
3230
James Smart858c9f62007-06-17 19:56:39 -05003231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3232 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3233 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3234
dea31012005-04-17 16:05:31 -05003235 switch (irsp->ulpStatus) {
3236 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003237 break;
James Smart1151e3e2011-02-16 12:39:35 -05003238 case IOSTAT_REMOTE_STOP:
3239 if (phba->sli_rev == LPFC_SLI_REV4) {
3240 /* This IO was aborted by the target, we don't
3241 * know the rxid and because we did not send the
3242 * ABTS we cannot generate and RRQ.
3243 */
3244 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003245 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003246 }
3247 break;
dea31012005-04-17 16:05:31 -05003248 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003249 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003250 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003251 if (cmd == ELS_CMD_FLOGI) {
3252 if (PCI_DEVICE_ID_HORNET ==
3253 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003254 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003255 phba->pport->fc_myDID = 0;
3256 phba->alpa_map[0] = 0;
3257 phba->alpa_map[1] = 0;
3258 }
3259 }
James Smart2e0fef82007-06-17 19:56:36 -05003260 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003261 delay = 1000;
dea31012005-04-17 16:05:31 -05003262 retry = 1;
3263 break;
3264
James Smart92d7f7b2007-06-17 19:56:38 -05003265 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003266 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3267 "0124 Retry illegal cmd x%x "
3268 "retry:x%x delay:x%x\n",
3269 cmd, cmdiocb->retry, delay);
3270 retry = 1;
3271 /* All command's retry policy */
3272 maxretry = 8;
3273 if (cmdiocb->retry > 2)
3274 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003275 break;
3276
dea31012005-04-17 16:05:31 -05003277 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003278 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003279 retry = 1;
3280 if (cmdiocb->retry > 100)
3281 delay = 100;
3282 maxretry = 250;
3283 break;
3284
3285 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003286 delay = 100;
dea31012005-04-17 16:05:31 -05003287 retry = 1;
3288 break;
3289
James Smart858c9f62007-06-17 19:56:39 -05003290 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003291 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003292 if (cmd == ELS_CMD_PLOGI &&
3293 did == NameServer_DID) {
3294 /* Continue forever if plogi to */
3295 /* the nameserver fails */
3296 maxretry = 0;
3297 delay = 100;
3298 }
dea31012005-04-17 16:05:31 -05003299 retry = 1;
3300 break;
3301 }
3302 break;
3303
3304 case IOSTAT_NPORT_RJT:
3305 case IOSTAT_FABRIC_RJT:
3306 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3307 retry = 1;
3308 break;
3309 }
3310 break;
3311
3312 case IOSTAT_NPORT_BSY:
3313 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003314 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003315 retry = 1;
3316 break;
3317
3318 case IOSTAT_LS_RJT:
3319 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3320 /* Added for Vendor specifc support
3321 * Just keep retrying for these Rsn / Exp codes
3322 */
3323 switch (stat.un.b.lsRjtRsnCode) {
3324 case LSRJT_UNABLE_TPC:
3325 if (stat.un.b.lsRjtRsnCodeExp ==
3326 LSEXP_CMD_IN_PROGRESS) {
3327 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003328 delay = 1000;
dea31012005-04-17 16:05:31 -05003329 maxretry = 48;
3330 }
3331 retry = 1;
3332 break;
3333 }
James Smartffc95492010-06-07 15:23:17 -04003334 if (stat.un.b.lsRjtRsnCodeExp ==
3335 LSEXP_CANT_GIVE_DATA) {
3336 if (cmd == ELS_CMD_PLOGI) {
3337 delay = 1000;
3338 maxretry = 48;
3339 }
3340 retry = 1;
3341 break;
3342 }
James Smart4c1b64b2012-09-29 11:31:11 -04003343 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08003344 (cmd == ELS_CMD_PRLI) ||
3345 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003346 delay = 1000;
dea31012005-04-17 16:05:31 -05003347 maxretry = lpfc_max_els_tries + 1;
3348 retry = 1;
3349 break;
3350 }
James Smart92d7f7b2007-06-17 19:56:38 -05003351 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3352 (cmd == ELS_CMD_FDISC) &&
3353 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003354 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3355 "0125 FDISC Failed (x%x). "
3356 "Fabric out of resources\n",
3357 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003358 lpfc_vport_set_state(vport,
3359 FC_VPORT_NO_FABRIC_RSCS);
3360 }
dea31012005-04-17 16:05:31 -05003361 break;
3362
3363 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003364 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08003365 (cmd == ELS_CMD_PRLI) ||
3366 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003367 delay = 1000;
dea31012005-04-17 16:05:31 -05003368 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003369 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003370 /* FDISC retry policy */
3371 maxretry = 48;
3372 if (cmdiocb->retry >= 32)
3373 delay = 1000;
dea31012005-04-17 16:05:31 -05003374 }
3375 retry = 1;
3376 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003377
3378 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003379 /* There are some cases where switches return this
3380 * error when they are not ready and should be returning
3381 * Logical Busy. We should delay every time.
3382 */
3383 if (cmd == ELS_CMD_FDISC &&
3384 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3385 maxretry = 3;
3386 delay = 1000;
3387 retry = 1;
3388 break;
3389 }
James Smart92d7f7b2007-06-17 19:56:38 -05003390 case LSRJT_PROTOCOL_ERR:
3391 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3392 (cmd == ELS_CMD_FDISC) &&
3393 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3394 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3395 ) {
James Smarte8b62012007-08-02 11:10:09 -04003396 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003397 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003398 "Fabric Detected Bad WWN\n",
3399 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003400 lpfc_vport_set_state(vport,
3401 FC_VPORT_FABRIC_REJ_WWN);
3402 }
3403 break;
James Smart7bdedb32016-07-06 12:36:00 -07003404 case LSRJT_VENDOR_UNIQUE:
3405 if ((stat.un.b.vendorUnique == 0x45) &&
3406 (cmd == ELS_CMD_FLOGI)) {
3407 goto out_retry;
3408 }
3409 break;
dea31012005-04-17 16:05:31 -05003410 }
3411 break;
3412
3413 case IOSTAT_INTERMED_RSP:
3414 case IOSTAT_BA_RJT:
3415 break;
3416
3417 default:
3418 break;
3419 }
3420
James Smart488d1462006-03-07 15:02:37 -05003421 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003422 retry = 1;
dea31012005-04-17 16:05:31 -05003423
James Smartdf9e1b52011-12-13 13:22:17 -05003424 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003425 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003426 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003427 /* FLOGI retry policy */
3428 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003429 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003430 if (phba->link_flag != LS_LOOPBACK_MODE)
3431 maxretry = 0;
3432 else
3433 maxretry = 2;
3434
James Smart6669f9b2009-10-02 15:16:45 -04003435 if (cmdiocb->retry >= 100)
3436 delay = 5000;
3437 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003438 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003439 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3440 /* retry FDISCs every second up to devloss */
3441 retry = 1;
3442 maxretry = vport->cfg_devloss_tmo;
3443 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003444 }
3445
James Smart6669f9b2009-10-02 15:16:45 -04003446 cmdiocb->retry++;
3447 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003448 phba->fc_stat.elsRetryExceeded++;
3449 retry = 0;
3450 }
3451
James Smarted957682007-06-17 19:56:37 -05003452 if ((vport->load_flag & FC_UNLOADING) != 0)
3453 retry = 0;
3454
James Smart7bdedb32016-07-06 12:36:00 -07003455out_retry:
dea31012005-04-17 16:05:31 -05003456 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003457 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3458 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3459 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3461 "2849 Stop retry ELS command "
3462 "x%x to remote NPORT x%x, "
3463 "Data: x%x x%x\n", cmd, did,
3464 cmdiocb->retry, delay);
3465 return 0;
3466 }
3467 }
dea31012005-04-17 16:05:31 -05003468
3469 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003470 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3471 "0107 Retry ELS command x%x to remote "
3472 "NPORT x%x Data: x%x x%x\n",
3473 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003474
James Smart858c9f62007-06-17 19:56:39 -05003475 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3476 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003477 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3478 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003479 /* Don't reset timer for no resources */
3480
dea31012005-04-17 16:05:31 -05003481 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003482 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003483 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003484 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003485 }
3486
3487 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003488 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003489 phba->fc_stat.elsDelayRetry++;
3490 ndlp->nlp_retry = cmdiocb->retry;
3491
James Smart92d7f7b2007-06-17 19:56:38 -05003492 /* delay is specified in milliseconds */
3493 mod_timer(&ndlp->nlp_delayfunc,
3494 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003495 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003496 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003497 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003498
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003499 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smarta0f2d3e2017-02-12 13:52:31 -08003500 if ((cmd == ELS_CMD_PRLI) ||
3501 (cmd == ELS_CMD_NVMEPRLI))
James Smart858c9f62007-06-17 19:56:39 -05003502 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003503 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003504 else
3505 lpfc_nlp_set_state(vport, ndlp,
3506 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003507 ndlp->nlp_last_elscmd = cmd;
3508
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003509 return 1;
dea31012005-04-17 16:05:31 -05003510 }
3511 switch (cmd) {
3512 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003513 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003514 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003515 case ELS_CMD_FDISC:
3516 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3517 return 1;
dea31012005-04-17 16:05:31 -05003518 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003519 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003520 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003521 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003522 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003523 }
James Smart2e0fef82007-06-17 19:56:36 -05003524 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003525 return 1;
dea31012005-04-17 16:05:31 -05003526 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003527 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003528 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3529 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003530 return 1;
dea31012005-04-17 16:05:31 -05003531 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003532 case ELS_CMD_NVMEPRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003533 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003534 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3535 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003536 return 1;
dea31012005-04-17 16:05:31 -05003537 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003538 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003540 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003541 return 1;
dea31012005-04-17 16:05:31 -05003542 }
3543 }
dea31012005-04-17 16:05:31 -05003544 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003545 if (logerr) {
3546 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3547 "0137 No retry ELS command x%x to remote "
3548 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3549 cmd, did, irsp->ulpStatus,
3550 irsp->un.ulpWord[4]);
3551 }
3552 else {
3553 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003554 "0108 No retry ELS command x%x to remote "
3555 "NPORT x%x Retried:%d Error:x%x/%x\n",
3556 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3557 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003558 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003559 return 0;
dea31012005-04-17 16:05:31 -05003560}
3561
James Smarte59058c2008-08-24 21:49:00 -04003562/**
James Smart3621a712009-04-06 18:47:14 -04003563 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003564 * @phba: pointer to lpfc hba data structure.
3565 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3566 *
3567 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3568 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3569 * checks to see whether there is a lpfc DMA buffer associated with the
3570 * response of the command IOCB. If so, it will be released before releasing
3571 * the lpfc DMA buffer associated with the IOCB itself.
3572 *
3573 * Return code
3574 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3575 **/
James Smart09372822008-01-11 01:52:54 -05003576static int
James Smart87af33f2007-10-27 13:37:43 -04003577lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3578{
3579 struct lpfc_dmabuf *buf_ptr;
3580
James Smarte59058c2008-08-24 21:49:00 -04003581 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003582 if (!list_empty(&buf_ptr1->list)) {
3583 list_remove_head(&buf_ptr1->list, buf_ptr,
3584 struct lpfc_dmabuf,
3585 list);
3586 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3587 kfree(buf_ptr);
3588 }
3589 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3590 kfree(buf_ptr1);
3591 return 0;
3592}
3593
James Smarte59058c2008-08-24 21:49:00 -04003594/**
James Smart3621a712009-04-06 18:47:14 -04003595 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003596 * @phba: pointer to lpfc hba data structure.
3597 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3598 *
3599 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3600 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3601 * pool.
3602 *
3603 * Return code
3604 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3605 **/
James Smart09372822008-01-11 01:52:54 -05003606static int
James Smart87af33f2007-10-27 13:37:43 -04003607lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3608{
3609 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3610 kfree(buf_ptr);
3611 return 0;
3612}
3613
James Smarte59058c2008-08-24 21:49:00 -04003614/**
James Smart3621a712009-04-06 18:47:14 -04003615 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003616 * @phba: pointer to lpfc hba data structure.
3617 * @elsiocb: pointer to lpfc els command iocb data structure.
3618 *
3619 * This routine frees a command IOCB and its associated resources. The
3620 * command IOCB data structure contains the reference to various associated
3621 * resources, these fields must be set to NULL if the associated reference
3622 * not present:
3623 * context1 - reference to ndlp
3624 * context2 - reference to cmd
3625 * context2->next - reference to rsp
3626 * context3 - reference to bpl
3627 *
3628 * It first properly decrements the reference count held on ndlp for the
3629 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3630 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3631 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3632 * adds the DMA buffer the @phba data structure for the delayed release.
3633 * If reference to the Buffer Pointer List (BPL) is present, the
3634 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3635 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3636 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3637 *
3638 * Return code
3639 * 0 - Success (currently, always return 0)
3640 **/
James Smart87af33f2007-10-27 13:37:43 -04003641int
James Smart329f9bc2007-04-25 09:53:01 -04003642lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003643{
3644 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003645 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003646
James Smarta8adb832007-10-27 13:37:53 -04003647 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3648 if (ndlp) {
3649 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3650 lpfc_nlp_put(ndlp);
3651
3652 /* If the ndlp is not being used by another discovery
3653 * thread, free it.
3654 */
3655 if (!lpfc_nlp_not_used(ndlp)) {
3656 /* If ndlp is being used by another discovery
3657 * thread, just clear NLP_DEFER_RM
3658 */
3659 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3660 }
3661 }
3662 else
3663 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003664 elsiocb->context1 = NULL;
3665 }
dea31012005-04-17 16:05:31 -05003666 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3667 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003668 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3669 /* Firmware could still be in progress of DMAing
3670 * payload, so don't free data buffer till after
3671 * a hbeat.
3672 */
3673 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3674 buf_ptr = elsiocb->context2;
3675 elsiocb->context2 = NULL;
3676 if (buf_ptr) {
3677 buf_ptr1 = NULL;
3678 spin_lock_irq(&phba->hbalock);
3679 if (!list_empty(&buf_ptr->list)) {
3680 list_remove_head(&buf_ptr->list,
3681 buf_ptr1, struct lpfc_dmabuf,
3682 list);
3683 INIT_LIST_HEAD(&buf_ptr1->list);
3684 list_add_tail(&buf_ptr1->list,
3685 &phba->elsbuf);
3686 phba->elsbuf_cnt++;
3687 }
3688 INIT_LIST_HEAD(&buf_ptr->list);
3689 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3690 phba->elsbuf_cnt++;
3691 spin_unlock_irq(&phba->hbalock);
3692 }
3693 } else {
3694 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3695 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01003696 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05003697 }
dea31012005-04-17 16:05:31 -05003698 }
3699
3700 if (elsiocb->context3) {
3701 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003702 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01003703 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05003704 }
James Bottomley604a3e32005-10-29 10:28:33 -05003705 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003706 return 0;
3707}
3708
James Smarte59058c2008-08-24 21:49:00 -04003709/**
James Smart3621a712009-04-06 18:47:14 -04003710 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003711 * @phba: pointer to lpfc hba data structure.
3712 * @cmdiocb: pointer to lpfc command iocb data structure.
3713 * @rspiocb: pointer to lpfc response iocb data structure.
3714 *
3715 * This routine is the completion callback function to the Logout (LOGO)
3716 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3717 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3718 * release the ndlp if it has the last reference remaining (reference count
3719 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3720 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3721 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3722 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3723 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3724 * IOCB data structure.
3725 **/
dea31012005-04-17 16:05:31 -05003726static void
James Smart2e0fef82007-06-17 19:56:36 -05003727lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3728 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003729{
James Smart2e0fef82007-06-17 19:56:36 -05003730 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3731 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003732 IOCB_t *irsp;
3733
3734 irsp = &rspiocb->iocb;
3735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3736 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3737 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003738 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003739 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3740 "0109 ACC to LOGO completes to NPort x%x "
3741 "Data: x%x x%x x%x\n",
3742 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3743 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003744
3745 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3746 /* NPort Recovery mode or node is just allocated */
3747 if (!lpfc_nlp_not_used(ndlp)) {
3748 /* If the ndlp is being used by another discovery
3749 * thread, just unregister the RPI.
3750 */
3751 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003752 } else {
3753 /* Indicate the node has already released, should
3754 * not reference to it from within lpfc_els_free_iocb.
3755 */
3756 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003757 }
dea31012005-04-17 16:05:31 -05003758 }
James Smart73d91e52011-10-10 21:32:10 -04003759
3760 /*
3761 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003762 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003763 */
dea31012005-04-17 16:05:31 -05003764 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003765}
3766
James Smarte59058c2008-08-24 21:49:00 -04003767/**
James Smart3621a712009-04-06 18:47:14 -04003768 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003769 * @phba: pointer to lpfc hba data structure.
3770 * @pmb: pointer to the driver internal queue element for mailbox command.
3771 *
3772 * This routine is the completion callback function for unregister default
3773 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3774 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3775 * decrements the ndlp reference count held for this completion callback
3776 * function. After that, it invokes the lpfc_nlp_not_used() to check
3777 * whether there is only one reference left on the ndlp. If so, it will
3778 * perform one more decrement and trigger the release of the ndlp.
3779 **/
James Smart858c9f62007-06-17 19:56:39 -05003780void
3781lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3782{
3783 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3784 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3785
3786 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003787 pmb->context2 = NULL;
3788
James Smart858c9f62007-06-17 19:56:39 -05003789 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3790 kfree(mp);
3791 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003792 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003793 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3794 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3795 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003796 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003797 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003798 if (NLP_CHK_NODE_ACT(ndlp)) {
3799 lpfc_nlp_put(ndlp);
3800 /* This is the end of the default RPI cleanup logic for
3801 * this ndlp. If no other discovery threads are using
3802 * this ndlp, free all resources associated with it.
3803 */
3804 lpfc_nlp_not_used(ndlp);
3805 } else {
3806 lpfc_drop_node(ndlp->vport, ndlp);
3807 }
James Smarta8adb832007-10-27 13:37:53 -04003808 }
James Smart3772a992009-05-22 14:50:54 -04003809
James Smart858c9f62007-06-17 19:56:39 -05003810 return;
3811}
3812
James Smarte59058c2008-08-24 21:49:00 -04003813/**
James Smart3621a712009-04-06 18:47:14 -04003814 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003815 * @phba: pointer to lpfc hba data structure.
3816 * @cmdiocb: pointer to lpfc command iocb data structure.
3817 * @rspiocb: pointer to lpfc response iocb data structure.
3818 *
3819 * This routine is the completion callback function for ELS Response IOCB
3820 * command. In normal case, this callback function just properly sets the
3821 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3822 * field in the command IOCB is not NULL, the referred mailbox command will
3823 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3824 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3825 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3826 * routine shall be invoked trying to release the ndlp if no other threads
3827 * are currently referring it.
3828 **/
dea31012005-04-17 16:05:31 -05003829static void
James Smart858c9f62007-06-17 19:56:39 -05003830lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003831 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003832{
James Smart2e0fef82007-06-17 19:56:36 -05003833 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3834 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3835 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003836 IOCB_t *irsp;
3837 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003838 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003839 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003840 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003841
James Smart33ccf8d2006-08-17 11:57:58 -04003842 irsp = &rspiocb->iocb;
3843
dea31012005-04-17 16:05:31 -05003844 if (cmdiocb->context_un.mbox)
3845 mbox = cmdiocb->context_un.mbox;
3846
James Smartfa4066b2008-01-11 01:53:27 -05003847 /* First determine if this is a LS_RJT cmpl. Note, this callback
3848 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3849 */
James Smart87af33f2007-10-27 13:37:43 -04003850 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003851 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3852 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003853 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003854 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003855 */
3856 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3857 ls_rjt = 1;
3858 }
3859
dea31012005-04-17 16:05:31 -05003860 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003861 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003862 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003863 mp = (struct lpfc_dmabuf *) mbox->context1;
3864 if (mp) {
3865 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3866 kfree(mp);
3867 }
James Smart329f9bc2007-04-25 09:53:01 -04003868 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003869 }
James Smart58da1ff2008-04-07 10:15:56 -04003870 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3871 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003872 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003873 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003874 /* Indicate the node has already released,
3875 * should not reference to it from within
3876 * the routine lpfc_els_free_iocb.
3877 */
3878 cmdiocb->context1 = NULL;
3879 }
dea31012005-04-17 16:05:31 -05003880 goto out;
3881 }
3882
James Smart858c9f62007-06-17 19:56:39 -05003883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003884 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003885 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003886 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003887 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003888 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3889 "0110 ELS response tag x%x completes "
3890 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3891 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3892 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3893 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3894 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003895 if (mbox) {
3896 if ((rspiocb->iocb.ulpStatus == 0)
3897 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003898 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003899 /* Increment reference count to ndlp to hold the
3900 * reference to ndlp for the callback function.
3901 */
James Smart329f9bc2007-04-25 09:53:01 -04003902 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003903 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003904 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3905 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3906 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3907 }
3908 else {
3909 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3910 ndlp->nlp_prev_state = ndlp->nlp_state;
3911 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003912 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003913 }
James Smart4b7789b2015-12-16 18:11:55 -05003914
3915 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04003916 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003917 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003918 goto out;
James Smart4b7789b2015-12-16 18:11:55 -05003919
3920 /* Decrement the ndlp reference count we
3921 * set for this failed mailbox command.
3922 */
3923 lpfc_nlp_put(ndlp);
3924 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04003925
3926 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3927 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3928 "0138 ELS rsp: Cannot issue reg_login for x%x "
3929 "Data: x%x x%x x%x\n",
3930 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3931 ndlp->nlp_rpi);
3932
James Smartfa4066b2008-01-11 01:53:27 -05003933 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003934 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003935 /* Indicate node has already been released,
3936 * should not reference to it from within
3937 * the routine lpfc_els_free_iocb.
3938 */
3939 cmdiocb->context1 = NULL;
3940 }
dea31012005-04-17 16:05:31 -05003941 } else {
James Smart858c9f62007-06-17 19:56:39 -05003942 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3943 if (!lpfc_error_lost_link(irsp) &&
3944 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003945 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003946 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003947 /* Indicate node has already been
3948 * released, should not reference
3949 * to it from within the routine
3950 * lpfc_els_free_iocb.
3951 */
3952 cmdiocb->context1 = NULL;
3953 }
dea31012005-04-17 16:05:31 -05003954 }
3955 }
James Smart14691152006-12-02 13:34:28 -05003956 mp = (struct lpfc_dmabuf *) mbox->context1;
3957 if (mp) {
3958 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3959 kfree(mp);
3960 }
3961 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003962 }
3963out:
James Smart58da1ff2008-04-07 10:15:56 -04003964 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003965 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003966 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003967 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003968
3969 /* If the node is not being used by another discovery thread,
3970 * and we are sending a reject, we are done with it.
3971 * Release driver reference count here and free associated
3972 * resources.
3973 */
3974 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003975 if (lpfc_nlp_not_used(ndlp))
3976 /* Indicate node has already been released,
3977 * should not reference to it from within
3978 * the routine lpfc_els_free_iocb.
3979 */
3980 cmdiocb->context1 = NULL;
James Smart4b7789b2015-12-16 18:11:55 -05003981
dea31012005-04-17 16:05:31 -05003982 }
James Smart87af33f2007-10-27 13:37:43 -04003983
dea31012005-04-17 16:05:31 -05003984 lpfc_els_free_iocb(phba, cmdiocb);
3985 return;
3986}
3987
James Smarte59058c2008-08-24 21:49:00 -04003988/**
James Smart3621a712009-04-06 18:47:14 -04003989 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003990 * @vport: pointer to a host virtual N_Port data structure.
3991 * @flag: the els command code to be accepted.
3992 * @oldiocb: pointer to the original lpfc command iocb data structure.
3993 * @ndlp: pointer to a node-list data structure.
3994 * @mbox: pointer to the driver internal queue element for mailbox command.
3995 *
3996 * This routine prepares and issues an Accept (ACC) response IOCB
3997 * command. It uses the @flag to properly set up the IOCB field for the
3998 * specific ACC response command to be issued and invokes the
3999 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4000 * @mbox pointer is passed in, it will be put into the context_un.mbox
4001 * field of the IOCB for the completion callback function to issue the
4002 * mailbox command to the HBA later when callback is invoked.
4003 *
4004 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4005 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4006 * will be stored into the context1 field of the IOCB for the completion
4007 * callback function to the corresponding response ELS IOCB command.
4008 *
4009 * Return code
4010 * 0 - Successfully issued acc response
4011 * 1 - Failed to issue acc response
4012 **/
dea31012005-04-17 16:05:31 -05004013int
James Smart2e0fef82007-06-17 19:56:36 -05004014lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4015 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04004016 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004017{
James Smart2e0fef82007-06-17 19:56:36 -05004018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4019 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004020 IOCB_t *icmd;
4021 IOCB_t *oldcmd;
4022 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004023 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05004024 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05004025 uint16_t cmdsize;
4026 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04004027 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05004028
dea31012005-04-17 16:05:31 -05004029 oldcmd = &oldiocb->iocb;
4030
4031 switch (flag) {
4032 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05004033 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004034 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4035 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004036 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05004037 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004038 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004039 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004040 return 1;
dea31012005-04-17 16:05:31 -05004041 }
James Smart2e0fef82007-06-17 19:56:36 -05004042
dea31012005-04-17 16:05:31 -05004043 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004044 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4045 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004046 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4047 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004048 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05004049
4050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4051 "Issue ACC: did:x%x flg:x%x",
4052 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004053 break;
James Smartd6de08c2015-12-16 18:11:53 -05004054 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05004055 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05004056 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05004057 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4058 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004059 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004060 return 1;
James Smart488d1462006-03-07 15:02:37 -05004061
dea31012005-04-17 16:05:31 -05004062 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004063 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4064 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004065 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4066
4067 if (mbox)
4068 elsiocb->context_un.mbox = mbox;
4069
4070 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004071 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05004072 sp = (struct serv_parm *)pcmd;
4073
4074 if (flag == ELS_CMD_FLOGI) {
4075 /* Copy the received service parameters back */
4076 memcpy(sp, &phba->fc_fabparam,
4077 sizeof(struct serv_parm));
4078
4079 /* Clear the F_Port bit */
4080 sp->cmn.fPort = 0;
4081
4082 /* Mark all class service parameters as invalid */
4083 sp->cls1.classValid = 0;
4084 sp->cls2.classValid = 0;
4085 sp->cls3.classValid = 0;
4086 sp->cls4.classValid = 0;
4087
4088 /* Copy our worldwide names */
4089 memcpy(&sp->portName, &vport->fc_sparam.portName,
4090 sizeof(struct lpfc_name));
4091 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4092 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08004093 } else {
James Smartd6de08c2015-12-16 18:11:53 -05004094 memcpy(pcmd, &vport->fc_sparam,
4095 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08004096
James Smart8c258642017-02-12 13:52:36 -08004097 sp->cmn.valid_vendor_ver_level = 0;
4098 memset(sp->un.vendorVersion, 0,
4099 sizeof(sp->un.vendorVersion));
4100
4101 /* If our firmware supports this feature, convey that
4102 * info to the target using the vendor specific field.
4103 */
4104 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4105 sp->cmn.valid_vendor_ver_level = 1;
4106 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4107 sp->un.vv.flags =
4108 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4109 }
4110 }
4111
James Smart858c9f62007-06-17 19:56:39 -05004112 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004113 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004114 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004115 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004116 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004117 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004118 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004119 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4120 if (!elsiocb)
4121 return 1;
4122
4123 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004124 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4125 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004126 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4127
4128 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004129 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004130 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4131 els_pkt_ptr = (ELS_PKT *) pcmd;
4132 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004133
4134 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4135 "Issue ACC PRLO: did:x%x flg:x%x",
4136 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004137 break;
dea31012005-04-17 16:05:31 -05004138 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004139 return 1;
dea31012005-04-17 16:05:31 -05004140 }
dea31012005-04-17 16:05:31 -05004141 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004142 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4143 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04004144 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4145 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004146 elsiocb->iotag, elsiocb->iocb.ulpContext,
4147 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04004148 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05004149 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004150 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004151 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4152 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4153 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004154 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004155 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4156 } else {
James Smart858c9f62007-06-17 19:56:39 -05004157 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004158 }
4159
4160 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004161 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004162 if (rc == IOCB_ERROR) {
4163 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004164 return 1;
dea31012005-04-17 16:05:31 -05004165 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004166 return 0;
dea31012005-04-17 16:05:31 -05004167}
4168
James Smarte59058c2008-08-24 21:49:00 -04004169/**
James Smart3621a712009-04-06 18:47:14 -04004170 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004171 * @vport: pointer to a virtual N_Port data structure.
4172 * @rejectError:
4173 * @oldiocb: pointer to the original lpfc command iocb data structure.
4174 * @ndlp: pointer to a node-list data structure.
4175 * @mbox: pointer to the driver internal queue element for mailbox command.
4176 *
4177 * This routine prepares and issue an Reject (RJT) response IOCB
4178 * command. If a @mbox pointer is passed in, it will be put into the
4179 * context_un.mbox field of the IOCB for the completion callback function
4180 * to issue to the HBA later.
4181 *
4182 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4183 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4184 * will be stored into the context1 field of the IOCB for the completion
4185 * callback function to the reject response ELS IOCB command.
4186 *
4187 * Return code
4188 * 0 - Successfully issued reject response
4189 * 1 - Failed to issue reject response
4190 **/
dea31012005-04-17 16:05:31 -05004191int
James Smart2e0fef82007-06-17 19:56:36 -05004192lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004193 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4194 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004195{
James Smart2e0fef82007-06-17 19:56:36 -05004196 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004197 IOCB_t *icmd;
4198 IOCB_t *oldcmd;
4199 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004200 uint8_t *pcmd;
4201 uint16_t cmdsize;
4202 int rc;
4203
James Smart92d7f7b2007-06-17 19:56:38 -05004204 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004205 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4206 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004207 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004208 return 1;
dea31012005-04-17 16:05:31 -05004209
4210 icmd = &elsiocb->iocb;
4211 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004212 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4213 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004214 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4215
4216 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004217 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004218 *((uint32_t *) (pcmd)) = rejectError;
4219
James Smart51ef4c22007-08-02 11:10:31 -04004220 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004221 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004222
dea31012005-04-17 16:05:31 -05004223 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004224 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4225 "0129 Xmit ELS RJT x%x response tag x%x "
4226 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4227 "rpi x%x\n",
4228 rejectError, elsiocb->iotag,
4229 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4230 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004231 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4232 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4233 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4234
dea31012005-04-17 16:05:31 -05004235 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004236 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004237 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004238
dea31012005-04-17 16:05:31 -05004239 if (rc == IOCB_ERROR) {
4240 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004241 return 1;
dea31012005-04-17 16:05:31 -05004242 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004243 return 0;
dea31012005-04-17 16:05:31 -05004244}
4245
James Smarte59058c2008-08-24 21:49:00 -04004246/**
James Smart3621a712009-04-06 18:47:14 -04004247 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004248 * @vport: pointer to a virtual N_Port data structure.
4249 * @oldiocb: pointer to the original lpfc command iocb data structure.
4250 * @ndlp: pointer to a node-list data structure.
4251 *
4252 * This routine prepares and issues an Accept (ACC) response to Address
4253 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4254 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4255 *
4256 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4257 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4258 * will be stored into the context1 field of the IOCB for the completion
4259 * callback function to the ADISC Accept response ELS IOCB command.
4260 *
4261 * Return code
4262 * 0 - Successfully issued acc adisc response
4263 * 1 - Failed to issue adisc acc response
4264 **/
dea31012005-04-17 16:05:31 -05004265int
James Smart2e0fef82007-06-17 19:56:36 -05004266lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4267 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004268{
James Smart2e0fef82007-06-17 19:56:36 -05004269 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004270 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004271 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004272 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004273 uint8_t *pcmd;
4274 uint16_t cmdsize;
4275 int rc;
4276
James Smart92d7f7b2007-06-17 19:56:38 -05004277 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004278 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4279 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004280 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004281 return 1;
dea31012005-04-17 16:05:31 -05004282
dea31012005-04-17 16:05:31 -05004283 icmd = &elsiocb->iocb;
4284 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004285 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4286 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004287
4288 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004289 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4290 "0130 Xmit ADISC ACC response iotag x%x xri: "
4291 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4292 elsiocb->iotag, elsiocb->iocb.ulpContext,
4293 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4294 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004295 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4296
4297 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004298 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004299
4300 ap = (ADISC *) (pcmd);
4301 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004302 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4303 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004304 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004305
James Smart858c9f62007-06-17 19:56:39 -05004306 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4307 "Issue ACC ADISC: did:x%x flg:x%x",
4308 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4309
dea31012005-04-17 16:05:31 -05004310 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004311 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004312 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004313 if (rc == IOCB_ERROR) {
4314 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004315 return 1;
dea31012005-04-17 16:05:31 -05004316 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004317 return 0;
dea31012005-04-17 16:05:31 -05004318}
4319
James Smarte59058c2008-08-24 21:49:00 -04004320/**
James Smart3621a712009-04-06 18:47:14 -04004321 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004322 * @vport: pointer to a virtual N_Port data structure.
4323 * @oldiocb: pointer to the original lpfc command iocb data structure.
4324 * @ndlp: pointer to a node-list data structure.
4325 *
4326 * This routine prepares and issues an Accept (ACC) response to Process
4327 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4328 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4329 *
4330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4332 * will be stored into the context1 field of the IOCB for the completion
4333 * callback function to the PRLI Accept response ELS IOCB command.
4334 *
4335 * Return code
4336 * 0 - Successfully issued acc prli response
4337 * 1 - Failed to issue acc prli response
4338 **/
dea31012005-04-17 16:05:31 -05004339int
James Smart2e0fef82007-06-17 19:56:36 -05004340lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004341 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004342{
James Smart2e0fef82007-06-17 19:56:36 -05004343 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004344 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08004345 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05004346 lpfc_vpd_t *vpd;
4347 IOCB_t *icmd;
4348 IOCB_t *oldcmd;
4349 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004350 uint8_t *pcmd;
4351 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08004352 uint32_t prli_fc4_req, *req_payload;
4353 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05004354 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08004355 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05004356
James Smarta0f2d3e2017-02-12 13:52:31 -08004357 /* Need the incoming PRLI payload to determine if the ACC is for an
4358 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4359 */
4360 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4361 req_payload = (((uint32_t *)req_buf->virt) + 1);
4362
4363 /* PRLI type payload is at byte 3 for FCP or NVME. */
4364 prli_fc4_req = be32_to_cpu(*req_payload);
4365 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4366 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4367 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4368 prli_fc4_req, *((uint32_t *)req_payload));
4369
4370 if (prli_fc4_req == PRLI_FCP_TYPE) {
4371 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4372 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4373 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4374 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4375 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4376 } else {
4377 return 1;
4378 }
4379
James Smart2e0fef82007-06-17 19:56:36 -05004380 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08004381 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004382 if (!elsiocb)
4383 return 1;
dea31012005-04-17 16:05:31 -05004384
dea31012005-04-17 16:05:31 -05004385 icmd = &elsiocb->iocb;
4386 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004387 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4388 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4389
James Smart5b8bd0c2007-04-25 09:52:49 -04004390 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004391 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4392 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4393 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4394 elsiocb->iotag, elsiocb->iocb.ulpContext,
4395 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4396 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004397 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08004398 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05004399
James Smartc07f10c2017-04-21 16:04:54 -07004400 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004401 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004402
4403 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05004404 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08004405
4406 if (prli_fc4_req == PRLI_FCP_TYPE) {
4407 /*
4408 * If the remote port is a target and our firmware version
4409 * is 3.20 or later, set the following bits for FC-TAPE
4410 * support.
4411 */
4412 npr = (PRLI *) pcmd;
4413 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4414 (vpd->rev.feaLevelHigh >= 0x02)) {
4415 npr->ConfmComplAllowed = 1;
4416 npr->Retry = 1;
4417 npr->TaskRetryIdReq = 1;
4418 }
4419 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4420 npr->estabImagePair = 1;
4421 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05004422 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08004423 npr->prliType = PRLI_FCP_TYPE;
4424 npr->initiatorFunc = 1;
4425 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4426 /* Respond with an NVME PRLI Type */
4427 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4428 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4429 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4430 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08004431 if (phba->nvmet_support) {
4432 bf_set(prli_tgt, npr_nvme, 1);
4433 bf_set(prli_disc, npr_nvme, 1);
4434 if (phba->cfg_nvme_enable_fb) {
4435 bf_set(prli_fba, npr_nvme, 1);
4436
4437 /* TBD. Target mode needs to post buffers
4438 * that support the configured first burst
4439 * byte size.
4440 */
4441 bf_set(prli_fb_sz, npr_nvme,
4442 phba->cfg_nvmet_fb_size);
4443 }
4444 } else {
4445 bf_set(prli_init, npr_nvme, 1);
4446 }
dea31012005-04-17 16:05:31 -05004447
James Smarta0f2d3e2017-02-12 13:52:31 -08004448 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4449 "6015 NVME issue PRLI ACC word1 x%08x "
4450 "word4 x%08x word5 x%08x flag x%x, "
4451 "fcp_info x%x nlp_type x%x\n",
4452 npr_nvme->word1, npr_nvme->word4,
4453 npr_nvme->word5, ndlp->nlp_flag,
4454 ndlp->nlp_fcp_info, ndlp->nlp_type);
4455 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4456 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4457 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4458 } else
4459 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4460 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4461 prli_fc4_req, ndlp->nlp_fc4_type,
4462 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05004463
James Smart858c9f62007-06-17 19:56:39 -05004464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4465 "Issue ACC PRLI: did:x%x flg:x%x",
4466 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4467
dea31012005-04-17 16:05:31 -05004468 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004469 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004470
James Smart3772a992009-05-22 14:50:54 -04004471 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004472 if (rc == IOCB_ERROR) {
4473 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004474 return 1;
dea31012005-04-17 16:05:31 -05004475 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004476 return 0;
dea31012005-04-17 16:05:31 -05004477}
4478
James Smarte59058c2008-08-24 21:49:00 -04004479/**
James Smart3621a712009-04-06 18:47:14 -04004480 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004481 * @vport: pointer to a virtual N_Port data structure.
4482 * @format: rnid command format.
4483 * @oldiocb: pointer to the original lpfc command iocb data structure.
4484 * @ndlp: pointer to a node-list data structure.
4485 *
4486 * This routine issues a Request Node Identification Data (RNID) Accept
4487 * (ACC) response. It constructs the RNID ACC response command according to
4488 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4489 * issue the response. Note that this command does not need to hold the ndlp
4490 * reference count for the callback. So, the ndlp reference count taken by
4491 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4492 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4493 * there is no ndlp reference available.
4494 *
4495 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4496 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4497 * will be stored into the context1 field of the IOCB for the completion
4498 * callback function. However, for the RNID Accept Response ELS command,
4499 * this is undone later by this routine after the IOCB is allocated.
4500 *
4501 * Return code
4502 * 0 - Successfully issued acc rnid response
4503 * 1 - Failed to issue acc rnid response
4504 **/
dea31012005-04-17 16:05:31 -05004505static int
James Smart2e0fef82007-06-17 19:56:36 -05004506lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004507 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004508{
James Smart2e0fef82007-06-17 19:56:36 -05004509 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004510 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004511 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004512 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004513 uint8_t *pcmd;
4514 uint16_t cmdsize;
4515 int rc;
4516
James Smart92d7f7b2007-06-17 19:56:38 -05004517 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4518 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004519 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004520 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004521
James Smart2e0fef82007-06-17 19:56:36 -05004522 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4523 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004524 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004525 return 1;
dea31012005-04-17 16:05:31 -05004526
dea31012005-04-17 16:05:31 -05004527 icmd = &elsiocb->iocb;
4528 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004529 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4530 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4531
James Smart5b8bd0c2007-04-25 09:52:49 -04004532 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004533 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4534 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4535 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004536 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004537 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004538 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004539
James Smart92d7f7b2007-06-17 19:56:38 -05004540 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004541 rn = (RNID *) (pcmd);
4542 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004543 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4544 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4545 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004546 switch (format) {
4547 case 0:
4548 rn->SpecificLen = 0;
4549 break;
4550 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004551 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004552 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004553 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004554 rn->un.topologyDisc.unitType = RNID_HBA;
4555 rn->un.topologyDisc.physPort = 0;
4556 rn->un.topologyDisc.attachedNodes = 0;
4557 break;
4558 default:
4559 rn->CommonLen = 0;
4560 rn->SpecificLen = 0;
4561 break;
4562 }
4563
James Smart858c9f62007-06-17 19:56:39 -05004564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4565 "Issue ACC RNID: did:x%x flg:x%x",
4566 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4567
dea31012005-04-17 16:05:31 -05004568 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004569 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004570
James Smart3772a992009-05-22 14:50:54 -04004571 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004572 if (rc == IOCB_ERROR) {
4573 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004574 return 1;
dea31012005-04-17 16:05:31 -05004575 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004576 return 0;
dea31012005-04-17 16:05:31 -05004577}
4578
James Smarte59058c2008-08-24 21:49:00 -04004579/**
James Smart19ca7602010-11-20 23:11:55 -05004580 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4581 * @vport: pointer to a virtual N_Port data structure.
4582 * @iocb: pointer to the lpfc command iocb data structure.
4583 * @ndlp: pointer to a node-list data structure.
4584 *
4585 * Return
4586 **/
4587static void
4588lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08004589 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05004590{
4591 struct lpfc_hba *phba = vport->phba;
4592 uint8_t *pcmd;
4593 struct RRQ *rrq;
4594 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004595 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004596 struct lpfc_node_rrq *prrq;
4597
4598
4599 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4600 pcmd += sizeof(uint32_t);
4601 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004602 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004603 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004604
4605 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4606 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4607 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004608 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004609 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004610 rxid,
4611 iocb->iotag, iocb->iocb.ulpContext);
4612
4613 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4614 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4615 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004616 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004617 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004618 else
4619 xri = rxid;
4620 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004621 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004622 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004623 return;
4624}
4625
4626/**
James Smart12265f62010-10-22 11:05:53 -04004627 * lpfc_els_rsp_echo_acc - Issue echo acc response
4628 * @vport: pointer to a virtual N_Port data structure.
4629 * @data: pointer to echo data to return in the accept.
4630 * @oldiocb: pointer to the original lpfc command iocb data structure.
4631 * @ndlp: pointer to a node-list data structure.
4632 *
4633 * Return code
4634 * 0 - Successfully issued acc echo response
4635 * 1 - Failed to issue acc echo response
4636 **/
4637static int
4638lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4639 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4640{
4641 struct lpfc_hba *phba = vport->phba;
4642 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04004643 uint8_t *pcmd;
4644 uint16_t cmdsize;
4645 int rc;
4646
James Smart12265f62010-10-22 11:05:53 -04004647 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4648
James Smartbf086112011-08-21 21:48:13 -04004649 /* The accumulated length can exceed the BPL_SIZE. For
4650 * now, use this as the limit
4651 */
4652 if (cmdsize > LPFC_BPL_SIZE)
4653 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004654 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4655 ndlp->nlp_DID, ELS_CMD_ACC);
4656 if (!elsiocb)
4657 return 1;
4658
James Smart7851fe22011-07-22 18:36:52 -04004659 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4660 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4661
James Smart12265f62010-10-22 11:05:53 -04004662 /* Xmit ECHO ACC response tag <ulpIoTag> */
4663 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4664 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4665 elsiocb->iotag, elsiocb->iocb.ulpContext);
4666 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4667 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4668 pcmd += sizeof(uint32_t);
4669 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4670
4671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4672 "Issue ACC ECHO: did:x%x flg:x%x",
4673 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4674
4675 phba->fc_stat.elsXmitACC++;
4676 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004677
4678 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4679 if (rc == IOCB_ERROR) {
4680 lpfc_els_free_iocb(phba, elsiocb);
4681 return 1;
4682 }
4683 return 0;
4684}
4685
4686/**
James Smart3621a712009-04-06 18:47:14 -04004687 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004688 * @vport: pointer to a host virtual N_Port data structure.
4689 *
4690 * This routine issues Address Discover (ADISC) ELS commands to those
4691 * N_Ports which are in node port recovery state and ADISC has not been issued
4692 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4693 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4694 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4695 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4696 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4697 * IOCBs quit for later pick up. On the other hand, after walking through
4698 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4699 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4700 * no more ADISC need to be sent.
4701 *
4702 * Return code
4703 * The number of N_Ports with adisc issued.
4704 **/
dea31012005-04-17 16:05:31 -05004705int
James Smart2e0fef82007-06-17 19:56:36 -05004706lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004707{
James Smart2e0fef82007-06-17 19:56:36 -05004708 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004709 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004710 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004711
James Smart685f0bf2007-04-25 09:53:08 -04004712 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004713 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004714 if (!NLP_CHK_NODE_ACT(ndlp))
4715 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004716 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4717 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4718 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004719 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004720 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004721 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004722 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4724 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004725 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004726 vport->num_disc_nodes++;
4727 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004728 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004729 spin_lock_irq(shost->host_lock);
4730 vport->fc_flag |= FC_NLP_MORE;
4731 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004732 break;
dea31012005-04-17 16:05:31 -05004733 }
4734 }
4735 }
4736 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004737 spin_lock_irq(shost->host_lock);
4738 vport->fc_flag &= ~FC_NLP_MORE;
4739 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004740 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004741 return sentadisc;
dea31012005-04-17 16:05:31 -05004742}
4743
James Smarte59058c2008-08-24 21:49:00 -04004744/**
James Smart3621a712009-04-06 18:47:14 -04004745 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004746 * @vport: pointer to a host virtual N_Port data structure.
4747 *
4748 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4749 * which are in node port recovery state, with a @vport. Each time an ELS
4750 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4751 * the per @vport number of discover count (num_disc_nodes) shall be
4752 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4753 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4754 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4755 * later pick up. On the other hand, after walking through all the ndlps with
4756 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4757 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4758 * PLOGI need to be sent.
4759 *
4760 * Return code
4761 * The number of N_Ports with plogi issued.
4762 **/
dea31012005-04-17 16:05:31 -05004763int
James Smart2e0fef82007-06-17 19:56:36 -05004764lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004765{
James Smart2e0fef82007-06-17 19:56:36 -05004766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004767 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004768 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004769
James Smart2e0fef82007-06-17 19:56:36 -05004770 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4771 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004772 if (!NLP_CHK_NODE_ACT(ndlp))
4773 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004774 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004775 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4776 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4777 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004778 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4780 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004781 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004782 vport->num_disc_nodes++;
4783 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004784 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004785 spin_lock_irq(shost->host_lock);
4786 vport->fc_flag |= FC_NLP_MORE;
4787 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004788 break;
dea31012005-04-17 16:05:31 -05004789 }
4790 }
4791 }
James Smart87af33f2007-10-27 13:37:43 -04004792 if (sentplogi) {
4793 lpfc_set_disctmo(vport);
4794 }
4795 else {
James Smart2e0fef82007-06-17 19:56:36 -05004796 spin_lock_irq(shost->host_lock);
4797 vport->fc_flag &= ~FC_NLP_MORE;
4798 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004799 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004800 return sentplogi;
dea31012005-04-17 16:05:31 -05004801}
4802
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004803static uint32_t
James Smart86478872015-05-21 13:55:21 -04004804lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4805 uint32_t word0)
4806{
4807
4808 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4809 desc->payload.els_req = word0;
4810 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07004811
4812 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04004813}
4814
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004815static uint32_t
James Smart86478872015-05-21 13:55:21 -04004816lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4817 uint8_t *page_a0, uint8_t *page_a2)
4818{
4819 uint16_t wavelength;
4820 uint16_t temperature;
4821 uint16_t rx_power;
4822 uint16_t tx_bias;
4823 uint16_t tx_power;
4824 uint16_t vcc;
4825 uint16_t flag = 0;
4826 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4827 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4828
4829 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4830
4831 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4832 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4833 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4834 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4835
4836 if ((trasn_code_byte4->fc_sw_laser) ||
4837 (trasn_code_byte5->fc_sw_laser_sl) ||
4838 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4839 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4840 } else if (trasn_code_byte4->fc_lw_laser) {
4841 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4842 page_a0[SSF_WAVELENGTH_B0];
4843 if (wavelength == SFP_WAVELENGTH_LC1310)
4844 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4845 if (wavelength == SFP_WAVELENGTH_LL1550)
4846 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4847 }
4848 /* check if its SFP+ */
4849 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4850 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4851 << SFP_FLAG_CT_SHIFT;
4852
4853 /* check if its OPTICAL */
4854 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4855 SFP_FLAG_IS_OPTICAL_PORT : 0)
4856 << SFP_FLAG_IS_OPTICAL_SHIFT;
4857
4858 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4859 page_a2[SFF_TEMPERATURE_B0]);
4860 vcc = (page_a2[SFF_VCC_B1] << 8 |
4861 page_a2[SFF_VCC_B0]);
4862 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4863 page_a2[SFF_TXPOWER_B0]);
4864 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4865 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4866 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4867 page_a2[SFF_RXPOWER_B0]);
4868 desc->sfp_info.temperature = cpu_to_be16(temperature);
4869 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4870 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4871 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4872 desc->sfp_info.vcc = cpu_to_be16(vcc);
4873
4874 desc->sfp_info.flags = cpu_to_be16(flag);
4875 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004876
4877 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04004878}
4879
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004880static uint32_t
James Smart86478872015-05-21 13:55:21 -04004881lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4882 READ_LNK_VAR *stat)
4883{
4884 uint32_t type;
4885
4886 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4887
4888 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4889
4890 desc->info.port_type = cpu_to_be32(type);
4891
4892 desc->info.link_status.link_failure_cnt =
4893 cpu_to_be32(stat->linkFailureCnt);
4894 desc->info.link_status.loss_of_synch_cnt =
4895 cpu_to_be32(stat->lossSyncCnt);
4896 desc->info.link_status.loss_of_signal_cnt =
4897 cpu_to_be32(stat->lossSignalCnt);
4898 desc->info.link_status.primitive_seq_proto_err =
4899 cpu_to_be32(stat->primSeqErrCnt);
4900 desc->info.link_status.invalid_trans_word =
4901 cpu_to_be32(stat->invalidXmitWord);
4902 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4903
4904 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07004905
4906 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04004907}
4908
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004909static uint32_t
James Smart56204982016-03-31 14:12:32 -07004910lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4911 struct lpfc_vport *vport)
4912{
James Smart3aaaa312016-07-06 12:35:57 -07004913 uint32_t bbCredit;
4914
James Smart56204982016-03-31 14:12:32 -07004915 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4916
James Smart3aaaa312016-07-06 12:35:57 -07004917 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4918 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4919 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4920 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4921 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4922 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4923 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4924 } else {
James Smart56204982016-03-31 14:12:32 -07004925 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07004926 }
James Smart56204982016-03-31 14:12:32 -07004927
4928 desc->bbc_info.rtt = 0;
4929 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004930
4931 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07004932}
4933
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004934static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004935lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4936 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07004937{
James Smart310429e2016-07-06 12:35:54 -07004938 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004939
4940 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4941
James Smart3aaaa312016-07-06 12:35:57 -07004942 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4943 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4944 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4945 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004946
4947 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4948 flags |= RDP_OET_HIGH_ALARM;
4949 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4950 flags |= RDP_OET_LOW_ALARM;
4951 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4952 flags |= RDP_OET_HIGH_WARNING;
4953 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4954 flags |= RDP_OET_LOW_WARNING;
4955
James Smart56204982016-03-31 14:12:32 -07004956 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4957 desc->oed_info.function_flags = cpu_to_be32(flags);
4958 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004959 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004960}
4961
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004962static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004963lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4964 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004965 uint8_t *page_a2)
4966{
James Smart310429e2016-07-06 12:35:54 -07004967 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004968
4969 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4970
James Smart3aaaa312016-07-06 12:35:57 -07004971 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4972 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4973 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4974 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004975
4976 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4977 flags |= RDP_OET_HIGH_ALARM;
4978 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4979 flags |= RDP_OET_LOW_ALARM;
4980 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4981 flags |= RDP_OET_HIGH_WARNING;
4982 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4983 flags |= RDP_OET_LOW_WARNING;
4984
James Smart56204982016-03-31 14:12:32 -07004985 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4986 desc->oed_info.function_flags = cpu_to_be32(flags);
4987 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004988 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004989}
4990
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004991static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004992lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4993 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004994 uint8_t *page_a2)
4995{
James Smart310429e2016-07-06 12:35:54 -07004996 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004997
4998 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4999
James Smart3aaaa312016-07-06 12:35:57 -07005000 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5001 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5002 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5003 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005004
5005 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5006 flags |= RDP_OET_HIGH_ALARM;
5007 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5008 flags |= RDP_OET_LOW_ALARM;
5009 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5010 flags |= RDP_OET_HIGH_WARNING;
5011 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5012 flags |= RDP_OET_LOW_WARNING;
5013
James Smart56204982016-03-31 14:12:32 -07005014 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5015 desc->oed_info.function_flags = cpu_to_be32(flags);
5016 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005017 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005018}
5019
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005020static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005021lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5022 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005023 uint8_t *page_a2)
5024{
James Smart310429e2016-07-06 12:35:54 -07005025 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005026
5027 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5028
James Smart3aaaa312016-07-06 12:35:57 -07005029 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5030 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5031 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5032 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005033
5034 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5035 flags |= RDP_OET_HIGH_ALARM;
5036 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5037 flags |= RDP_OET_LOW_ALARM;
5038 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5039 flags |= RDP_OET_HIGH_WARNING;
5040 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5041 flags |= RDP_OET_LOW_WARNING;
5042
James Smart56204982016-03-31 14:12:32 -07005043 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5044 desc->oed_info.function_flags = cpu_to_be32(flags);
5045 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005046 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005047}
5048
5049
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005050static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005051lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5052 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005053 uint8_t *page_a2)
5054{
James Smart310429e2016-07-06 12:35:54 -07005055 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005056
5057 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5058
James Smart3aaaa312016-07-06 12:35:57 -07005059 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5060 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5061 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5062 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005063
5064 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5065 flags |= RDP_OET_HIGH_ALARM;
5066 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5067 flags |= RDP_OET_LOW_ALARM;
5068 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5069 flags |= RDP_OET_HIGH_WARNING;
5070 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5071 flags |= RDP_OET_LOW_WARNING;
5072
James Smart56204982016-03-31 14:12:32 -07005073 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5074 desc->oed_info.function_flags = cpu_to_be32(flags);
5075 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005076 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005077}
5078
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005079static uint32_t
James Smart56204982016-03-31 14:12:32 -07005080lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5081 uint8_t *page_a0, struct lpfc_vport *vport)
5082{
5083 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5084 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5085 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5086 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08005087 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07005088 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5089 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005090 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005091}
5092
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005093static uint32_t
James Smart4258e982015-12-16 18:11:58 -05005094lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5095{
5096 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5097 return 0;
5098 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5099
5100 desc->info.CorrectedBlocks =
5101 cpu_to_be32(stat->fecCorrBlkCount);
5102 desc->info.UncorrectableBlocks =
5103 cpu_to_be32(stat->fecUncorrBlkCount);
5104
5105 desc->length = cpu_to_be32(sizeof(desc->info));
5106
5107 return sizeof(struct fc_fec_rdp_desc);
5108}
5109
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005110static uint32_t
James Smart86478872015-05-21 13:55:21 -04005111lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5112{
5113 uint16_t rdp_cap = 0;
5114 uint16_t rdp_speed;
5115
5116 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5117
James Smart81e75172015-12-16 18:11:59 -05005118 switch (phba->fc_linkspeed) {
5119 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04005120 rdp_speed = RDP_PS_1GB;
5121 break;
James Smart81e75172015-12-16 18:11:59 -05005122 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04005123 rdp_speed = RDP_PS_2GB;
5124 break;
James Smart81e75172015-12-16 18:11:59 -05005125 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04005126 rdp_speed = RDP_PS_4GB;
5127 break;
James Smart81e75172015-12-16 18:11:59 -05005128 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04005129 rdp_speed = RDP_PS_8GB;
5130 break;
James Smart81e75172015-12-16 18:11:59 -05005131 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04005132 rdp_speed = RDP_PS_10GB;
5133 break;
James Smart81e75172015-12-16 18:11:59 -05005134 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04005135 rdp_speed = RDP_PS_16GB;
5136 break;
James Smarta085e872015-12-16 18:12:02 -05005137 case LPFC_LINK_SPEED_32GHZ:
5138 rdp_speed = RDP_PS_32GB;
5139 break;
James Smart86478872015-05-21 13:55:21 -04005140 default:
5141 rdp_speed = RDP_PS_UNKNOWN;
5142 break;
5143 }
5144
5145 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5146
James Smartd38dd522015-08-31 16:48:17 -04005147 if (phba->lmt & LMT_32Gb)
5148 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04005149 if (phba->lmt & LMT_16Gb)
5150 rdp_cap |= RDP_PS_16GB;
5151 if (phba->lmt & LMT_10Gb)
5152 rdp_cap |= RDP_PS_10GB;
5153 if (phba->lmt & LMT_8Gb)
5154 rdp_cap |= RDP_PS_8GB;
5155 if (phba->lmt & LMT_4Gb)
5156 rdp_cap |= RDP_PS_4GB;
5157 if (phba->lmt & LMT_2Gb)
5158 rdp_cap |= RDP_PS_2GB;
5159 if (phba->lmt & LMT_1Gb)
5160 rdp_cap |= RDP_PS_1GB;
5161
5162 if (rdp_cap == 0)
5163 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07005164 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5165 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04005166
5167 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5168 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005169 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04005170}
5171
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005172static uint32_t
James Smart86478872015-05-21 13:55:21 -04005173lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08005174 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04005175{
5176
5177 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5178
James Smartcd46cde2017-03-04 09:30:37 -08005179 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04005180 sizeof(desc->port_names.wwnn));
5181
James Smartcd46cde2017-03-04 09:30:37 -08005182 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04005183 sizeof(desc->port_names.wwpn));
5184
5185 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005186 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005187}
5188
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005189static uint32_t
James Smart86478872015-05-21 13:55:21 -04005190lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5191 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5192{
5193
5194 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5195 if (vport->fc_flag & FC_FABRIC) {
5196 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5197 sizeof(desc->port_names.wwnn));
5198
5199 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5200 sizeof(desc->port_names.wwpn));
5201 } else { /* Point to Point */
5202 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5203 sizeof(desc->port_names.wwnn));
5204
5205 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5206 sizeof(desc->port_names.wwpn));
5207 }
5208
5209 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005210 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005211}
5212
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005213static void
James Smart86478872015-05-21 13:55:21 -04005214lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5215 int status)
5216{
5217 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5218 struct lpfc_vport *vport = ndlp->vport;
5219 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005220 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005221 IOCB_t *icmd;
5222 uint8_t *pcmd;
5223 struct ls_rjt *stat;
5224 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005225 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005226 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005227 int rc;
James Smart86478872015-05-21 13:55:21 -04005228
5229 if (status != SUCCESS)
5230 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005231
5232 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005233 cmdsize = sizeof(struct fc_rdp_res_frame);
5234
5235 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5236 lpfc_max_els_tries, rdp_context->ndlp,
5237 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5238 lpfc_nlp_put(ndlp);
5239 if (!elsiocb)
5240 goto free_rdp_context;
5241
5242 icmd = &elsiocb->iocb;
5243 icmd->ulpContext = rdp_context->rx_id;
5244 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5245
5246 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5247 "2171 Xmit RDP response tag x%x xri x%x, "
5248 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5249 elsiocb->iotag, elsiocb->iocb.ulpContext,
5250 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5251 ndlp->nlp_rpi);
5252 rdp_res = (struct fc_rdp_res_frame *)
5253 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5254 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5255 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5256 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5257
James Smart310429e2016-07-06 12:35:54 -07005258 /* Update Alarm and Warning */
5259 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5260 phba->sfp_alarm |= *flag_ptr;
5261 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5262 phba->sfp_warning |= *flag_ptr;
5263
James Smart86478872015-05-21 13:55:21 -04005264 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07005265 len = 8;
5266 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5267 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04005268
James Smart6c92d1d2016-07-06 12:35:55 -07005269 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04005270 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07005271 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5272 phba);
5273 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5274 (len + pcmd), &rdp_context->link_stat);
5275 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08005276 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07005277 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5278 (len + pcmd), vport, ndlp);
5279 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05005280 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07005281 /* Check if nport is logged, BZ190632 */
5282 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5283 goto lpfc_skip_descriptor;
5284
5285 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5286 &rdp_context->link_stat, vport);
5287 len += lpfc_rdp_res_oed_temp_desc(phba,
5288 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5289 rdp_context->page_a2);
5290 len += lpfc_rdp_res_oed_voltage_desc(phba,
5291 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5292 rdp_context->page_a2);
5293 len += lpfc_rdp_res_oed_txbias_desc(phba,
5294 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5295 rdp_context->page_a2);
5296 len += lpfc_rdp_res_oed_txpower_desc(phba,
5297 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5298 rdp_context->page_a2);
5299 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5300 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5301 rdp_context->page_a2);
5302 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5303 rdp_context->page_a0, vport);
5304
5305lpfc_skip_descriptor:
5306 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04005307 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5308
James Smarteb8d68c2015-12-16 18:12:00 -05005309 /* Now that we know the true size of the payload, update the BPL */
5310 bpl = (struct ulp_bde64 *)
5311 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07005312 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05005313 bpl->tus.f.bdeFlags = 0;
5314 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5315
James Smart86478872015-05-21 13:55:21 -04005316 phba->fc_stat.elsXmitACC++;
5317 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5318 if (rc == IOCB_ERROR)
5319 lpfc_els_free_iocb(phba, elsiocb);
5320
5321 kfree(rdp_context);
5322
5323 return;
5324error:
5325 cmdsize = 2 * sizeof(uint32_t);
5326 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5327 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5328 lpfc_nlp_put(ndlp);
5329 if (!elsiocb)
5330 goto free_rdp_context;
5331
5332 icmd = &elsiocb->iocb;
5333 icmd->ulpContext = rdp_context->rx_id;
5334 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5335 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5336
5337 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5338 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5339 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5340
5341 phba->fc_stat.elsXmitLSRJT++;
5342 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5343 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5344
5345 if (rc == IOCB_ERROR)
5346 lpfc_els_free_iocb(phba, elsiocb);
5347free_rdp_context:
5348 kfree(rdp_context);
5349}
5350
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005351static int
James Smart86478872015-05-21 13:55:21 -04005352lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5353{
5354 LPFC_MBOXQ_t *mbox = NULL;
5355 int rc;
5356
5357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5358 if (!mbox) {
5359 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5360 "7105 failed to allocate mailbox memory");
5361 return 1;
5362 }
5363
5364 if (lpfc_sli4_dump_page_a0(phba, mbox))
5365 goto prep_mbox_fail;
5366 mbox->vport = rdp_context->ndlp->vport;
5367 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5368 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5369 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5370 if (rc == MBX_NOT_FINISHED)
5371 goto issue_mbox_fail;
5372
5373 return 0;
5374
5375prep_mbox_fail:
5376issue_mbox_fail:
5377 mempool_free(mbox, phba->mbox_mem_pool);
5378 return 1;
5379}
5380
5381/*
5382 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5383 * @vport: pointer to a host virtual N_Port data structure.
5384 * @cmdiocb: pointer to lpfc command iocb data structure.
5385 * @ndlp: pointer to a node-list data structure.
5386 *
5387 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5388 * IOCB. First, the payload of the unsolicited RDP is checked.
5389 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5390 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5391 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5392 * gather all data and send RDP response.
5393 *
5394 * Return code
5395 * 0 - Sent the acc response
5396 * 1 - Sent the reject response.
5397 */
5398static int
5399lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5400 struct lpfc_nodelist *ndlp)
5401{
5402 struct lpfc_hba *phba = vport->phba;
5403 struct lpfc_dmabuf *pcmd;
5404 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5405 struct fc_rdp_req_frame *rdp_req;
5406 struct lpfc_rdp_context *rdp_context;
5407 IOCB_t *cmd = NULL;
5408 struct ls_rjt stat;
5409
5410 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smarta0f2d3e2017-02-12 13:52:31 -08005411 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5412 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04005413 rjt_err = LSRJT_UNABLE_TPC;
5414 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5415 goto error;
5416 }
5417
5418 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5419 rjt_err = LSRJT_UNABLE_TPC;
5420 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5421 goto error;
5422 }
5423
5424 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5425 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5426
5427
5428 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5429 "2422 ELS RDP Request "
5430 "dec len %d tag x%x port_id %d len %d\n",
5431 be32_to_cpu(rdp_req->rdp_des_length),
5432 be32_to_cpu(rdp_req->nport_id_desc.tag),
5433 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5434 be32_to_cpu(rdp_req->nport_id_desc.length));
5435
James Smart7d933312016-07-06 12:35:58 -07005436 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5437 !phba->cfg_enable_SmartSAN) {
5438 rjt_err = LSRJT_UNABLE_TPC;
5439 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5440 goto error;
5441 }
James Smart86478872015-05-21 13:55:21 -04005442 if (sizeof(struct fc_rdp_nport_desc) !=
5443 be32_to_cpu(rdp_req->rdp_des_length))
5444 goto rjt_logerr;
5445 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5446 goto rjt_logerr;
5447 if (RDP_NPORT_ID_SIZE !=
5448 be32_to_cpu(rdp_req->nport_id_desc.length))
5449 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05005450 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04005451 if (!rdp_context) {
5452 rjt_err = LSRJT_UNABLE_TPC;
5453 goto error;
5454 }
5455
James Smart86478872015-05-21 13:55:21 -04005456 cmd = &cmdiocb->iocb;
5457 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5458 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5459 rdp_context->rx_id = cmd->ulpContext;
5460 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5461 if (lpfc_get_rdp_info(phba, rdp_context)) {
5462 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5463 "2423 Unable to send mailbox");
5464 kfree(rdp_context);
5465 rjt_err = LSRJT_UNABLE_TPC;
5466 lpfc_nlp_put(ndlp);
5467 goto error;
5468 }
5469
5470 return 0;
5471
5472rjt_logerr:
5473 rjt_err = LSRJT_LOGICAL_ERR;
5474
5475error:
5476 memset(&stat, 0, sizeof(stat));
5477 stat.un.b.lsRjtRsnCode = rjt_err;
5478 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5479 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5480 return 1;
5481}
5482
5483
James Smart8b017a32015-05-21 13:55:18 -04005484static void
5485lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5486{
5487 MAILBOX_t *mb;
5488 IOCB_t *icmd;
5489 uint8_t *pcmd;
5490 struct lpfc_iocbq *elsiocb;
5491 struct lpfc_nodelist *ndlp;
5492 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005493 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005494 struct lpfc_lcb_context *lcb_context;
5495 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005496 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005497 int rc;
5498
5499 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005500 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5501 ndlp = lcb_context->ndlp;
5502 pmb->context1 = NULL;
5503 pmb->context2 = NULL;
5504
James Smart481ad962015-05-22 10:42:35 -04005505 shdr = (union lpfc_sli4_cfg_shdr *)
5506 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5507 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5508 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5509
5510 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5511 "0194 SET_BEACON_CONFIG mailbox "
5512 "completed with status x%x add_status x%x,"
5513 " mbx status x%x\n",
5514 shdr_status, shdr_add_status, mb->mbxStatus);
5515
5516 if (mb->mbxStatus && !(shdr_status &&
5517 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005518 mempool_free(pmb, phba->mbox_mem_pool);
5519 goto error;
5520 }
5521
5522 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005523 cmdsize = sizeof(struct fc_lcb_res_frame);
5524 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5525 lpfc_max_els_tries, ndlp,
5526 ndlp->nlp_DID, ELS_CMD_ACC);
5527
5528 /* Decrement the ndlp reference count from previous mbox command */
5529 lpfc_nlp_put(ndlp);
5530
5531 if (!elsiocb)
5532 goto free_lcb_context;
5533
5534 lcb_res = (struct fc_lcb_res_frame *)
5535 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5536
5537 icmd = &elsiocb->iocb;
5538 icmd->ulpContext = lcb_context->rx_id;
5539 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5540
5541 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5542 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5543 lcb_res->lcb_sub_command = lcb_context->sub_command;
5544 lcb_res->lcb_type = lcb_context->type;
5545 lcb_res->lcb_frequency = lcb_context->frequency;
5546 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5547 phba->fc_stat.elsXmitACC++;
5548 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5549 if (rc == IOCB_ERROR)
5550 lpfc_els_free_iocb(phba, elsiocb);
5551
5552 kfree(lcb_context);
5553 return;
5554
5555error:
5556 cmdsize = sizeof(struct fc_lcb_res_frame);
5557 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5558 lpfc_max_els_tries, ndlp,
5559 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5560 lpfc_nlp_put(ndlp);
5561 if (!elsiocb)
5562 goto free_lcb_context;
5563
5564 icmd = &elsiocb->iocb;
5565 icmd->ulpContext = lcb_context->rx_id;
5566 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5567 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5568
5569 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5570 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5571 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5572
5573 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5574 phba->fc_stat.elsXmitLSRJT++;
5575 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5576 if (rc == IOCB_ERROR)
5577 lpfc_els_free_iocb(phba, elsiocb);
5578free_lcb_context:
5579 kfree(lcb_context);
5580}
5581
5582static int
5583lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5584 struct lpfc_lcb_context *lcb_context,
5585 uint32_t beacon_state)
5586{
5587 struct lpfc_hba *phba = vport->phba;
5588 LPFC_MBOXQ_t *mbox = NULL;
5589 uint32_t len;
5590 int rc;
5591
5592 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5593 if (!mbox)
5594 return 1;
5595
5596 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5597 sizeof(struct lpfc_sli4_cfg_mhdr);
5598 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5599 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5600 LPFC_SLI4_MBX_EMBED);
5601 mbox->context1 = (void *)lcb_context;
5602 mbox->vport = phba->pport;
5603 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5604 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5605 phba->sli4_hba.physical_port);
5606 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5607 beacon_state);
5608 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5609 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5610 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5611 if (rc == MBX_NOT_FINISHED) {
5612 mempool_free(mbox, phba->mbox_mem_pool);
5613 return 1;
5614 }
5615
5616 return 0;
5617}
5618
5619
5620/**
5621 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5622 * @vport: pointer to a host virtual N_Port data structure.
5623 * @cmdiocb: pointer to lpfc command iocb data structure.
5624 * @ndlp: pointer to a node-list data structure.
5625 *
5626 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5627 * First, the payload of the unsolicited LCB is checked.
5628 * Then based on Subcommand beacon will either turn on or off.
5629 *
5630 * Return code
5631 * 0 - Sent the acc response
5632 * 1 - Sent the reject response.
5633 **/
5634static int
5635lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5636 struct lpfc_nodelist *ndlp)
5637{
5638 struct lpfc_hba *phba = vport->phba;
5639 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04005640 uint8_t *lp;
5641 struct fc_lcb_request_frame *beacon;
5642 struct lpfc_lcb_context *lcb_context;
5643 uint8_t state, rjt_err;
5644 struct ls_rjt stat;
5645
James Smart8b017a32015-05-21 13:55:18 -04005646 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5647 lp = (uint8_t *)pcmd->virt;
5648 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5649
5650 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5651 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5652 "type x%x frequency %x duration x%x\n",
5653 lp[0], lp[1], lp[2],
5654 beacon->lcb_command,
5655 beacon->lcb_sub_command,
5656 beacon->lcb_type,
5657 beacon->lcb_frequency,
5658 be16_to_cpu(beacon->lcb_duration));
5659
5660 if (phba->sli_rev < LPFC_SLI_REV4 ||
5661 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5662 LPFC_SLI_INTF_IF_TYPE_2)) {
5663 rjt_err = LSRJT_CMD_UNSUPPORTED;
5664 goto rjt;
5665 }
James Smart8b017a32015-05-21 13:55:18 -04005666
5667 if (phba->hba_flag & HBA_FCOE_MODE) {
5668 rjt_err = LSRJT_CMD_UNSUPPORTED;
5669 goto rjt;
5670 }
5671 if (beacon->lcb_frequency == 0) {
5672 rjt_err = LSRJT_CMD_UNSUPPORTED;
5673 goto rjt;
5674 }
5675 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5676 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5677 rjt_err = LSRJT_CMD_UNSUPPORTED;
5678 goto rjt;
5679 }
5680 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5681 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5682 rjt_err = LSRJT_CMD_UNSUPPORTED;
5683 goto rjt;
5684 }
5685 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5686 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5687 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5688 rjt_err = LSRJT_CMD_UNSUPPORTED;
5689 goto rjt;
5690 }
5691 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5692 rjt_err = LSRJT_CMD_UNSUPPORTED;
5693 goto rjt;
5694 }
5695
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305696 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5697 if (!lcb_context) {
5698 rjt_err = LSRJT_UNABLE_TPC;
5699 goto rjt;
5700 }
5701
James Smart8b017a32015-05-21 13:55:18 -04005702 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5703 lcb_context->sub_command = beacon->lcb_sub_command;
5704 lcb_context->type = beacon->lcb_type;
5705 lcb_context->frequency = beacon->lcb_frequency;
5706 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5707 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5708 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5709 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5710 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5711 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305712 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04005713 lpfc_nlp_put(ndlp);
5714 rjt_err = LSRJT_UNABLE_TPC;
5715 goto rjt;
5716 }
5717 return 0;
5718rjt:
5719 memset(&stat, 0, sizeof(stat));
5720 stat.un.b.lsRjtRsnCode = rjt_err;
5721 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5722 return 1;
5723}
5724
5725
James Smarte59058c2008-08-24 21:49:00 -04005726/**
James Smart3621a712009-04-06 18:47:14 -04005727 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005728 * @vport: pointer to a host virtual N_Port data structure.
5729 *
5730 * This routine cleans up any Registration State Change Notification
5731 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5732 * @vport together with the host_lock is used to prevent multiple thread
5733 * trying to access the RSCN array on a same @vport at the same time.
5734 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005735void
James Smart2e0fef82007-06-17 19:56:36 -05005736lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005737{
James Smart2e0fef82007-06-17 19:56:36 -05005738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5739 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005740 int i;
5741
James Smart7f5f3d02008-02-08 18:50:14 -05005742 spin_lock_irq(shost->host_lock);
5743 if (vport->fc_rscn_flush) {
5744 /* Another thread is walking fc_rscn_id_list on this vport */
5745 spin_unlock_irq(shost->host_lock);
5746 return;
5747 }
5748 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5749 vport->fc_rscn_flush = 1;
5750 spin_unlock_irq(shost->host_lock);
5751
James Smart2e0fef82007-06-17 19:56:36 -05005752 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005753 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005754 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005755 }
James Smart2e0fef82007-06-17 19:56:36 -05005756 spin_lock_irq(shost->host_lock);
5757 vport->fc_rscn_id_cnt = 0;
5758 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5759 spin_unlock_irq(shost->host_lock);
5760 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005761 /* Indicate we are done walking this fc_rscn_id_list */
5762 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005763}
5764
James Smarte59058c2008-08-24 21:49:00 -04005765/**
James Smart3621a712009-04-06 18:47:14 -04005766 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005767 * @vport: pointer to a host virtual N_Port data structure.
5768 * @did: remote destination port identifier.
5769 *
5770 * This routine checks whether there is any pending Registration State
5771 * Configuration Notification (RSCN) to a @did on @vport.
5772 *
5773 * Return code
5774 * None zero - The @did matched with a pending rscn
5775 * 0 - not able to match @did with a pending rscn
5776 **/
dea31012005-04-17 16:05:31 -05005777int
James Smart2e0fef82007-06-17 19:56:36 -05005778lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005779{
5780 D_ID ns_did;
5781 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005782 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005783 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005784 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005785
5786 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005787
5788 /* Never match fabric nodes for RSCNs */
5789 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005790 return 0;
dea31012005-04-17 16:05:31 -05005791
5792 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005793 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005794 return did;
dea31012005-04-17 16:05:31 -05005795
James Smart7f5f3d02008-02-08 18:50:14 -05005796 spin_lock_irq(shost->host_lock);
5797 if (vport->fc_rscn_flush) {
5798 /* Another thread is walking fc_rscn_id_list on this vport */
5799 spin_unlock_irq(shost->host_lock);
5800 return 0;
5801 }
5802 /* Indicate we are walking fc_rscn_id_list on this vport */
5803 vport->fc_rscn_flush = 1;
5804 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005805 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005806 lp = vport->fc_rscn_id_list[i]->virt;
5807 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5808 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005809 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005810 rscn_did.un.word = be32_to_cpu(*lp++);
5811 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005812 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5813 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005814 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5815 && (ns_did.un.b.area == rscn_did.un.b.area)
5816 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005817 goto return_did_out;
dea31012005-04-17 16:05:31 -05005818 break;
James Smarteaf15d52008-12-04 22:39:29 -05005819 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005820 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5821 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005822 goto return_did_out;
dea31012005-04-17 16:05:31 -05005823 break;
James Smarteaf15d52008-12-04 22:39:29 -05005824 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005825 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005826 goto return_did_out;
dea31012005-04-17 16:05:31 -05005827 break;
James Smarteaf15d52008-12-04 22:39:29 -05005828 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005829 goto return_did_out;
dea31012005-04-17 16:05:31 -05005830 }
5831 }
James Smart92d7f7b2007-06-17 19:56:38 -05005832 }
James Smart7f5f3d02008-02-08 18:50:14 -05005833 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5834 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005835 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005836return_did_out:
5837 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5838 vport->fc_rscn_flush = 0;
5839 return did;
dea31012005-04-17 16:05:31 -05005840}
5841
James Smarte59058c2008-08-24 21:49:00 -04005842/**
James Smart3621a712009-04-06 18:47:14 -04005843 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005844 * @vport: pointer to a host virtual N_Port data structure.
5845 *
5846 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5847 * state machine for a @vport's nodes that are with pending RSCN (Registration
5848 * State Change Notification).
5849 *
5850 * Return code
5851 * 0 - Successful (currently alway return 0)
5852 **/
dea31012005-04-17 16:05:31 -05005853static int
James Smart2e0fef82007-06-17 19:56:36 -05005854lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005855{
James Smart685f0bf2007-04-25 09:53:08 -04005856 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005857
James Smart0d2b6b82008-06-14 22:52:47 -04005858 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005859 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005860 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005861 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5862 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005863 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07005864
5865 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08005866 if (vport->phba->nvmet_support)
5867 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07005868
James Smart2e0fef82007-06-17 19:56:36 -05005869 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005870 NLP_EVT_DEVICE_RECOVERY);
5871 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005872 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005873 return 0;
dea31012005-04-17 16:05:31 -05005874}
5875
James Smarte59058c2008-08-24 21:49:00 -04005876/**
James Smart3621a712009-04-06 18:47:14 -04005877 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005878 * @vport: pointer to a host virtual N_Port data structure.
5879 * @cmdiocb: pointer to lpfc command iocb data structure.
5880 *
5881 * lpfc_send_rscn_event sends an RSCN netlink event to management
5882 * applications.
5883 */
5884static void
5885lpfc_send_rscn_event(struct lpfc_vport *vport,
5886 struct lpfc_iocbq *cmdiocb)
5887{
5888 struct lpfc_dmabuf *pcmd;
5889 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5890 uint32_t *payload_ptr;
5891 uint32_t payload_len;
5892 struct lpfc_rscn_event_header *rscn_event_data;
5893
5894 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5895 payload_ptr = (uint32_t *) pcmd->virt;
5896 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5897
5898 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5899 payload_len, GFP_KERNEL);
5900 if (!rscn_event_data) {
5901 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5902 "0147 Failed to allocate memory for RSCN event\n");
5903 return;
5904 }
5905 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5906 rscn_event_data->payload_length = payload_len;
5907 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5908 payload_len);
5909
5910 fc_host_post_vendor_event(shost,
5911 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04005912 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05005913 (char *)rscn_event_data,
5914 LPFC_NL_VENDOR_ID);
5915
5916 kfree(rscn_event_data);
5917}
5918
5919/**
James Smart3621a712009-04-06 18:47:14 -04005920 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04005921 * @vport: pointer to a host virtual N_Port data structure.
5922 * @cmdiocb: pointer to lpfc command iocb data structure.
5923 * @ndlp: pointer to a node-list data structure.
5924 *
5925 * This routine processes an unsolicited RSCN (Registration State Change
5926 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5927 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5928 * discover state machine is about to begin discovery, it just accepts the
5929 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5930 * contains N_Port IDs for other vports on this HBA, it just accepts the
5931 * RSCN and ignore processing it. If the state machine is in the recovery
5932 * state, the fc_rscn_id_list of this @vport is walked and the
5933 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5934 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5935 * routine is invoked to handle the RSCN event.
5936 *
5937 * Return code
5938 * 0 - Just sent the acc response
5939 * 1 - Sent the acc response and waited for name server completion
5940 **/
dea31012005-04-17 16:05:31 -05005941static int
James Smart2e0fef82007-06-17 19:56:36 -05005942lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005943 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005944{
James Smart2e0fef82007-06-17 19:56:36 -05005945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5946 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005947 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005948 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05005949 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005950 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05005951 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04005952 int i;
dea31012005-04-17 16:05:31 -05005953
dea31012005-04-17 16:05:31 -05005954 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5955 lp = (uint32_t *) pcmd->virt;
5956
James Smart92d7f7b2007-06-17 19:56:38 -05005957 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5958 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005959 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04005960 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5961 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05005962 vport->fc_flag, payload_len, *lp,
5963 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05005964
5965 /* Send an RSCN event to the management application */
5966 lpfc_send_rscn_event(vport, cmdiocb);
5967
James Smartd2873e42006-08-18 17:46:43 -04005968 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05005969 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04005970 FCH_EVT_RSCN, lp[i]);
5971
dea31012005-04-17 16:05:31 -05005972 /* If we are about to begin discovery, just ACC the RSCN.
5973 * Discovery processing will satisfy it.
5974 */
James Smart2e0fef82007-06-17 19:56:36 -05005975 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05005976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5977 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5978 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5979
James Smart51ef4c22007-08-02 11:10:31 -04005980 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005981 return 0;
dea31012005-04-17 16:05:31 -05005982 }
5983
James Smart92d7f7b2007-06-17 19:56:38 -05005984 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5985 * just ACC and ignore it.
5986 */
5987 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04005988 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05005989 i = payload_len;
5990 datap = lp;
5991 while (i > 0) {
5992 nportid = *datap++;
5993 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5994 i -= sizeof(uint32_t);
5995 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04005996 if (lpfc_find_vport_by_did(phba, nportid))
5997 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05005998 }
5999 if (rscn_id == hba_id) {
6000 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04006001 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006002 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04006003 "Data: x%x x%x x%x x%x\n",
6004 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05006005 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05006006 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6007 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6008 ndlp->nlp_DID, vport->port_state,
6009 ndlp->nlp_flag);
6010
James Smart92d7f7b2007-06-17 19:56:38 -05006011 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006012 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05006013 return 0;
6014 }
6015 }
6016
James Smart7f5f3d02008-02-08 18:50:14 -05006017 spin_lock_irq(shost->host_lock);
6018 if (vport->fc_rscn_flush) {
6019 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05006020 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05006021 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04006022 /* Send back ACC */
6023 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05006024 return 0;
6025 }
6026 /* Indicate we are walking fc_rscn_id_list on this vport */
6027 vport->fc_rscn_flush = 1;
6028 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006029 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05006030 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05006031 /* If we are already processing an RSCN, save the received
6032 * RSCN payload buffer, cmdiocb->context2 to process later.
6033 */
James Smart2e0fef82007-06-17 19:56:36 -05006034 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05006035 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6036 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6037 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6038
James Smart09372822008-01-11 01:52:54 -05006039 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006040 vport->fc_flag |= FC_RSCN_DEFERRED;
6041 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05006042 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05006043 vport->fc_flag |= FC_RSCN_MODE;
6044 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006045 if (rscn_cnt) {
6046 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6047 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6048 }
6049 if ((rscn_cnt) &&
6050 (payload_len + length <= LPFC_BPL_SIZE)) {
6051 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05006052 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05006053 memcpy(((uint8_t *)cmd) + length, lp,
6054 payload_len);
6055 } else {
6056 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6057 vport->fc_rscn_id_cnt++;
6058 /* If we zero, cmdiocb->context2, the calling
6059 * routine will not try to free it.
6060 */
6061 cmdiocb->context2 = NULL;
6062 }
dea31012005-04-17 16:05:31 -05006063 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006064 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6065 "0235 Deferred RSCN "
6066 "Data: x%x x%x x%x\n",
6067 vport->fc_rscn_id_cnt, vport->fc_flag,
6068 vport->port_state);
dea31012005-04-17 16:05:31 -05006069 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006070 vport->fc_flag |= FC_RSCN_DISCOVERY;
6071 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006072 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006073 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6074 "0234 ReDiscovery RSCN "
6075 "Data: x%x x%x x%x\n",
6076 vport->fc_rscn_id_cnt, vport->fc_flag,
6077 vport->port_state);
dea31012005-04-17 16:05:31 -05006078 }
James Smart7f5f3d02008-02-08 18:50:14 -05006079 /* Indicate we are done walking fc_rscn_id_list on this vport */
6080 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006081 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006082 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006083 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006084 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05006085 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006086 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05006087 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006088 return 0;
dea31012005-04-17 16:05:31 -05006089 }
James Smart858c9f62007-06-17 19:56:39 -05006090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6091 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6092 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6093
James Smart2e0fef82007-06-17 19:56:36 -05006094 spin_lock_irq(shost->host_lock);
6095 vport->fc_flag |= FC_RSCN_MODE;
6096 spin_unlock_irq(shost->host_lock);
6097 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006098 /* Indicate we are done walking fc_rscn_id_list on this vport */
6099 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006100 /*
6101 * If we zero, cmdiocb->context2, the calling routine will
6102 * not try to free it.
6103 */
6104 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006105 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006106 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006107 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006108 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006109 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006110 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006111}
6112
James Smarte59058c2008-08-24 21:49:00 -04006113/**
James Smart3621a712009-04-06 18:47:14 -04006114 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04006115 * @vport: pointer to a host virtual N_Port data structure.
6116 *
6117 * This routine handles the Registration State Configuration Notification
6118 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6119 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6120 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6121 * NameServer shall be issued. If CT command to the NameServer fails to be
6122 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6123 * RSCN activities with the @vport.
6124 *
6125 * Return code
6126 * 0 - Cleaned up rscn on the @vport
6127 * 1 - Wait for plogi to name server before proceed
6128 **/
dea31012005-04-17 16:05:31 -05006129int
James Smart2e0fef82007-06-17 19:56:36 -05006130lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006131{
6132 struct lpfc_nodelist *ndlp;
6133
James Smart92d7f7b2007-06-17 19:56:38 -05006134 /* Ignore RSCN if the port is being torn down. */
6135 if (vport->load_flag & FC_UNLOADING) {
6136 lpfc_els_flush_rscn(vport);
6137 return 0;
6138 }
6139
dea31012005-04-17 16:05:31 -05006140 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05006141 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006142
6143 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04006144 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6145 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6146 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6147 vport->port_state);
dea31012005-04-17 16:05:31 -05006148
6149 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05006150 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05006151 vport->num_disc_nodes = 0;
6152
James Smart2e0fef82007-06-17 19:56:36 -05006153 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006154 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6155 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07006156 /* Good ndlp, issue CT Request to NameServer. Need to
6157 * know how many gidfts were issued. If none, then just
6158 * flush the RSCN. Otherwise, the outstanding requests
6159 * need to complete.
6160 */
James Smarta0f2d3e2017-02-12 13:52:31 -08006161 vport->gidft_inp = 0;
James Smart1c5b12f2017-04-21 16:05:03 -07006162 if (lpfc_issue_gidft(vport) > 0)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006163 return 1;
dea31012005-04-17 16:05:31 -05006164 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07006165 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05006166 if (ndlp) {
6167 ndlp = lpfc_enable_node(vport, ndlp,
6168 NLP_STE_PLOGI_ISSUE);
6169 if (!ndlp) {
6170 lpfc_els_flush_rscn(vport);
6171 return 0;
6172 }
6173 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05006174 } else {
James Smart9d3d3402017-04-21 16:05:00 -07006175 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006176 if (!ndlp) {
6177 lpfc_els_flush_rscn(vport);
6178 return 0;
6179 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006180 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006181 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05006182 }
James Smarte47c9092008-02-08 18:49:26 -05006183 ndlp->nlp_type |= NLP_FABRIC;
6184 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6185 /* Wait for NameServer login cmpl before we can
6186 * continue
6187 */
6188 return 1;
dea31012005-04-17 16:05:31 -05006189 }
6190
James Smart2e0fef82007-06-17 19:56:36 -05006191 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006192 return 0;
dea31012005-04-17 16:05:31 -05006193}
6194
James Smarte59058c2008-08-24 21:49:00 -04006195/**
James Smart3621a712009-04-06 18:47:14 -04006196 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04006197 * @vport: pointer to a host virtual N_Port data structure.
6198 * @cmdiocb: pointer to lpfc command iocb data structure.
6199 * @ndlp: pointer to a node-list data structure.
6200 *
6201 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6202 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6203 * point topology. As an unsolicited FLOGI should not be received in a loop
6204 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6205 * lpfc_check_sparm() routine is invoked to check the parameters in the
6206 * unsolicited FLOGI. If parameters validation failed, the routine
6207 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6208 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6209 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6210 * will initiate PLOGI. The higher lexicographical value party shall has
6211 * higher priority (as the winning port) and will initiate PLOGI and
6212 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6213 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6214 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6215 *
6216 * Return code
6217 * 0 - Successfully processed the unsolicited flogi
6218 * 1 - Failed to process the unsolicited flogi
6219 **/
dea31012005-04-17 16:05:31 -05006220static int
James Smart2e0fef82007-06-17 19:56:36 -05006221lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006222 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006223{
James Smart2e0fef82007-06-17 19:56:36 -05006224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6225 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006226 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6227 uint32_t *lp = (uint32_t *) pcmd->virt;
6228 IOCB_t *icmd = &cmdiocb->iocb;
6229 struct serv_parm *sp;
6230 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05006231 uint32_t cmd, did;
6232 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04006233 uint32_t fc_flag = 0;
6234 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05006235
6236 cmd = *lp++;
6237 sp = (struct serv_parm *) lp;
6238
6239 /* FLOGI received */
6240
James Smart2e0fef82007-06-17 19:56:36 -05006241 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006242
James Smart76a95d72010-11-20 23:11:48 -05006243 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006244 /* We should never receive a FLOGI in loop mode, ignore it */
6245 did = icmd->un.elsreq64.remoteID;
6246
6247 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6248 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04006249 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6250 "0113 An FLOGI ELS command x%x was "
6251 "received from DID x%x in Loop Mode\n",
6252 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006253 return 1;
dea31012005-04-17 16:05:31 -05006254 }
6255
James Smartd6de08c2015-12-16 18:11:53 -05006256 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05006257
James Smartd6de08c2015-12-16 18:11:53 -05006258 /*
6259 * If our portname is greater than the remote portname,
6260 * then we initiate Nport login.
6261 */
6262
6263 rc = memcmp(&vport->fc_portname, &sp->portName,
6264 sizeof(struct lpfc_name));
6265
6266 if (!rc) {
6267 if (phba->sli_rev < LPFC_SLI_REV4) {
6268 mbox = mempool_alloc(phba->mbox_mem_pool,
6269 GFP_KERNEL);
6270 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006271 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05006272 lpfc_linkdown(phba);
6273 lpfc_init_link(phba, mbox,
6274 phba->cfg_topology,
6275 phba->cfg_link_speed);
6276 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6277 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6278 mbox->vport = vport;
6279 rc = lpfc_sli_issue_mbox(phba, mbox,
6280 MBX_NOWAIT);
6281 lpfc_set_loopback_flag(phba);
6282 if (rc == MBX_NOT_FINISHED)
6283 mempool_free(mbox, phba->mbox_mem_pool);
6284 return 1;
6285 }
James Smart939723a2012-05-09 21:19:03 -04006286
James Smartd6de08c2015-12-16 18:11:53 -05006287 /* abort the flogi coming back to ourselves
6288 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04006289 */
James Smartd6de08c2015-12-16 18:11:53 -05006290 lpfc_els_abort_flogi(phba);
6291 return 0;
6292
6293 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05006294 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05006295 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05006296 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04006297
James Smartd6de08c2015-12-16 18:11:53 -05006298 /* If we have the high WWPN we can assign our own
6299 * myDID; otherwise, we have to WAIT for a PLOGI
6300 * from the remote NPort to find out what it
6301 * will be.
James Smart939723a2012-05-09 21:19:03 -04006302 */
James Smartd6de08c2015-12-16 18:11:53 -05006303 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05006304 } else {
James Smartd6de08c2015-12-16 18:11:53 -05006305 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05006306 }
6307
James Smartd6de08c2015-12-16 18:11:53 -05006308 /*
6309 * The vport state should go to LPFC_FLOGI only
6310 * AFTER we issue a FLOGI, not receive one.
6311 */
6312 spin_lock_irq(shost->host_lock);
6313 fc_flag = vport->fc_flag;
6314 port_state = vport->port_state;
6315 vport->fc_flag |= FC_PT2PT;
6316 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6317 spin_unlock_irq(shost->host_lock);
6318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6319 "3311 Rcv Flogi PS x%x new PS x%x "
6320 "fc_flag x%x new fc_flag x%x\n",
6321 port_state, vport->port_state,
6322 fc_flag, vport->fc_flag);
6323
6324 /*
6325 * We temporarily set fc_myDID to make it look like we are
6326 * a Fabric. This is done just so we end up with the right
6327 * did / sid on the FLOGI ACC rsp.
6328 */
6329 did = vport->fc_myDID;
6330 vport->fc_myDID = Fabric_DID;
6331
6332 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04006333
dea31012005-04-17 16:05:31 -05006334 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05006335 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006336
James Smart939723a2012-05-09 21:19:03 -04006337 /* Now lets put fc_myDID back to what its supposed to be */
6338 vport->fc_myDID = did;
6339
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006340 return 0;
dea31012005-04-17 16:05:31 -05006341}
6342
James Smarte59058c2008-08-24 21:49:00 -04006343/**
James Smart3621a712009-04-06 18:47:14 -04006344 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04006345 * @vport: pointer to a host virtual N_Port data structure.
6346 * @cmdiocb: pointer to lpfc command iocb data structure.
6347 * @ndlp: pointer to a node-list data structure.
6348 *
6349 * This routine processes Request Node Identification Data (RNID) IOCB
6350 * received as an ELS unsolicited event. Only when the RNID specified format
6351 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6352 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6353 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6354 * rejected by invoking the lpfc_els_rsp_reject() routine.
6355 *
6356 * Return code
6357 * 0 - Successfully processed rnid iocb (currently always return 0)
6358 **/
dea31012005-04-17 16:05:31 -05006359static int
James Smart2e0fef82007-06-17 19:56:36 -05006360lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6361 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006362{
6363 struct lpfc_dmabuf *pcmd;
6364 uint32_t *lp;
dea31012005-04-17 16:05:31 -05006365 RNID *rn;
6366 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04006367 uint32_t cmd;
dea31012005-04-17 16:05:31 -05006368
dea31012005-04-17 16:05:31 -05006369 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6370 lp = (uint32_t *) pcmd->virt;
6371
6372 cmd = *lp++;
6373 rn = (RNID *) lp;
6374
6375 /* RNID received */
6376
6377 switch (rn->Format) {
6378 case 0:
6379 case RNID_TOPOLOGY_DISC:
6380 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05006381 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006382 break;
6383 default:
6384 /* Reject this request because format not supported */
6385 stat.un.b.lsRjtRsvd0 = 0;
6386 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6387 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6388 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006389 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6390 NULL);
dea31012005-04-17 16:05:31 -05006391 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006392 return 0;
dea31012005-04-17 16:05:31 -05006393}
6394
James Smarte59058c2008-08-24 21:49:00 -04006395/**
James Smart12265f62010-10-22 11:05:53 -04006396 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6397 * @vport: pointer to a host virtual N_Port data structure.
6398 * @cmdiocb: pointer to lpfc command iocb data structure.
6399 * @ndlp: pointer to a node-list data structure.
6400 *
6401 * Return code
6402 * 0 - Successfully processed echo iocb (currently always return 0)
6403 **/
6404static int
6405lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6406 struct lpfc_nodelist *ndlp)
6407{
6408 uint8_t *pcmd;
6409
6410 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6411
6412 /* skip over first word of echo command to find echo data */
6413 pcmd += sizeof(uint32_t);
6414
6415 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6416 return 0;
6417}
6418
6419/**
James Smart3621a712009-04-06 18:47:14 -04006420 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04006421 * @vport: pointer to a host virtual N_Port data structure.
6422 * @cmdiocb: pointer to lpfc command iocb data structure.
6423 * @ndlp: pointer to a node-list data structure.
6424 *
6425 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6426 * received as an ELS unsolicited event. Currently, this function just invokes
6427 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6428 *
6429 * Return code
6430 * 0 - Successfully processed lirr iocb (currently always return 0)
6431 **/
dea31012005-04-17 16:05:31 -05006432static int
James Smart2e0fef82007-06-17 19:56:36 -05006433lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6434 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006435{
6436 struct ls_rjt stat;
6437
6438 /* For now, unconditionally reject this command */
6439 stat.un.b.lsRjtRsvd0 = 0;
6440 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6441 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6442 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006443 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006444 return 0;
6445}
6446
James Smarte59058c2008-08-24 21:49:00 -04006447/**
James Smart5ffc2662009-11-18 15:39:44 -05006448 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6449 * @vport: pointer to a host virtual N_Port data structure.
6450 * @cmdiocb: pointer to lpfc command iocb data structure.
6451 * @ndlp: pointer to a node-list data structure.
6452 *
6453 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6454 * received as an ELS unsolicited event. A request to RRQ shall only
6455 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6456 * Nx_Port N_Port_ID of the target Exchange is the same as the
6457 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6458 * not accepted, an LS_RJT with reason code "Unable to perform
6459 * command request" and reason code explanation "Invalid Originator
6460 * S_ID" shall be returned. For now, we just unconditionally accept
6461 * RRQ from the target.
6462 **/
6463static void
6464lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6465 struct lpfc_nodelist *ndlp)
6466{
6467 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05006468 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6469 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05006470}
6471
6472/**
James Smart12265f62010-10-22 11:05:53 -04006473 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6474 * @phba: pointer to lpfc hba data structure.
6475 * @pmb: pointer to the driver internal queue element for mailbox command.
6476 *
6477 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6478 * mailbox command. This callback function is to actually send the Accept
6479 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6480 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6481 * mailbox command, constructs the RPS response with the link statistics
6482 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6483 * response to the RPS.
6484 *
6485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6487 * will be stored into the context1 field of the IOCB for the completion
6488 * callback function to the RPS Accept Response ELS IOCB command.
6489 *
6490 **/
6491static void
6492lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6493{
6494 MAILBOX_t *mb;
6495 IOCB_t *icmd;
6496 struct RLS_RSP *rls_rsp;
6497 uint8_t *pcmd;
6498 struct lpfc_iocbq *elsiocb;
6499 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006500 uint16_t oxid;
6501 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006502 uint32_t cmdsize;
6503
6504 mb = &pmb->u.mb;
6505
6506 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006507 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6508 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006509 pmb->context1 = NULL;
6510 pmb->context2 = NULL;
6511
6512 if (mb->mbxStatus) {
6513 mempool_free(pmb, phba->mbox_mem_pool);
6514 return;
6515 }
6516
6517 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006518 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6519 lpfc_max_els_tries, ndlp,
6520 ndlp->nlp_DID, ELS_CMD_ACC);
6521
6522 /* Decrement the ndlp reference count from previous mbox command */
6523 lpfc_nlp_put(ndlp);
6524
James Smart37db57e2012-05-09 21:17:16 -04006525 if (!elsiocb) {
6526 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006527 return;
James Smart37db57e2012-05-09 21:17:16 -04006528 }
James Smart12265f62010-10-22 11:05:53 -04006529
6530 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006531 icmd->ulpContext = rxid;
6532 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006533
6534 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6535 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6536 pcmd += sizeof(uint32_t); /* Skip past command */
6537 rls_rsp = (struct RLS_RSP *)pcmd;
6538
6539 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6540 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6541 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6542 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6543 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6544 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006545 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006546 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6547 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6548 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6549 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6550 elsiocb->iotag, elsiocb->iocb.ulpContext,
6551 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6552 ndlp->nlp_rpi);
6553 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6554 phba->fc_stat.elsXmitACC++;
6555 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6556 lpfc_els_free_iocb(phba, elsiocb);
6557}
6558
6559/**
James Smart3621a712009-04-06 18:47:14 -04006560 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006561 * @phba: pointer to lpfc hba data structure.
6562 * @pmb: pointer to the driver internal queue element for mailbox command.
6563 *
6564 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6565 * mailbox command. This callback function is to actually send the Accept
6566 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6567 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6568 * mailbox command, constructs the RPS response with the link statistics
6569 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6570 * response to the RPS.
6571 *
6572 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6573 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6574 * will be stored into the context1 field of the IOCB for the completion
6575 * callback function to the RPS Accept Response ELS IOCB command.
6576 *
6577 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006578static void
James Smart329f9bc2007-04-25 09:53:01 -04006579lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006580{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006581 MAILBOX_t *mb;
6582 IOCB_t *icmd;
6583 RPS_RSP *rps_rsp;
6584 uint8_t *pcmd;
6585 struct lpfc_iocbq *elsiocb;
6586 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006587 uint16_t status;
6588 uint16_t oxid;
6589 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006590 uint32_t cmdsize;
6591
James Smart04c68492009-05-22 14:52:52 -04006592 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006593
6594 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006595 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6596 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006597 pmb->context1 = NULL;
6598 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006599
6600 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006601 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006602 return;
6603 }
6604
6605 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006606 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006607 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6608 lpfc_max_els_tries, ndlp,
6609 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006610
6611 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006612 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006613
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006614 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006615 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006616
6617 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006618 icmd->ulpContext = rxid;
6619 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006620
6621 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6622 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006623 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006624 rps_rsp = (RPS_RSP *)pcmd;
6625
James Smart76a95d72010-11-20 23:11:48 -05006626 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006627 status = 0x10;
6628 else
6629 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006630 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006631 status |= 0x4;
6632
6633 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006634 rps_rsp->portStatus = cpu_to_be16(status);
6635 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6636 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6637 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6638 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6639 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6640 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006641 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006642 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6643 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6644 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6645 elsiocb->iotag, elsiocb->iocb.ulpContext,
6646 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6647 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006648 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006649 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006650 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006651 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006652 return;
6653}
6654
James Smarte59058c2008-08-24 21:49:00 -04006655/**
James Smart12265f62010-10-22 11:05:53 -04006656 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6657 * @vport: pointer to a host virtual N_Port data structure.
6658 * @cmdiocb: pointer to lpfc command iocb data structure.
6659 * @ndlp: pointer to a node-list data structure.
6660 *
6661 * This routine processes Read Port Status (RPL) IOCB received as an
6662 * ELS unsolicited event. It first checks the remote port state. If the
6663 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6664 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6665 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6666 * for reading the HBA link statistics. It is for the callback function,
6667 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6668 * to actually sending out RPL Accept (ACC) response.
6669 *
6670 * Return codes
6671 * 0 - Successfully processed rls iocb (currently always return 0)
6672 **/
6673static int
6674lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6675 struct lpfc_nodelist *ndlp)
6676{
6677 struct lpfc_hba *phba = vport->phba;
6678 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04006679 struct ls_rjt stat;
6680
6681 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6682 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6683 /* reject the unsolicited RPS request and done with it */
6684 goto reject_out;
6685
James Smart12265f62010-10-22 11:05:53 -04006686 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6687 if (mbox) {
6688 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006689 mbox->context1 = (void *)((unsigned long)
6690 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6691 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006692 mbox->context2 = lpfc_nlp_get(ndlp);
6693 mbox->vport = vport;
6694 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6695 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6696 != MBX_NOT_FINISHED)
6697 /* Mbox completion will send ELS Response */
6698 return 0;
6699 /* Decrement reference count used for the failed mbox
6700 * command.
6701 */
6702 lpfc_nlp_put(ndlp);
6703 mempool_free(mbox, phba->mbox_mem_pool);
6704 }
6705reject_out:
6706 /* issue rejection response */
6707 stat.un.b.lsRjtRsvd0 = 0;
6708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6709 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6710 stat.un.b.vendorUnique = 0;
6711 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6712 return 0;
6713}
6714
6715/**
6716 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6717 * @vport: pointer to a host virtual N_Port data structure.
6718 * @cmdiocb: pointer to lpfc command iocb data structure.
6719 * @ndlp: pointer to a node-list data structure.
6720 *
6721 * This routine processes Read Timout Value (RTV) IOCB received as an
6722 * ELS unsolicited event. It first checks the remote port state. If the
6723 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6724 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6725 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6726 * Value (RTV) unsolicited IOCB event.
6727 *
6728 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6729 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6730 * will be stored into the context1 field of the IOCB for the completion
6731 * callback function to the RPS Accept Response ELS IOCB command.
6732 *
6733 * Return codes
6734 * 0 - Successfully processed rtv iocb (currently always return 0)
6735 **/
6736static int
6737lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6738 struct lpfc_nodelist *ndlp)
6739{
6740 struct lpfc_hba *phba = vport->phba;
6741 struct ls_rjt stat;
6742 struct RTV_RSP *rtv_rsp;
6743 uint8_t *pcmd;
6744 struct lpfc_iocbq *elsiocb;
6745 uint32_t cmdsize;
6746
6747
6748 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6749 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6750 /* reject the unsolicited RPS request and done with it */
6751 goto reject_out;
6752
6753 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6754 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6755 lpfc_max_els_tries, ndlp,
6756 ndlp->nlp_DID, ELS_CMD_ACC);
6757
6758 if (!elsiocb)
6759 return 1;
6760
6761 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6762 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6763 pcmd += sizeof(uint32_t); /* Skip past command */
6764
6765 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006766 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6767 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006768
6769 rtv_rsp = (struct RTV_RSP *)pcmd;
6770
6771 /* populate RTV payload */
6772 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6773 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6774 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6775 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6776 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6777
6778 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6779 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6780 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6781 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6782 "Data: x%x x%x x%x\n",
6783 elsiocb->iotag, elsiocb->iocb.ulpContext,
6784 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6785 ndlp->nlp_rpi,
6786 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6787 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6788 phba->fc_stat.elsXmitACC++;
6789 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6790 lpfc_els_free_iocb(phba, elsiocb);
6791 return 0;
6792
6793reject_out:
6794 /* issue rejection response */
6795 stat.un.b.lsRjtRsvd0 = 0;
6796 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6797 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6798 stat.un.b.vendorUnique = 0;
6799 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6800 return 0;
6801}
6802
6803/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006804 * @vport: pointer to a host virtual N_Port data structure.
6805 * @cmdiocb: pointer to lpfc command iocb data structure.
6806 * @ndlp: pointer to a node-list data structure.
6807 *
6808 * This routine processes Read Port Status (RPS) IOCB received as an
6809 * ELS unsolicited event. It first checks the remote port state. If the
6810 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6811 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6812 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6813 * for reading the HBA link statistics. It is for the callback function,
6814 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6815 * to actually sending out RPS Accept (ACC) response.
6816 *
6817 * Return codes
6818 * 0 - Successfully processed rps iocb (currently always return 0)
6819 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006820static int
James Smart2e0fef82007-06-17 19:56:36 -05006821lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6822 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006823{
James Smart2e0fef82007-06-17 19:56:36 -05006824 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006825 uint32_t *lp;
6826 uint8_t flag;
6827 LPFC_MBOXQ_t *mbox;
6828 struct lpfc_dmabuf *pcmd;
6829 RPS *rps;
6830 struct ls_rjt stat;
6831
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006832 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006833 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6834 /* reject the unsolicited RPS request and done with it */
6835 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006836
6837 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6838 lp = (uint32_t *) pcmd->virt;
6839 flag = (be32_to_cpu(*lp++) & 0xf);
6840 rps = (RPS *) lp;
6841
6842 if ((flag == 0) ||
6843 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006844 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006845 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006846
James Smart92d7f7b2007-06-17 19:56:38 -05006847 printk("Fix me....\n");
6848 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006849 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6850 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006851 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006852 mbox->context1 = (void *)((unsigned long)
6853 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6854 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006855 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006856 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006857 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006858 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006859 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006860 /* Mbox completion will send ELS Response */
6861 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006862 /* Decrement reference count used for the failed mbox
6863 * command.
6864 */
James Smart329f9bc2007-04-25 09:53:01 -04006865 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006866 mempool_free(mbox, phba->mbox_mem_pool);
6867 }
6868 }
James Smart90160e02008-08-24 21:49:45 -04006869
6870reject_out:
6871 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006872 stat.un.b.lsRjtRsvd0 = 0;
6873 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6874 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6875 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006876 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006877 return 0;
6878}
6879
James Smart19ca7602010-11-20 23:11:55 -05006880/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6881 * @vport: pointer to a host virtual N_Port data structure.
6882 * @ndlp: pointer to a node-list data structure.
6883 * @did: DID of the target.
6884 * @rrq: Pointer to the rrq struct.
6885 *
6886 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6887 * Successful the the completion handler will clear the RRQ.
6888 *
6889 * Return codes
6890 * 0 - Successfully sent rrq els iocb.
6891 * 1 - Failed to send rrq els iocb.
6892 **/
6893static int
6894lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6895 uint32_t did, struct lpfc_node_rrq *rrq)
6896{
6897 struct lpfc_hba *phba = vport->phba;
6898 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05006899 struct lpfc_iocbq *elsiocb;
6900 uint8_t *pcmd;
6901 uint16_t cmdsize;
6902 int ret;
6903
6904
6905 if (ndlp != rrq->ndlp)
6906 ndlp = rrq->ndlp;
6907 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6908 return 1;
6909
6910 /* If ndlp is not NULL, we will bump the reference count on it */
6911 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6912 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6913 ELS_CMD_RRQ);
6914 if (!elsiocb)
6915 return 1;
6916
James Smart19ca7602010-11-20 23:11:55 -05006917 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6918
6919 /* For RRQ request, remainder of payload is Exchange IDs */
6920 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6921 pcmd += sizeof(uint32_t);
6922 els_rrq = (struct RRQ *) pcmd;
6923
James Smartee0f4fe2012-05-09 21:19:14 -04006924 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05006925 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6926 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6927 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6928 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6929
6930
6931 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6932 "Issue RRQ: did:x%x",
6933 did, rrq->xritag, rrq->rxid);
6934 elsiocb->context_un.rrq = rrq;
6935 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6936 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6937
6938 if (ret == IOCB_ERROR) {
6939 lpfc_els_free_iocb(phba, elsiocb);
6940 return 1;
6941 }
6942 return 0;
6943}
6944
6945/**
6946 * lpfc_send_rrq - Sends ELS RRQ if needed.
6947 * @phba: pointer to lpfc hba data structure.
6948 * @rrq: pointer to the active rrq.
6949 *
6950 * This routine will call the lpfc_issue_els_rrq if the rrq is
6951 * still active for the xri. If this function returns a failure then
6952 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6953 *
6954 * Returns 0 Success.
6955 * 1 Failure.
6956 **/
6957int
6958lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6959{
6960 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6961 rrq->nlp_DID);
6962 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6963 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6964 rrq->nlp_DID, rrq);
6965 else
6966 return 1;
6967}
6968
James Smarte59058c2008-08-24 21:49:00 -04006969/**
James Smart3621a712009-04-06 18:47:14 -04006970 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04006971 * @vport: pointer to a host virtual N_Port data structure.
6972 * @cmdsize: size of the ELS command.
6973 * @oldiocb: pointer to the original lpfc command iocb data structure.
6974 * @ndlp: pointer to a node-list data structure.
6975 *
6976 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6977 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6978 *
6979 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6980 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6981 * will be stored into the context1 field of the IOCB for the completion
6982 * callback function to the RPL Accept Response ELS command.
6983 *
6984 * Return code
6985 * 0 - Successfully issued ACC RPL ELS command
6986 * 1 - Failed to issue ACC RPL ELS command
6987 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006988static int
James Smart2e0fef82007-06-17 19:56:36 -05006989lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6990 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006991{
James Smart2e0fef82007-06-17 19:56:36 -05006992 struct lpfc_hba *phba = vport->phba;
6993 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006994 RPL_RSP rpl_rsp;
6995 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006996 uint8_t *pcmd;
6997
James Smart2e0fef82007-06-17 19:56:36 -05006998 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6999 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007000
James Smart488d1462006-03-07 15:02:37 -05007001 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007002 return 1;
James Smart488d1462006-03-07 15:02:37 -05007003
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007004 icmd = &elsiocb->iocb;
7005 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007006 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7007 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007008
7009 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7010 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05007011 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007012 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7013 pcmd += sizeof(uint16_t);
7014
7015 /* Setup the RPL ACC payload */
7016 rpl_rsp.listLen = be32_to_cpu(1);
7017 rpl_rsp.index = 0;
7018 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007019 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7020 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007021 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007022 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007023 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04007024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7025 "0120 Xmit ELS RPL ACC response tag x%x "
7026 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7027 "rpi x%x\n",
7028 elsiocb->iotag, elsiocb->iocb.ulpContext,
7029 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7030 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05007031 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007032 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04007033 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7034 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007035 lpfc_els_free_iocb(phba, elsiocb);
7036 return 1;
7037 }
7038 return 0;
7039}
7040
James Smarte59058c2008-08-24 21:49:00 -04007041/**
James Smart3621a712009-04-06 18:47:14 -04007042 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04007043 * @vport: pointer to a host virtual N_Port data structure.
7044 * @cmdiocb: pointer to lpfc command iocb data structure.
7045 * @ndlp: pointer to a node-list data structure.
7046 *
7047 * This routine processes Read Port List (RPL) IOCB received as an ELS
7048 * unsolicited event. It first checks the remote port state. If the remote
7049 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7050 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7051 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7052 * to accept the RPL.
7053 *
7054 * Return code
7055 * 0 - Successfully processed rpl iocb (currently always return 0)
7056 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007057static int
James Smart2e0fef82007-06-17 19:56:36 -05007058lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7059 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007060{
7061 struct lpfc_dmabuf *pcmd;
7062 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007063 uint32_t maxsize;
7064 uint16_t cmdsize;
7065 RPL *rpl;
7066 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007067
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007068 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7069 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04007070 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007071 stat.un.b.lsRjtRsvd0 = 0;
7072 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7073 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7074 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007075 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7076 NULL);
James Smart90160e02008-08-24 21:49:45 -04007077 /* rejected the unsolicited RPL request and done with it */
7078 return 0;
dea31012005-04-17 16:05:31 -05007079 }
7080
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007081 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7082 lp = (uint32_t *) pcmd->virt;
7083 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007084 maxsize = be32_to_cpu(rpl->maxsize);
7085
7086 /* We support only one port */
7087 if ((rpl->index == 0) &&
7088 ((maxsize == 0) ||
7089 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7090 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007091 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007092 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7093 }
James Smart2e0fef82007-06-17 19:56:36 -05007094 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007095
7096 return 0;
7097}
7098
James Smarte59058c2008-08-24 21:49:00 -04007099/**
James Smart3621a712009-04-06 18:47:14 -04007100 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04007101 * @vport: pointer to a virtual N_Port data structure.
7102 * @cmdiocb: pointer to lpfc command iocb data structure.
7103 * @ndlp: pointer to a node-list data structure.
7104 *
7105 * This routine processes Fibre Channel Address Resolution Protocol
7106 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7107 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7108 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7109 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7110 * remote PortName is compared against the FC PortName stored in the @vport
7111 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7112 * compared against the FC NodeName stored in the @vport data structure.
7113 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7114 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7115 * invoked to send out FARP Response to the remote node. Before sending the
7116 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7117 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7118 * routine is invoked to log into the remote port first.
7119 *
7120 * Return code
7121 * 0 - Either the FARP Match Mode not supported or successfully processed
7122 **/
dea31012005-04-17 16:05:31 -05007123static int
James Smart2e0fef82007-06-17 19:56:36 -05007124lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7125 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007126{
7127 struct lpfc_dmabuf *pcmd;
7128 uint32_t *lp;
7129 IOCB_t *icmd;
7130 FARP *fp;
7131 uint32_t cmd, cnt, did;
7132
7133 icmd = &cmdiocb->iocb;
7134 did = icmd->un.elsreq64.remoteID;
7135 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7136 lp = (uint32_t *) pcmd->virt;
7137
7138 cmd = *lp++;
7139 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05007140 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007141 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7142 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007143 /* We will only support match on WWPN or WWNN */
7144 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007145 return 0;
dea31012005-04-17 16:05:31 -05007146 }
7147
7148 cnt = 0;
7149 /* If this FARP command is searching for my portname */
7150 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05007151 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05007152 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007153 cnt = 1;
7154 }
7155
7156 /* If this FARP command is searching for my nodename */
7157 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05007158 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05007159 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007160 cnt = 1;
7161 }
7162
7163 if (cnt) {
7164 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7165 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7166 /* Log back into the node before sending the FARP. */
7167 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007168 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007169 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007170 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007171 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007172 }
7173
7174 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007175 if (fp->Rflags & FARP_REQUEST_FARPR)
7176 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007177 }
7178 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007179 return 0;
dea31012005-04-17 16:05:31 -05007180}
7181
James Smarte59058c2008-08-24 21:49:00 -04007182/**
James Smart3621a712009-04-06 18:47:14 -04007183 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007184 * @vport: pointer to a host virtual N_Port data structure.
7185 * @cmdiocb: pointer to lpfc command iocb data structure.
7186 * @ndlp: pointer to a node-list data structure.
7187 *
7188 * This routine processes Fibre Channel Address Resolution Protocol
7189 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7190 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7191 * the FARP response request.
7192 *
7193 * Return code
7194 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7195 **/
dea31012005-04-17 16:05:31 -05007196static int
James Smart2e0fef82007-06-17 19:56:36 -05007197lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7198 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007199{
7200 struct lpfc_dmabuf *pcmd;
7201 uint32_t *lp;
7202 IOCB_t *icmd;
7203 uint32_t cmd, did;
7204
7205 icmd = &cmdiocb->iocb;
7206 did = icmd->un.elsreq64.remoteID;
7207 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7208 lp = (uint32_t *) pcmd->virt;
7209
7210 cmd = *lp++;
7211 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007212 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7213 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007214 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007215 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007216
7217 return 0;
7218}
7219
James Smarte59058c2008-08-24 21:49:00 -04007220/**
James Smart3621a712009-04-06 18:47:14 -04007221 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007222 * @vport: pointer to a host virtual N_Port data structure.
7223 * @cmdiocb: pointer to lpfc command iocb data structure.
7224 * @fan_ndlp: pointer to a node-list data structure.
7225 *
7226 * This routine processes a Fabric Address Notification (FAN) IOCB
7227 * command received as an ELS unsolicited event. The FAN ELS command will
7228 * only be processed on a physical port (i.e., the @vport represents the
7229 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7230 * compared against those in the phba data structure. If any of those is
7231 * different, the lpfc_initial_flogi() routine is invoked to initialize
7232 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7233 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7234 * is invoked to register login to the fabric.
7235 *
7236 * Return code
7237 * 0 - Successfully processed fan iocb (currently always return 0).
7238 **/
dea31012005-04-17 16:05:31 -05007239static int
James Smart2e0fef82007-06-17 19:56:36 -05007240lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7241 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007242{
James Smart2e0fef82007-06-17 19:56:36 -05007243 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007244 uint32_t *lp;
7245 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007246
James Smart0d2b6b82008-06-14 22:52:47 -04007247 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7248 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7249 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007250 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007251 if ((vport == phba->pport) &&
7252 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007253 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007254 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007255 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007256 sizeof(struct lpfc_name)))) {
7257 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007258 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007259 } else {
7260 /* FAN verified - skip FLOGI */
7261 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007262 if (phba->sli_rev < LPFC_SLI_REV4)
7263 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007264 else {
7265 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7266 "3138 Need register VFI: (x%x/%x)\n",
7267 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04007268 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05007269 }
dea31012005-04-17 16:05:31 -05007270 }
dea31012005-04-17 16:05:31 -05007271 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007272 return 0;
dea31012005-04-17 16:05:31 -05007273}
7274
James Smarte59058c2008-08-24 21:49:00 -04007275/**
James Smart3621a712009-04-06 18:47:14 -04007276 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04007277 * @ptr: holder for the timer function associated data.
7278 *
7279 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7280 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7281 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7282 * up the worker thread. It is for the worker thread to invoke the routine
7283 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7284 **/
dea31012005-04-17 16:05:31 -05007285void
7286lpfc_els_timeout(unsigned long ptr)
7287{
James Smart2e0fef82007-06-17 19:56:36 -05007288 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7289 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04007290 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05007291 unsigned long iflag;
7292
James Smart2e0fef82007-06-17 19:56:36 -05007293 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04007294 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05007295 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05007296 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04007297 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05007298
James Smart06918ac2014-02-20 09:57:57 -05007299 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04007300 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05007301 return;
7302}
7303
James Smart2a9bf3d2010-06-07 15:24:45 -04007304
James Smarte59058c2008-08-24 21:49:00 -04007305/**
James Smart3621a712009-04-06 18:47:14 -04007306 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04007307 * @vport: pointer to a virtual N_Port data structure.
7308 *
7309 * This routine is the actual handler function that processes an ELS timeout
7310 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7311 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7312 * invoking the lpfc_sli_issue_abort_iotag() routine.
7313 **/
dea31012005-04-17 16:05:31 -05007314void
James Smart2e0fef82007-06-17 19:56:36 -05007315lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007316{
James Smart2e0fef82007-06-17 19:56:36 -05007317 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007318 struct lpfc_sli_ring *pring;
7319 struct lpfc_iocbq *tmp_iocb, *piocb;
7320 IOCB_t *cmd = NULL;
7321 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05007322 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05007323 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05007324 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04007325 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05007326
James Smart2a9bf3d2010-06-07 15:24:45 -04007327
dea31012005-04-17 16:05:31 -05007328 timeout = (uint32_t)(phba->fc_ratov << 1);
7329
James Smart895427b2017-02-12 13:52:30 -08007330 pring = lpfc_phba_elsring(phba);
7331
James Smart06918ac2014-02-20 09:57:57 -05007332 if ((phba->pport->load_flag & FC_UNLOADING))
7333 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04007334 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007335 if (phba->sli_rev == LPFC_SLI_REV4)
7336 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04007337
James Smart06918ac2014-02-20 09:57:57 -05007338 if ((phba->pport->load_flag & FC_UNLOADING)) {
7339 if (phba->sli_rev == LPFC_SLI_REV4)
7340 spin_unlock(&pring->ring_lock);
7341 spin_unlock_irq(&phba->hbalock);
7342 return;
7343 }
7344
James Smart0976e1a2013-12-17 20:29:36 -05007345 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05007346 cmd = &piocb->iocb;
7347
James Smart2e0fef82007-06-17 19:56:36 -05007348 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7349 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7350 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05007351 continue;
James Smart2e0fef82007-06-17 19:56:36 -05007352
7353 if (piocb->vport != vport)
7354 continue;
7355
dea31012005-04-17 16:05:31 -05007356 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05007357 if (pcmd)
7358 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05007359
James Smart92d7f7b2007-06-17 19:56:38 -05007360 if (els_command == ELS_CMD_FARP ||
7361 els_command == ELS_CMD_FARPR ||
7362 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05007363 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05007364
dea31012005-04-17 16:05:31 -05007365 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05007366 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05007367 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05007368 else
dea31012005-04-17 16:05:31 -05007369 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05007370 continue;
7371 }
7372
James Smart2e0fef82007-06-17 19:56:36 -05007373 remote_ID = 0xffffffff;
7374 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05007375 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05007376 else {
7377 struct lpfc_nodelist *ndlp;
7378 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04007379 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05007380 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05007381 }
James Smart2a9bf3d2010-06-07 15:24:45 -04007382 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05007383 }
James Smart0976e1a2013-12-17 20:29:36 -05007384 if (phba->sli_rev == LPFC_SLI_REV4)
7385 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007386 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04007387
James Smart2a9bf3d2010-06-07 15:24:45 -04007388 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05007389 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04007390 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7391 "0127 ELS timeout Data: x%x x%x x%x "
7392 "x%x\n", els_command,
7393 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7394 spin_lock_irq(&phba->hbalock);
7395 list_del_init(&piocb->dlist);
7396 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7397 spin_unlock_irq(&phba->hbalock);
7398 }
7399
James Smart895427b2017-02-12 13:52:30 -08007400 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05007401 if (!(phba->pport->load_flag & FC_UNLOADING))
7402 mod_timer(&vport->els_tmofunc,
7403 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05007404}
7405
James Smarte59058c2008-08-24 21:49:00 -04007406/**
James Smart3621a712009-04-06 18:47:14 -04007407 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04007408 * @vport: pointer to a host virtual N_Port data structure.
7409 *
7410 * This routine is used to clean up all the outstanding ELS commands on a
7411 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7412 * routine. After that, it walks the ELS transmit queue to remove all the
7413 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7414 * the IOCBs with a non-NULL completion callback function, the callback
7415 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7416 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7417 * callback function, the IOCB will simply be released. Finally, it walks
7418 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7419 * completion queue IOCB that is associated with the @vport and is not
7420 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7421 * part of the discovery state machine) out to HBA by invoking the
7422 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7423 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7424 * the IOCBs are aborted when this function returns.
7425 **/
dea31012005-04-17 16:05:31 -05007426void
James Smart2e0fef82007-06-17 19:56:36 -05007427lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007428{
James Smart0976e1a2013-12-17 20:29:36 -05007429 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05007430 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08007431 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05007432 struct lpfc_iocbq *tmp_iocb, *piocb;
7433 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007434
7435 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05007436 /*
7437 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7438 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7439 * ultimately grabs the ring_lock, the driver must splice the list into
7440 * a working list and release the locks before calling the abort.
7441 */
7442 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08007443 pring = lpfc_phba_elsring(phba);
James Smart0976e1a2013-12-17 20:29:36 -05007444 if (phba->sli_rev == LPFC_SLI_REV4)
7445 spin_lock(&pring->ring_lock);
7446
7447 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7448 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7449 continue;
7450
7451 if (piocb->vport != vport)
7452 continue;
7453 list_add_tail(&piocb->dlist, &abort_list);
7454 }
7455 if (phba->sli_rev == LPFC_SLI_REV4)
7456 spin_unlock(&pring->ring_lock);
7457 spin_unlock_irq(&phba->hbalock);
7458 /* Abort each iocb on the aborted list and remove the dlist links. */
7459 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7460 spin_lock_irq(&phba->hbalock);
7461 list_del_init(&piocb->dlist);
7462 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7463 spin_unlock_irq(&phba->hbalock);
7464 }
7465 if (!list_empty(&abort_list))
7466 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7467 "3387 abort list for txq not empty\n");
7468 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05007469
James Smart2e0fef82007-06-17 19:56:36 -05007470 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007471 if (phba->sli_rev == LPFC_SLI_REV4)
7472 spin_lock(&pring->ring_lock);
7473
dea31012005-04-17 16:05:31 -05007474 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7475 cmd = &piocb->iocb;
7476
7477 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7478 continue;
7479 }
7480
7481 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007482 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7483 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7484 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7485 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007486 continue;
dea31012005-04-17 16:05:31 -05007487
James Smart2e0fef82007-06-17 19:56:36 -05007488 if (piocb->vport != vport)
7489 continue;
7490
James Smart0976e1a2013-12-17 20:29:36 -05007491 list_del_init(&piocb->list);
7492 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007493 }
James Smart0976e1a2013-12-17 20:29:36 -05007494 if (phba->sli_rev == LPFC_SLI_REV4)
7495 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007496 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007497
James Smarta257bf92009-04-06 18:48:10 -04007498 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007499 lpfc_sli_cancel_iocbs(phba, &abort_list,
7500 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007501
dea31012005-04-17 16:05:31 -05007502 return;
7503}
7504
James Smarte59058c2008-08-24 21:49:00 -04007505/**
James Smart3621a712009-04-06 18:47:14 -04007506 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007507 * @phba: pointer to lpfc hba data structure.
7508 *
7509 * This routine is used to clean up all the outstanding ELS commands on a
7510 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7511 * routine. After that, it walks the ELS transmit queue to remove all the
7512 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7513 * the IOCBs with the completion callback function associated, the callback
7514 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7515 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7516 * callback function associated, the IOCB will simply be released. Finally,
7517 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7518 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7519 * management plane IOCBs that are not part of the discovery state machine)
7520 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7521 **/
James Smart549e55c2007-08-02 11:09:51 -04007522void
7523lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7524{
James Smart0976e1a2013-12-17 20:29:36 -05007525 struct lpfc_vport *vport;
7526 list_for_each_entry(vport, &phba->port_list, listentry)
7527 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007528
James Smart549e55c2007-08-02 11:09:51 -04007529 return;
7530}
7531
James Smarte59058c2008-08-24 21:49:00 -04007532/**
James Smart3621a712009-04-06 18:47:14 -04007533 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007534 * @phba: Pointer to hba context object.
7535 * @cmdiocbp: Pointer to command iocb which reported error.
7536 * @rspiocbp: Pointer to response iocb which reported error.
7537 *
7538 * This function sends an event when there is an ELS command
7539 * failure.
7540 **/
7541void
7542lpfc_send_els_failure_event(struct lpfc_hba *phba,
7543 struct lpfc_iocbq *cmdiocbp,
7544 struct lpfc_iocbq *rspiocbp)
7545{
7546 struct lpfc_vport *vport = cmdiocbp->vport;
7547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7548 struct lpfc_lsrjt_event lsrjt_event;
7549 struct lpfc_fabric_event_header fabric_event;
7550 struct ls_rjt stat;
7551 struct lpfc_nodelist *ndlp;
7552 uint32_t *pcmd;
7553
7554 ndlp = cmdiocbp->context1;
7555 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7556 return;
7557
7558 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7559 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7560 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7561 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7562 sizeof(struct lpfc_name));
7563 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7564 sizeof(struct lpfc_name));
7565 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7566 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007567 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007568 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7569 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7570 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7571 fc_host_post_vendor_event(shost,
7572 fc_get_event_number(),
7573 sizeof(lsrjt_event),
7574 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007575 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007576 return;
7577 }
7578 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7579 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7580 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7581 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7582 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7583 else
7584 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7585 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7586 sizeof(struct lpfc_name));
7587 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7588 sizeof(struct lpfc_name));
7589 fc_host_post_vendor_event(shost,
7590 fc_get_event_number(),
7591 sizeof(fabric_event),
7592 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007593 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007594 return;
7595 }
7596
7597}
7598
7599/**
James Smart3621a712009-04-06 18:47:14 -04007600 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007601 * @vport: Pointer to vport object.
7602 * @ndlp: Pointer FC node object.
7603 * @cmd: ELS command code.
7604 *
7605 * This function posts an event when there is an incoming
7606 * unsolicited ELS command.
7607 **/
7608static void
7609lpfc_send_els_event(struct lpfc_vport *vport,
7610 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007611 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007612{
James Smartddcc50f2008-12-04 22:38:46 -05007613 struct lpfc_els_event_header *els_data = NULL;
7614 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7616
James Smartddcc50f2008-12-04 22:38:46 -05007617 if (*payload == ELS_CMD_LOGO) {
7618 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7619 if (!logo_data) {
7620 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7621 "0148 Failed to allocate memory "
7622 "for LOGO event\n");
7623 return;
7624 }
7625 els_data = &logo_data->header;
7626 } else {
7627 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7628 GFP_KERNEL);
7629 if (!els_data) {
7630 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7631 "0149 Failed to allocate memory "
7632 "for ELS event\n");
7633 return;
7634 }
7635 }
7636 els_data->event_type = FC_REG_ELS_EVENT;
7637 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007638 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007639 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007640 break;
7641 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007642 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007643 break;
7644 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007645 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7646 break;
7647 case ELS_CMD_LOGO:
7648 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7649 /* Copy the WWPN in the LOGO payload */
7650 memcpy(logo_data->logo_wwpn, &payload[2],
7651 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007652 break;
7653 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007654 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007655 return;
7656 }
James Smartddcc50f2008-12-04 22:38:46 -05007657 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7658 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7659 if (*payload == ELS_CMD_LOGO) {
7660 fc_host_post_vendor_event(shost,
7661 fc_get_event_number(),
7662 sizeof(struct lpfc_logo_event),
7663 (char *)logo_data,
7664 LPFC_NL_VENDOR_ID);
7665 kfree(logo_data);
7666 } else {
7667 fc_host_post_vendor_event(shost,
7668 fc_get_event_number(),
7669 sizeof(struct lpfc_els_event_header),
7670 (char *)els_data,
7671 LPFC_NL_VENDOR_ID);
7672 kfree(els_data);
7673 }
James Smartea2151b2008-09-07 11:52:10 -04007674
7675 return;
7676}
7677
7678
7679/**
James Smart3621a712009-04-06 18:47:14 -04007680 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007681 * @phba: pointer to lpfc hba data structure.
7682 * @pring: pointer to a SLI ring.
7683 * @vport: pointer to a host virtual N_Port data structure.
7684 * @elsiocb: pointer to lpfc els command iocb data structure.
7685 *
7686 * This routine is used for processing the IOCB associated with a unsolicited
7687 * event. It first determines whether there is an existing ndlp that matches
7688 * the DID from the unsolicited IOCB. If not, it will create a new one with
7689 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7690 * IOCB is then used to invoke the proper routine and to set up proper state
7691 * of the discovery state machine.
7692 **/
James Smarted957682007-06-17 19:56:37 -05007693static void
7694lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007695 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007696{
James Smart87af33f2007-10-27 13:37:43 -04007697 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007698 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007699 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007700 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007701 uint32_t cmd, did, newnode;
7702 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007703 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007704
James Smarte47c9092008-02-08 18:49:26 -05007705 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007706 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007707
dea31012005-04-17 16:05:31 -05007708 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007709 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7710 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007711 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007712 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007713
James Smart858c9f62007-06-17 19:56:39 -05007714 did = icmd->un.rcvels.remoteID;
7715 if (icmd->ulpStatus) {
7716 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7717 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7718 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007719 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007720 }
dea31012005-04-17 16:05:31 -05007721
7722 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007723 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007724 goto dropit;
dea31012005-04-17 16:05:31 -05007725
James Smartc8685952009-11-18 15:39:16 -05007726 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007727 if (vport->load_flag & FC_UNLOADING)
7728 goto dropit;
7729
James Smart92494142011-02-16 12:39:44 -05007730 /* If NPort discovery is delayed drop incoming ELS */
7731 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7732 (cmd != ELS_CMD_PLOGI))
7733 goto dropit;
7734
James Smart2e0fef82007-06-17 19:56:36 -05007735 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007736 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007737 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07007738 ndlp = lpfc_nlp_init(vport, did);
James Smarted957682007-06-17 19:56:37 -05007739 if (!ndlp)
dea31012005-04-17 16:05:31 -05007740 goto dropit;
James Smart98c9ea52007-10-27 13:37:33 -04007741 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007742 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007743 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007744 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007745 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7746 ndlp = lpfc_enable_node(vport, ndlp,
7747 NLP_STE_UNUSED_NODE);
7748 if (!ndlp)
7749 goto dropit;
7750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7751 newnode = 1;
7752 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7753 ndlp->nlp_type |= NLP_FABRIC;
7754 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7755 /* This is similar to the new node path */
7756 ndlp = lpfc_nlp_get(ndlp);
7757 if (!ndlp)
7758 goto dropit;
7759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7760 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007761 }
dea31012005-04-17 16:05:31 -05007762
7763 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007764
James Smart12838e72014-09-03 12:57:19 -04007765 /*
7766 * Do not process any unsolicited ELS commands
7767 * if the ndlp is in DEV_LOSS
7768 */
James Smart466e8402015-05-21 13:55:28 -04007769 shost = lpfc_shost_from_vport(vport);
7770 spin_lock_irq(shost->host_lock);
7771 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7772 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007773 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007774 }
7775 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007776
James Smart329f9bc2007-04-25 09:53:01 -04007777 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007778 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007779
7780 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7781 cmd &= ELS_CMD_MASK;
7782 }
7783 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7785 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007786 "Data: x%x x%x x%x x%x\n",
7787 cmd, did, vport->port_state, vport->fc_flag,
7788 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04007789
7790 /* reject till our FLOGI completes */
7791 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smartd6de08c2015-12-16 18:11:53 -05007792 (cmd != ELS_CMD_FLOGI)) {
James Smart401304c2016-10-13 15:06:14 -07007793 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04007794 rjt_exp = LSEXP_NOTHING_MORE;
7795 goto lsrjt;
7796 }
7797
dea31012005-04-17 16:05:31 -05007798 switch (cmd) {
7799 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7801 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7802 did, vport->port_state, ndlp->nlp_flag);
7803
dea31012005-04-17 16:05:31 -05007804 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007805 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007806 if (phba->sli_rev == LPFC_SLI_REV4 &&
7807 (phba->pport->fc_flag & FC_PT2PT)) {
7808 vport->fc_prevDID = vport->fc_myDID;
7809 /* Our DID needs to be updated before registering
7810 * the vfi. This is done in lpfc_rcv_plogi but
7811 * that is called after the reg_vfi.
7812 */
7813 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7814 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7815 "3312 Remote port assigned DID x%x "
7816 "%x\n", vport->fc_myDID,
7817 vport->fc_prevDID);
7818 }
James Smart858c9f62007-06-17 19:56:39 -05007819
James Smartddcc50f2008-12-04 22:38:46 -05007820 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007821
7822 /* If Nport discovery is delayed, reject PLOGIs */
7823 if (vport->fc_flag & FC_DISC_DELAYED) {
7824 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007825 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007826 break;
7827 }
James Smartd6de08c2015-12-16 18:11:53 -05007828
James Smart858c9f62007-06-17 19:56:39 -05007829 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007830 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7831 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7832 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007833 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007834 break;
7835 }
dea31012005-04-17 16:05:31 -05007836 }
James Smart87af33f2007-10-27 13:37:43 -04007837
James Smart87af33f2007-10-27 13:37:43 -04007838 spin_lock_irq(shost->host_lock);
7839 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7840 spin_unlock_irq(shost->host_lock);
7841
James Smart2e0fef82007-06-17 19:56:36 -05007842 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7843 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007844
dea31012005-04-17 16:05:31 -05007845 break;
7846 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007847 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7848 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7849 did, vport->port_state, ndlp->nlp_flag);
7850
dea31012005-04-17 16:05:31 -05007851 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007852 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007853 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007854 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007855 break;
7856 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7858 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7859 did, vport->port_state, ndlp->nlp_flag);
7860
dea31012005-04-17 16:05:31 -05007861 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007862 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007863 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007864 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007865 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007866 break;
7867 }
James Smart2e0fef82007-06-17 19:56:36 -05007868 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007869 break;
7870 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7872 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7873 did, vport->port_state, ndlp->nlp_flag);
7874
dea31012005-04-17 16:05:31 -05007875 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007876 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007877 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007878 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007879 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007880 break;
7881 }
James Smart2e0fef82007-06-17 19:56:36 -05007882 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05007883 break;
James Smart8b017a32015-05-21 13:55:18 -04007884 case ELS_CMD_LCB:
7885 phba->fc_stat.elsRcvLCB++;
7886 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7887 break;
James Smart86478872015-05-21 13:55:21 -04007888 case ELS_CMD_RDP:
7889 phba->fc_stat.elsRcvRDP++;
7890 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7891 break;
dea31012005-04-17 16:05:31 -05007892 case ELS_CMD_RSCN:
7893 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04007894 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007895 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007896 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007897 break;
7898 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05007899 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7900 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7901 did, vport->port_state, ndlp->nlp_flag);
7902
James Smartddcc50f2008-12-04 22:38:46 -05007903 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05007904 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007905 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007906 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007907 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007908 break;
7909 }
James Smart2e0fef82007-06-17 19:56:36 -05007910 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7911 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05007912 break;
7913 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05007914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7915 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7916 did, vport->port_state, ndlp->nlp_flag);
7917
dea31012005-04-17 16:05:31 -05007918 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007919 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007920 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007921 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007922 break;
7923 }
James Smart2e0fef82007-06-17 19:56:36 -05007924 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7925 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05007926 break;
7927 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05007928 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7929 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7930 did, vport->port_state, ndlp->nlp_flag);
7931
dea31012005-04-17 16:05:31 -05007932 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05007933 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007934 break;
7935 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05007936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7937 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7938 did, vport->port_state, ndlp->nlp_flag);
7939
dea31012005-04-17 16:05:31 -05007940 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05007941 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007942 break;
7943 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05007944 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7945 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7946 did, vport->port_state, ndlp->nlp_flag);
7947
dea31012005-04-17 16:05:31 -05007948 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05007949 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007950 break;
dea31012005-04-17 16:05:31 -05007951 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08007952 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -05007953 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7954 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7955 did, vport->port_state, ndlp->nlp_flag);
7956
dea31012005-04-17 16:05:31 -05007957 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -04007958 if ((vport->port_state < LPFC_DISC_AUTH) &&
7959 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05007960 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007961 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007962 break;
7963 }
James Smart2e0fef82007-06-17 19:56:36 -05007964 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05007965 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007966 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05007967 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7968 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7969 did, vport->port_state, ndlp->nlp_flag);
7970
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007971 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05007972 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007973 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007974 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007975 break;
James Smart12265f62010-10-22 11:05:53 -04007976 case ELS_CMD_RLS:
7977 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7978 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7979 did, vport->port_state, ndlp->nlp_flag);
7980
7981 phba->fc_stat.elsRcvRLS++;
7982 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7983 if (newnode)
7984 lpfc_nlp_put(ndlp);
7985 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007986 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05007987 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7988 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7989 did, vport->port_state, ndlp->nlp_flag);
7990
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007991 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05007992 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007993 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007994 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007995 break;
7996 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05007997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7998 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7999 did, vport->port_state, ndlp->nlp_flag);
8000
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008001 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05008002 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008003 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008004 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008005 break;
dea31012005-04-17 16:05:31 -05008006 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05008007 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8008 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8009 did, vport->port_state, ndlp->nlp_flag);
8010
dea31012005-04-17 16:05:31 -05008011 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05008012 lpfc_els_rcv_rnid(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;
James Smart12265f62010-10-22 11:05:53 -04008016 case ELS_CMD_RTV:
8017 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8018 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8019 did, vport->port_state, ndlp->nlp_flag);
8020 phba->fc_stat.elsRcvRTV++;
8021 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8022 if (newnode)
8023 lpfc_nlp_put(ndlp);
8024 break;
James Smart5ffc2662009-11-18 15:39:44 -05008025 case ELS_CMD_RRQ:
8026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8027 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8028 did, vport->port_state, ndlp->nlp_flag);
8029
8030 phba->fc_stat.elsRcvRRQ++;
8031 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8032 if (newnode)
8033 lpfc_nlp_put(ndlp);
8034 break;
James Smart12265f62010-10-22 11:05:53 -04008035 case ELS_CMD_ECHO:
8036 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8037 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8038 did, vport->port_state, ndlp->nlp_flag);
8039
8040 phba->fc_stat.elsRcvECHO++;
8041 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8042 if (newnode)
8043 lpfc_nlp_put(ndlp);
8044 break;
James Smart303f2f92013-01-03 15:43:11 -05008045 case ELS_CMD_REC:
8046 /* receive this due to exchange closed */
8047 rjt_err = LSRJT_UNABLE_TPC;
8048 rjt_exp = LSEXP_INVALID_OX_RX;
8049 break;
dea31012005-04-17 16:05:31 -05008050 default:
James Smart858c9f62007-06-17 19:56:39 -05008051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8052 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8053 cmd, did, vport->port_state);
8054
dea31012005-04-17 16:05:31 -05008055 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05008056 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05008057 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008058
8059 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008060 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8061 "0115 Unknown ELS command x%x "
8062 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04008063 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008064 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008065 break;
8066 }
8067
James Smarteec3d312015-08-31 16:48:18 -04008068lsrjt:
dea31012005-04-17 16:05:31 -05008069 /* check if need to LS_RJT received ELS cmd */
8070 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05008071 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05008072 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05008073 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05008074 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8075 NULL);
dea31012005-04-17 16:05:31 -05008076 }
8077
James Smartd7c255b2008-08-24 21:50:00 -04008078 lpfc_nlp_put(elsiocb->context1);
8079 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05008080 return;
8081
8082dropit:
James Smart98c9ea52007-10-27 13:37:33 -04008083 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04008084 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8085 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05008086 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04008087 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05008088 phba->fc_stat.elsRcvDrop++;
8089}
8090
James Smarte59058c2008-08-24 21:49:00 -04008091/**
James Smart3621a712009-04-06 18:47:14 -04008092 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04008093 * @phba: pointer to lpfc hba data structure.
8094 * @pring: pointer to a SLI ring.
8095 * @elsiocb: pointer to lpfc els iocb data structure.
8096 *
8097 * This routine is used to process an unsolicited event received from a SLI
8098 * (Service Level Interface) ring. The actual processing of the data buffer
8099 * associated with the unsolicited event is done by invoking the routine
8100 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8101 * SLI ring on which the unsolicited event was received.
8102 **/
James Smarted957682007-06-17 19:56:37 -05008103void
8104lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8105 struct lpfc_iocbq *elsiocb)
8106{
8107 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05008108 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05008109 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05008110 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8111 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05008112
James Smartd7c255b2008-08-24 21:50:00 -04008113 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05008114 elsiocb->context2 = NULL;
8115 elsiocb->context3 = NULL;
8116
8117 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8118 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8119 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04008120 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8121 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05008122 phba->fc_stat.NoRcvBuf++;
8123 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05008124 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04008125 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05008126 return;
8127 }
8128
James Smart92d7f7b2007-06-17 19:56:38 -05008129 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8130 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8131 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8132 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8133 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04008134 else
8135 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04008136 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05008137 }
James Smart6d368e52011-05-24 11:44:12 -04008138
James Smart7f5f3d02008-02-08 18:50:14 -05008139 /* If there are no BDEs associated
8140 * with this IOCB, there is nothing to do.
8141 */
James Smarted957682007-06-17 19:56:37 -05008142 if (icmd->ulpBdeCount == 0)
8143 return;
8144
James Smart7f5f3d02008-02-08 18:50:14 -05008145 /* type of ELS cmd is first 32bit word
8146 * in packet
8147 */
James Smarted957682007-06-17 19:56:37 -05008148 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05008149 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05008150 } else {
8151 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8152 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05008153 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8154 paddr);
James Smarted957682007-06-17 19:56:37 -05008155 }
8156
James Smart92d7f7b2007-06-17 19:56:38 -05008157 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8158 /*
8159 * The different unsolicited event handlers would tell us
8160 * if they are done with "mp" by setting context2 to NULL.
8161 */
dea31012005-04-17 16:05:31 -05008162 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008163 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8164 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05008165 }
James Smarted957682007-06-17 19:56:37 -05008166
8167 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05008168 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05008169 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008170 elsiocb->context2 = bdeBuf2;
8171 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05008172 /* free mp if we are done with it */
8173 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008174 lpfc_in_buf_free(phba, elsiocb->context2);
8175 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05008176 }
dea31012005-04-17 16:05:31 -05008177 }
dea31012005-04-17 16:05:31 -05008178}
James Smart92d7f7b2007-06-17 19:56:38 -05008179
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08008180static void
James Smart4258e982015-12-16 18:11:58 -05008181lpfc_start_fdmi(struct lpfc_vport *vport)
8182{
James Smart4258e982015-12-16 18:11:58 -05008183 struct lpfc_nodelist *ndlp;
8184
8185 /* If this is the first time, allocate an ndlp and initialize
8186 * it. Otherwise, make sure the node is enabled and then do the
8187 * login.
8188 */
8189 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8190 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008191 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -05008192 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -05008193 ndlp->nlp_type |= NLP_FABRIC;
8194 } else {
8195 return;
8196 }
8197 }
8198 if (!NLP_CHK_NODE_ACT(ndlp))
8199 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8200
8201 if (ndlp) {
8202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8203 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8204 }
8205}
8206
James Smarte59058c2008-08-24 21:49:00 -04008207/**
James Smart3621a712009-04-06 18:47:14 -04008208 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04008209 * @phba: pointer to lpfc hba data structure.
8210 * @vport: pointer to a virtual N_Port data structure.
8211 *
8212 * This routine issues a Port Login (PLOGI) to the Name Server with
8213 * State Change Request (SCR) for a @vport. This routine will create an
8214 * ndlp for the Name Server associated to the @vport if such node does
8215 * not already exist. The PLOGI to Name Server is issued by invoking the
8216 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8217 * (FDMI) is configured to the @vport, a FDMI node will be created and
8218 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8219 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008220void
8221lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8222{
James Smart4258e982015-12-16 18:11:58 -05008223 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05008224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8225
8226 /*
8227 * If lpfc_delay_discovery parameter is set and the clean address
8228 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8229 * discovery.
8230 */
8231 spin_lock_irq(shost->host_lock);
8232 if (vport->fc_flag & FC_DISC_DELAYED) {
8233 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04008234 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8235 "3334 Delay fc port discovery for %d seconds\n",
8236 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05008237 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04008238 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05008239 return;
8240 }
8241 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008242
8243 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8244 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008245 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05008246 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008247 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05008248 lpfc_disc_start(vport);
8249 return;
8250 }
8251 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008252 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8253 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008254 return;
8255 }
James Smarte47c9092008-02-08 18:49:26 -05008256 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8257 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8258 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008259 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05008260 lpfc_disc_start(vport);
8261 return;
8262 }
8263 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8264 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8265 "0348 NameServer login: node freed\n");
8266 return;
8267 }
James Smart92d7f7b2007-06-17 19:56:38 -05008268 }
James Smart58da1ff2008-04-07 10:15:56 -04008269 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05008270
8271 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8272
8273 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8274 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008275 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8276 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008277 return;
8278 }
8279
James Smart8663cbb2016-03-31 14:12:33 -07008280 if ((phba->cfg_enable_SmartSAN ||
8281 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8282 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05008283 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008284}
8285
James Smarte59058c2008-08-24 21:49:00 -04008286/**
James Smart3621a712009-04-06 18:47:14 -04008287 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04008288 * @phba: pointer to lpfc hba data structure.
8289 * @pmb: pointer to the driver internal queue element for mailbox command.
8290 *
8291 * This routine is the completion callback function to register new vport
8292 * mailbox command. If the new vport mailbox command completes successfully,
8293 * the fabric registration login shall be performed on physical port (the
8294 * new vport created is actually a physical port, with VPI 0) or the port
8295 * login to Name Server for State Change Request (SCR) will be performed
8296 * on virtual port (real virtual port, with VPI greater than 0).
8297 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008298static void
8299lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8300{
8301 struct lpfc_vport *vport = pmb->vport;
8302 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8303 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04008304 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05008305 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008306
James Smart09372822008-01-11 01:52:54 -05008307 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008308 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008309 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008310
8311 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04008312 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04008313 "0915 Register VPI failed : Status: x%x"
8314 " upd bit: x%x \n", mb->mbxStatus,
8315 mb->un.varRegVpi.upd);
8316 if (phba->sli_rev == LPFC_SLI_REV4 &&
8317 mb->un.varRegVpi.upd)
8318 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05008319
8320 switch (mb->mbxStatus) {
8321 case 0x11: /* unsupported feature */
8322 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05008323 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05008324 /* giving up on vport registration */
8325 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8326 spin_lock_irq(shost->host_lock);
8327 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8328 spin_unlock_irq(shost->host_lock);
8329 lpfc_can_disctmo(vport);
8330 break;
James Smart695a8142010-01-26 23:08:03 -05008331 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8332 case 0x20:
8333 spin_lock_irq(shost->host_lock);
8334 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8335 spin_unlock_irq(shost->host_lock);
8336 lpfc_init_vpi(phba, pmb, vport->vpi);
8337 pmb->vport = vport;
8338 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8339 rc = lpfc_sli_issue_mbox(phba, pmb,
8340 MBX_NOWAIT);
8341 if (rc == MBX_NOT_FINISHED) {
8342 lpfc_printf_vlog(vport,
8343 KERN_ERR, LOG_MBOX,
8344 "2732 Failed to issue INIT_VPI"
8345 " mailbox command\n");
8346 } else {
8347 lpfc_nlp_put(ndlp);
8348 return;
8349 }
8350
James Smart92d7f7b2007-06-17 19:56:38 -05008351 default:
8352 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04008353 if (phba->sli_rev == LPFC_SLI_REV4)
8354 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008355 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05008356 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008357 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008358 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -08008359 if (mb->mbxStatus == MBX_NOT_FINISHED)
8360 break;
8361 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8362 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8363 if (phba->sli_rev == LPFC_SLI_REV4)
8364 lpfc_issue_init_vfi(vport);
8365 else
8366 lpfc_initial_flogi(vport);
8367 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05008368 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -08008369 }
James Smart92d7f7b2007-06-17 19:56:38 -05008370 break;
8371 }
James Smart92d7f7b2007-06-17 19:56:38 -05008372 } else {
James Smart695a8142010-01-26 23:08:03 -05008373 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05008374 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05008375 spin_unlock_irq(shost->host_lock);
8376 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04008377 if (phba->sli_rev < LPFC_SLI_REV4)
8378 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05008379 else {
James Smartfc2b9892010-02-26 14:15:29 -05008380 /*
8381 * If the physical port is instantiated using
8382 * FDISC, do not start vport discovery.
8383 */
8384 if (vport->port_state != LPFC_FDISC)
8385 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05008386 lpfc_do_scr_ns_plogi(phba, vport);
8387 }
8388 } else
James Smart92d7f7b2007-06-17 19:56:38 -05008389 lpfc_do_scr_ns_plogi(phba, vport);
8390 }
James Smart38b92ef2010-08-04 16:11:39 -04008391mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05008392 /* Now, we decrement the ndlp reference count held for this
8393 * callback function
8394 */
8395 lpfc_nlp_put(ndlp);
8396
James Smart92d7f7b2007-06-17 19:56:38 -05008397 mempool_free(pmb, phba->mbox_mem_pool);
8398 return;
8399}
8400
James Smarte59058c2008-08-24 21:49:00 -04008401/**
James Smart3621a712009-04-06 18:47:14 -04008402 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04008403 * @phba: pointer to lpfc hba data structure.
8404 * @vport: pointer to a host virtual N_Port data structure.
8405 * @ndlp: pointer to a node-list data structure.
8406 *
8407 * This routine registers the @vport as a new virtual port with a HBA.
8408 * It is done through a registering vpi mailbox command.
8409 **/
James Smart695a8142010-01-26 23:08:03 -05008410void
James Smart92d7f7b2007-06-17 19:56:38 -05008411lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8412 struct lpfc_nodelist *ndlp)
8413{
James Smart09372822008-01-11 01:52:54 -05008414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008415 LPFC_MBOXQ_t *mbox;
8416
8417 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8418 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04008419 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05008420 mbox->vport = vport;
8421 mbox->context2 = lpfc_nlp_get(ndlp);
8422 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04008423 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05008424 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05008425 /* mailbox command not success, decrement ndlp
8426 * reference count for this command
8427 */
8428 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008429 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05008430
James Smarte8b62012007-08-02 11:10:09 -04008431 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8432 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05008433 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008434 }
8435 } else {
James Smarte8b62012007-08-02 11:10:09 -04008436 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8437 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05008438 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008439 }
James Smartfa4066b2008-01-11 01:53:27 -05008440 return;
8441
8442mbox_err_exit:
8443 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8444 spin_lock_irq(shost->host_lock);
8445 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8446 spin_unlock_irq(shost->host_lock);
8447 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008448}
8449
James Smarte59058c2008-08-24 21:49:00 -04008450/**
James Smart0c9ab6f2010-02-26 14:15:57 -05008451 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05008452 * @phba: pointer to lpfc hba data structure.
8453 *
James Smart0c9ab6f2010-02-26 14:15:57 -05008454 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05008455 **/
8456void
James Smart0c9ab6f2010-02-26 14:15:57 -05008457lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05008458{
8459 struct lpfc_vport **vports;
8460 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05008461 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05008462 int i;
James Smart695a8142010-01-26 23:08:03 -05008463
8464 /* Treat this failure as linkdown for all vports */
8465 link_state = phba->link_state;
8466 lpfc_linkdown(phba);
8467 phba->link_state = link_state;
8468
8469 vports = lpfc_create_vport_work_array(phba);
8470
8471 if (vports) {
8472 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8473 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8474 if (ndlp)
8475 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8476 lpfc_els_flush_cmd(vports[i]);
8477 }
8478 lpfc_destroy_vport_work_array(phba, vports);
8479 }
James Smart0c9ab6f2010-02-26 14:15:57 -05008480}
8481
8482/**
8483 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8484 * @phba: pointer to lpfc hba data structure.
8485 *
8486 * This routine abort all pending discovery commands and
8487 * start a timer to retry FLOGI for the physical port
8488 * discovery.
8489 **/
8490void
8491lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8492{
8493 struct lpfc_nodelist *ndlp;
8494 struct Scsi_Host *shost;
8495
8496 /* Cancel the all vports retry delay retry timers */
8497 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008498
8499 /* If fabric require FLOGI, then re-instantiate physical login */
8500 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8501 if (!ndlp)
8502 return;
8503
James Smart695a8142010-01-26 23:08:03 -05008504 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008505 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008506 spin_lock_irq(shost->host_lock);
8507 ndlp->nlp_flag |= NLP_DELAY_TMO;
8508 spin_unlock_irq(shost->host_lock);
8509 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8510 phba->pport->port_state = LPFC_FLOGI;
8511 return;
8512}
8513
8514/**
8515 * lpfc_fabric_login_reqd - Check if FLOGI required.
8516 * @phba: pointer to lpfc hba data structure.
8517 * @cmdiocb: pointer to FDISC command iocb.
8518 * @rspiocb: pointer to FDISC response iocb.
8519 *
8520 * This routine checks if a FLOGI is reguired for FDISC
8521 * to succeed.
8522 **/
8523static int
8524lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8525 struct lpfc_iocbq *cmdiocb,
8526 struct lpfc_iocbq *rspiocb)
8527{
8528
8529 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8530 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8531 return 0;
8532 else
8533 return 1;
8534}
8535
8536/**
James Smart3621a712009-04-06 18:47:14 -04008537 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008538 * @phba: pointer to lpfc hba data structure.
8539 * @cmdiocb: pointer to lpfc command iocb data structure.
8540 * @rspiocb: pointer to lpfc response iocb data structure.
8541 *
8542 * This routine is the completion callback function to a Fabric Discover
8543 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8544 * single threaded, each FDISC completion callback function will reset
8545 * the discovery timer for all vports such that the timers will not get
8546 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8547 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8548 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8549 * assigned to the vport has been changed with the completion of the FDISC
8550 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8551 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8552 * routine is invoked to register new vport with the HBA. Otherwise, the
8553 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8554 * Server for State Change Request (SCR).
8555 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008556static void
8557lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8558 struct lpfc_iocbq *rspiocb)
8559{
8560 struct lpfc_vport *vport = cmdiocb->vport;
8561 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8562 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8563 struct lpfc_nodelist *np;
8564 struct lpfc_nodelist *next_np;
8565 IOCB_t *irsp = &rspiocb->iocb;
8566 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008567 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8568 struct serv_parm *sp;
8569 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008570
James Smarte8b62012007-08-02 11:10:09 -04008571 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8572 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8573 irsp->ulpStatus, irsp->un.ulpWord[4],
8574 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008575 /* Since all FDISCs are being single threaded, we
8576 * must reset the discovery timer for ALL vports
8577 * waiting to send FDISC when one completes.
8578 */
8579 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8580 lpfc_set_disctmo(piocb->vport);
8581 }
8582
James Smart858c9f62007-06-17 19:56:39 -05008583 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8584 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8585 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8586
James Smart92d7f7b2007-06-17 19:56:38 -05008587 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008588
8589 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8590 lpfc_retry_pport_discovery(phba);
8591 goto out;
8592 }
8593
James Smart92d7f7b2007-06-17 19:56:38 -05008594 /* Check for retry */
8595 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8596 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008597 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008598 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008599 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008600 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008601 goto fdisc_failed;
8602 }
James Smartd7c255b2008-08-24 21:50:00 -04008603 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008604 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008605 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008606 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008607 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008608 vport->fc_flag |= FC_PUBLIC_LOOP;
8609 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008610
James Smartd7c255b2008-08-24 21:50:00 -04008611 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8612 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008613 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008614 if (!prsp)
8615 goto out;
James Smart92494142011-02-16 12:39:44 -05008616 sp = prsp->virt + sizeof(uint32_t);
8617 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8618 memcpy(&vport->fabric_portname, &sp->portName,
8619 sizeof(struct lpfc_name));
8620 memcpy(&vport->fabric_nodename, &sp->nodeName,
8621 sizeof(struct lpfc_name));
8622 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008623 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8624 /* If our NportID changed, we need to ensure all
8625 * remaining NPORTs get unreg_login'ed so we can
8626 * issue unreg_vpi.
8627 */
8628 list_for_each_entry_safe(np, next_np,
8629 &vport->fc_nodes, nlp_listp) {
8630 if (!NLP_CHK_NODE_ACT(ndlp) ||
8631 (np->nlp_state != NLP_STE_NPR_NODE) ||
8632 !(np->nlp_flag & NLP_NPR_ADISC))
8633 continue;
James Smart09372822008-01-11 01:52:54 -05008634 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008635 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008636 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008637 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008638 }
James Smart78730cf2010-04-06 15:06:30 -04008639 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008640
8641 if (phba->sli_rev == LPFC_SLI_REV4)
8642 lpfc_sli4_unreg_all_rpis(vport);
8643
James Smartd7c255b2008-08-24 21:50:00 -04008644 lpfc_mbx_unreg_vpi(vport);
8645 spin_lock_irq(shost->host_lock);
8646 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008647 if (phba->sli_rev == LPFC_SLI_REV4)
8648 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008649 else
8650 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008651 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008652 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8653 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8654 /*
8655 * Driver needs to re-reg VPI in order for f/w
8656 * to update the MAC address.
8657 */
8658 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008659 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008660 }
8661
James Smartecfd03c2010-02-12 14:41:27 -05008662 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8663 lpfc_issue_init_vpi(vport);
8664 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008665 lpfc_register_new_vport(phba, vport, ndlp);
8666 else
8667 lpfc_do_scr_ns_plogi(phba, vport);
8668 goto out;
8669fdisc_failed:
James Smartc84163d2015-05-21 13:55:22 -04008670 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8671 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008672 /* Cancel discovery timer */
8673 lpfc_can_disctmo(vport);
8674 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008675out:
8676 lpfc_els_free_iocb(phba, cmdiocb);
8677}
8678
James Smarte59058c2008-08-24 21:49:00 -04008679/**
James Smart3621a712009-04-06 18:47:14 -04008680 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008681 * @vport: pointer to a virtual N_Port data structure.
8682 * @ndlp: pointer to a node-list data structure.
8683 * @retry: number of retries to the command IOCB.
8684 *
8685 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8686 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8687 * routine to issue the IOCB, which makes sure only one outstanding fabric
8688 * IOCB will be sent off HBA at any given time.
8689 *
8690 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8691 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8692 * will be stored into the context1 field of the IOCB for the completion
8693 * callback function to the FDISC ELS command.
8694 *
8695 * Return code
8696 * 0 - Successfully issued fdisc iocb command
8697 * 1 - Failed to issue fdisc iocb command
8698 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008699static int
James Smart92d7f7b2007-06-17 19:56:38 -05008700lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8701 uint8_t retry)
8702{
8703 struct lpfc_hba *phba = vport->phba;
8704 IOCB_t *icmd;
8705 struct lpfc_iocbq *elsiocb;
8706 struct serv_parm *sp;
8707 uint8_t *pcmd;
8708 uint16_t cmdsize;
8709 int did = ndlp->nlp_DID;
8710 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008711
James Smart5ffc2662009-11-18 15:39:44 -05008712 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008713 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008714 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8715 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8716 ELS_CMD_FDISC);
8717 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008718 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008719 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8720 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008721 return 1;
8722 }
8723
8724 icmd = &elsiocb->iocb;
8725 icmd->un.elsreq64.myID = 0;
8726 icmd->un.elsreq64.fl = 1;
8727
James Smart73d91e52011-10-10 21:32:10 -04008728 /*
8729 * SLI3 ports require a different context type value than SLI4.
8730 * Catch SLI3 ports here and override the prep.
8731 */
8732 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008733 icmd->ulpCt_h = 1;
8734 icmd->ulpCt_l = 0;
8735 }
James Smart92d7f7b2007-06-17 19:56:38 -05008736
8737 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8738 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8739 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8740 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8741 sp = (struct serv_parm *) pcmd;
8742 /* Setup CSPs accordingly for Fabric */
8743 sp->cmn.e_d_tov = 0;
8744 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008745 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008746 sp->cls1.classValid = 0;
8747 sp->cls2.seqDelivery = 1;
8748 sp->cls3.seqDelivery = 1;
8749
8750 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8751 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8752 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8753 pcmd += sizeof(uint32_t); /* Port Name */
8754 memcpy(pcmd, &vport->fc_portname, 8);
8755 pcmd += sizeof(uint32_t); /* Node Name */
8756 pcmd += sizeof(uint32_t); /* Node Name */
8757 memcpy(pcmd, &vport->fc_nodename, 8);
James Smartaeb3c812017-04-21 16:05:02 -07008758 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -05008759 lpfc_set_disctmo(vport);
8760
8761 phba->fc_stat.elsXmitFDISC++;
8762 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8763
James Smart858c9f62007-06-17 19:56:39 -05008764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8765 "Issue FDISC: did:x%x",
8766 did, 0, 0);
8767
James Smart92d7f7b2007-06-17 19:56:38 -05008768 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8769 if (rc == IOCB_ERROR) {
8770 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008771 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8773 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008774 return 1;
8775 }
8776 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008777 return 0;
8778}
8779
James Smarte59058c2008-08-24 21:49:00 -04008780/**
James Smart3621a712009-04-06 18:47:14 -04008781 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008782 * @phba: pointer to lpfc hba data structure.
8783 * @cmdiocb: pointer to lpfc command iocb data structure.
8784 * @rspiocb: pointer to lpfc response iocb data structure.
8785 *
8786 * This routine is the completion callback function to the issuing of a LOGO
8787 * ELS command off a vport. It frees the command IOCB and then decrement the
8788 * reference count held on ndlp for this completion function, indicating that
8789 * the reference to the ndlp is no long needed. Note that the
8790 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8791 * callback function and an additional explicit ndlp reference decrementation
8792 * will trigger the actual release of the ndlp.
8793 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008794static void
8795lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8796 struct lpfc_iocbq *rspiocb)
8797{
8798 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008799 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008800 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008802
James Smart9589b0622011-04-16 11:03:17 -04008803 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008804 irsp = &rspiocb->iocb;
8805 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8806 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8807 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008808
8809 lpfc_els_free_iocb(phba, cmdiocb);
8810 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008811
8812 /* Trigger the release of the ndlp after logo */
8813 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008814
8815 /* NPIV LOGO completes to NPort <nlp_DID> */
8816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8817 "2928 NPIV LOGO completes to NPort x%x "
8818 "Data: x%x x%x x%x x%x\n",
8819 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8820 irsp->ulpTimeout, vport->num_disc_nodes);
8821
8822 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8823 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008824 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008825 vport->fc_flag &= ~FC_FABRIC;
8826 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008827 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008828 }
James Smart92d7f7b2007-06-17 19:56:38 -05008829}
8830
James Smarte59058c2008-08-24 21:49:00 -04008831/**
James Smart3621a712009-04-06 18:47:14 -04008832 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008833 * @vport: pointer to a virtual N_Port data structure.
8834 * @ndlp: pointer to a node-list data structure.
8835 *
8836 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8837 *
8838 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8839 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8840 * will be stored into the context1 field of the IOCB for the completion
8841 * callback function to the LOGO ELS command.
8842 *
8843 * Return codes
8844 * 0 - Successfully issued logo off the @vport
8845 * 1 - Failed to issue logo off the @vport
8846 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008847int
8848lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8849{
8850 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8851 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008852 struct lpfc_iocbq *elsiocb;
8853 uint8_t *pcmd;
8854 uint16_t cmdsize;
8855
8856 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8857 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8858 ELS_CMD_LOGO);
8859 if (!elsiocb)
8860 return 1;
8861
James Smart92d7f7b2007-06-17 19:56:38 -05008862 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8863 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8864 pcmd += sizeof(uint32_t);
8865
8866 /* Fill in LOGO payload */
8867 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8868 pcmd += sizeof(uint32_t);
8869 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8870
James Smart858c9f62007-06-17 19:56:39 -05008871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8872 "Issue LOGO npiv did:x%x flg:x%x",
8873 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8874
James Smart92d7f7b2007-06-17 19:56:38 -05008875 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8876 spin_lock_irq(shost->host_lock);
8877 ndlp->nlp_flag |= NLP_LOGO_SND;
8878 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008879 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8880 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05008881 spin_lock_irq(shost->host_lock);
8882 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8883 spin_unlock_irq(shost->host_lock);
8884 lpfc_els_free_iocb(phba, elsiocb);
8885 return 1;
8886 }
8887 return 0;
8888}
8889
James Smarte59058c2008-08-24 21:49:00 -04008890/**
James Smart3621a712009-04-06 18:47:14 -04008891 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04008892 * @ptr: holder for the timer function associated data.
8893 *
8894 * This routine is invoked by the fabric iocb block timer after
8895 * timeout. It posts the fabric iocb block timeout event by setting the
8896 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8897 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8898 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8899 * posted event WORKER_FABRIC_BLOCK_TMO.
8900 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008901void
8902lpfc_fabric_block_timeout(unsigned long ptr)
8903{
8904 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8905 unsigned long iflags;
8906 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04008907
James Smart92d7f7b2007-06-17 19:56:38 -05008908 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8909 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8910 if (!tmo_posted)
8911 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8912 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8913
James Smart5e9d9b82008-06-14 22:52:53 -04008914 if (!tmo_posted)
8915 lpfc_worker_wake_up(phba);
8916 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008917}
8918
James Smarte59058c2008-08-24 21:49:00 -04008919/**
James Smart3621a712009-04-06 18:47:14 -04008920 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04008921 * @phba: pointer to lpfc hba data structure.
8922 *
8923 * This routine issues one fabric iocb from the driver internal list to
8924 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8925 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8926 * remove one pending fabric iocb from the driver internal list and invokes
8927 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8928 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008929static void
8930lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8931{
8932 struct lpfc_iocbq *iocb;
8933 unsigned long iflags;
8934 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05008935 IOCB_t *cmd;
8936
8937repeat:
8938 iocb = NULL;
8939 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05008940 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05008941 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8942 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8943 list);
8944 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05008945 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05008946 atomic_inc(&phba->fabric_iocb_count);
8947 }
8948 spin_unlock_irqrestore(&phba->hbalock, iflags);
8949 if (iocb) {
8950 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8951 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8952 iocb->iocb_flag |= LPFC_IO_FABRIC;
8953
James Smart858c9f62007-06-17 19:56:39 -05008954 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8955 "Fabric sched1: ste:x%x",
8956 iocb->vport->port_state, 0, 0);
8957
James Smart3772a992009-05-22 14:50:54 -04008958 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008959
8960 if (ret == IOCB_ERROR) {
8961 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8962 iocb->fabric_iocb_cmpl = NULL;
8963 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8964 cmd = &iocb->iocb;
8965 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8966 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8967 iocb->iocb_cmpl(phba, iocb, iocb);
8968
8969 atomic_dec(&phba->fabric_iocb_count);
8970 goto repeat;
8971 }
8972 }
8973
8974 return;
8975}
8976
James Smarte59058c2008-08-24 21:49:00 -04008977/**
James Smart3621a712009-04-06 18:47:14 -04008978 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008979 * @phba: pointer to lpfc hba data structure.
8980 *
8981 * This routine unblocks the issuing fabric iocb command. The function
8982 * will clear the fabric iocb block bit and then invoke the routine
8983 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8984 * from the driver internal fabric iocb list.
8985 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008986void
8987lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8988{
8989 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8990
8991 lpfc_resume_fabric_iocbs(phba);
8992 return;
8993}
8994
James Smarte59058c2008-08-24 21:49:00 -04008995/**
James Smart3621a712009-04-06 18:47:14 -04008996 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008997 * @phba: pointer to lpfc hba data structure.
8998 *
8999 * This routine blocks the issuing fabric iocb for a specified amount of
9000 * time (currently 100 ms). This is done by set the fabric iocb block bit
9001 * and set up a timeout timer for 100ms. When the block bit is set, no more
9002 * fabric iocb will be issued out of the HBA.
9003 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009004static void
9005lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9006{
9007 int blocked;
9008
9009 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05009010 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05009011 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04009012 mod_timer(&phba->fabric_block_timer,
9013 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05009014
9015 return;
9016}
9017
James Smarte59058c2008-08-24 21:49:00 -04009018/**
James Smart3621a712009-04-06 18:47:14 -04009019 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04009020 * @phba: pointer to lpfc hba data structure.
9021 * @cmdiocb: pointer to lpfc command iocb data structure.
9022 * @rspiocb: pointer to lpfc response iocb data structure.
9023 *
9024 * This routine is the callback function that is put to the fabric iocb's
9025 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9026 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9027 * function first restores and invokes the original iocb's callback function
9028 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9029 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9030 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009031static void
9032lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9033 struct lpfc_iocbq *rspiocb)
9034{
9035 struct ls_rjt stat;
9036
Shyam Sainie01ea5e2016-12-24 16:21:07 +05309037 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -05009038
9039 switch (rspiocb->iocb.ulpStatus) {
9040 case IOSTAT_NPORT_RJT:
9041 case IOSTAT_FABRIC_RJT:
9042 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9043 lpfc_block_fabric_iocbs(phba);
9044 }
9045 break;
9046
9047 case IOSTAT_NPORT_BSY:
9048 case IOSTAT_FABRIC_BSY:
9049 lpfc_block_fabric_iocbs(phba);
9050 break;
9051
9052 case IOSTAT_LS_RJT:
9053 stat.un.lsRjtError =
9054 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9055 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9056 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9057 lpfc_block_fabric_iocbs(phba);
9058 break;
9059 }
9060
James Smarta0f2d3e2017-02-12 13:52:31 -08009061 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009062
9063 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9064 cmdiocb->fabric_iocb_cmpl = NULL;
9065 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9066 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9067
9068 atomic_dec(&phba->fabric_iocb_count);
9069 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05009070 /* Post any pending iocbs to HBA */
9071 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009072 }
9073}
9074
James Smarte59058c2008-08-24 21:49:00 -04009075/**
James Smart3621a712009-04-06 18:47:14 -04009076 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009077 * @phba: pointer to lpfc hba data structure.
9078 * @iocb: pointer to lpfc command iocb data structure.
9079 *
9080 * This routine is used as the top-level API for issuing a fabric iocb command
9081 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9082 * function makes sure that only one fabric bound iocb will be outstanding at
9083 * any given time. As such, this function will first check to see whether there
9084 * is already an outstanding fabric iocb on the wire. If so, it will put the
9085 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9086 * issued later. Otherwise, it will issue the iocb on the wire and update the
9087 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9088 *
9089 * Note, this implementation has a potential sending out fabric IOCBs out of
9090 * order. The problem is caused by the construction of the "ready" boolen does
9091 * not include the condition that the internal fabric IOCB list is empty. As
9092 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9093 * ahead of the fabric IOCBs in the internal list.
9094 *
9095 * Return code
9096 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9097 * IOCB_ERROR - failed to issue fabric iocb
9098 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009099static int
James Smart92d7f7b2007-06-17 19:56:38 -05009100lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9101{
9102 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05009103 int ready;
9104 int ret;
9105
James Smarta0f2d3e2017-02-12 13:52:31 -08009106 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -05009107
9108 spin_lock_irqsave(&phba->hbalock, iflags);
9109 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9110 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9111
James Smart7f5f3d02008-02-08 18:50:14 -05009112 if (ready)
9113 /* Increment fabric iocb count to hold the position */
9114 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05009115 spin_unlock_irqrestore(&phba->hbalock, iflags);
9116 if (ready) {
9117 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9118 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9119 iocb->iocb_flag |= LPFC_IO_FABRIC;
9120
James Smart858c9f62007-06-17 19:56:39 -05009121 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9122 "Fabric sched2: ste:x%x",
9123 iocb->vport->port_state, 0, 0);
9124
James Smart3772a992009-05-22 14:50:54 -04009125 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009126
9127 if (ret == IOCB_ERROR) {
9128 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9129 iocb->fabric_iocb_cmpl = NULL;
9130 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9131 atomic_dec(&phba->fabric_iocb_count);
9132 }
9133 } else {
9134 spin_lock_irqsave(&phba->hbalock, iflags);
9135 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9136 spin_unlock_irqrestore(&phba->hbalock, iflags);
9137 ret = IOCB_SUCCESS;
9138 }
9139 return ret;
9140}
9141
James Smarte59058c2008-08-24 21:49:00 -04009142/**
James Smart3621a712009-04-06 18:47:14 -04009143 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009144 * @vport: pointer to a virtual N_Port data structure.
9145 *
9146 * This routine aborts all the IOCBs associated with a @vport from the
9147 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9148 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9149 * list, removes each IOCB associated with the @vport off the list, set the
9150 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9151 * associated with the IOCB.
9152 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009153static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05009154{
9155 LIST_HEAD(completions);
9156 struct lpfc_hba *phba = vport->phba;
9157 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05009158
9159 spin_lock_irq(&phba->hbalock);
9160 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9161 list) {
9162
9163 if (piocb->vport != vport)
9164 continue;
9165
9166 list_move_tail(&piocb->list, &completions);
9167 }
9168 spin_unlock_irq(&phba->hbalock);
9169
James Smarta257bf92009-04-06 18:48:10 -04009170 /* Cancel all the IOCBs from the completions list */
9171 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9172 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009173}
9174
James Smarte59058c2008-08-24 21:49:00 -04009175/**
James Smart3621a712009-04-06 18:47:14 -04009176 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009177 * @ndlp: pointer to a node-list data structure.
9178 *
9179 * This routine aborts all the IOCBs associated with an @ndlp from the
9180 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9181 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9182 * list, removes each IOCB associated with the @ndlp off the list, set the
9183 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9184 * associated with the IOCB.
9185 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009186void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9187{
9188 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04009189 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009190 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -08009191 struct lpfc_sli_ring *pring;
9192
9193 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009194
9195 spin_lock_irq(&phba->hbalock);
9196 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9197 list) {
9198 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9199
9200 list_move_tail(&piocb->list, &completions);
9201 }
9202 }
9203 spin_unlock_irq(&phba->hbalock);
9204
James Smarta257bf92009-04-06 18:48:10 -04009205 /* Cancel all the IOCBs from the completions list */
9206 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9207 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009208}
9209
James Smarte59058c2008-08-24 21:49:00 -04009210/**
James Smart3621a712009-04-06 18:47:14 -04009211 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009212 * @phba: pointer to lpfc hba data structure.
9213 *
9214 * This routine aborts all the IOCBs currently on the driver internal
9215 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9216 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9217 * list, removes IOCBs off the list, set the status feild to
9218 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9219 * the IOCB.
9220 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009221void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9222{
9223 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009224
9225 spin_lock_irq(&phba->hbalock);
9226 list_splice_init(&phba->fabric_iocb_list, &completions);
9227 spin_unlock_irq(&phba->hbalock);
9228
James Smarta257bf92009-04-06 18:48:10 -04009229 /* Cancel all the IOCBs from the completions list */
9230 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9231 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009232}
James Smart6fb120a2009-05-22 14:52:59 -04009233
9234/**
James Smart1151e3e2011-02-16 12:39:35 -05009235 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9236 * @vport: pointer to lpfc vport data structure.
9237 *
9238 * This routine is invoked by the vport cleanup for deletions and the cleanup
9239 * for an ndlp on removal.
9240 **/
9241void
9242lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9243{
9244 struct lpfc_hba *phba = vport->phba;
9245 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9246 unsigned long iflag = 0;
9247
9248 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -08009249 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -05009250 list_for_each_entry_safe(sglq_entry, sglq_next,
9251 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9252 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9253 sglq_entry->ndlp = NULL;
9254 }
James Smart895427b2017-02-12 13:52:30 -08009255 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -05009256 spin_unlock_irqrestore(&phba->hbalock, iflag);
9257 return;
9258}
9259
9260/**
James Smart6fb120a2009-05-22 14:52:59 -04009261 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9262 * @phba: pointer to lpfc hba data structure.
9263 * @axri: pointer to the els xri abort wcqe structure.
9264 *
9265 * This routine is invoked by the worker thread to process a SLI4 slow-path
9266 * ELS aborted xri.
9267 **/
9268void
9269lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9270 struct sli4_wcqe_xri_aborted *axri)
9271{
9272 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05009273 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04009274 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05009275
James Smart6fb120a2009-05-22 14:52:59 -04009276 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9277 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05009278 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -08009279 struct lpfc_sli_ring *pring;
9280
9281 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009282
James Smart0f65ff62010-02-26 14:14:23 -05009283 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -08009284 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009285 list_for_each_entry_safe(sglq_entry, sglq_next,
9286 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9287 if (sglq_entry->sli4_xritag == xri) {
9288 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05009289 ndlp = sglq_entry->ndlp;
9290 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04009291 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -08009292 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05009293 sglq_entry->state = SGL_FREED;
James Smart895427b2017-02-12 13:52:30 -08009294 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009295 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04009296 lpfc_set_rrq_active(phba, ndlp,
9297 sglq_entry->sli4_lxritag,
9298 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04009299
9300 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05009301 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04009302 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009303 return;
9304 }
9305 }
James Smart895427b2017-02-12 13:52:30 -08009306 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009307 lxri = lpfc_sli4_xri_inrange(phba, xri);
9308 if (lxri == NO_XRI) {
9309 spin_unlock_irqrestore(&phba->hbalock, iflag);
9310 return;
9311 }
James Smart895427b2017-02-12 13:52:30 -08009312 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009313 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05009314 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smart895427b2017-02-12 13:52:30 -08009315 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009316 spin_unlock_irqrestore(&phba->hbalock, iflag);
9317 return;
9318 }
9319 sglq_entry->state = SGL_XRI_ABORTED;
James Smart895427b2017-02-12 13:52:30 -08009320 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009321 spin_unlock_irqrestore(&phba->hbalock, iflag);
9322 return;
James Smart6fb120a2009-05-22 14:52:59 -04009323}
James Smart086a3452012-08-14 14:25:21 -04009324
9325/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9326 * @vport: pointer to virtual port object.
9327 * @ndlp: nodelist pointer for the impacted node.
9328 *
9329 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9330 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9331 * the driver is required to send a LOGO to the remote node before it
9332 * attempts to recover its login to the remote node.
9333 */
9334void
9335lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9336 struct lpfc_nodelist *ndlp)
9337{
9338 struct Scsi_Host *shost;
9339 struct lpfc_hba *phba;
9340 unsigned long flags = 0;
9341
9342 shost = lpfc_shost_from_vport(vport);
9343 phba = vport->phba;
9344 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9345 lpfc_printf_log(phba, KERN_INFO,
9346 LOG_SLI, "3093 No rport recovery needed. "
9347 "rport in state 0x%x\n", ndlp->nlp_state);
9348 return;
9349 }
9350 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9351 "3094 Start rport recovery on shost id 0x%x "
9352 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9353 "flags 0x%x\n",
9354 shost->host_no, ndlp->nlp_DID,
9355 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9356 ndlp->nlp_flag);
9357 /*
9358 * The rport is not responding. Remove the FCP-2 flag to prevent
9359 * an ADISC in the follow-up recovery code.
9360 */
9361 spin_lock_irqsave(shost->host_lock, flags);
9362 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9363 spin_unlock_irqrestore(shost->host_lock, flags);
9364 lpfc_issue_els_logo(vport, ndlp, 0);
9365 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
9366}
9367