blob: 95733981828d48424f9d443e4723b40a460a9bf1 [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 Wellnitzc9f8735b2006-02-28 19:25:23 -0500119 return 1;
dea31012005-04-17 16:05:31 -0500120}
121
James Smarte59058c2008-08-24 21:49:00 -0400122/**
James Smart3621a712009-04-06 18:47:14 -0400123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
131 *
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
145 *
146 * Return code
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
149 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400150struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500151lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
152 uint16_t cmdSize, uint8_t retry,
153 struct lpfc_nodelist *ndlp, uint32_t did,
154 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500155{
James Smart2e0fef82007-06-17 19:56:36 -0500156 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400157 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500158 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
159 struct ulp_bde64 *bpl;
160 IOCB_t *icmd;
161
dea31012005-04-17 16:05:31 -0500162
James Smart2e0fef82007-06-17 19:56:36 -0500163 if (!lpfc_is_link_up(phba))
164 return NULL;
dea31012005-04-17 16:05:31 -0500165
dea31012005-04-17 16:05:31 -0500166 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400167 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500168
169 if (elsiocb == NULL)
170 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500171
James Smart0c287582009-06-10 17:22:56 -0400172 /*
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
175 */
176 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400177 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400178 ((elscmd == ELS_CMD_FLOGI) ||
179 (elscmd == ELS_CMD_FDISC) ||
180 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500181 switch (elscmd) {
182 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400183 elsiocb->iocb_flag |=
184 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500185 & LPFC_FIP_ELS_ID_MASK);
186 break;
187 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400188 elsiocb->iocb_flag |=
189 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500190 & LPFC_FIP_ELS_ID_MASK);
191 break;
192 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400193 elsiocb->iocb_flag |=
194 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500195 & LPFC_FIP_ELS_ID_MASK);
196 break;
197 }
James Smart0c287582009-06-10 17:22:56 -0400198 else
James Smartc8685952009-11-18 15:39:16 -0500199 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400200
dea31012005-04-17 16:05:31 -0500201 icmd = &elsiocb->iocb;
202
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400205 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
206 if (pcmd)
207 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500208 if (!pcmd || !pcmd->virt)
209 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500210
211 INIT_LIST_HEAD(&pcmd->list);
212
213 /* Allocate buffer for response payload */
214 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500215 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500216 if (prsp)
217 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
218 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500219 if (!prsp || !prsp->virt)
220 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500221 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500222 } else
dea31012005-04-17 16:05:31 -0500223 prsp = NULL;
dea31012005-04-17 16:05:31 -0500224
225 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500226 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500227 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500228 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
229 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500230 if (!pbuflist || !pbuflist->virt)
231 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500232
233 INIT_LIST_HEAD(&pbuflist->list);
234
dea31012005-04-17 16:05:31 -0500235 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400236 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
237 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
238 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500239 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400240
241 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500242 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400243 if (elscmd == ELS_CMD_FLOGI)
244 icmd->ulpTimeout = FF_DEF_RATOV * 2;
245 else
246 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500247 } else {
James Smart939723a2012-05-09 21:19:03 -0400248 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
249 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
250 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
251 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
252 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500253 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
254 }
dea31012005-04-17 16:05:31 -0500255 icmd->ulpBdeCount = 1;
256 icmd->ulpLe = 1;
257 icmd->ulpClass = CLASS3;
258
James Smart939723a2012-05-09 21:19:03 -0400259 /*
260 * If we have NPIV enabled, we want to send ELS traffic by VPI.
261 * For SLI4, since the driver controls VPIs we also want to include
262 * all ELS pt2pt protocol traffic as well.
263 */
264 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
265 ((phba->sli_rev == LPFC_SLI_REV4) &&
266 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500267
James Smart939723a2012-05-09 21:19:03 -0400268 if (expectRsp) {
269 icmd->un.elsreq64.myID = vport->fc_myDID;
270
271 /* For ELS_REQUEST64_CR, use the VPI by default */
272 icmd->ulpContext = phba->vpi_ids[vport->vpi];
273 }
274
James Smart92d7f7b2007-06-17 19:56:38 -0500275 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500276 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
277 if (elscmd == ELS_CMD_ECHO)
278 icmd->ulpCt_l = 0; /* context = invalid RPI */
279 else
280 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500281 }
282
dea31012005-04-17 16:05:31 -0500283 bpl = (struct ulp_bde64 *) pbuflist->virt;
284 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
285 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
286 bpl->tus.f.bdeSize = cmdSize;
287 bpl->tus.f.bdeFlags = 0;
288 bpl->tus.w = le32_to_cpu(bpl->tus.w);
289
290 if (expectRsp) {
291 bpl++;
292 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
293 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
294 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400295 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500296 bpl->tus.w = le32_to_cpu(bpl->tus.w);
297 }
298
James Smartfa4066b2008-01-11 01:53:27 -0500299 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400300 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500301 if (!elsiocb->context1)
302 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400303 elsiocb->context2 = pcmd;
304 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500305 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500306 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500307 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
308
309 if (prsp) {
310 list_add(&prsp->list, &pcmd->list);
311 }
dea31012005-04-17 16:05:31 -0500312 if (expectRsp) {
313 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
315 "0116 Xmit ELS command x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400316 "NPORT x%x I/O tag: x%x, port state:x%x"
317 " fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400318 elscmd, did, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400319 vport->port_state,
320 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500321 } else {
322 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
324 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400325 "NPORT x%x I/O tag: x%x, size: x%x "
326 "port_state x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400327 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400328 cmdSize, vport->port_state,
329 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500330 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500331 return elsiocb;
dea31012005-04-17 16:05:31 -0500332
James Smartfa4066b2008-01-11 01:53:27 -0500333els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500334 if (expectRsp)
335 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500336 kfree(pbuflist);
337
338els_iocb_free_prsp_exit:
339 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
340 kfree(prsp);
341
342els_iocb_free_pcmb_exit:
343 kfree(pcmd);
344 lpfc_sli_release_iocbq(phba, elsiocb);
345 return NULL;
346}
dea31012005-04-17 16:05:31 -0500347
James Smarte59058c2008-08-24 21:49:00 -0400348/**
James Smart3621a712009-04-06 18:47:14 -0400349 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400350 * @vport: pointer to a host virtual N_Port data structure.
351 *
352 * This routine issues a fabric registration login for a @vport. An
353 * active ndlp node with Fabric_DID must already exist for this @vport.
354 * The routine invokes two mailbox commands to carry out fabric registration
355 * login through the HBA firmware: the first mailbox command requests the
356 * HBA to perform link configuration for the @vport; and the second mailbox
357 * command requests the HBA to perform the actual fabric registration login
358 * with the @vport.
359 *
360 * Return code
361 * 0 - successfully issued fabric registration login for @vport
362 * -ENXIO -- failed to issue fabric registration login for @vport
363 **/
James Smart3772a992009-05-22 14:50:54 -0400364int
James Smart92d7f7b2007-06-17 19:56:38 -0500365lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
366{
367 struct lpfc_hba *phba = vport->phba;
368 LPFC_MBOXQ_t *mbox;
369 struct lpfc_dmabuf *mp;
370 struct lpfc_nodelist *ndlp;
371 struct serv_parm *sp;
372 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400373 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500374
375 sp = &phba->fc_fabparam;
376 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500377 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400378 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500379 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400380 }
James Smart92d7f7b2007-06-17 19:56:38 -0500381
382 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400383 if (!mbox) {
384 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500385 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400386 }
James Smart92d7f7b2007-06-17 19:56:38 -0500387
388 vport->port_state = LPFC_FABRIC_CFG_LINK;
389 lpfc_config_link(phba, mbox);
390 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
391 mbox->vport = vport;
392
James Smart0b727fe2007-10-27 13:37:25 -0400393 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400394 if (rc == MBX_NOT_FINISHED) {
395 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500396 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400397 }
James Smart92d7f7b2007-06-17 19:56:38 -0500398
399 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400400 if (!mbox) {
401 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500402 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400403 }
James Smart40426292010-12-15 17:58:10 -0500404 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
405 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400406 if (rc) {
407 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500408 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400409 }
James Smart92d7f7b2007-06-17 19:56:38 -0500410
411 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
412 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500413 /* increment the reference count on ndlp to hold reference
414 * for the callback routine.
415 */
James Smart92d7f7b2007-06-17 19:56:38 -0500416 mbox->context2 = lpfc_nlp_get(ndlp);
417
James Smart0b727fe2007-10-27 13:37:25 -0400418 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400419 if (rc == MBX_NOT_FINISHED) {
420 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500421 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400422 }
James Smart92d7f7b2007-06-17 19:56:38 -0500423
424 return 0;
425
426fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500427 /* decrement the reference count on ndlp just incremented
428 * for the failed mbox command.
429 */
James Smart92d7f7b2007-06-17 19:56:38 -0500430 lpfc_nlp_put(ndlp);
431 mp = (struct lpfc_dmabuf *) mbox->context1;
432 lpfc_mbuf_free(phba, mp->virt, mp->phys);
433 kfree(mp);
434fail_free_mbox:
435 mempool_free(mbox, phba->mbox_mem_pool);
436
437fail:
438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400440 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500441 return -ENXIO;
442}
443
James Smarte59058c2008-08-24 21:49:00 -0400444/**
James Smart6fb120a2009-05-22 14:52:59 -0400445 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
446 * @vport: pointer to a host virtual N_Port data structure.
447 *
448 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500449 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400450 *
451 * Return code
452 * 0 - successfully issued REG_VFI for @vport
453 * A failure code otherwise.
454 **/
James Smart1b511972011-12-13 13:23:09 -0500455int
James Smart6fb120a2009-05-22 14:52:59 -0400456lpfc_issue_reg_vfi(struct lpfc_vport *vport)
457{
458 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500459 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400460 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500461 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400462 int rc = 0;
463
James Smart939723a2012-05-09 21:19:03 -0400464 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500465 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400466 !(phba->link_flag & LS_LOOPBACK_MODE) &&
467 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500468 ndlp = lpfc_findnode_did(vport, Fabric_DID);
469 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
470 rc = -ENODEV;
471 goto fail;
472 }
James Smart6fb120a2009-05-22 14:52:59 -0400473 }
474
James Smart6fb120a2009-05-22 14:52:59 -0400475 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
476 if (!mboxq) {
477 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500478 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400479 }
James Smartd6de08c2015-12-16 18:11:53 -0500480
481 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
482 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
483 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
484 if (!dmabuf) {
485 rc = -ENOMEM;
486 goto fail;
487 }
488 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
489 if (!dmabuf->virt) {
490 rc = -ENOMEM;
491 goto fail;
492 }
493 memcpy(dmabuf->virt, &phba->fc_fabparam,
494 sizeof(struct serv_parm));
495 }
496
James Smart6fb120a2009-05-22 14:52:59 -0400497 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500498 if (dmabuf)
499 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
500 else
501 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500502
James Smart6fb120a2009-05-22 14:52:59 -0400503 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
504 mboxq->vport = vport;
505 mboxq->context1 = dmabuf;
506 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
507 if (rc == MBX_NOT_FINISHED) {
508 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500509 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400510 }
511 return 0;
512
James Smart6fb120a2009-05-22 14:52:59 -0400513fail:
James Smartd6de08c2015-12-16 18:11:53 -0500514 if (mboxq)
515 mempool_free(mboxq, phba->mbox_mem_pool);
516 if (dmabuf) {
517 if (dmabuf->virt)
518 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
519 kfree(dmabuf);
520 }
521
James Smart6fb120a2009-05-22 14:52:59 -0400522 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
523 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
524 "0289 Issue Register VFI failed: Err %d\n", rc);
525 return rc;
526}
527
528/**
James Smart1b511972011-12-13 13:23:09 -0500529 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
530 * @vport: pointer to a host virtual N_Port data structure.
531 *
532 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
533 * the @vport. This mailbox command is necessary for SLI4 port only.
534 *
535 * Return code
536 * 0 - successfully issued REG_VFI for @vport
537 * A failure code otherwise.
538 **/
539int
540lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
541{
542 struct lpfc_hba *phba = vport->phba;
543 struct Scsi_Host *shost;
544 LPFC_MBOXQ_t *mboxq;
545 int rc;
546
547 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
548 if (!mboxq) {
549 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
550 "2556 UNREG_VFI mbox allocation failed"
551 "HBA state x%x\n", phba->pport->port_state);
552 return -ENOMEM;
553 }
554
555 lpfc_unreg_vfi(mboxq, vport);
556 mboxq->vport = vport;
557 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
558
559 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
560 if (rc == MBX_NOT_FINISHED) {
561 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
562 "2557 UNREG_VFI issue mbox failed rc x%x "
563 "HBA state x%x\n",
564 rc, phba->pport->port_state);
565 mempool_free(mboxq, phba->mbox_mem_pool);
566 return -EIO;
567 }
568
569 shost = lpfc_shost_from_vport(vport);
570 spin_lock_irq(shost->host_lock);
571 vport->fc_flag &= ~FC_VFI_REGISTERED;
572 spin_unlock_irq(shost->host_lock);
573 return 0;
574}
575
576/**
James Smart92494142011-02-16 12:39:44 -0500577 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
578 * @vport: pointer to a host virtual N_Port data structure.
579 * @sp: pointer to service parameter data structure.
580 *
581 * This routine is called from FLOGI/FDISC completion handler functions.
582 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
583 * node nodename is changed in the completion service parameter else return
584 * 0. This function also set flag in the vport data structure to delay
585 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
586 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
587 * node nodename is changed in the completion service parameter.
588 *
589 * Return code
590 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
591 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
592 *
593 **/
594static uint8_t
595lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
596 struct serv_parm *sp)
597{
James Smart8eb8b962016-07-06 12:36:08 -0700598 struct lpfc_hba *phba = vport->phba;
James Smart92494142011-02-16 12:39:44 -0500599 uint8_t fabric_param_changed = 0;
600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
601
602 if ((vport->fc_prevDID != vport->fc_myDID) ||
603 memcmp(&vport->fabric_portname, &sp->portName,
604 sizeof(struct lpfc_name)) ||
605 memcmp(&vport->fabric_nodename, &sp->nodeName,
James Smartaeb3c812017-04-21 16:05:02 -0700606 sizeof(struct lpfc_name)) ||
607 (vport->vport_flag & FAWWPN_PARAM_CHG)) {
James Smart92494142011-02-16 12:39:44 -0500608 fabric_param_changed = 1;
James Smartaeb3c812017-04-21 16:05:02 -0700609 vport->vport_flag &= ~FAWWPN_PARAM_CHG;
610 }
James Smart92494142011-02-16 12:39:44 -0500611 /*
612 * Word 1 Bit 31 in common service parameter is overloaded.
613 * Word 1 Bit 31 in FLOGI request is multiple NPort request
614 * Word 1 Bit 31 in FLOGI response is clean address bit
615 *
616 * If fabric parameter is changed and clean address bit is
617 * cleared delay nport discovery if
618 * - vport->fc_prevDID != 0 (not initial discovery) OR
619 * - lpfc_delay_discovery module parameter is set.
620 */
621 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
James Smart8eb8b962016-07-06 12:36:08 -0700622 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
James Smart92494142011-02-16 12:39:44 -0500623 spin_lock_irq(shost->host_lock);
624 vport->fc_flag |= FC_DISC_DELAYED;
625 spin_unlock_irq(shost->host_lock);
626 }
627
628 return fabric_param_changed;
629}
630
631
632/**
James Smart3621a712009-04-06 18:47:14 -0400633 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400634 * @vport: pointer to a host virtual N_Port data structure.
635 * @ndlp: pointer to a node-list data structure.
636 * @sp: pointer to service parameter data structure.
637 * @irsp: pointer to the IOCB within the lpfc response IOCB.
638 *
639 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
640 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
641 * port in a fabric topology. It properly sets up the parameters to the @ndlp
642 * from the IOCB response. It also check the newly assigned N_Port ID to the
643 * @vport against the previously assigned N_Port ID. If it is different from
644 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
645 * is invoked on all the remaining nodes with the @vport to unregister the
646 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
647 * is invoked to register login to the fabric.
648 *
649 * Return code
650 * 0 - Success (currently, always return 0)
651 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500652static int
James Smart2e0fef82007-06-17 19:56:36 -0500653lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
654 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500655{
James Smart2e0fef82007-06-17 19:56:36 -0500656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
657 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500658 struct lpfc_nodelist *np;
659 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500660 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500661
James Smart2e0fef82007-06-17 19:56:36 -0500662 spin_lock_irq(shost->host_lock);
663 vport->fc_flag |= FC_FABRIC;
664 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500665
666 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
667 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
668 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
669
James Smart12265f62010-10-22 11:05:53 -0400670 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500671 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
672
James Smart76a95d72010-11-20 23:11:48 -0500673 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500674 spin_lock_irq(shost->host_lock);
675 vport->fc_flag |= FC_PUBLIC_LOOP;
676 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500677 }
678
James Smart2e0fef82007-06-17 19:56:36 -0500679 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500680 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500681 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500682 ndlp->nlp_class_sup = 0;
683 if (sp->cls1.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS1;
685 if (sp->cls2.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS2;
687 if (sp->cls3.classValid)
688 ndlp->nlp_class_sup |= FC_COS_CLASS3;
689 if (sp->cls4.classValid)
690 ndlp->nlp_class_sup |= FC_COS_CLASS4;
691 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
692 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500693
694 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500695 if (fabric_param_changed) {
696 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700697 if (phba->cfg_enable_SmartSAN ||
698 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500699 /* Setup appropriate attribute masks */
700 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700701 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500702 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
703 else
704 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700705 } else {
706 vport->fdmi_hba_mask = 0;
707 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500708 }
709
710 }
James Smart92494142011-02-16 12:39:44 -0500711 memcpy(&vport->fabric_portname, &sp->portName,
712 sizeof(struct lpfc_name));
713 memcpy(&vport->fabric_nodename, &sp->nodeName,
714 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500715 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
716
James Smart92d7f7b2007-06-17 19:56:38 -0500717 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
718 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400719 lpfc_printf_vlog(vport, KERN_WARNING,
720 LOG_ELS | LOG_VPORT,
721 "1816 FLOGI NPIV supported, "
722 "response data 0x%x\n",
723 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500724 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500725 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500726 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500727 } else {
728 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400729 to call reg_vnpid atleast for the physcial host */
730 lpfc_printf_vlog(vport, KERN_WARNING,
731 LOG_ELS | LOG_VPORT,
732 "1817 Fabric does not support NPIV "
733 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500734 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500735 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500736 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500737 }
738 }
739
James Smartae05ebe2013-03-01 16:35:38 -0500740 /*
741 * For FC we need to do some special processing because of the SLI
742 * Port's default settings of the Common Service Parameters.
743 */
James Smartd6de08c2015-12-16 18:11:53 -0500744 if ((phba->sli_rev == LPFC_SLI_REV4) &&
745 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500746 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500747 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500748 lpfc_unregister_fcf_prep(phba);
749
750 /* This should just update the VFI CSPs*/
751 if (vport->fc_flag & FC_VFI_REGISTERED)
752 lpfc_issue_reg_vfi(vport);
753 }
754
James Smart92494142011-02-16 12:39:44 -0500755 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500756 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
757
758 /* If our NportID changed, we need to ensure all
759 * remaining NPORTs get unreg_login'ed.
760 */
761 list_for_each_entry_safe(np, next_np,
762 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400763 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500764 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500765 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
766 !(np->nlp_flag & NLP_NPR_ADISC))
767 continue;
768 spin_lock_irq(shost->host_lock);
769 np->nlp_flag &= ~NLP_NPR_ADISC;
770 spin_unlock_irq(shost->host_lock);
771 lpfc_unreg_rpi(vport, np);
772 }
James Smart78730cf2010-04-06 15:06:30 -0400773 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400774
James Smart5248a742011-07-22 18:37:06 -0400775 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400776 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500777 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500778 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500779 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
780 spin_unlock_irq(shost->host_lock);
781 }
James Smart27aa1b72012-05-09 21:18:49 -0400782
783 /*
784 * For SLI3 and SLI4, the VPI needs to be reregistered in
785 * response to this fabric parameter change event.
786 */
787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
789 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400790 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
791 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
792 /*
793 * Driver needs to re-reg VPI in order for f/w
794 * to update the MAC address.
795 */
James Smart9589b0622011-04-16 11:03:17 -0400796 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400797 lpfc_register_new_vport(phba, vport, ndlp);
798 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500799 }
800
James Smart6fb120a2009-05-22 14:52:59 -0400801 if (phba->sli_rev < LPFC_SLI_REV4) {
802 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
803 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
804 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
805 lpfc_register_new_vport(phba, vport, ndlp);
806 else
807 lpfc_issue_fabric_reglogin(vport);
808 } else {
809 ndlp->nlp_type |= NLP_FABRIC;
810 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500811 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
812 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400813 lpfc_start_fdiscs(phba);
814 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500815 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500816 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500817 else {
818 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
819 "3135 Need register VFI: (x%x/%x)\n",
820 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400821 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500822 }
James Smart92d7f7b2007-06-17 19:56:38 -0500823 }
dea31012005-04-17 16:05:31 -0500824 return 0;
dea31012005-04-17 16:05:31 -0500825}
James Smart1b511972011-12-13 13:23:09 -0500826
James Smarte59058c2008-08-24 21:49:00 -0400827/**
James Smart3621a712009-04-06 18:47:14 -0400828 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400829 * @vport: pointer to a host virtual N_Port data structure.
830 * @ndlp: pointer to a node-list data structure.
831 * @sp: pointer to service parameter data structure.
832 *
833 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
834 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
835 * in a point-to-point topology. First, the @vport's N_Port Name is compared
836 * with the received N_Port Name: if the @vport's N_Port Name is greater than
837 * the received N_Port Name lexicographically, this node shall assign local
838 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
839 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
840 * this node shall just wait for the remote node to issue PLOGI and assign
841 * N_Port IDs.
842 *
843 * Return code
844 * 0 - Success
845 * -ENXIO - Fail
846 **/
dea31012005-04-17 16:05:31 -0500847static int
James Smart2e0fef82007-06-17 19:56:36 -0500848lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
849 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500850{
James Smart2e0fef82007-06-17 19:56:36 -0500851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
852 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500853 LPFC_MBOXQ_t *mbox;
854 int rc;
855
James Smart2e0fef82007-06-17 19:56:36 -0500856 spin_lock_irq(shost->host_lock);
857 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500858 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500859 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500860
James Smartd33d0eb2017-11-20 16:00:34 -0800861 /* If we are pt2pt with another NPort, force NPIV off! */
862 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
863
James Smartd6de08c2015-12-16 18:11:53 -0500864 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
865 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
866 lpfc_unregister_fcf_prep(phba);
867
868 spin_lock_irq(shost->host_lock);
869 vport->fc_flag &= ~FC_VFI_REGISTERED;
870 spin_unlock_irq(shost->host_lock);
871 phba->fc_topology_changed = 0;
872 }
873
James Smart2e0fef82007-06-17 19:56:36 -0500874 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500875 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400876
dea31012005-04-17 16:05:31 -0500877 if (rc >= 0) {
878 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500879 spin_lock_irq(shost->host_lock);
880 vport->fc_flag |= FC_PT2PT_PLOGI;
881 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500882
883 /*
James Smartd6de08c2015-12-16 18:11:53 -0500884 * N_Port ID cannot be 0, set our Id to LocalID
885 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500886 */
887
888 /* not equal */
889 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500890 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500891
James Smarte47c9092008-02-08 18:49:26 -0500892 /* Decrement ndlp reference count indicating that ndlp can be
893 * safely released when other references to it are done.
894 */
James Smart329f9bc2007-04-25 09:53:01 -0400895 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500896
James Smart2e0fef82007-06-17 19:56:36 -0500897 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500898 if (!ndlp) {
899 /*
900 * Cannot find existing Fabric ndlp, so allocate a
901 * new one
902 */
James Smart9d3d3402017-04-21 16:05:00 -0700903 ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500904 if (!ndlp)
905 goto fail;
James Smarte47c9092008-02-08 18:49:26 -0500906 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
907 ndlp = lpfc_enable_node(vport, ndlp,
908 NLP_STE_UNUSED_NODE);
909 if(!ndlp)
910 goto fail;
dea31012005-04-17 16:05:31 -0500911 }
912
913 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500914 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500915 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500916 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500917 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500918 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
919 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500920 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500921 spin_unlock_irq(shost->host_lock);
James Smartd33d0eb2017-11-20 16:00:34 -0800922
923 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
924 if (!mbox)
925 goto fail;
926
927 lpfc_config_link(phba, mbox);
928
929 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
930 mbox->vport = vport;
931 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
932 if (rc == MBX_NOT_FINISHED) {
933 mempool_free(mbox, phba->mbox_mem_pool);
934 goto fail;
935 }
936 } else {
James Smarte47c9092008-02-08 18:49:26 -0500937 /* This side will wait for the PLOGI, decrement ndlp reference
938 * count indicating that ndlp can be released when other
939 * references to it are done.
940 */
James Smart329f9bc2007-04-25 09:53:01 -0400941 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500942
James Smartd33d0eb2017-11-20 16:00:34 -0800943 /* Start discovery - this should just do CLEAR_LA */
944 lpfc_disc_start(vport);
James Smarte74c03c2013-04-17 20:15:19 -0400945 }
dea31012005-04-17 16:05:31 -0500946
dea31012005-04-17 16:05:31 -0500947 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500948fail:
dea31012005-04-17 16:05:31 -0500949 return -ENXIO;
950}
951
James Smarte59058c2008-08-24 21:49:00 -0400952/**
James Smart3621a712009-04-06 18:47:14 -0400953 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400954 * @phba: pointer to lpfc hba data structure.
955 * @cmdiocb: pointer to lpfc command iocb data structure.
956 * @rspiocb: pointer to lpfc response iocb data structure.
957 *
958 * This routine is the top-level completion callback function for issuing
959 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
960 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
961 * retry has been made (either immediately or delayed with lpfc_els_retry()
962 * returning 1), the command IOCB will be released and function returned.
963 * If the retry attempt has been given up (possibly reach the maximum
964 * number of retries), one additional decrement of ndlp reference shall be
965 * invoked before going out after releasing the command IOCB. This will
966 * actually release the remote node (Note, lpfc_els_free_iocb() will also
967 * invoke one decrement of ndlp reference count). If no error reported in
968 * the IOCB status, the command Port ID field is used to determine whether
969 * this is a point-to-point topology or a fabric topology: if the Port ID
970 * field is assigned, it is a fabric topology; otherwise, it is a
971 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
972 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
973 * specific topology completion conditions.
974 **/
dea31012005-04-17 16:05:31 -0500975static void
James Smart329f9bc2007-04-25 09:53:01 -0400976lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
977 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500978{
James Smart2e0fef82007-06-17 19:56:36 -0500979 struct lpfc_vport *vport = cmdiocb->vport;
980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500981 IOCB_t *irsp = &rspiocb->iocb;
982 struct lpfc_nodelist *ndlp = cmdiocb->context1;
983 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
984 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500985 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500986 int rc;
987
988 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500989 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500990 /* One additional decrement on node reference count to
991 * trigger the release of the node
992 */
James Smart329f9bc2007-04-25 09:53:01 -0400993 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500994 goto out;
995 }
996
James Smart858c9f62007-06-17 19:56:39 -0500997 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
998 "FLOGI cmpl: status:x%x/x%x state:x%x",
999 irsp->ulpStatus, irsp->un.ulpWord[4],
1000 vport->port_state);
1001
dea31012005-04-17 16:05:31 -05001002 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001003 /*
James Smarta93ff372010-10-22 11:06:08 -04001004 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05001005 * due to new FCF discovery
1006 */
1007 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001008 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1009 if (phba->link_state < LPFC_LINK_UP)
1010 goto stop_rr_fcf_flogi;
1011 if ((phba->fcoe_cvl_eventtag_attn ==
1012 phba->fcoe_cvl_eventtag) &&
1013 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001014 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1015 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001016 goto stop_rr_fcf_flogi;
1017 else
1018 phba->fcoe_cvl_eventtag_attn =
1019 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001020 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001021 "2611 FLOGI failed on FCF (x%x), "
1022 "status:x%x/x%x, tmo:x%x, perform "
1023 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001024 phba->fcf.current_rec.fcf_indx,
1025 irsp->ulpStatus, irsp->un.ulpWord[4],
1026 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001027 lpfc_sli4_set_fcf_flogi_fail(phba,
1028 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001029 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001030 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1031 if (rc)
1032 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001033 }
1034
James Smart80c17842012-03-01 22:35:45 -05001035stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001036 /* FLOGI failure */
James Smartc73455e2017-11-20 16:00:28 -08001037 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1038 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1039 IOERR_LOOP_OPEN_FAILURE)))
1040 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1041 "2858 FLOGI failure Status:x%x/x%x "
1042 "TMO:x%x Data x%x x%x\n",
1043 irsp->ulpStatus, irsp->un.ulpWord[4],
1044 irsp->ulpTimeout, phba->hba_flag,
1045 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001046
dea31012005-04-17 16:05:31 -05001047 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001048 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001049 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001050
James Smartae9e28f2017-05-15 15:20:51 -07001051 /* If this is not a loop open failure, bail out */
1052 if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1053 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1054 IOERR_LOOP_OPEN_FAILURE)))
1055 goto flogifail;
1056
James Smartc73455e2017-11-20 16:00:28 -08001057 lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
1058 "0150 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1059 irsp->ulpStatus, irsp->un.ulpWord[4],
1060 irsp->ulpTimeout);
1061
dea31012005-04-17 16:05:31 -05001062 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1065 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001066
James Smart329f9bc2007-04-25 09:53:01 -04001067 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001068 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1069 * alpa map would take too long otherwise.
1070 */
James Smart1b511972011-12-13 13:23:09 -05001071 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001072 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001073 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1074 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001075 (vport->fc_prevDID != vport->fc_myDID) ||
1076 phba->fc_topology_changed)) {
1077 if (vport->fc_flag & FC_VFI_REGISTERED) {
1078 if (phba->fc_topology_changed) {
1079 lpfc_unregister_fcf_prep(phba);
1080 spin_lock_irq(shost->host_lock);
1081 vport->fc_flag &= ~FC_VFI_REGISTERED;
1082 spin_unlock_irq(shost->host_lock);
1083 phba->fc_topology_changed = 0;
1084 } else {
1085 lpfc_sli4_unreg_all_rpis(vport);
1086 }
1087 }
James Smart342b59c2016-03-31 14:12:31 -07001088
1089 /* Do not register VFI if the driver aborted FLOGI */
1090 if (!lpfc_error_lost_link(irsp))
1091 lpfc_issue_reg_vfi(vport);
James Smartff78d8f2011-12-13 13:21:35 -05001092 lpfc_nlp_put(ndlp);
1093 goto out;
dea31012005-04-17 16:05:31 -05001094 }
dea31012005-04-17 16:05:31 -05001095 goto flogifail;
1096 }
James Smart695a8142010-01-26 23:08:03 -05001097 spin_lock_irq(shost->host_lock);
1098 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001099 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001100 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001101
1102 /*
1103 * The FLogI succeeded. Sync the data for the CPU before
1104 * accessing it.
1105 */
1106 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001107 if (!prsp)
1108 goto out;
dea31012005-04-17 16:05:31 -05001109 sp = prsp->virt + sizeof(uint32_t);
1110
1111 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001112 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001113 "0101 FLOGI completes successfully, I/O tag:x%x, "
1114 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001115 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001116 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1117 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001118
James Smart2e0fef82007-06-17 19:56:36 -05001119 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001120 /*
1121 * If Common Service Parameters indicate Nport
1122 * we are point to point, if Fport we are Fabric.
1123 */
1124 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001125 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001126 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001127 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001128 else {
1129 lpfc_printf_vlog(vport, KERN_ERR,
1130 LOG_FIP | LOG_ELS,
1131 "2831 FLOGI response with cleared Fabric "
1132 "bit fcf_index 0x%x "
1133 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1134 "Fabric Name "
1135 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1136 phba->fcf.current_rec.fcf_indx,
1137 phba->fcf.current_rec.switch_name[0],
1138 phba->fcf.current_rec.switch_name[1],
1139 phba->fcf.current_rec.switch_name[2],
1140 phba->fcf.current_rec.switch_name[3],
1141 phba->fcf.current_rec.switch_name[4],
1142 phba->fcf.current_rec.switch_name[5],
1143 phba->fcf.current_rec.switch_name[6],
1144 phba->fcf.current_rec.switch_name[7],
1145 phba->fcf.current_rec.fabric_name[0],
1146 phba->fcf.current_rec.fabric_name[1],
1147 phba->fcf.current_rec.fabric_name[2],
1148 phba->fcf.current_rec.fabric_name[3],
1149 phba->fcf.current_rec.fabric_name[4],
1150 phba->fcf.current_rec.fabric_name[5],
1151 phba->fcf.current_rec.fabric_name[6],
1152 phba->fcf.current_rec.fabric_name[7]);
1153 lpfc_nlp_put(ndlp);
1154 spin_lock_irq(&phba->hbalock);
1155 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001156 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001157 spin_unlock_irq(&phba->hbalock);
1158 goto out;
1159 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001160 if (!rc) {
1161 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001162 if (phba->hba_flag & HBA_FIP_SUPPORT)
1163 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1164 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001165 "2769 FLOGI to FCF (x%x) "
1166 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001167 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001168 spin_lock_irq(&phba->hbalock);
1169 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001170 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001171 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001172 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001173 }
dea31012005-04-17 16:05:31 -05001174 }
1175
1176flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001177 spin_lock_irq(&phba->hbalock);
1178 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1179 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001180
James Smart329f9bc2007-04-25 09:53:01 -04001181 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001182
James Smart858c9f62007-06-17 19:56:39 -05001183 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001184 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001185 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001186
1187 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001188 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001189 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001190 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1191 IOERR_SLI_ABORTED) &&
1192 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1193 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001194 (phba->link_state != LPFC_CLEAR_LA)) {
1195 /* If FLOGI failed enable link interrupt. */
1196 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001197 }
dea31012005-04-17 16:05:31 -05001198out:
1199 lpfc_els_free_iocb(phba, cmdiocb);
1200}
1201
James Smarte59058c2008-08-24 21:49:00 -04001202/**
James Smart3621a712009-04-06 18:47:14 -04001203 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001204 * @vport: pointer to a host virtual N_Port data structure.
1205 * @ndlp: pointer to a node-list data structure.
1206 * @retry: number of retries to the command IOCB.
1207 *
1208 * This routine issues a Fabric Login (FLOGI) Request ELS command
1209 * for a @vport. The initiator service parameters are put into the payload
1210 * of the FLOGI Request IOCB and the top-level callback function pointer
1211 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1212 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1213 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1214 *
1215 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1216 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1217 * will be stored into the context1 field of the IOCB for the completion
1218 * callback function to the FLOGI ELS command.
1219 *
1220 * Return code
1221 * 0 - successfully issued flogi iocb for @vport
1222 * 1 - failed to issue flogi iocb for @vport
1223 **/
dea31012005-04-17 16:05:31 -05001224static int
James Smart2e0fef82007-06-17 19:56:36 -05001225lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001226 uint8_t retry)
1227{
James Smart2e0fef82007-06-17 19:56:36 -05001228 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001229 struct serv_parm *sp;
1230 IOCB_t *icmd;
1231 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001232 uint8_t *pcmd;
1233 uint16_t cmdsize;
1234 uint32_t tmo;
1235 int rc;
1236
James Smart92d7f7b2007-06-17 19:56:38 -05001237 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001238 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1239 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001240
James Smart488d1462006-03-07 15:02:37 -05001241 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001242 return 1;
dea31012005-04-17 16:05:31 -05001243
1244 icmd = &elsiocb->iocb;
1245 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1246
1247 /* For FLOGI request, remainder of payload is service parameters */
1248 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001249 pcmd += sizeof(uint32_t);
1250 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001251 sp = (struct serv_parm *) pcmd;
1252
1253 /* Setup CSPs accordingly for Fabric */
1254 sp->cmn.e_d_tov = 0;
1255 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001256 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001257 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001258 if (sp->cmn.fcphLow < FC_PH3)
1259 sp->cmn.fcphLow = FC_PH3;
1260 if (sp->cmn.fcphHigh < FC_PH3)
1261 sp->cmn.fcphHigh = FC_PH3;
1262
James Smartc31098c2011-04-16 11:03:33 -04001263 if (phba->sli_rev == LPFC_SLI_REV4) {
1264 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1265 LPFC_SLI_INTF_IF_TYPE_0) {
1266 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1267 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1268 /* FLOGI needs to be 3 for WQE FCFI */
1269 /* Set the fcfi to the fcfi we registered with */
1270 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1271 }
James Smart0f378872012-10-31 14:45:01 -04001272 /* Can't do SLI4 class2 without support sequence coalescing */
1273 sp->cls2.classValid = 0;
1274 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001275 } else {
James Smart0f378872012-10-31 14:45:01 -04001276 /* Historical, setting sequential-delivery bit for SLI3 */
1277 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1278 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001279 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1280 sp->cmn.request_multiple_Nport = 1;
1281 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1282 icmd->ulpCt_h = 1;
1283 icmd->ulpCt_l = 0;
1284 } else
1285 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001286 }
1287
James Smart76a95d72010-11-20 23:11:48 -05001288 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001289 icmd->un.elsreq64.myID = 0;
1290 icmd->un.elsreq64.fl = 1;
1291 }
1292
dea31012005-04-17 16:05:31 -05001293 tmo = phba->fc_ratov;
1294 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001295 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001296 phba->fc_ratov = tmo;
1297
1298 phba->fc_stat.elsXmitFLOGI++;
1299 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001300
1301 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1302 "Issue FLOGI: opt:x%x",
1303 phba->sli3_options, 0, 0);
1304
James Smart92d7f7b2007-06-17 19:56:38 -05001305 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001306 if (rc == IOCB_ERROR) {
1307 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001308 return 1;
dea31012005-04-17 16:05:31 -05001309 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001310 return 0;
dea31012005-04-17 16:05:31 -05001311}
1312
James Smarte59058c2008-08-24 21:49:00 -04001313/**
James Smart3621a712009-04-06 18:47:14 -04001314 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001315 * @phba: pointer to lpfc hba data structure.
1316 *
1317 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1318 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1319 * list and issues an abort IOCB commond on each outstanding IOCB that
1320 * contains a active Fabric_DID ndlp. Note that this function is to issue
1321 * the abort IOCB command on all the outstanding IOCBs, thus when this
1322 * function returns, it does not guarantee all the IOCBs are actually aborted.
1323 *
1324 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001325 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001326 **/
dea31012005-04-17 16:05:31 -05001327int
James Smart2e0fef82007-06-17 19:56:36 -05001328lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001329{
1330 struct lpfc_sli_ring *pring;
1331 struct lpfc_iocbq *iocb, *next_iocb;
1332 struct lpfc_nodelist *ndlp;
1333 IOCB_t *icmd;
1334
1335 /* Abort outstanding I/O on NPort <nlp_DID> */
1336 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001337 "0201 Abort outstanding I/O on NPort x%x\n",
1338 Fabric_DID);
dea31012005-04-17 16:05:31 -05001339
James Smart895427b2017-02-12 13:52:30 -08001340 pring = lpfc_phba_elsring(phba);
dea31012005-04-17 16:05:31 -05001341
1342 /*
1343 * Check the txcmplq for an iocb that matches the nport the driver is
1344 * searching for.
1345 */
James Smart2e0fef82007-06-17 19:56:36 -05001346 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001347 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1348 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001349 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001350 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001351 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1352 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001353 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001354 }
1355 }
James Smart2e0fef82007-06-17 19:56:36 -05001356 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001357
1358 return 0;
1359}
1360
James Smarte59058c2008-08-24 21:49:00 -04001361/**
James Smart3621a712009-04-06 18:47:14 -04001362 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001363 * @vport: pointer to a host virtual N_Port data structure.
1364 *
1365 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1366 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1367 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1368 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1369 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1370 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1371 * @vport.
1372 *
1373 * Return code
1374 * 0 - failed to issue initial flogi for @vport
1375 * 1 - successfully issued initial flogi for @vport
1376 **/
dea31012005-04-17 16:05:31 -05001377int
James Smart2e0fef82007-06-17 19:56:36 -05001378lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001379{
1380 struct lpfc_nodelist *ndlp;
1381
James Smart98c9ea52007-10-27 13:37:33 -04001382 vport->port_state = LPFC_FLOGI;
1383 lpfc_set_disctmo(vport);
1384
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001385 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001386 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001387 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001388 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001389 ndlp = lpfc_nlp_init(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001390 if (!ndlp)
1391 return 0;
James Smart6fb120a2009-05-22 14:52:59 -04001392 /* Set the node type */
1393 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001394 /* Put ndlp onto node list */
1395 lpfc_enqueue_node(vport, ndlp);
1396 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1397 /* re-setup ndlp without removing from node list */
1398 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1399 if (!ndlp)
1400 return 0;
dea31012005-04-17 16:05:31 -05001401 }
James Smart87af33f2007-10-27 13:37:43 -04001402
James Smart5ac6b302010-10-22 11:05:36 -04001403 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001404 /* This decrement of reference count to node shall kick off
1405 * the release of the node.
1406 */
James Smart329f9bc2007-04-25 09:53:01 -04001407 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001408 return 0;
1409 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001410 return 1;
dea31012005-04-17 16:05:31 -05001411}
1412
James Smarte59058c2008-08-24 21:49:00 -04001413/**
James Smart3621a712009-04-06 18:47:14 -04001414 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001415 * @vport: pointer to a host virtual N_Port data structure.
1416 *
1417 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1418 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1419 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1420 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1421 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1422 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1423 * @vport.
1424 *
1425 * Return code
1426 * 0 - failed to issue initial fdisc for @vport
1427 * 1 - successfully issued initial fdisc for @vport
1428 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001429int
1430lpfc_initial_fdisc(struct lpfc_vport *vport)
1431{
James Smart92d7f7b2007-06-17 19:56:38 -05001432 struct lpfc_nodelist *ndlp;
1433
1434 /* First look for the Fabric ndlp */
1435 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1436 if (!ndlp) {
1437 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07001438 ndlp = lpfc_nlp_init(vport, Fabric_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05001439 if (!ndlp)
1440 return 0;
James Smarte47c9092008-02-08 18:49:26 -05001441 /* Put ndlp onto node list */
1442 lpfc_enqueue_node(vport, ndlp);
1443 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1444 /* re-setup ndlp without removing from node list */
1445 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1446 if (!ndlp)
1447 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001448 }
James Smarte47c9092008-02-08 18:49:26 -05001449
James Smart92d7f7b2007-06-17 19:56:38 -05001450 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001451 /* decrement node reference count to trigger the release of
1452 * the node.
1453 */
James Smart92d7f7b2007-06-17 19:56:38 -05001454 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001455 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001456 }
1457 return 1;
1458}
James Smart87af33f2007-10-27 13:37:43 -04001459
James Smarte59058c2008-08-24 21:49:00 -04001460/**
James Smart3621a712009-04-06 18:47:14 -04001461 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001462 * @vport: pointer to a host virtual N_Port data structure.
1463 *
1464 * This routine checks whether there are more remaining Port Logins
1465 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1466 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1467 * to issue ELS PLOGIs up to the configured discover threads with the
1468 * @vport (@vport->cfg_discovery_threads). The function also decrement
1469 * the @vport's num_disc_node by 1 if it is not already 0.
1470 **/
James Smart87af33f2007-10-27 13:37:43 -04001471void
James Smart2e0fef82007-06-17 19:56:36 -05001472lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001473{
James Smart2e0fef82007-06-17 19:56:36 -05001474 if (vport->num_disc_nodes)
1475 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001476
1477 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001478 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1479 "0232 Continue discovery with %d PLOGIs to go "
1480 "Data: x%x x%x x%x\n",
1481 vport->num_disc_nodes, vport->fc_plogi_cnt,
1482 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001483 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001484 if (vport->fc_flag & FC_NLP_MORE)
1485 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001486 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001487
dea31012005-04-17 16:05:31 -05001488 return;
1489}
1490
James Smarte59058c2008-08-24 21:49:00 -04001491/**
James Smart3621a712009-04-06 18:47:14 -04001492 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001493 * @phba: pointer to lpfc hba data structure.
1494 * @prsp: pointer to response IOCB payload.
1495 * @ndlp: pointer to a node-list data structure.
1496 *
1497 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1498 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1499 * The following cases are considered N_Port confirmed:
1500 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1501 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1502 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1503 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1504 * 1) if there is a node on vport list other than the @ndlp with the same
1505 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1506 * on that node to release the RPI associated with the node; 2) if there is
1507 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1508 * into, a new node shall be allocated (or activated). In either case, the
1509 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1510 * be released and the new_ndlp shall be put on to the vport node list and
1511 * its pointer returned as the confirmed node.
1512 *
1513 * Note that before the @ndlp got "released", the keepDID from not-matching
1514 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1515 * of the @ndlp. This is because the release of @ndlp is actually to put it
1516 * into an inactive state on the vport node list and the vport node list
1517 * management algorithm does not allow two node with a same DID.
1518 *
1519 * Return code
1520 * pointer to the PLOGI N_Port @ndlp
1521 **/
James Smart488d1462006-03-07 15:02:37 -05001522static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001523lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001524 struct lpfc_nodelist *ndlp)
1525{
James Smarta0f2d3e2017-02-12 13:52:31 -08001526 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001527 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001528 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001529 struct lpfc_rport_data *rdata;
1530 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001531 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001532 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001533 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001534 uint16_t keep_nlp_state;
Dick Kennedy4adc0412017-08-23 16:55:37 -07001535 struct lpfc_nvme_rport *keep_nrport = NULL;
James Smart38b92ef2010-08-04 16:11:39 -04001536 int put_node;
1537 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001538 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001539
James Smart2fb9bd82006-12-02 13:33:57 -05001540 /* Fabric nodes can have the same WWPN so we don't bother searching
1541 * by WWPN. Just return the ndlp that was given to us.
1542 */
1543 if (ndlp->nlp_type & NLP_FABRIC)
1544 return ndlp;
1545
James Smart92d7f7b2007-06-17 19:56:38 -05001546 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001547 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001548
James Smart685f0bf2007-04-25 09:53:08 -04001549 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001550 * we have for that ndlp. If not, we have some work to do.
1551 */
James Smart2e0fef82007-06-17 19:56:36 -05001552 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001553
James Smarte47c9092008-02-08 18:49:26 -05001554 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001555 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001556 if (phba->sli_rev == LPFC_SLI_REV4) {
1557 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1558 GFP_KERNEL);
1559 if (active_rrqs_xri_bitmap)
1560 memset(active_rrqs_xri_bitmap, 0,
1561 phba->cfg_rrq_xri_bitmap_sz);
1562 }
James Smart488d1462006-03-07 15:02:37 -05001563
James Smart34f5ad82012-08-03 12:35:03 -04001564 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1565 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1566 ndlp, ndlp->nlp_DID, new_ndlp);
1567
James Smart488d1462006-03-07 15:02:37 -05001568 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001569 rc = memcmp(&ndlp->nlp_portname, name,
1570 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001571 if (!rc) {
1572 if (active_rrqs_xri_bitmap)
1573 mempool_free(active_rrqs_xri_bitmap,
1574 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001575 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001576 }
James Smart9d3d3402017-04-21 16:05:00 -07001577 new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
James Smartcff261f2013-12-17 20:29:47 -05001578 if (!new_ndlp) {
1579 if (active_rrqs_xri_bitmap)
1580 mempool_free(active_rrqs_xri_bitmap,
1581 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001582 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001583 }
James Smarte47c9092008-02-08 18:49:26 -05001584 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001585 rc = memcmp(&ndlp->nlp_portname, name,
1586 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001587 if (!rc) {
1588 if (active_rrqs_xri_bitmap)
1589 mempool_free(active_rrqs_xri_bitmap,
1590 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001591 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001592 }
James Smarte47c9092008-02-08 18:49:26 -05001593 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1594 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001595 if (!new_ndlp) {
1596 if (active_rrqs_xri_bitmap)
1597 mempool_free(active_rrqs_xri_bitmap,
1598 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001599 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001600 }
James Smart58da1ff2008-04-07 10:15:56 -04001601 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001602 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1603 memcpy(active_rrqs_xri_bitmap,
1604 new_ndlp->active_rrqs_xri_bitmap,
1605 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001606 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001607 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001608 if (phba->sli_rev == LPFC_SLI_REV4 &&
1609 active_rrqs_xri_bitmap)
1610 memcpy(active_rrqs_xri_bitmap,
1611 new_ndlp->active_rrqs_xri_bitmap,
1612 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001613 }
James Smart488d1462006-03-07 15:02:37 -05001614
James Smart2e0fef82007-06-17 19:56:36 -05001615 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001616 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001617 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001618 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001619 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1620 ndlp->active_rrqs_xri_bitmap,
1621 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001622
James Smart953ceed2015-05-22 10:42:37 -04001623 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001624 keep_nlp_flag = new_ndlp->nlp_flag;
1625 new_ndlp->nlp_flag = ndlp->nlp_flag;
1626 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001627 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001628
James Smart953ceed2015-05-22 10:42:37 -04001629 /* Set nlp_states accordingly */
1630 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001631 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001632
Dick Kennedy4adc0412017-08-23 16:55:37 -07001633 /* interchange the nvme remoteport structs */
1634 keep_nrport = new_ndlp->nrport;
1635 new_ndlp->nrport = ndlp->nrport;
1636
James Smart2e0fef82007-06-17 19:56:36 -05001637 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001638 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1639 /* The new_ndlp is replacing ndlp totally, so we need
1640 * to put ndlp on UNUSED list and try to free it.
1641 */
James Smart34f5ad82012-08-03 12:35:03 -04001642 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1643 "3179 PLOGI confirm NEW: %x %x\n",
1644 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001645
1646 /* Fix up the rport accordingly */
1647 rport = ndlp->rport;
1648 if (rport) {
1649 rdata = rport->dd_data;
1650 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001651 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001652 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001653 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001654 rdata->pnode = lpfc_nlp_get(new_ndlp);
1655 new_ndlp->rport = rport;
1656 }
1657 new_ndlp->nlp_type = ndlp->nlp_type;
1658 }
Dick Kennedy4adc0412017-08-23 16:55:37 -07001659
1660 /* Fix up the nvme rport */
1661 if (ndlp->nrport) {
1662 ndlp->nrport = NULL;
1663 lpfc_nlp_put(ndlp);
1664 }
1665
James Smart58da1ff2008-04-07 10:15:56 -04001666 /* We shall actually free the ndlp with both nlp_DID and
1667 * nlp_portname fields equals 0 to avoid any ndlp on the
1668 * nodelist never to be used.
1669 */
1670 if (ndlp->nlp_DID == 0) {
1671 spin_lock_irq(&phba->ndlp_lock);
1672 NLP_SET_FREE_REQ(ndlp);
1673 spin_unlock_irq(&phba->ndlp_lock);
1674 }
James Smart0ff10d42008-01-11 01:52:36 -05001675
James Smart58da1ff2008-04-07 10:15:56 -04001676 /* Two ndlps cannot have the same did on the nodelist */
1677 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001678 if (phba->sli_rev == LPFC_SLI_REV4 &&
1679 active_rrqs_xri_bitmap)
1680 memcpy(ndlp->active_rrqs_xri_bitmap,
1681 active_rrqs_xri_bitmap,
1682 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001683
1684 if (!NLP_CHK_NODE_ACT(ndlp))
1685 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001686 }
James Smart92795652006-07-06 15:50:02 -04001687 else {
James Smart34f5ad82012-08-03 12:35:03 -04001688 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1689 "3180 PLOGI confirm SWAP: %x %x\n",
1690 new_ndlp->nlp_DID, keepDID);
1691
James Smart2e0fef82007-06-17 19:56:36 -05001692 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001693
James Smart58da1ff2008-04-07 10:15:56 -04001694 /* Two ndlps cannot have the same did */
1695 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001696 if (phba->sli_rev == LPFC_SLI_REV4 &&
1697 active_rrqs_xri_bitmap)
1698 memcpy(ndlp->active_rrqs_xri_bitmap,
1699 active_rrqs_xri_bitmap,
1700 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001701
James Smart953ceed2015-05-22 10:42:37 -04001702 /* Since we are switching over to the new_ndlp,
1703 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001704 */
1705 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1706 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001707 keep_nlp_state = NLP_STE_NPR_NODE;
1708 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001709
Dick Kennedy4adc0412017-08-23 16:55:37 -07001710 /* Previous ndlp no longer active with nvme host transport.
1711 * Remove reference from earlier registration unless the
1712 * nvme host took care of it.
1713 */
1714 if (ndlp->nrport)
1715 lpfc_nlp_put(ndlp);
1716 ndlp->nrport = keep_nrport;
1717
James Smart38b92ef2010-08-04 16:11:39 -04001718 /* Fix up the rport accordingly */
1719 rport = ndlp->rport;
1720 if (rport) {
1721 rdata = rport->dd_data;
1722 put_node = rdata->pnode != NULL;
1723 put_rport = ndlp->rport != NULL;
1724 rdata->pnode = NULL;
1725 ndlp->rport = NULL;
1726 if (put_node)
1727 lpfc_nlp_put(ndlp);
1728 if (put_rport)
1729 put_device(&rport->dev);
1730 }
James Smart92795652006-07-06 15:50:02 -04001731 }
James Smartcff261f2013-12-17 20:29:47 -05001732 if (phba->sli_rev == LPFC_SLI_REV4 &&
1733 active_rrqs_xri_bitmap)
1734 mempool_free(active_rrqs_xri_bitmap,
1735 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001736 return new_ndlp;
1737}
1738
James Smarte59058c2008-08-24 21:49:00 -04001739/**
James Smart3621a712009-04-06 18:47:14 -04001740 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001741 * @vport: pointer to a host virtual N_Port data structure.
1742 *
1743 * This routine checks whether more Registration State Change
1744 * Notifications (RSCNs) came in while the discovery state machine was in
1745 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1746 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1747 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1748 * handling the RSCNs.
1749 **/
James Smart87af33f2007-10-27 13:37:43 -04001750void
1751lpfc_end_rscn(struct lpfc_vport *vport)
1752{
1753 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1754
1755 if (vport->fc_flag & FC_RSCN_MODE) {
1756 /*
1757 * Check to see if more RSCNs came in while we were
1758 * processing this one.
1759 */
1760 if (vport->fc_rscn_id_cnt ||
1761 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1762 lpfc_els_handle_rscn(vport);
1763 else {
1764 spin_lock_irq(shost->host_lock);
1765 vport->fc_flag &= ~FC_RSCN_MODE;
1766 spin_unlock_irq(shost->host_lock);
1767 }
1768 }
1769}
1770
James Smarte59058c2008-08-24 21:49:00 -04001771/**
James Smart19ca7602010-11-20 23:11:55 -05001772 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1773 * @phba: pointer to lpfc hba data structure.
1774 * @cmdiocb: pointer to lpfc command iocb data structure.
1775 * @rspiocb: pointer to lpfc response iocb data structure.
1776 *
1777 * This routine will call the clear rrq function to free the rrq and
1778 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1779 * exist then the clear_rrq is still called because the rrq needs to
1780 * be freed.
1781 **/
1782
1783static void
1784lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1785 struct lpfc_iocbq *rspiocb)
1786{
1787 struct lpfc_vport *vport = cmdiocb->vport;
1788 IOCB_t *irsp;
1789 struct lpfc_nodelist *ndlp;
1790 struct lpfc_node_rrq *rrq;
1791
1792 /* we pass cmdiocb to state machine which needs rspiocb as well */
1793 rrq = cmdiocb->context_un.rrq;
1794 cmdiocb->context_un.rsp_iocb = rspiocb;
1795
1796 irsp = &rspiocb->iocb;
1797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1798 "RRQ cmpl: status:x%x/x%x did:x%x",
1799 irsp->ulpStatus, irsp->un.ulpWord[4],
1800 irsp->un.elsreq64.remoteID);
1801
1802 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1803 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1804 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1805 "2882 RRQ completes to NPort x%x "
1806 "with no ndlp. Data: x%x x%x x%x\n",
1807 irsp->un.elsreq64.remoteID,
1808 irsp->ulpStatus, irsp->un.ulpWord[4],
1809 irsp->ulpIoTag);
1810 goto out;
1811 }
1812
1813 /* rrq completes to NPort <nlp_DID> */
1814 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1815 "2880 RRQ completes to NPort x%x "
1816 "Data: x%x x%x x%x x%x x%x\n",
1817 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1818 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1819
1820 if (irsp->ulpStatus) {
1821 /* Check for retry */
1822 /* RRQ failed Don't print the vport to vport rjts */
1823 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1824 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1825 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1826 (phba)->pport->cfg_log_verbose & LOG_ELS)
1827 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1828 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1829 ndlp->nlp_DID, irsp->ulpStatus,
1830 irsp->un.ulpWord[4]);
1831 }
1832out:
1833 if (rrq)
1834 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1835 lpfc_els_free_iocb(phba, cmdiocb);
1836 return;
1837}
1838/**
James Smart3621a712009-04-06 18:47:14 -04001839 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001840 * @phba: pointer to lpfc hba data structure.
1841 * @cmdiocb: pointer to lpfc command iocb data structure.
1842 * @rspiocb: pointer to lpfc response iocb data structure.
1843 *
1844 * This routine is the completion callback function for issuing the Port
1845 * Login (PLOGI) command. For PLOGI completion, there must be an active
1846 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001847 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001848 * ignored and command IOCB released. The PLOGI response IOCB status is
1849 * checked for error conditons. If there is error status reported, PLOGI
1850 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1851 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1852 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1853 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1854 * there are additional N_Port nodes with the vport that need to perform
1855 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1856 * PLOGIs.
1857 **/
dea31012005-04-17 16:05:31 -05001858static void
James Smart2e0fef82007-06-17 19:56:36 -05001859lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1860 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001861{
James Smart2e0fef82007-06-17 19:56:36 -05001862 struct lpfc_vport *vport = cmdiocb->vport;
1863 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001864 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001865 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001866 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001867 int disc, rc;
dea31012005-04-17 16:05:31 -05001868
dea31012005-04-17 16:05:31 -05001869 /* we pass cmdiocb to state machine which needs rspiocb as well */
1870 cmdiocb->context_un.rsp_iocb = rspiocb;
1871
1872 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001873 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1874 "PLOGI cmpl: status:x%x/x%x did:x%x",
1875 irsp->ulpStatus, irsp->un.ulpWord[4],
1876 irsp->un.elsreq64.remoteID);
1877
James Smart2e0fef82007-06-17 19:56:36 -05001878 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001879 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001880 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1881 "0136 PLOGI completes to NPort x%x "
1882 "with no ndlp. Data: x%x x%x x%x\n",
1883 irsp->un.elsreq64.remoteID,
1884 irsp->ulpStatus, irsp->un.ulpWord[4],
1885 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001886 goto out;
James Smarted957682007-06-17 19:56:37 -05001887 }
dea31012005-04-17 16:05:31 -05001888
1889 /* Since ndlp can be freed in the disc state machine, note if this node
1890 * is being used during discovery.
1891 */
James Smart2e0fef82007-06-17 19:56:36 -05001892 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001893 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001894 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001895 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001896 rc = 0;
1897
1898 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001899 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08001900 "0102 PLOGI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04001901 "Data: x%x x%x x%x x%x x%x\n",
James Smarta0f2d3e2017-02-12 13:52:31 -08001902 ndlp->nlp_DID, ndlp->nlp_fc4_type,
1903 irsp->ulpStatus, irsp->un.ulpWord[4],
1904 disc, vport->num_disc_nodes);
1905
dea31012005-04-17 16:05:31 -05001906 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001907 if (lpfc_els_chk_latt(vport)) {
1908 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001909 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001910 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001911 goto out;
1912 }
1913
dea31012005-04-17 16:05:31 -05001914 if (irsp->ulpStatus) {
1915 /* Check for retry */
1916 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1917 /* ELS command is being retried */
1918 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001919 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001920 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001921 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001922 }
1923 goto out;
1924 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001925 /* PLOGI failed Don't print the vport to vport rjts */
1926 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1927 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1928 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1929 (phba)->pport->cfg_log_verbose & LOG_ELS)
1930 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001931 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1932 ndlp->nlp_DID, irsp->ulpStatus,
1933 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001934 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001935 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001936 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001937 else
James Smart2e0fef82007-06-17 19:56:36 -05001938 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001939 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001940 } else {
1941 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001942 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001943 cmdiocb->context2)->list.next,
1944 struct lpfc_dmabuf, list);
1945 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001946 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001947 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001948 }
1949
James Smart2e0fef82007-06-17 19:56:36 -05001950 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001951 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001952 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001953
James Smart2e0fef82007-06-17 19:56:36 -05001954 if (vport->num_disc_nodes == 0) {
1955 spin_lock_irq(shost->host_lock);
1956 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1957 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001958
James Smart2e0fef82007-06-17 19:56:36 -05001959 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001960 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001961 }
1962 }
1963
1964out:
1965 lpfc_els_free_iocb(phba, cmdiocb);
1966 return;
1967}
1968
James Smarte59058c2008-08-24 21:49:00 -04001969/**
James Smart3621a712009-04-06 18:47:14 -04001970 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001971 * @vport: pointer to a host virtual N_Port data structure.
1972 * @did: destination port identifier.
1973 * @retry: number of retries to the command IOCB.
1974 *
1975 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1976 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1977 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1978 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1979 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1980 *
1981 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1982 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1983 * will be stored into the context1 field of the IOCB for the completion
1984 * callback function to the PLOGI ELS command.
1985 *
1986 * Return code
1987 * 0 - Successfully issued a plogi for @vport
1988 * 1 - failed to issue a plogi for @vport
1989 **/
dea31012005-04-17 16:05:31 -05001990int
James Smart2e0fef82007-06-17 19:56:36 -05001991lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001992{
James Smart2e0fef82007-06-17 19:56:36 -05001993 struct lpfc_hba *phba = vport->phba;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07001994 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05001995 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04001996 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001997 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001998 uint8_t *pcmd;
1999 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002000 int ret;
dea31012005-04-17 16:05:31 -05002001
James Smart98c9ea52007-10-27 13:37:33 -04002002 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002003 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
2004 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04002005
James Smarte47c9092008-02-08 18:49:26 -05002006 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05002007 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04002008 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05002009 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002010 if (!elsiocb)
2011 return 1;
dea31012005-04-17 16:05:31 -05002012
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07002013 shost = lpfc_shost_from_vport(vport);
2014 spin_lock_irq(shost->host_lock);
2015 ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2016 spin_unlock_irq(shost->host_lock);
2017
dea31012005-04-17 16:05:31 -05002018 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2019
2020 /* For PLOGI request, remainder of payload is service parameters */
2021 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05002022 pcmd += sizeof(uint32_t);
2023 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05002024 sp = (struct serv_parm *) pcmd;
2025
James Smart5ac6b302010-10-22 11:05:36 -04002026 /*
2027 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2028 * to device on remote loops work.
2029 */
2030 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2031 sp->cmn.altBbCredit = 1;
2032
dea31012005-04-17 16:05:31 -05002033 if (sp->cmn.fcphLow < FC_PH_4_3)
2034 sp->cmn.fcphLow = FC_PH_4_3;
2035
2036 if (sp->cmn.fcphHigh < FC_PH3)
2037 sp->cmn.fcphHigh = FC_PH3;
2038
James Smarte0165f22016-12-19 15:07:20 -08002039 sp->cmn.valid_vendor_ver_level = 0;
James Smart8c258642017-02-12 13:52:36 -08002040 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07002041 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smarte0165f22016-12-19 15:07:20 -08002042
James Smart858c9f62007-06-17 19:56:39 -05002043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2044 "Issue PLOGI: did:x%x",
2045 did, 0, 0);
2046
James Smart8c258642017-02-12 13:52:36 -08002047 /* If our firmware supports this feature, convey that
2048 * information to the target using the vendor specific field.
2049 */
2050 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2051 sp->cmn.valid_vendor_ver_level = 1;
2052 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2053 sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2054 }
2055
dea31012005-04-17 16:05:31 -05002056 phba->fc_stat.elsXmitPLOGI++;
2057 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002058 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002059
2060 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002061 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002062 return 1;
dea31012005-04-17 16:05:31 -05002063 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002064 return 0;
dea31012005-04-17 16:05:31 -05002065}
2066
James Smarte59058c2008-08-24 21:49:00 -04002067/**
James Smart3621a712009-04-06 18:47:14 -04002068 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002069 * @phba: pointer to lpfc hba data structure.
2070 * @cmdiocb: pointer to lpfc command iocb data structure.
2071 * @rspiocb: pointer to lpfc response iocb data structure.
2072 *
2073 * This routine is the completion callback function for a Process Login
2074 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2075 * status. If there is error status reported, PRLI retry shall be attempted
2076 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2077 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2078 * ndlp to mark the PRLI completion.
2079 **/
dea31012005-04-17 16:05:31 -05002080static void
James Smart2e0fef82007-06-17 19:56:36 -05002081lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2082 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002083{
James Smart2e0fef82007-06-17 19:56:36 -05002084 struct lpfc_vport *vport = cmdiocb->vport;
2085 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002086 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002087 struct lpfc_nodelist *ndlp;
2088
dea31012005-04-17 16:05:31 -05002089 /* we pass cmdiocb to state machine which needs rspiocb as well */
2090 cmdiocb->context_un.rsp_iocb = rspiocb;
2091
2092 irsp = &(rspiocb->iocb);
2093 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002094 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002095 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002096 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002097
James Smart858c9f62007-06-17 19:56:39 -05002098 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2099 "PRLI cmpl: status:x%x/x%x did:x%x",
2100 irsp->ulpStatus, irsp->un.ulpWord[4],
2101 ndlp->nlp_DID);
James Smarta0f2d3e2017-02-12 13:52:31 -08002102
2103 /* Ddriver supports multiple FC4 types. Counters matter. */
2104 vport->fc_prli_sent--;
2105
dea31012005-04-17 16:05:31 -05002106 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002107 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta0f2d3e2017-02-12 13:52:31 -08002108 "0103 PRLI completes to NPort x%06x "
James Smarte8b62012007-08-02 11:10:09 -04002109 "Data: x%x x%x x%x x%x\n",
2110 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
James Smarta0f2d3e2017-02-12 13:52:31 -08002111 vport->num_disc_nodes, ndlp->fc4_prli_sent);
dea31012005-04-17 16:05:31 -05002112
dea31012005-04-17 16:05:31 -05002113 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002114 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002115 goto out;
2116
2117 if (irsp->ulpStatus) {
2118 /* Check for retry */
James Smart31200462017-05-15 15:20:42 -07002119 ndlp->fc4_prli_sent--;
dea31012005-04-17 16:05:31 -05002120 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2121 /* ELS command is being retried */
2122 goto out;
2123 }
James Smart31200462017-05-15 15:20:42 -07002124
dea31012005-04-17 16:05:31 -05002125 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002126 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart31200462017-05-15 15:20:42 -07002127 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2128 "data: x%x\n",
James Smarte40a02c2010-02-26 14:13:54 -05002129 ndlp->nlp_DID, irsp->ulpStatus,
James Smart31200462017-05-15 15:20:42 -07002130 irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2131
dea31012005-04-17 16:05:31 -05002132 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002133 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002134 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002135 else
James Smart2e0fef82007-06-17 19:56:36 -05002136 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002137 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002138 } else
James Smarta0f2d3e2017-02-12 13:52:31 -08002139 /* Good status, call state machine. However, if another
2140 * PRLI is outstanding, don't call the state machine
2141 * because final disposition to Mapped or Unmapped is
2142 * completed there.
2143 */
James Smart2e0fef82007-06-17 19:56:36 -05002144 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002145 NLP_EVT_CMPL_PRLI);
James Smarta0f2d3e2017-02-12 13:52:31 -08002146
dea31012005-04-17 16:05:31 -05002147out:
2148 lpfc_els_free_iocb(phba, cmdiocb);
2149 return;
2150}
2151
James Smarte59058c2008-08-24 21:49:00 -04002152/**
James Smart3621a712009-04-06 18:47:14 -04002153 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002154 * @vport: pointer to a host virtual N_Port data structure.
2155 * @ndlp: pointer to a node-list data structure.
2156 * @retry: number of retries to the command IOCB.
2157 *
2158 * This routine issues a Process Login (PRLI) ELS command for the
2159 * @vport. The PRLI service parameters are set up in the payload of the
2160 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2161 * is put to the IOCB completion callback func field before invoking the
2162 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2163 *
2164 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2165 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2166 * will be stored into the context1 field of the IOCB for the completion
2167 * callback function to the PRLI ELS command.
2168 *
2169 * Return code
2170 * 0 - successfully issued prli iocb command for @vport
2171 * 1 - failed to issue prli iocb command for @vport
2172 **/
dea31012005-04-17 16:05:31 -05002173int
James Smart2e0fef82007-06-17 19:56:36 -05002174lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002175 uint8_t retry)
2176{
James Smart2e0fef82007-06-17 19:56:36 -05002177 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2178 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002179 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08002180 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05002181 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002182 uint8_t *pcmd;
2183 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08002184 u32 local_nlp_type, elscmd;
dea31012005-04-17 16:05:31 -05002185
Dick Kennedy991f0c02017-08-23 16:55:39 -07002186 /*
2187 * If we are in RSCN mode, the FC4 types supported from a
2188 * previous GFT_ID command may not be accurate. So, if we
2189 * are a NVME Initiator, always look for the possibility of
2190 * the remote NPort beng a NVME Target.
2191 */
2192 if (phba->sli_rev == LPFC_SLI_REV4 &&
2193 vport->fc_flag & FC_RSCN_MODE &&
2194 vport->nvmei_support)
2195 ndlp->nlp_fc4_type |= NLP_FC4_NVME;
James Smarta0f2d3e2017-02-12 13:52:31 -08002196 local_nlp_type = ndlp->nlp_fc4_type;
2197
2198 send_next_prli:
2199 if (local_nlp_type & NLP_FC4_FCP) {
2200 /* Payload is 4 + 16 = 20 x14 bytes. */
2201 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2202 elscmd = ELS_CMD_PRLI;
2203 } else if (local_nlp_type & NLP_FC4_NVME) {
2204 /* Payload is 4 + 20 = 24 x18 bytes. */
2205 cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2206 elscmd = ELS_CMD_NVMEPRLI;
2207 } else {
2208 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2209 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2210 ndlp->nlp_fc4_type, ndlp->nlp_DID);
2211 return 1;
2212 }
James Smart09559e82017-06-15 22:56:46 -07002213
2214 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2215 * FC4 type, implicitly LOGO.
2216 */
2217 if (phba->sli_rev == LPFC_SLI_REV3 &&
2218 ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2219 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2220 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2221 ndlp->nlp_type);
2222 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2223 return 1;
2224 }
2225
James Smart2e0fef82007-06-17 19:56:36 -05002226 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08002227 ndlp->nlp_DID, elscmd);
James Smart488d1462006-03-07 15:02:37 -05002228 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002229 return 1;
dea31012005-04-17 16:05:31 -05002230
dea31012005-04-17 16:05:31 -05002231 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2232
2233 /* For PRLI request, remainder of payload is service parameters */
James Smarta0f2d3e2017-02-12 13:52:31 -08002234 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05002235
James Smarta0f2d3e2017-02-12 13:52:31 -08002236 if (local_nlp_type & NLP_FC4_FCP) {
2237 /* Remainder of payload is FCP PRLI parameter page.
2238 * Note: this data structure is defined as
2239 * BE/LE in the structure definition so no
2240 * byte swap call is made.
2241 */
2242 *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2243 pcmd += sizeof(uint32_t);
2244 npr = (PRLI *)pcmd;
2245
2246 /*
2247 * If our firmware version is 3.20 or later,
2248 * set the following bits for FC-TAPE support.
2249 */
2250 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2251 npr->ConfmComplAllowed = 1;
2252 npr->Retry = 1;
2253 npr->TaskRetryIdReq = 1;
2254 }
2255 npr->estabImagePair = 1;
2256 npr->readXferRdyDis = 1;
2257 if (vport->cfg_first_burst_size)
2258 npr->writeXferRdyDis = 1;
2259
2260 /* For FCP support */
2261 npr->prliType = PRLI_FCP_TYPE;
2262 npr->initiatorFunc = 1;
2263 elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2264
2265 /* Remove FCP type - processed. */
2266 local_nlp_type &= ~NLP_FC4_FCP;
2267 } else if (local_nlp_type & NLP_FC4_NVME) {
2268 /* Remainder of payload is NVME PRLI parameter page.
2269 * This data structure is the newer definition that
2270 * uses bf macros so a byte swap is required.
2271 */
2272 *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2273 pcmd += sizeof(uint32_t);
2274 npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2275 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2276 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2277
2278 /* Only initiators request first burst. */
2279 if ((phba->cfg_nvme_enable_fb) &&
2280 !phba->nvmet_support)
2281 bf_set(prli_fba, npr_nvme, 1);
2282
James Smart8c258642017-02-12 13:52:36 -08002283 if (phba->nvmet_support) {
2284 bf_set(prli_tgt, npr_nvme, 1);
2285 bf_set(prli_disc, npr_nvme, 1);
2286
2287 } else {
2288 bf_set(prli_init, npr_nvme, 1);
2289 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002290 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2291 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2292 elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2293
2294 /* Remove NVME type - processed. */
2295 local_nlp_type &= ~NLP_FC4_NVME;
dea31012005-04-17 16:05:31 -05002296 }
dea31012005-04-17 16:05:31 -05002297
James Smart858c9f62007-06-17 19:56:39 -05002298 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2299 "Issue PRLI: did:x%x",
2300 ndlp->nlp_DID, 0, 0);
2301
dea31012005-04-17 16:05:31 -05002302 phba->fc_stat.elsXmitPRLI++;
2303 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002304 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002305 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002306 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002307 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2308 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002309 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002310 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002311 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002312 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002313 return 1;
dea31012005-04-17 16:05:31 -05002314 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002315
2316 /* The vport counters are used for lpfc_scan_finished, but
2317 * the ndlp is used to track outstanding PRLIs for different
2318 * FC4 types.
2319 */
James Smart2e0fef82007-06-17 19:56:36 -05002320 vport->fc_prli_sent++;
James Smarta0f2d3e2017-02-12 13:52:31 -08002321 ndlp->fc4_prli_sent++;
2322
2323 /* The driver supports 2 FC4 types. Make sure
2324 * a PRLI is issued for all types before exiting.
2325 */
James Smart09559e82017-06-15 22:56:46 -07002326 if (phba->sli_rev == LPFC_SLI_REV4 &&
2327 local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
James Smarta0f2d3e2017-02-12 13:52:31 -08002328 goto send_next_prli;
2329
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002330 return 0;
dea31012005-04-17 16:05:31 -05002331}
2332
James Smarte59058c2008-08-24 21:49:00 -04002333/**
James Smart3621a712009-04-06 18:47:14 -04002334 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002335 * @vport: pointer to a host virtual N_Port data structure.
2336 *
2337 * This routine performs Registration State Change Notification (RSCN)
2338 * discovery for a @vport. If the @vport's node port recovery count is not
2339 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2340 * the nodes that need recovery. If none of the PLOGI were needed through
2341 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2342 * invoked to check and handle possible more RSCN came in during the period
2343 * of processing the current ones.
2344 **/
2345static void
2346lpfc_rscn_disc(struct lpfc_vport *vport)
2347{
2348 lpfc_can_disctmo(vport);
2349
2350 /* RSCN discovery */
2351 /* go thru NPR nodes and issue ELS PLOGIs */
2352 if (vport->fc_npr_cnt)
2353 if (lpfc_els_disc_plogi(vport))
2354 return;
2355
2356 lpfc_end_rscn(vport);
2357}
2358
2359/**
James Smart3621a712009-04-06 18:47:14 -04002360 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002361 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2362 *
2363 * This function is called when the final ADISC is completed during discovery.
2364 * This function handles clearing link attention or issuing reg_vpi depending
2365 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2366 * discovery.
2367 * This function is called with no locks held.
2368 **/
2369static void
2370lpfc_adisc_done(struct lpfc_vport *vport)
2371{
2372 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2373 struct lpfc_hba *phba = vport->phba;
2374
2375 /*
2376 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2377 * and continue discovery.
2378 */
2379 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002380 !(vport->fc_flag & FC_RSCN_MODE) &&
2381 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002382 /* The ADISCs are complete. Doesn't matter if they
2383 * succeeded or failed because the ADISC completion
2384 * routine guarantees to call the state machine and
2385 * the RPI is either unregistered (failed ADISC response)
2386 * or the RPI is still valid and the node is marked
2387 * mapped for a target. The exchanges should be in the
2388 * correct state. This code is specific to SLI3.
2389 */
2390 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002391 lpfc_issue_reg_vpi(phba, vport);
2392 return;
2393 }
2394 /*
2395 * For SLI2, we need to set port_state to READY
2396 * and continue discovery.
2397 */
2398 if (vport->port_state < LPFC_VPORT_READY) {
2399 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002400 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002401 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2402 vport->num_disc_nodes = 0;
2403 /* go thru NPR list, issue ELS PLOGIs */
2404 if (vport->fc_npr_cnt)
2405 lpfc_els_disc_plogi(vport);
2406 if (!vport->num_disc_nodes) {
2407 spin_lock_irq(shost->host_lock);
2408 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2409 spin_unlock_irq(shost->host_lock);
2410 lpfc_can_disctmo(vport);
2411 lpfc_end_rscn(vport);
2412 }
2413 }
2414 vport->port_state = LPFC_VPORT_READY;
2415 } else
2416 lpfc_rscn_disc(vport);
2417}
2418
2419/**
James Smart3621a712009-04-06 18:47:14 -04002420 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002421 * @vport: pointer to a host virtual N_Port data structure.
2422 *
2423 * This routine determines whether there are more ndlps on a @vport
2424 * node list need to have Address Discover (ADISC) issued. If so, it will
2425 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2426 * remaining nodes which need to have ADISC sent.
2427 **/
James Smart0ff10d42008-01-11 01:52:36 -05002428void
James Smart2e0fef82007-06-17 19:56:36 -05002429lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002430{
James Smart2e0fef82007-06-17 19:56:36 -05002431 if (vport->num_disc_nodes)
2432 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002433 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002434 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2435 "0210 Continue discovery with %d ADISCs to go "
2436 "Data: x%x x%x x%x\n",
2437 vport->num_disc_nodes, vport->fc_adisc_cnt,
2438 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002439 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002440 if (vport->fc_flag & FC_NLP_MORE) {
2441 lpfc_set_disctmo(vport);
2442 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002443 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002444 }
James Smart90160e02008-08-24 21:49:45 -04002445 if (!vport->num_disc_nodes)
2446 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002447 return;
2448}
2449
James Smarte59058c2008-08-24 21:49:00 -04002450/**
James Smart3621a712009-04-06 18:47:14 -04002451 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002452 * @phba: pointer to lpfc hba data structure.
2453 * @cmdiocb: pointer to lpfc command iocb data structure.
2454 * @rspiocb: pointer to lpfc response iocb data structure.
2455 *
2456 * This routine is the completion function for issuing the Address Discover
2457 * (ADISC) command. It first checks to see whether link went down during
2458 * the discovery process. If so, the node will be marked as node port
2459 * recovery for issuing discover IOCB by the link attention handler and
2460 * exit. Otherwise, the response status is checked. If error was reported
2461 * in the response status, the ADISC command shall be retried by invoking
2462 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2463 * the response status, the state machine is invoked to set transition
2464 * with respect to NLP_EVT_CMPL_ADISC event.
2465 **/
dea31012005-04-17 16:05:31 -05002466static void
James Smart2e0fef82007-06-17 19:56:36 -05002467lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2468 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002469{
James Smart2e0fef82007-06-17 19:56:36 -05002470 struct lpfc_vport *vport = cmdiocb->vport;
2471 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002472 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002473 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002474 int disc;
dea31012005-04-17 16:05:31 -05002475
2476 /* we pass cmdiocb to state machine which needs rspiocb as well */
2477 cmdiocb->context_un.rsp_iocb = rspiocb;
2478
2479 irsp = &(rspiocb->iocb);
2480 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002481
James Smart858c9f62007-06-17 19:56:39 -05002482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2483 "ADISC cmpl: status:x%x/x%x did:x%x",
2484 irsp->ulpStatus, irsp->un.ulpWord[4],
2485 ndlp->nlp_DID);
2486
dea31012005-04-17 16:05:31 -05002487 /* Since ndlp can be freed in the disc state machine, note if this node
2488 * is being used during discovery.
2489 */
James Smart2e0fef82007-06-17 19:56:36 -05002490 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002491 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002492 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002493 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002494 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002495 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2496 "0104 ADISC completes to NPort x%x "
2497 "Data: x%x x%x x%x x%x x%x\n",
2498 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2499 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002500 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002501 if (lpfc_els_chk_latt(vport)) {
2502 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002503 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002504 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002505 goto out;
2506 }
2507
2508 if (irsp->ulpStatus) {
2509 /* Check for retry */
2510 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2511 /* ELS command is being retried */
2512 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002513 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002514 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002515 spin_unlock_irq(shost->host_lock);
2516 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002517 }
2518 goto out;
2519 }
2520 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002521 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2522 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2523 ndlp->nlp_DID, irsp->ulpStatus,
2524 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002525 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002526 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002527 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002528 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002529 } else
dea31012005-04-17 16:05:31 -05002530 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002531 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002532 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002533
James Smart90160e02008-08-24 21:49:45 -04002534 /* Check to see if there are more ADISCs to be sent */
2535 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002536 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002537out:
2538 lpfc_els_free_iocb(phba, cmdiocb);
2539 return;
2540}
2541
James Smarte59058c2008-08-24 21:49:00 -04002542/**
James Smart3621a712009-04-06 18:47:14 -04002543 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002544 * @vport: pointer to a virtual N_Port data structure.
2545 * @ndlp: pointer to a node-list data structure.
2546 * @retry: number of retries to the command IOCB.
2547 *
2548 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2549 * @vport. It prepares the payload of the ADISC ELS command, updates the
2550 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2551 * to issue the ADISC ELS command.
2552 *
2553 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2554 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2555 * will be stored into the context1 field of the IOCB for the completion
2556 * callback function to the ADISC ELS command.
2557 *
2558 * Return code
2559 * 0 - successfully issued adisc
2560 * 1 - failed to issue adisc
2561 **/
dea31012005-04-17 16:05:31 -05002562int
James Smart2e0fef82007-06-17 19:56:36 -05002563lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002564 uint8_t retry)
2565{
James Smart2e0fef82007-06-17 19:56:36 -05002566 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2567 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002568 ADISC *ap;
dea31012005-04-17 16:05:31 -05002569 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002570 uint8_t *pcmd;
2571 uint16_t cmdsize;
2572
James Smart92d7f7b2007-06-17 19:56:38 -05002573 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002574 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2575 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002576 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002577 return 1;
dea31012005-04-17 16:05:31 -05002578
dea31012005-04-17 16:05:31 -05002579 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2580
2581 /* For ADISC request, remainder of payload is service parameters */
2582 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002583 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002584
2585 /* Fill in ADISC payload */
2586 ap = (ADISC *) pcmd;
2587 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002588 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2589 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002590 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002591
James Smart858c9f62007-06-17 19:56:39 -05002592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2593 "Issue ADISC: did:x%x",
2594 ndlp->nlp_DID, 0, 0);
2595
dea31012005-04-17 16:05:31 -05002596 phba->fc_stat.elsXmitADISC++;
2597 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002598 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002599 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002600 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002601 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2602 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002603 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002604 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002605 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002606 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002607 return 1;
dea31012005-04-17 16:05:31 -05002608 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002609 return 0;
dea31012005-04-17 16:05:31 -05002610}
2611
James Smarte59058c2008-08-24 21:49:00 -04002612/**
James Smart3621a712009-04-06 18:47:14 -04002613 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002614 * @phba: pointer to lpfc hba data structure.
2615 * @cmdiocb: pointer to lpfc command iocb data structure.
2616 * @rspiocb: pointer to lpfc response iocb data structure.
2617 *
2618 * This routine is the completion function for issuing the ELS Logout (LOGO)
2619 * command. If no error status was reported from the LOGO response, the
2620 * state machine of the associated ndlp shall be invoked for transition with
2621 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2622 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2623 **/
dea31012005-04-17 16:05:31 -05002624static void
James Smart2e0fef82007-06-17 19:56:36 -05002625lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2626 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002627{
James Smart2e0fef82007-06-17 19:56:36 -05002628 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2629 struct lpfc_vport *vport = ndlp->vport;
2630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002631 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002632 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002633 unsigned long flags;
2634 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002635
dea31012005-04-17 16:05:31 -05002636 /* we pass cmdiocb to state machine which needs rspiocb as well */
2637 cmdiocb->context_un.rsp_iocb = rspiocb;
2638
2639 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002640 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002641 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002642 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002643
James Smart858c9f62007-06-17 19:56:39 -05002644 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2645 "LOGO cmpl: status:x%x/x%x did:x%x",
2646 irsp->ulpStatus, irsp->un.ulpWord[4],
2647 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002648
dea31012005-04-17 16:05:31 -05002649 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002650 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2651 "0105 LOGO completes to NPort x%x "
2652 "Data: x%x x%x x%x x%x\n",
2653 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2654 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002655
James Smart086a3452012-08-14 14:25:21 -04002656 if (lpfc_els_chk_latt(vport)) {
2657 skip_recovery = 1;
2658 goto out;
2659 }
2660
2661 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002662 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2663 /* NLP_EVT_DEVICE_RM should unregister the RPI
2664 * which should abort all outstanding IOs.
2665 */
2666 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2667 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002668 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002669 goto out;
2670 }
2671
dea31012005-04-17 16:05:31 -05002672 if (irsp->ulpStatus) {
2673 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002674 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002675 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002676 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002677 goto out;
James Smart086a3452012-08-14 14:25:21 -04002678 }
dea31012005-04-17 16:05:31 -05002679 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002680 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2681 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2682 ndlp->nlp_DID, irsp->ulpStatus,
2683 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002684 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002685 if (lpfc_error_lost_link(irsp)) {
2686 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002687 goto out;
James Smart086a3452012-08-14 14:25:21 -04002688 }
2689 }
2690
2691 /* Call state machine. This will unregister the rpi if needed. */
2692 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2693
dea31012005-04-17 16:05:31 -05002694out:
2695 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002696 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2697 if ((vport->fc_flag & FC_PT2PT) &&
2698 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2699 phba->pport->fc_myDID = 0;
James Smarta0f2d3e2017-02-12 13:52:31 -08002700
James Smart01649562017-02-12 13:52:32 -08002701 if ((phba->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
James Smart8c258642017-02-12 13:52:36 -08002702 (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
James Smartd613b6a2017-02-12 13:52:37 -08002703 if (phba->nvmet_support)
2704 lpfc_nvmet_update_targetport(phba);
2705 else
James Smart8c258642017-02-12 13:52:36 -08002706 lpfc_nvme_update_localport(phba->pport);
James Smart8c258642017-02-12 13:52:36 -08002707 }
James Smarta0f2d3e2017-02-12 13:52:31 -08002708
James Smart92494142011-02-16 12:39:44 -05002709 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2710 if (mbox) {
2711 lpfc_config_link(phba, mbox);
2712 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2713 mbox->vport = vport;
2714 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2715 MBX_NOT_FINISHED) {
2716 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002717 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002718 }
2719 }
2720 }
James Smart086a3452012-08-14 14:25:21 -04002721
2722 /*
2723 * If the node is a target, the handling attempts to recover the port.
2724 * For any other port type, the rpi is unregistered as an implicit
2725 * LOGO.
2726 */
2727 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2728 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2729 spin_lock_irqsave(shost->host_lock, flags);
2730 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2731 spin_unlock_irqrestore(shost->host_lock, flags);
2732
2733 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2734 "3187 LOGO completes to NPort x%x: Start "
2735 "Recovery Data: x%x x%x x%x x%x\n",
2736 ndlp->nlp_DID, irsp->ulpStatus,
2737 irsp->un.ulpWord[4], irsp->ulpTimeout,
2738 vport->num_disc_nodes);
2739 lpfc_disc_start(vport);
2740 }
dea31012005-04-17 16:05:31 -05002741 return;
2742}
2743
James Smarte59058c2008-08-24 21:49:00 -04002744/**
James Smart3621a712009-04-06 18:47:14 -04002745 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002746 * @vport: pointer to a virtual N_Port data structure.
2747 * @ndlp: pointer to a node-list data structure.
2748 * @retry: number of retries to the command IOCB.
2749 *
2750 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2751 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2752 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2753 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2754 *
2755 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2756 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2757 * will be stored into the context1 field of the IOCB for the completion
2758 * callback function to the LOGO ELS command.
2759 *
2760 * Return code
2761 * 0 - successfully issued logo
2762 * 1 - failed to issue logo
2763 **/
dea31012005-04-17 16:05:31 -05002764int
James Smart2e0fef82007-06-17 19:56:36 -05002765lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002766 uint8_t retry)
2767{
James Smart2e0fef82007-06-17 19:56:36 -05002768 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2769 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002770 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002771 uint8_t *pcmd;
2772 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002773 int rc;
dea31012005-04-17 16:05:31 -05002774
James Smart98c9ea52007-10-27 13:37:33 -04002775 spin_lock_irq(shost->host_lock);
2776 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2777 spin_unlock_irq(shost->host_lock);
2778 return 0;
2779 }
2780 spin_unlock_irq(shost->host_lock);
2781
James Smart92d7f7b2007-06-17 19:56:38 -05002782 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002783 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2784 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002785 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002786 return 1;
dea31012005-04-17 16:05:31 -05002787
dea31012005-04-17 16:05:31 -05002788 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2789 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002790 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002791
2792 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002793 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002794 pcmd += sizeof(uint32_t);
2795 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002796
James Smart858c9f62007-06-17 19:56:39 -05002797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2798 "Issue LOGO: did:x%x",
2799 ndlp->nlp_DID, 0, 0);
2800
James Smart086a3452012-08-14 14:25:21 -04002801 /*
2802 * If we are issuing a LOGO, we may try to recover the remote NPort
2803 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2804 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2805 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2806 * for that ELS cmd. To avoid this situation, lets get rid of the
2807 * RPI right now, before any ELS cmds are sent.
2808 */
2809 spin_lock_irq(shost->host_lock);
2810 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2811 spin_unlock_irq(shost->host_lock);
2812 if (lpfc_unreg_rpi(vport, ndlp)) {
2813 lpfc_els_free_iocb(phba, elsiocb);
2814 return 0;
2815 }
2816
dea31012005-04-17 16:05:31 -05002817 phba->fc_stat.elsXmitLOGO++;
2818 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002819 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002820 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002821 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002822 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002823 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002824
2825 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002826 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002827 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002828 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002829 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002830 return 1;
dea31012005-04-17 16:05:31 -05002831 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002832 return 0;
dea31012005-04-17 16:05:31 -05002833}
2834
James Smarte59058c2008-08-24 21:49:00 -04002835/**
James Smart3621a712009-04-06 18:47:14 -04002836 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002837 * @phba: pointer to lpfc hba data structure.
2838 * @cmdiocb: pointer to lpfc command iocb data structure.
2839 * @rspiocb: pointer to lpfc response iocb data structure.
2840 *
2841 * This routine is a generic completion callback function for ELS commands.
2842 * Specifically, it is the callback function which does not need to perform
2843 * any command specific operations. It is currently used by the ELS command
2844 * issuing routines for the ELS State Change Request (SCR),
2845 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2846 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2847 * certain debug loggings, this callback function simply invokes the
2848 * lpfc_els_chk_latt() routine to check whether link went down during the
2849 * discovery process.
2850 **/
dea31012005-04-17 16:05:31 -05002851static void
James Smart2e0fef82007-06-17 19:56:36 -05002852lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2853 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002854{
James Smart2e0fef82007-06-17 19:56:36 -05002855 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002856 IOCB_t *irsp;
2857
2858 irsp = &rspiocb->iocb;
2859
James Smart858c9f62007-06-17 19:56:39 -05002860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2861 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2862 irsp->ulpStatus, irsp->un.ulpWord[4],
2863 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002864 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002865 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2866 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2867 irsp->ulpIoTag, irsp->ulpStatus,
2868 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002869 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002870 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002871 lpfc_els_free_iocb(phba, cmdiocb);
2872 return;
2873}
2874
James Smarte59058c2008-08-24 21:49:00 -04002875/**
James Smart3621a712009-04-06 18:47:14 -04002876 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002877 * @vport: pointer to a host virtual N_Port data structure.
2878 * @nportid: N_Port identifier to the remote node.
2879 * @retry: number of retries to the command IOCB.
2880 *
2881 * This routine issues a State Change Request (SCR) to a fabric node
2882 * on a @vport. The remote node @nportid is passed into the function. It
2883 * first search the @vport node list to find the matching ndlp. If no such
2884 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2885 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2886 * routine is invoked to send the SCR IOCB.
2887 *
2888 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2889 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2890 * will be stored into the context1 field of the IOCB for the completion
2891 * callback function to the SCR ELS command.
2892 *
2893 * Return code
2894 * 0 - Successfully issued scr command
2895 * 1 - Failed to issue scr command
2896 **/
dea31012005-04-17 16:05:31 -05002897int
James Smart2e0fef82007-06-17 19:56:36 -05002898lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002899{
James Smart2e0fef82007-06-17 19:56:36 -05002900 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002901 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002902 uint8_t *pcmd;
2903 uint16_t cmdsize;
2904 struct lpfc_nodelist *ndlp;
2905
James Smart92d7f7b2007-06-17 19:56:38 -05002906 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002907
James Smarte47c9092008-02-08 18:49:26 -05002908 ndlp = lpfc_findnode_did(vport, nportid);
2909 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07002910 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002911 if (!ndlp)
2912 return 1;
James Smarte47c9092008-02-08 18:49:26 -05002913 lpfc_enqueue_node(vport, ndlp);
2914 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2915 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2916 if (!ndlp)
2917 return 1;
2918 }
dea31012005-04-17 16:05:31 -05002919
James Smart2e0fef82007-06-17 19:56:36 -05002920 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2921 ndlp->nlp_DID, ELS_CMD_SCR);
2922
James Smart488d1462006-03-07 15:02:37 -05002923 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002924 /* This will trigger the release of the node just
2925 * allocated
2926 */
James Smart329f9bc2007-04-25 09:53:01 -04002927 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002928 return 1;
dea31012005-04-17 16:05:31 -05002929 }
2930
dea31012005-04-17 16:05:31 -05002931 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2932
2933 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002934 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002935
2936 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002937 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002938 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2939
James Smart858c9f62007-06-17 19:56:39 -05002940 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2941 "Issue SCR: did:x%x",
2942 ndlp->nlp_DID, 0, 0);
2943
dea31012005-04-17 16:05:31 -05002944 phba->fc_stat.elsXmitSCR++;
2945 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002946 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2947 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002948 /* The additional lpfc_nlp_put will cause the following
2949 * lpfc_els_free_iocb routine to trigger the rlease of
2950 * the node.
2951 */
James Smart329f9bc2007-04-25 09:53:01 -04002952 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002953 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002954 return 1;
dea31012005-04-17 16:05:31 -05002955 }
James Smartfa4066b2008-01-11 01:53:27 -05002956 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2957 * trigger the release of node.
2958 */
James Smartb7e50c52017-11-20 16:00:37 -08002959 if (!(vport->fc_flag & FC_PT2PT))
2960 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002961 return 0;
dea31012005-04-17 16:05:31 -05002962}
2963
James Smarte59058c2008-08-24 21:49:00 -04002964/**
James Smart3621a712009-04-06 18:47:14 -04002965 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002966 * @vport: pointer to a host virtual N_Port data structure.
2967 * @nportid: N_Port identifier to the remote node.
2968 * @retry: number of retries to the command IOCB.
2969 *
2970 * This routine issues a Fibre Channel Address Resolution Response
2971 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2972 * is passed into the function. It first search the @vport node list to find
2973 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2974 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2975 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2976 *
2977 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2978 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2979 * will be stored into the context1 field of the IOCB for the completion
2980 * callback function to the PARPR ELS command.
2981 *
2982 * Return code
2983 * 0 - Successfully issued farpr command
2984 * 1 - Failed to issue farpr command
2985 **/
dea31012005-04-17 16:05:31 -05002986static int
James Smart2e0fef82007-06-17 19:56:36 -05002987lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002988{
James Smart2e0fef82007-06-17 19:56:36 -05002989 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002990 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002991 FARP *fp;
2992 uint8_t *pcmd;
2993 uint32_t *lp;
2994 uint16_t cmdsize;
2995 struct lpfc_nodelist *ondlp;
2996 struct lpfc_nodelist *ndlp;
2997
James Smart92d7f7b2007-06-17 19:56:38 -05002998 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002999
James Smarte47c9092008-02-08 18:49:26 -05003000 ndlp = lpfc_findnode_did(vport, nportid);
3001 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07003002 ndlp = lpfc_nlp_init(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003003 if (!ndlp)
3004 return 1;
James Smarte47c9092008-02-08 18:49:26 -05003005 lpfc_enqueue_node(vport, ndlp);
3006 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3007 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3008 if (!ndlp)
3009 return 1;
3010 }
James Smart2e0fef82007-06-17 19:56:36 -05003011
3012 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3013 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05003014 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05003015 /* This will trigger the release of the node just
3016 * allocated
3017 */
James Smart329f9bc2007-04-25 09:53:01 -04003018 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003019 return 1;
dea31012005-04-17 16:05:31 -05003020 }
3021
dea31012005-04-17 16:05:31 -05003022 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3023
3024 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05003025 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003026
3027 /* Fill in FARPR payload */
3028 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05003029 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05003030 lp = (uint32_t *) pcmd;
3031 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05003032 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003033 fp->Rflags = 0;
3034 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3035
James Smart92d7f7b2007-06-17 19:56:38 -05003036 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3037 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003038 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05003039 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05003040 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003041 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003042 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003043 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003044 }
3045
James Smart858c9f62007-06-17 19:56:39 -05003046 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3047 "Issue FARPR: did:x%x",
3048 ndlp->nlp_DID, 0, 0);
3049
dea31012005-04-17 16:05:31 -05003050 phba->fc_stat.elsXmitFARPR++;
3051 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04003052 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3053 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05003054 /* The additional lpfc_nlp_put will cause the following
3055 * lpfc_els_free_iocb routine to trigger the release of
3056 * the node.
3057 */
James Smart329f9bc2007-04-25 09:53:01 -04003058 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003059 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003060 return 1;
dea31012005-04-17 16:05:31 -05003061 }
James Smartfa4066b2008-01-11 01:53:27 -05003062 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3063 * trigger the release of the node.
3064 */
James Smart329f9bc2007-04-25 09:53:01 -04003065 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003066 return 0;
dea31012005-04-17 16:05:31 -05003067}
3068
James Smarte59058c2008-08-24 21:49:00 -04003069/**
James Smart3621a712009-04-06 18:47:14 -04003070 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04003071 * @vport: pointer to a host virtual N_Port data structure.
3072 * @nlp: pointer to a node-list data structure.
3073 *
3074 * This routine cancels the timer with a delayed IOCB-command retry for
3075 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3076 * removes the ELS retry event if it presents. In addition, if the
3077 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3078 * commands are sent for the @vport's nodes that require issuing discovery
3079 * ADISC.
3080 **/
dea31012005-04-17 16:05:31 -05003081void
James Smart2e0fef82007-06-17 19:56:36 -05003082lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05003083{
James Smart2e0fef82007-06-17 19:56:36 -05003084 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05003085 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05003086
James Smart0d2b6b82008-06-14 22:52:47 -04003087 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3088 return;
James Smart2e0fef82007-06-17 19:56:36 -05003089 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003090 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003091 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003092 del_timer_sync(&nlp->nlp_delayfunc);
3093 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05003094 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05003095 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05003096 /* Decrement nlp reference count held for the delayed retry */
3097 evtp = &nlp->els_retry_evt;
3098 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3099 }
James Smartfdcebe22006-03-07 15:04:01 -05003100 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05003101 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05003102 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05003103 spin_unlock_irq(shost->host_lock);
3104 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04003105 if (vport->port_state < LPFC_VPORT_READY) {
3106 /* Check if there are more ADISCs to be sent */
3107 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003108 } else {
3109 /* Check if there are more PLOGIs to be sent */
3110 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04003111 if (vport->num_disc_nodes == 0) {
3112 spin_lock_irq(shost->host_lock);
3113 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3114 spin_unlock_irq(shost->host_lock);
3115 lpfc_can_disctmo(vport);
3116 lpfc_end_rscn(vport);
3117 }
James Smartfdcebe22006-03-07 15:04:01 -05003118 }
3119 }
3120 }
3121 return;
3122}
3123
James Smarte59058c2008-08-24 21:49:00 -04003124/**
James Smart3621a712009-04-06 18:47:14 -04003125 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04003126 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3127 *
3128 * This routine is invoked by the ndlp delayed-function timer to check
3129 * whether there is any pending ELS retry event(s) with the node. If not, it
3130 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3131 * adds the delayed events to the HBA work list and invokes the
3132 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3133 * event. Note that lpfc_nlp_get() is called before posting the event to
3134 * the work list to hold reference count of ndlp so that it guarantees the
3135 * reference to ndlp will still be available when the worker thread gets
3136 * to the event associated with the ndlp.
3137 **/
James Smartfdcebe22006-03-07 15:04:01 -05003138void
Kees Cookf22eb4d2017-09-06 20:24:26 -07003139lpfc_els_retry_delay(struct timer_list *t)
dea31012005-04-17 16:05:31 -05003140{
Kees Cookf22eb4d2017-09-06 20:24:26 -07003141 struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
James Smart2e0fef82007-06-17 19:56:36 -05003142 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05003143 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05003144 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05003145 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05003146
James Smart92d7f7b2007-06-17 19:56:38 -05003147 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003148 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003149 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003150 return;
3151 }
3152
James Smartfa4066b2008-01-11 01:53:27 -05003153 /* We need to hold the node by incrementing the reference
3154 * count until the queued work is done
3155 */
3156 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04003157 if (evtp->evt_arg1) {
3158 evtp->evt = LPFC_EVT_ELS_RETRY;
3159 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05003160 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003161 }
James Smart92d7f7b2007-06-17 19:56:38 -05003162 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003163 return;
3164}
3165
James Smarte59058c2008-08-24 21:49:00 -04003166/**
James Smart3621a712009-04-06 18:47:14 -04003167 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003168 * @ndlp: pointer to a node-list data structure.
3169 *
3170 * This routine is the worker-thread handler for processing the @ndlp delayed
3171 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3172 * the last ELS command from the associated ndlp and invokes the proper ELS
3173 * function according to the delayed ELS command to retry the command.
3174 **/
dea31012005-04-17 16:05:31 -05003175void
3176lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3177{
James Smart2e0fef82007-06-17 19:56:36 -05003178 struct lpfc_vport *vport = ndlp->vport;
3179 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003180 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003181
James Smart2e0fef82007-06-17 19:56:36 -05003182 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003183 cmd = ndlp->nlp_last_elscmd;
3184 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003185
3186 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003187 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003188 return;
3189 }
3190
3191 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003192 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003193 /*
3194 * If a discovery event readded nlp_delayfunc after timer
3195 * firing and before processing the timer, cancel the
3196 * nlp_delayfunc.
3197 */
3198 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003199 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003200 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003201
3202 switch (cmd) {
3203 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003204 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003205 break;
3206 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003207 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003208 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003209 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003210 }
dea31012005-04-17 16:05:31 -05003211 break;
3212 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003213 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003214 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003215 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003216 }
dea31012005-04-17 16:05:31 -05003217 break;
3218 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003219 case ELS_CMD_NVMEPRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003220 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003221 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003222 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003223 }
dea31012005-04-17 16:05:31 -05003224 break;
3225 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003226 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003227 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003228 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003229 }
dea31012005-04-17 16:05:31 -05003230 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003231 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003232 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3233 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003234 break;
dea31012005-04-17 16:05:31 -05003235 }
3236 return;
3237}
3238
James Smarte59058c2008-08-24 21:49:00 -04003239/**
James Smart3621a712009-04-06 18:47:14 -04003240 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003241 * @phba: pointer to lpfc hba data structure.
3242 * @cmdiocb: pointer to lpfc command iocb data structure.
3243 * @rspiocb: pointer to lpfc response iocb data structure.
3244 *
3245 * This routine makes a retry decision on an ELS command IOCB, which has
3246 * failed. The following ELS IOCBs use this function for retrying the command
3247 * when previously issued command responsed with error status: FLOGI, PLOGI,
3248 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3249 * returned error status, it makes the decision whether a retry shall be
3250 * issued for the command, and whether a retry shall be made immediately or
3251 * delayed. In the former case, the corresponding ELS command issuing-function
3252 * is called to retry the command. In the later case, the ELS command shall
3253 * be posted to the ndlp delayed event and delayed function timer set to the
3254 * ndlp for the delayed command issusing.
3255 *
3256 * Return code
3257 * 0 - No retry of els command is made
3258 * 1 - Immediate or delayed retry of els command is made
3259 **/
dea31012005-04-17 16:05:31 -05003260static int
James Smart2e0fef82007-06-17 19:56:36 -05003261lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3262 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003263{
James Smart2e0fef82007-06-17 19:56:36 -05003264 struct lpfc_vport *vport = cmdiocb->vport;
3265 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3266 IOCB_t *irsp = &rspiocb->iocb;
3267 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3268 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003269 uint32_t *elscmd;
3270 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003271 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003272 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003273 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003274 uint32_t did;
dea31012005-04-17 16:05:31 -05003275
James Smart488d1462006-03-07 15:02:37 -05003276
dea31012005-04-17 16:05:31 -05003277 /* Note: context2 may be 0 for internal driver abort
3278 * of delays ELS command.
3279 */
3280
3281 if (pcmd && pcmd->virt) {
3282 elscmd = (uint32_t *) (pcmd->virt);
3283 cmd = *elscmd++;
3284 }
3285
James Smarte47c9092008-02-08 18:49:26 -05003286 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003287 did = ndlp->nlp_DID;
3288 else {
3289 /* We should only hit this case for retrying PLOGI */
3290 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003291 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003292 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3293 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003294 return 1;
3295 }
3296
James Smart858c9f62007-06-17 19:56:39 -05003297 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3298 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3299 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3300
dea31012005-04-17 16:05:31 -05003301 switch (irsp->ulpStatus) {
3302 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003303 break;
James Smart1151e3e2011-02-16 12:39:35 -05003304 case IOSTAT_REMOTE_STOP:
3305 if (phba->sli_rev == LPFC_SLI_REV4) {
3306 /* This IO was aborted by the target, we don't
3307 * know the rxid and because we did not send the
3308 * ABTS we cannot generate and RRQ.
3309 */
3310 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003311 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003312 }
3313 break;
dea31012005-04-17 16:05:31 -05003314 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003315 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003316 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003317 if (cmd == ELS_CMD_FLOGI) {
3318 if (PCI_DEVICE_ID_HORNET ==
3319 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003320 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003321 phba->pport->fc_myDID = 0;
3322 phba->alpa_map[0] = 0;
3323 phba->alpa_map[1] = 0;
3324 }
3325 }
James Smart2e0fef82007-06-17 19:56:36 -05003326 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003327 delay = 1000;
dea31012005-04-17 16:05:31 -05003328 retry = 1;
3329 break;
3330
James Smart92d7f7b2007-06-17 19:56:38 -05003331 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003332 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3333 "0124 Retry illegal cmd x%x "
3334 "retry:x%x delay:x%x\n",
3335 cmd, cmdiocb->retry, delay);
3336 retry = 1;
3337 /* All command's retry policy */
3338 maxretry = 8;
3339 if (cmdiocb->retry > 2)
3340 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003341 break;
3342
dea31012005-04-17 16:05:31 -05003343 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003344 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003345 retry = 1;
3346 if (cmdiocb->retry > 100)
3347 delay = 100;
3348 maxretry = 250;
3349 break;
3350
3351 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003352 delay = 100;
dea31012005-04-17 16:05:31 -05003353 retry = 1;
3354 break;
3355
James Smart858c9f62007-06-17 19:56:39 -05003356 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003357 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003358 if (cmd == ELS_CMD_PLOGI &&
3359 did == NameServer_DID) {
3360 /* Continue forever if plogi to */
3361 /* the nameserver fails */
3362 maxretry = 0;
3363 delay = 100;
3364 }
dea31012005-04-17 16:05:31 -05003365 retry = 1;
3366 break;
3367 }
3368 break;
3369
3370 case IOSTAT_NPORT_RJT:
3371 case IOSTAT_FABRIC_RJT:
3372 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3373 retry = 1;
3374 break;
3375 }
3376 break;
3377
3378 case IOSTAT_NPORT_BSY:
3379 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003380 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003381 retry = 1;
3382 break;
3383
3384 case IOSTAT_LS_RJT:
3385 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3386 /* Added for Vendor specifc support
3387 * Just keep retrying for these Rsn / Exp codes
3388 */
3389 switch (stat.un.b.lsRjtRsnCode) {
3390 case LSRJT_UNABLE_TPC:
James Smartdea37e82017-06-01 21:07:07 -07003391 /* The driver has a VALID PLOGI but the rport has
3392 * rejected the PRLI - can't do it now. Delay
3393 * for 1 second and try again - don't care about
3394 * the explanation.
3395 */
3396 if (cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) {
3397 delay = 1000;
3398 maxretry = lpfc_max_els_tries + 1;
3399 retry = 1;
3400 break;
3401 }
3402
3403 /* Legacy bug fix code for targets with PLOGI delays. */
dea31012005-04-17 16:05:31 -05003404 if (stat.un.b.lsRjtRsnCodeExp ==
3405 LSEXP_CMD_IN_PROGRESS) {
3406 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003407 delay = 1000;
dea31012005-04-17 16:05:31 -05003408 maxretry = 48;
3409 }
3410 retry = 1;
3411 break;
3412 }
James Smartffc95492010-06-07 15:23:17 -04003413 if (stat.un.b.lsRjtRsnCodeExp ==
3414 LSEXP_CANT_GIVE_DATA) {
3415 if (cmd == ELS_CMD_PLOGI) {
3416 delay = 1000;
3417 maxretry = 48;
3418 }
3419 retry = 1;
3420 break;
3421 }
James Smartdea37e82017-06-01 21:07:07 -07003422 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003423 delay = 1000;
dea31012005-04-17 16:05:31 -05003424 maxretry = lpfc_max_els_tries + 1;
3425 retry = 1;
3426 break;
3427 }
James Smart92d7f7b2007-06-17 19:56:38 -05003428 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3429 (cmd == ELS_CMD_FDISC) &&
3430 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003431 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3432 "0125 FDISC Failed (x%x). "
3433 "Fabric out of resources\n",
3434 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003435 lpfc_vport_set_state(vport,
3436 FC_VPORT_NO_FABRIC_RSCS);
3437 }
dea31012005-04-17 16:05:31 -05003438 break;
3439
3440 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003441 if ((cmd == ELS_CMD_PLOGI) ||
James Smarta0f2d3e2017-02-12 13:52:31 -08003442 (cmd == ELS_CMD_PRLI) ||
3443 (cmd == ELS_CMD_NVMEPRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003444 delay = 1000;
dea31012005-04-17 16:05:31 -05003445 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003446 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003447 /* FDISC retry policy */
3448 maxretry = 48;
3449 if (cmdiocb->retry >= 32)
3450 delay = 1000;
dea31012005-04-17 16:05:31 -05003451 }
3452 retry = 1;
3453 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003454
3455 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003456 /* There are some cases where switches return this
3457 * error when they are not ready and should be returning
3458 * Logical Busy. We should delay every time.
3459 */
3460 if (cmd == ELS_CMD_FDISC &&
3461 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3462 maxretry = 3;
3463 delay = 1000;
3464 retry = 1;
James Smart44fd7fe2017-08-23 16:55:47 -07003465 } else if (cmd == ELS_CMD_FLOGI &&
3466 stat.un.b.lsRjtRsnCodeExp ==
3467 LSEXP_NOTHING_MORE) {
3468 vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
3469 retry = 1;
3470 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3471 "0820 FLOGI Failed (x%x). "
3472 "BBCredit Not Supported\n",
3473 stat.un.lsRjtError);
James Smart7f5f3d02008-02-08 18:50:14 -05003474 }
James Smart44fd7fe2017-08-23 16:55:47 -07003475 break;
3476
James Smart92d7f7b2007-06-17 19:56:38 -05003477 case LSRJT_PROTOCOL_ERR:
3478 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3479 (cmd == ELS_CMD_FDISC) &&
3480 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3481 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3482 ) {
James Smarte8b62012007-08-02 11:10:09 -04003483 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003484 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003485 "Fabric Detected Bad WWN\n",
3486 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003487 lpfc_vport_set_state(vport,
3488 FC_VPORT_FABRIC_REJ_WWN);
3489 }
3490 break;
James Smart7bdedb32016-07-06 12:36:00 -07003491 case LSRJT_VENDOR_UNIQUE:
3492 if ((stat.un.b.vendorUnique == 0x45) &&
3493 (cmd == ELS_CMD_FLOGI)) {
3494 goto out_retry;
3495 }
3496 break;
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07003497 case LSRJT_CMD_UNSUPPORTED:
3498 /* lpfc nvmet returns this type of LS_RJT when it
3499 * receives an FCP PRLI because lpfc nvmet only
3500 * support NVME. ELS request is terminated for FCP4
3501 * on this rport.
3502 */
3503 if (stat.un.b.lsRjtRsnCodeExp ==
3504 LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
3505 spin_lock_irq(shost->host_lock);
3506 ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
3507 spin_unlock_irq(shost->host_lock);
3508 retry = 0;
3509 goto out_retry;
3510 }
3511 break;
dea31012005-04-17 16:05:31 -05003512 }
3513 break;
3514
3515 case IOSTAT_INTERMED_RSP:
3516 case IOSTAT_BA_RJT:
3517 break;
3518
3519 default:
3520 break;
3521 }
3522
James Smart488d1462006-03-07 15:02:37 -05003523 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003524 retry = 1;
dea31012005-04-17 16:05:31 -05003525
James Smartdf9e1b52011-12-13 13:22:17 -05003526 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003527 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003528 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003529 /* FLOGI retry policy */
3530 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003531 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003532 if (phba->link_flag != LS_LOOPBACK_MODE)
3533 maxretry = 0;
3534 else
3535 maxretry = 2;
3536
James Smart6669f9b2009-10-02 15:16:45 -04003537 if (cmdiocb->retry >= 100)
3538 delay = 5000;
3539 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003540 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003541 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3542 /* retry FDISCs every second up to devloss */
3543 retry = 1;
3544 maxretry = vport->cfg_devloss_tmo;
3545 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003546 }
3547
James Smart6669f9b2009-10-02 15:16:45 -04003548 cmdiocb->retry++;
3549 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003550 phba->fc_stat.elsRetryExceeded++;
3551 retry = 0;
3552 }
3553
James Smarted957682007-06-17 19:56:37 -05003554 if ((vport->load_flag & FC_UNLOADING) != 0)
3555 retry = 0;
3556
James Smart7bdedb32016-07-06 12:36:00 -07003557out_retry:
dea31012005-04-17 16:05:31 -05003558 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003559 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3560 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3561 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3562 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3563 "2849 Stop retry ELS command "
3564 "x%x to remote NPORT x%x, "
3565 "Data: x%x x%x\n", cmd, did,
3566 cmdiocb->retry, delay);
3567 return 0;
3568 }
3569 }
dea31012005-04-17 16:05:31 -05003570
3571 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003572 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3573 "0107 Retry ELS command x%x to remote "
3574 "NPORT x%x Data: x%x x%x\n",
3575 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003576
James Smart858c9f62007-06-17 19:56:39 -05003577 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3578 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003579 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3580 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003581 /* Don't reset timer for no resources */
3582
dea31012005-04-17 16:05:31 -05003583 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003584 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003585 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003586 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003587 }
3588
3589 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003590 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003591 phba->fc_stat.elsDelayRetry++;
3592 ndlp->nlp_retry = cmdiocb->retry;
3593
James Smart92d7f7b2007-06-17 19:56:38 -05003594 /* delay is specified in milliseconds */
3595 mod_timer(&ndlp->nlp_delayfunc,
3596 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003597 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003598 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003599 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003600
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003601 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smarta0f2d3e2017-02-12 13:52:31 -08003602 if ((cmd == ELS_CMD_PRLI) ||
3603 (cmd == ELS_CMD_NVMEPRLI))
James Smart858c9f62007-06-17 19:56:39 -05003604 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003605 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003606 else
3607 lpfc_nlp_set_state(vport, ndlp,
3608 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003609 ndlp->nlp_last_elscmd = cmd;
3610
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003611 return 1;
dea31012005-04-17 16:05:31 -05003612 }
3613 switch (cmd) {
3614 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003615 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003616 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003617 case ELS_CMD_FDISC:
3618 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3619 return 1;
dea31012005-04-17 16:05:31 -05003620 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003621 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003622 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003623 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003624 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003625 }
James Smart2e0fef82007-06-17 19:56:36 -05003626 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003627 return 1;
dea31012005-04-17 16:05:31 -05003628 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003629 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3631 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003632 return 1;
dea31012005-04-17 16:05:31 -05003633 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08003634 case ELS_CMD_NVMEPRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003635 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003636 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3637 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003638 return 1;
dea31012005-04-17 16:05:31 -05003639 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003640 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003641 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003642 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003643 return 1;
dea31012005-04-17 16:05:31 -05003644 }
3645 }
dea31012005-04-17 16:05:31 -05003646 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003647 if (logerr) {
3648 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3649 "0137 No retry ELS command x%x to remote "
3650 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3651 cmd, did, irsp->ulpStatus,
3652 irsp->un.ulpWord[4]);
3653 }
3654 else {
3655 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003656 "0108 No retry ELS command x%x to remote "
3657 "NPORT x%x Retried:%d Error:x%x/%x\n",
3658 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3659 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003660 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003661 return 0;
dea31012005-04-17 16:05:31 -05003662}
3663
James Smarte59058c2008-08-24 21:49:00 -04003664/**
James Smart3621a712009-04-06 18:47:14 -04003665 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003666 * @phba: pointer to lpfc hba data structure.
3667 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3668 *
3669 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3670 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3671 * checks to see whether there is a lpfc DMA buffer associated with the
3672 * response of the command IOCB. If so, it will be released before releasing
3673 * the lpfc DMA buffer associated with the IOCB itself.
3674 *
3675 * Return code
3676 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3677 **/
James Smart09372822008-01-11 01:52:54 -05003678static int
James Smart87af33f2007-10-27 13:37:43 -04003679lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3680{
3681 struct lpfc_dmabuf *buf_ptr;
3682
James Smarte59058c2008-08-24 21:49:00 -04003683 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003684 if (!list_empty(&buf_ptr1->list)) {
3685 list_remove_head(&buf_ptr1->list, buf_ptr,
3686 struct lpfc_dmabuf,
3687 list);
3688 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3689 kfree(buf_ptr);
3690 }
3691 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3692 kfree(buf_ptr1);
3693 return 0;
3694}
3695
James Smarte59058c2008-08-24 21:49:00 -04003696/**
James Smart3621a712009-04-06 18:47:14 -04003697 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003698 * @phba: pointer to lpfc hba data structure.
3699 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3700 *
3701 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3702 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3703 * pool.
3704 *
3705 * Return code
3706 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3707 **/
James Smart09372822008-01-11 01:52:54 -05003708static int
James Smart87af33f2007-10-27 13:37:43 -04003709lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3710{
3711 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3712 kfree(buf_ptr);
3713 return 0;
3714}
3715
James Smarte59058c2008-08-24 21:49:00 -04003716/**
James Smart3621a712009-04-06 18:47:14 -04003717 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003718 * @phba: pointer to lpfc hba data structure.
3719 * @elsiocb: pointer to lpfc els command iocb data structure.
3720 *
3721 * This routine frees a command IOCB and its associated resources. The
3722 * command IOCB data structure contains the reference to various associated
3723 * resources, these fields must be set to NULL if the associated reference
3724 * not present:
3725 * context1 - reference to ndlp
3726 * context2 - reference to cmd
3727 * context2->next - reference to rsp
3728 * context3 - reference to bpl
3729 *
3730 * It first properly decrements the reference count held on ndlp for the
3731 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3732 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3733 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3734 * adds the DMA buffer the @phba data structure for the delayed release.
3735 * If reference to the Buffer Pointer List (BPL) is present, the
3736 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3737 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3738 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3739 *
3740 * Return code
3741 * 0 - Success (currently, always return 0)
3742 **/
James Smart87af33f2007-10-27 13:37:43 -04003743int
James Smart329f9bc2007-04-25 09:53:01 -04003744lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003745{
3746 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003747 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003748
James Smarta8adb832007-10-27 13:37:53 -04003749 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3750 if (ndlp) {
3751 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3752 lpfc_nlp_put(ndlp);
3753
3754 /* If the ndlp is not being used by another discovery
3755 * thread, free it.
3756 */
3757 if (!lpfc_nlp_not_used(ndlp)) {
3758 /* If ndlp is being used by another discovery
3759 * thread, just clear NLP_DEFER_RM
3760 */
3761 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3762 }
3763 }
3764 else
3765 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003766 elsiocb->context1 = NULL;
3767 }
dea31012005-04-17 16:05:31 -05003768 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3769 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003770 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3771 /* Firmware could still be in progress of DMAing
3772 * payload, so don't free data buffer till after
3773 * a hbeat.
3774 */
3775 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3776 buf_ptr = elsiocb->context2;
3777 elsiocb->context2 = NULL;
3778 if (buf_ptr) {
3779 buf_ptr1 = NULL;
3780 spin_lock_irq(&phba->hbalock);
3781 if (!list_empty(&buf_ptr->list)) {
3782 list_remove_head(&buf_ptr->list,
3783 buf_ptr1, struct lpfc_dmabuf,
3784 list);
3785 INIT_LIST_HEAD(&buf_ptr1->list);
3786 list_add_tail(&buf_ptr1->list,
3787 &phba->elsbuf);
3788 phba->elsbuf_cnt++;
3789 }
3790 INIT_LIST_HEAD(&buf_ptr->list);
3791 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3792 phba->elsbuf_cnt++;
3793 spin_unlock_irq(&phba->hbalock);
3794 }
3795 } else {
3796 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3797 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01003798 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05003799 }
dea31012005-04-17 16:05:31 -05003800 }
3801
3802 if (elsiocb->context3) {
3803 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003804 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn8667f512017-01-10 12:05:54 +01003805 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05003806 }
James Bottomley604a3e32005-10-29 10:28:33 -05003807 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003808 return 0;
3809}
3810
James Smarte59058c2008-08-24 21:49:00 -04003811/**
James Smart3621a712009-04-06 18:47:14 -04003812 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003813 * @phba: pointer to lpfc hba data structure.
3814 * @cmdiocb: pointer to lpfc command iocb data structure.
3815 * @rspiocb: pointer to lpfc response iocb data structure.
3816 *
3817 * This routine is the completion callback function to the Logout (LOGO)
3818 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3819 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3820 * release the ndlp if it has the last reference remaining (reference count
3821 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3822 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3823 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3824 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3825 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3826 * IOCB data structure.
3827 **/
dea31012005-04-17 16:05:31 -05003828static void
James Smart2e0fef82007-06-17 19:56:36 -05003829lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3830 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003831{
James Smart2e0fef82007-06-17 19:56:36 -05003832 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3833 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003834 IOCB_t *irsp;
3835
3836 irsp = &rspiocb->iocb;
3837 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3838 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3839 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003840 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003841 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3842 "0109 ACC to LOGO completes to NPort x%x "
3843 "Data: x%x x%x x%x\n",
3844 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3845 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003846
3847 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3848 /* NPort Recovery mode or node is just allocated */
3849 if (!lpfc_nlp_not_used(ndlp)) {
3850 /* If the ndlp is being used by another discovery
3851 * thread, just unregister the RPI.
3852 */
3853 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003854 } else {
3855 /* Indicate the node has already released, should
3856 * not reference to it from within lpfc_els_free_iocb.
3857 */
3858 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003859 }
dea31012005-04-17 16:05:31 -05003860 }
James Smart73d91e52011-10-10 21:32:10 -04003861
3862 /*
3863 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003864 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003865 */
dea31012005-04-17 16:05:31 -05003866 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003867}
3868
James Smarte59058c2008-08-24 21:49:00 -04003869/**
James Smart3621a712009-04-06 18:47:14 -04003870 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003871 * @phba: pointer to lpfc hba data structure.
3872 * @pmb: pointer to the driver internal queue element for mailbox command.
3873 *
3874 * This routine is the completion callback function for unregister default
3875 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3876 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3877 * decrements the ndlp reference count held for this completion callback
3878 * function. After that, it invokes the lpfc_nlp_not_used() to check
3879 * whether there is only one reference left on the ndlp. If so, it will
3880 * perform one more decrement and trigger the release of the ndlp.
3881 **/
James Smart858c9f62007-06-17 19:56:39 -05003882void
3883lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3884{
3885 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3886 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3887
3888 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003889 pmb->context2 = NULL;
3890
James Smart858c9f62007-06-17 19:56:39 -05003891 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3892 kfree(mp);
3893 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003894 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003895 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3896 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3897 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
Peter Zijlstra2c935bc2016-11-14 17:29:48 +01003898 kref_read(&ndlp->kref),
James Smartbe6bb942015-04-07 15:07:22 -04003899 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003900 if (NLP_CHK_NODE_ACT(ndlp)) {
3901 lpfc_nlp_put(ndlp);
3902 /* This is the end of the default RPI cleanup logic for
3903 * this ndlp. If no other discovery threads are using
3904 * this ndlp, free all resources associated with it.
3905 */
3906 lpfc_nlp_not_used(ndlp);
3907 } else {
3908 lpfc_drop_node(ndlp->vport, ndlp);
3909 }
James Smarta8adb832007-10-27 13:37:53 -04003910 }
James Smart3772a992009-05-22 14:50:54 -04003911
James Smart858c9f62007-06-17 19:56:39 -05003912 return;
3913}
3914
James Smarte59058c2008-08-24 21:49:00 -04003915/**
James Smart3621a712009-04-06 18:47:14 -04003916 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003917 * @phba: pointer to lpfc hba data structure.
3918 * @cmdiocb: pointer to lpfc command iocb data structure.
3919 * @rspiocb: pointer to lpfc response iocb data structure.
3920 *
3921 * This routine is the completion callback function for ELS Response IOCB
3922 * command. In normal case, this callback function just properly sets the
3923 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3924 * field in the command IOCB is not NULL, the referred mailbox command will
3925 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3926 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3927 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3928 * routine shall be invoked trying to release the ndlp if no other threads
3929 * are currently referring it.
3930 **/
dea31012005-04-17 16:05:31 -05003931static void
James Smart858c9f62007-06-17 19:56:39 -05003932lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003933 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003934{
James Smart2e0fef82007-06-17 19:56:36 -05003935 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3936 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3937 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003938 IOCB_t *irsp;
3939 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003940 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003941 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003942 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003943
James Smart33ccf8d2006-08-17 11:57:58 -04003944 irsp = &rspiocb->iocb;
3945
dea31012005-04-17 16:05:31 -05003946 if (cmdiocb->context_un.mbox)
3947 mbox = cmdiocb->context_un.mbox;
3948
James Smartfa4066b2008-01-11 01:53:27 -05003949 /* First determine if this is a LS_RJT cmpl. Note, this callback
3950 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3951 */
James Smart87af33f2007-10-27 13:37:43 -04003952 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003953 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3954 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003955 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003956 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003957 */
3958 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3959 ls_rjt = 1;
3960 }
3961
dea31012005-04-17 16:05:31 -05003962 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003963 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003964 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003965 mp = (struct lpfc_dmabuf *) mbox->context1;
3966 if (mp) {
3967 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3968 kfree(mp);
3969 }
James Smart329f9bc2007-04-25 09:53:01 -04003970 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003971 }
James Smart58da1ff2008-04-07 10:15:56 -04003972 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3973 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003974 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003975 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003976 /* Indicate the node has already released,
3977 * should not reference to it from within
3978 * the routine lpfc_els_free_iocb.
3979 */
3980 cmdiocb->context1 = NULL;
3981 }
dea31012005-04-17 16:05:31 -05003982 goto out;
3983 }
3984
James Smart858c9f62007-06-17 19:56:39 -05003985 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003986 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003987 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003988 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003989 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003990 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3991 "0110 ELS response tag x%x completes "
3992 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3993 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3994 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3995 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3996 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003997 if (mbox) {
3998 if ((rspiocb->iocb.ulpStatus == 0)
3999 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
Dick Kennedy1fe68472017-08-23 16:55:30 -07004000 if (!lpfc_unreg_rpi(vport, ndlp) &&
4001 (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4002 ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4003 lpfc_printf_vlog(vport, KERN_INFO,
4004 LOG_DISCOVERY,
4005 "0314 PLOGI recov DID x%x "
4006 "Data: x%x x%x x%x\n",
4007 ndlp->nlp_DID, ndlp->nlp_state,
4008 ndlp->nlp_rpi, ndlp->nlp_flag);
4009 mp = mbox->context1;
4010 if (mp) {
4011 lpfc_mbuf_free(phba, mp->virt,
4012 mp->phys);
4013 kfree(mp);
4014 }
4015 mempool_free(mbox, phba->mbox_mem_pool);
4016 goto out;
4017 }
4018
James Smarte47c9092008-02-08 18:49:26 -05004019 /* Increment reference count to ndlp to hold the
4020 * reference to ndlp for the callback function.
4021 */
James Smart329f9bc2007-04-25 09:53:01 -04004022 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004023 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05004024 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4025 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4026 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4027 }
4028 else {
4029 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4030 ndlp->nlp_prev_state = ndlp->nlp_state;
4031 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05004032 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05004033 }
James Smart4b7789b72015-12-16 18:11:55 -05004034
4035 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04004036 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05004037 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05004038 goto out;
James Smart4b7789b72015-12-16 18:11:55 -05004039
4040 /* Decrement the ndlp reference count we
4041 * set for this failed mailbox command.
4042 */
4043 lpfc_nlp_put(ndlp);
4044 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04004045
4046 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4047 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4048 "0138 ELS rsp: Cannot issue reg_login for x%x "
4049 "Data: x%x x%x x%x\n",
4050 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4051 ndlp->nlp_rpi);
4052
James Smartfa4066b2008-01-11 01:53:27 -05004053 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004054 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004055 /* Indicate node has already been released,
4056 * should not reference to it from within
4057 * the routine lpfc_els_free_iocb.
4058 */
4059 cmdiocb->context1 = NULL;
4060 }
dea31012005-04-17 16:05:31 -05004061 } else {
James Smart858c9f62007-06-17 19:56:39 -05004062 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4063 if (!lpfc_error_lost_link(irsp) &&
4064 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05004065 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04004066 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05004067 /* Indicate node has already been
4068 * released, should not reference
4069 * to it from within the routine
4070 * lpfc_els_free_iocb.
4071 */
4072 cmdiocb->context1 = NULL;
4073 }
dea31012005-04-17 16:05:31 -05004074 }
4075 }
James Smart14691152006-12-02 13:34:28 -05004076 mp = (struct lpfc_dmabuf *) mbox->context1;
4077 if (mp) {
4078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4079 kfree(mp);
4080 }
4081 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004082 }
4083out:
James Smart58da1ff2008-04-07 10:15:56 -04004084 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05004085 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004086 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05004087 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04004088
4089 /* If the node is not being used by another discovery thread,
4090 * and we are sending a reject, we are done with it.
4091 * Release driver reference count here and free associated
4092 * resources.
4093 */
4094 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05004095 if (lpfc_nlp_not_used(ndlp))
4096 /* Indicate node has already been released,
4097 * should not reference to it from within
4098 * the routine lpfc_els_free_iocb.
4099 */
4100 cmdiocb->context1 = NULL;
James Smart4b7789b72015-12-16 18:11:55 -05004101
dea31012005-04-17 16:05:31 -05004102 }
James Smart87af33f2007-10-27 13:37:43 -04004103
dea31012005-04-17 16:05:31 -05004104 lpfc_els_free_iocb(phba, cmdiocb);
4105 return;
4106}
4107
James Smarte59058c2008-08-24 21:49:00 -04004108/**
James Smart3621a712009-04-06 18:47:14 -04004109 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004110 * @vport: pointer to a host virtual N_Port data structure.
4111 * @flag: the els command code to be accepted.
4112 * @oldiocb: pointer to the original lpfc command iocb data structure.
4113 * @ndlp: pointer to a node-list data structure.
4114 * @mbox: pointer to the driver internal queue element for mailbox command.
4115 *
4116 * This routine prepares and issues an Accept (ACC) response IOCB
4117 * command. It uses the @flag to properly set up the IOCB field for the
4118 * specific ACC response command to be issued and invokes the
4119 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4120 * @mbox pointer is passed in, it will be put into the context_un.mbox
4121 * field of the IOCB for the completion callback function to issue the
4122 * mailbox command to the HBA later when callback is invoked.
4123 *
4124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4126 * will be stored into the context1 field of the IOCB for the completion
4127 * callback function to the corresponding response ELS IOCB command.
4128 *
4129 * Return code
4130 * 0 - Successfully issued acc response
4131 * 1 - Failed to issue acc response
4132 **/
dea31012005-04-17 16:05:31 -05004133int
James Smart2e0fef82007-06-17 19:56:36 -05004134lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4135 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04004136 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004137{
James Smart2e0fef82007-06-17 19:56:36 -05004138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4139 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004140 IOCB_t *icmd;
4141 IOCB_t *oldcmd;
4142 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004143 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05004144 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05004145 uint16_t cmdsize;
4146 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04004147 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05004148
dea31012005-04-17 16:05:31 -05004149 oldcmd = &oldiocb->iocb;
4150
4151 switch (flag) {
4152 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05004153 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004154 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4155 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004156 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05004157 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004158 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004159 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004160 return 1;
dea31012005-04-17 16:05:31 -05004161 }
James Smart2e0fef82007-06-17 19:56:36 -05004162
dea31012005-04-17 16:05:31 -05004163 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004164 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4165 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004166 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4167 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004168 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05004169
4170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4171 "Issue ACC: did:x%x flg:x%x",
4172 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004173 break;
James Smartd6de08c2015-12-16 18:11:53 -05004174 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05004175 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05004176 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05004177 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4178 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004179 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004180 return 1;
James Smart488d1462006-03-07 15:02:37 -05004181
dea31012005-04-17 16:05:31 -05004182 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004183 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4184 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004185 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4186
4187 if (mbox)
4188 elsiocb->context_un.mbox = mbox;
4189
4190 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004191 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05004192 sp = (struct serv_parm *)pcmd;
4193
4194 if (flag == ELS_CMD_FLOGI) {
4195 /* Copy the received service parameters back */
4196 memcpy(sp, &phba->fc_fabparam,
4197 sizeof(struct serv_parm));
4198
4199 /* Clear the F_Port bit */
4200 sp->cmn.fPort = 0;
4201
4202 /* Mark all class service parameters as invalid */
4203 sp->cls1.classValid = 0;
4204 sp->cls2.classValid = 0;
4205 sp->cls3.classValid = 0;
4206 sp->cls4.classValid = 0;
4207
4208 /* Copy our worldwide names */
4209 memcpy(&sp->portName, &vport->fc_sparam.portName,
4210 sizeof(struct lpfc_name));
4211 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4212 sizeof(struct lpfc_name));
James Smart8c258642017-02-12 13:52:36 -08004213 } else {
James Smartd6de08c2015-12-16 18:11:53 -05004214 memcpy(pcmd, &vport->fc_sparam,
4215 sizeof(struct serv_parm));
James Smarte0165f22016-12-19 15:07:20 -08004216
James Smart8c258642017-02-12 13:52:36 -08004217 sp->cmn.valid_vendor_ver_level = 0;
4218 memset(sp->un.vendorVersion, 0,
4219 sizeof(sp->un.vendorVersion));
James Smart44fd7fe2017-08-23 16:55:47 -07004220 sp->cmn.bbRcvSizeMsb &= 0xF;
James Smart8c258642017-02-12 13:52:36 -08004221
4222 /* If our firmware supports this feature, convey that
4223 * info to the target using the vendor specific field.
4224 */
4225 if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4226 sp->cmn.valid_vendor_ver_level = 1;
4227 sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4228 sp->un.vv.flags =
4229 cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4230 }
4231 }
4232
James Smart858c9f62007-06-17 19:56:39 -05004233 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004234 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004235 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004236 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004237 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004238 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004239 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004240 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4241 if (!elsiocb)
4242 return 1;
4243
4244 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004245 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4246 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004247 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4248
4249 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004250 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004251 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4252 els_pkt_ptr = (ELS_PKT *) pcmd;
4253 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004254
4255 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4256 "Issue ACC PRLO: did:x%x flg:x%x",
4257 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004258 break;
dea31012005-04-17 16:05:31 -05004259 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004260 return 1;
dea31012005-04-17 16:05:31 -05004261 }
dea31012005-04-17 16:05:31 -05004262 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004263 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4264 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04004265 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4266 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004267 elsiocb->iotag, elsiocb->iocb.ulpContext,
4268 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04004269 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05004270 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004271 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004272 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4273 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4274 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004275 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004276 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4277 } else {
James Smart858c9f62007-06-17 19:56:39 -05004278 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004279 }
4280
4281 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004282 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004283 if (rc == IOCB_ERROR) {
4284 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004285 return 1;
dea31012005-04-17 16:05:31 -05004286 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004287 return 0;
dea31012005-04-17 16:05:31 -05004288}
4289
James Smarte59058c2008-08-24 21:49:00 -04004290/**
James Smart3621a712009-04-06 18:47:14 -04004291 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004292 * @vport: pointer to a virtual N_Port data structure.
4293 * @rejectError:
4294 * @oldiocb: pointer to the original lpfc command iocb data structure.
4295 * @ndlp: pointer to a node-list data structure.
4296 * @mbox: pointer to the driver internal queue element for mailbox command.
4297 *
4298 * This routine prepares and issue an Reject (RJT) response IOCB
4299 * command. If a @mbox pointer is passed in, it will be put into the
4300 * context_un.mbox field of the IOCB for the completion callback function
4301 * to issue to the HBA later.
4302 *
4303 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4304 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4305 * will be stored into the context1 field of the IOCB for the completion
4306 * callback function to the reject response ELS IOCB command.
4307 *
4308 * Return code
4309 * 0 - Successfully issued reject response
4310 * 1 - Failed to issue reject response
4311 **/
dea31012005-04-17 16:05:31 -05004312int
James Smart2e0fef82007-06-17 19:56:36 -05004313lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004314 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4315 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004316{
James Smart2e0fef82007-06-17 19:56:36 -05004317 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004318 IOCB_t *icmd;
4319 IOCB_t *oldcmd;
4320 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004321 uint8_t *pcmd;
4322 uint16_t cmdsize;
4323 int rc;
4324
James Smart92d7f7b2007-06-17 19:56:38 -05004325 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004326 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4327 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004328 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004329 return 1;
dea31012005-04-17 16:05:31 -05004330
4331 icmd = &elsiocb->iocb;
4332 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004333 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4334 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004335 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4336
4337 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004338 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004339 *((uint32_t *) (pcmd)) = rejectError;
4340
James Smart51ef4c22007-08-02 11:10:31 -04004341 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004342 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004343
dea31012005-04-17 16:05:31 -05004344 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004345 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4346 "0129 Xmit ELS RJT x%x response tag x%x "
4347 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4348 "rpi x%x\n",
4349 rejectError, elsiocb->iotag,
4350 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4351 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004352 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4353 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4354 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4355
dea31012005-04-17 16:05:31 -05004356 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004357 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004358 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004359
dea31012005-04-17 16:05:31 -05004360 if (rc == IOCB_ERROR) {
4361 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004362 return 1;
dea31012005-04-17 16:05:31 -05004363 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004364 return 0;
dea31012005-04-17 16:05:31 -05004365}
4366
James Smarte59058c2008-08-24 21:49:00 -04004367/**
James Smart3621a712009-04-06 18:47:14 -04004368 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004369 * @vport: pointer to a virtual N_Port data structure.
4370 * @oldiocb: pointer to the original lpfc command iocb data structure.
4371 * @ndlp: pointer to a node-list data structure.
4372 *
4373 * This routine prepares and issues an Accept (ACC) response to Address
4374 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4375 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4376 *
4377 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4378 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4379 * will be stored into the context1 field of the IOCB for the completion
4380 * callback function to the ADISC Accept response ELS IOCB command.
4381 *
4382 * Return code
4383 * 0 - Successfully issued acc adisc response
4384 * 1 - Failed to issue adisc acc response
4385 **/
dea31012005-04-17 16:05:31 -05004386int
James Smart2e0fef82007-06-17 19:56:36 -05004387lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4388 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004389{
James Smart2e0fef82007-06-17 19:56:36 -05004390 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004391 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004392 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004393 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004394 uint8_t *pcmd;
4395 uint16_t cmdsize;
4396 int rc;
4397
James Smart92d7f7b2007-06-17 19:56:38 -05004398 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004399 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4400 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004401 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004402 return 1;
dea31012005-04-17 16:05:31 -05004403
dea31012005-04-17 16:05:31 -05004404 icmd = &elsiocb->iocb;
4405 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004406 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4407 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004408
4409 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004410 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4411 "0130 Xmit ADISC ACC response iotag x%x xri: "
4412 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4413 elsiocb->iotag, elsiocb->iocb.ulpContext,
4414 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4415 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004416 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4417
4418 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004419 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004420
4421 ap = (ADISC *) (pcmd);
4422 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004423 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4424 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004425 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004426
James Smart858c9f62007-06-17 19:56:39 -05004427 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4428 "Issue ACC ADISC: did:x%x flg:x%x",
4429 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4430
dea31012005-04-17 16:05:31 -05004431 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004432 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004433 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004434 if (rc == IOCB_ERROR) {
4435 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004436 return 1;
dea31012005-04-17 16:05:31 -05004437 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004438 return 0;
dea31012005-04-17 16:05:31 -05004439}
4440
James Smarte59058c2008-08-24 21:49:00 -04004441/**
James Smart3621a712009-04-06 18:47:14 -04004442 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004443 * @vport: pointer to a virtual N_Port data structure.
4444 * @oldiocb: pointer to the original lpfc command iocb data structure.
4445 * @ndlp: pointer to a node-list data structure.
4446 *
4447 * This routine prepares and issues an Accept (ACC) response to Process
4448 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4449 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4450 *
4451 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4452 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4453 * will be stored into the context1 field of the IOCB for the completion
4454 * callback function to the PRLI Accept response ELS IOCB command.
4455 *
4456 * Return code
4457 * 0 - Successfully issued acc prli response
4458 * 1 - Failed to issue acc prli response
4459 **/
dea31012005-04-17 16:05:31 -05004460int
James Smart2e0fef82007-06-17 19:56:36 -05004461lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004462 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004463{
James Smart2e0fef82007-06-17 19:56:36 -05004464 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004465 PRLI *npr;
James Smarta0f2d3e2017-02-12 13:52:31 -08004466 struct lpfc_nvme_prli *npr_nvme;
dea31012005-04-17 16:05:31 -05004467 lpfc_vpd_t *vpd;
4468 IOCB_t *icmd;
4469 IOCB_t *oldcmd;
4470 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004471 uint8_t *pcmd;
4472 uint16_t cmdsize;
James Smarta0f2d3e2017-02-12 13:52:31 -08004473 uint32_t prli_fc4_req, *req_payload;
4474 struct lpfc_dmabuf *req_buf;
dea31012005-04-17 16:05:31 -05004475 int rc;
James Smarta0f2d3e2017-02-12 13:52:31 -08004476 u32 elsrspcmd;
dea31012005-04-17 16:05:31 -05004477
James Smarta0f2d3e2017-02-12 13:52:31 -08004478 /* Need the incoming PRLI payload to determine if the ACC is for an
4479 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4480 */
4481 req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
4482 req_payload = (((uint32_t *)req_buf->virt) + 1);
4483
4484 /* PRLI type payload is at byte 3 for FCP or NVME. */
4485 prli_fc4_req = be32_to_cpu(*req_payload);
4486 prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
4487 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4488 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4489 prli_fc4_req, *((uint32_t *)req_payload));
4490
4491 if (prli_fc4_req == PRLI_FCP_TYPE) {
4492 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
4493 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
4494 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4495 cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
4496 elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
4497 } else {
4498 return 1;
4499 }
4500
James Smart2e0fef82007-06-17 19:56:36 -05004501 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smarta0f2d3e2017-02-12 13:52:31 -08004502 ndlp->nlp_DID, elsrspcmd);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004503 if (!elsiocb)
4504 return 1;
dea31012005-04-17 16:05:31 -05004505
dea31012005-04-17 16:05:31 -05004506 icmd = &elsiocb->iocb;
4507 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004508 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4509 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4510
James Smart5b8bd0c2007-04-25 09:52:49 -04004511 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004512 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4513 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4514 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4515 elsiocb->iotag, elsiocb->iocb.ulpContext,
4516 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4517 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004518 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
James Smarta0f2d3e2017-02-12 13:52:31 -08004519 memset(pcmd, 0, cmdsize);
dea31012005-04-17 16:05:31 -05004520
James Smartc07f10c2017-04-21 16:04:54 -07004521 *((uint32_t *)(pcmd)) = elsrspcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004522 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004523
4524 /* For PRLI, remainder of payload is PRLI parameter page */
dea31012005-04-17 16:05:31 -05004525 vpd = &phba->vpd;
James Smarta0f2d3e2017-02-12 13:52:31 -08004526
4527 if (prli_fc4_req == PRLI_FCP_TYPE) {
4528 /*
4529 * If the remote port is a target and our firmware version
4530 * is 3.20 or later, set the following bits for FC-TAPE
4531 * support.
4532 */
4533 npr = (PRLI *) pcmd;
4534 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4535 (vpd->rev.feaLevelHigh >= 0x02)) {
4536 npr->ConfmComplAllowed = 1;
4537 npr->Retry = 1;
4538 npr->TaskRetryIdReq = 1;
4539 }
4540 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4541 npr->estabImagePair = 1;
4542 npr->readXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05004543 npr->ConfmComplAllowed = 1;
James Smarta0f2d3e2017-02-12 13:52:31 -08004544 npr->prliType = PRLI_FCP_TYPE;
4545 npr->initiatorFunc = 1;
4546 } else if (prli_fc4_req & PRLI_NVME_TYPE) {
4547 /* Respond with an NVME PRLI Type */
4548 npr_nvme = (struct lpfc_nvme_prli *) pcmd;
4549 bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
4550 bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
4551 bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
James Smart8c258642017-02-12 13:52:36 -08004552 if (phba->nvmet_support) {
4553 bf_set(prli_tgt, npr_nvme, 1);
4554 bf_set(prli_disc, npr_nvme, 1);
4555 if (phba->cfg_nvme_enable_fb) {
4556 bf_set(prli_fba, npr_nvme, 1);
4557
4558 /* TBD. Target mode needs to post buffers
4559 * that support the configured first burst
4560 * byte size.
4561 */
4562 bf_set(prli_fb_sz, npr_nvme,
4563 phba->cfg_nvmet_fb_size);
4564 }
4565 } else {
4566 bf_set(prli_init, npr_nvme, 1);
4567 }
dea31012005-04-17 16:05:31 -05004568
James Smarta0f2d3e2017-02-12 13:52:31 -08004569 lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
4570 "6015 NVME issue PRLI ACC word1 x%08x "
4571 "word4 x%08x word5 x%08x flag x%x, "
4572 "fcp_info x%x nlp_type x%x\n",
4573 npr_nvme->word1, npr_nvme->word4,
4574 npr_nvme->word5, ndlp->nlp_flag,
4575 ndlp->nlp_fcp_info, ndlp->nlp_type);
4576 npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
4577 npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
4578 npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
4579 } else
4580 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4581 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4582 prli_fc4_req, ndlp->nlp_fc4_type,
4583 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05004584
James Smart858c9f62007-06-17 19:56:39 -05004585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4586 "Issue ACC PRLI: did:x%x flg:x%x",
4587 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4588
dea31012005-04-17 16:05:31 -05004589 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004590 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004591
James Smart3772a992009-05-22 14:50:54 -04004592 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004593 if (rc == IOCB_ERROR) {
4594 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004595 return 1;
dea31012005-04-17 16:05:31 -05004596 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004597 return 0;
dea31012005-04-17 16:05:31 -05004598}
4599
James Smarte59058c2008-08-24 21:49:00 -04004600/**
James Smart3621a712009-04-06 18:47:14 -04004601 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004602 * @vport: pointer to a virtual N_Port data structure.
4603 * @format: rnid command format.
4604 * @oldiocb: pointer to the original lpfc command iocb data structure.
4605 * @ndlp: pointer to a node-list data structure.
4606 *
4607 * This routine issues a Request Node Identification Data (RNID) Accept
4608 * (ACC) response. It constructs the RNID ACC response command according to
4609 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4610 * issue the response. Note that this command does not need to hold the ndlp
4611 * reference count for the callback. So, the ndlp reference count taken by
4612 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4613 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4614 * there is no ndlp reference available.
4615 *
4616 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4617 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4618 * will be stored into the context1 field of the IOCB for the completion
4619 * callback function. However, for the RNID Accept Response ELS command,
4620 * this is undone later by this routine after the IOCB is allocated.
4621 *
4622 * Return code
4623 * 0 - Successfully issued acc rnid response
4624 * 1 - Failed to issue acc rnid response
4625 **/
dea31012005-04-17 16:05:31 -05004626static int
James Smart2e0fef82007-06-17 19:56:36 -05004627lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004628 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004629{
James Smart2e0fef82007-06-17 19:56:36 -05004630 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004631 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004632 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004633 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004634 uint8_t *pcmd;
4635 uint16_t cmdsize;
4636 int rc;
4637
James Smart92d7f7b2007-06-17 19:56:38 -05004638 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4639 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004640 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004641 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004642
James Smart2e0fef82007-06-17 19:56:36 -05004643 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4644 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004645 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004646 return 1;
dea31012005-04-17 16:05:31 -05004647
dea31012005-04-17 16:05:31 -05004648 icmd = &elsiocb->iocb;
4649 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004650 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4651 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4652
James Smart5b8bd0c2007-04-25 09:52:49 -04004653 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004654 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4655 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4656 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004657 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004658 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004659 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004660
James Smart92d7f7b2007-06-17 19:56:38 -05004661 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004662 rn = (RNID *) (pcmd);
4663 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004664 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4665 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4666 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004667 switch (format) {
4668 case 0:
4669 rn->SpecificLen = 0;
4670 break;
4671 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004672 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004673 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004674 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004675 rn->un.topologyDisc.unitType = RNID_HBA;
4676 rn->un.topologyDisc.physPort = 0;
4677 rn->un.topologyDisc.attachedNodes = 0;
4678 break;
4679 default:
4680 rn->CommonLen = 0;
4681 rn->SpecificLen = 0;
4682 break;
4683 }
4684
James Smart858c9f62007-06-17 19:56:39 -05004685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4686 "Issue ACC RNID: did:x%x flg:x%x",
4687 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4688
dea31012005-04-17 16:05:31 -05004689 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004690 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004691
James Smart3772a992009-05-22 14:50:54 -04004692 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004693 if (rc == IOCB_ERROR) {
4694 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004695 return 1;
dea31012005-04-17 16:05:31 -05004696 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004697 return 0;
dea31012005-04-17 16:05:31 -05004698}
4699
James Smarte59058c2008-08-24 21:49:00 -04004700/**
James Smart19ca7602010-11-20 23:11:55 -05004701 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4702 * @vport: pointer to a virtual N_Port data structure.
4703 * @iocb: pointer to the lpfc command iocb data structure.
4704 * @ndlp: pointer to a node-list data structure.
4705 *
4706 * Return
4707 **/
4708static void
4709lpfc_els_clear_rrq(struct lpfc_vport *vport,
James Smarta0f2d3e2017-02-12 13:52:31 -08004710 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
James Smart19ca7602010-11-20 23:11:55 -05004711{
4712 struct lpfc_hba *phba = vport->phba;
4713 uint8_t *pcmd;
4714 struct RRQ *rrq;
4715 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004716 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004717 struct lpfc_node_rrq *prrq;
4718
4719
4720 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4721 pcmd += sizeof(uint32_t);
4722 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004723 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004724 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004725
4726 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4727 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4728 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004729 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004730 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004731 rxid,
4732 iocb->iotag, iocb->iocb.ulpContext);
4733
4734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4735 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4736 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004737 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004738 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004739 else
4740 xri = rxid;
4741 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004742 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004743 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004744 return;
4745}
4746
4747/**
James Smart12265f62010-10-22 11:05:53 -04004748 * lpfc_els_rsp_echo_acc - Issue echo acc response
4749 * @vport: pointer to a virtual N_Port data structure.
4750 * @data: pointer to echo data to return in the accept.
4751 * @oldiocb: pointer to the original lpfc command iocb data structure.
4752 * @ndlp: pointer to a node-list data structure.
4753 *
4754 * Return code
4755 * 0 - Successfully issued acc echo response
4756 * 1 - Failed to issue acc echo response
4757 **/
4758static int
4759lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4760 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4761{
4762 struct lpfc_hba *phba = vport->phba;
4763 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04004764 uint8_t *pcmd;
4765 uint16_t cmdsize;
4766 int rc;
4767
James Smart12265f62010-10-22 11:05:53 -04004768 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4769
James Smartbf086112011-08-21 21:48:13 -04004770 /* The accumulated length can exceed the BPL_SIZE. For
4771 * now, use this as the limit
4772 */
4773 if (cmdsize > LPFC_BPL_SIZE)
4774 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004775 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4776 ndlp->nlp_DID, ELS_CMD_ACC);
4777 if (!elsiocb)
4778 return 1;
4779
James Smart7851fe22011-07-22 18:36:52 -04004780 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4781 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4782
James Smart12265f62010-10-22 11:05:53 -04004783 /* Xmit ECHO ACC response tag <ulpIoTag> */
4784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4785 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4786 elsiocb->iotag, elsiocb->iocb.ulpContext);
4787 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4788 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4789 pcmd += sizeof(uint32_t);
4790 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4791
4792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4793 "Issue ACC ECHO: did:x%x flg:x%x",
4794 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4795
4796 phba->fc_stat.elsXmitACC++;
4797 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004798
4799 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4800 if (rc == IOCB_ERROR) {
4801 lpfc_els_free_iocb(phba, elsiocb);
4802 return 1;
4803 }
4804 return 0;
4805}
4806
4807/**
James Smart3621a712009-04-06 18:47:14 -04004808 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004809 * @vport: pointer to a host virtual N_Port data structure.
4810 *
4811 * This routine issues Address Discover (ADISC) ELS commands to those
4812 * N_Ports which are in node port recovery state and ADISC has not been issued
4813 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4814 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4815 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4816 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4817 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4818 * IOCBs quit for later pick up. On the other hand, after walking through
4819 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4820 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4821 * no more ADISC need to be sent.
4822 *
4823 * Return code
4824 * The number of N_Ports with adisc issued.
4825 **/
dea31012005-04-17 16:05:31 -05004826int
James Smart2e0fef82007-06-17 19:56:36 -05004827lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004828{
James Smart2e0fef82007-06-17 19:56:36 -05004829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004830 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004831 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004832
James Smart685f0bf2007-04-25 09:53:08 -04004833 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004834 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004835 if (!NLP_CHK_NODE_ACT(ndlp))
4836 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004837 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4838 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4839 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004840 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004841 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004842 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004843 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004844 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4845 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004846 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004847 vport->num_disc_nodes++;
4848 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004849 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004850 spin_lock_irq(shost->host_lock);
4851 vport->fc_flag |= FC_NLP_MORE;
4852 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004853 break;
dea31012005-04-17 16:05:31 -05004854 }
4855 }
4856 }
4857 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004858 spin_lock_irq(shost->host_lock);
4859 vport->fc_flag &= ~FC_NLP_MORE;
4860 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004861 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004862 return sentadisc;
dea31012005-04-17 16:05:31 -05004863}
4864
James Smarte59058c2008-08-24 21:49:00 -04004865/**
James Smart3621a712009-04-06 18:47:14 -04004866 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004867 * @vport: pointer to a host virtual N_Port data structure.
4868 *
4869 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4870 * which are in node port recovery state, with a @vport. Each time an ELS
4871 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4872 * the per @vport number of discover count (num_disc_nodes) shall be
4873 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4874 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4875 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4876 * later pick up. On the other hand, after walking through all the ndlps with
4877 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4878 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4879 * PLOGI need to be sent.
4880 *
4881 * Return code
4882 * The number of N_Ports with plogi issued.
4883 **/
dea31012005-04-17 16:05:31 -05004884int
James Smart2e0fef82007-06-17 19:56:36 -05004885lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004886{
James Smart2e0fef82007-06-17 19:56:36 -05004887 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004888 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004889 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004890
James Smart2e0fef82007-06-17 19:56:36 -05004891 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4892 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004893 if (!NLP_CHK_NODE_ACT(ndlp))
4894 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004895 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004896 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4897 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4898 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004899 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004900 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4901 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004902 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004903 vport->num_disc_nodes++;
4904 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004905 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004906 spin_lock_irq(shost->host_lock);
4907 vport->fc_flag |= FC_NLP_MORE;
4908 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004909 break;
dea31012005-04-17 16:05:31 -05004910 }
4911 }
4912 }
James Smart87af33f2007-10-27 13:37:43 -04004913 if (sentplogi) {
4914 lpfc_set_disctmo(vport);
4915 }
4916 else {
James Smart2e0fef82007-06-17 19:56:36 -05004917 spin_lock_irq(shost->host_lock);
4918 vport->fc_flag &= ~FC_NLP_MORE;
4919 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004920 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004921 return sentplogi;
dea31012005-04-17 16:05:31 -05004922}
4923
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004924static uint32_t
James Smart86478872015-05-21 13:55:21 -04004925lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4926 uint32_t word0)
4927{
4928
4929 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4930 desc->payload.els_req = word0;
4931 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07004932
4933 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04004934}
4935
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004936static uint32_t
James Smart86478872015-05-21 13:55:21 -04004937lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4938 uint8_t *page_a0, uint8_t *page_a2)
4939{
4940 uint16_t wavelength;
4941 uint16_t temperature;
4942 uint16_t rx_power;
4943 uint16_t tx_bias;
4944 uint16_t tx_power;
4945 uint16_t vcc;
4946 uint16_t flag = 0;
4947 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4948 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4949
4950 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4951
4952 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4953 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4954 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4955 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4956
4957 if ((trasn_code_byte4->fc_sw_laser) ||
4958 (trasn_code_byte5->fc_sw_laser_sl) ||
4959 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4960 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4961 } else if (trasn_code_byte4->fc_lw_laser) {
4962 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4963 page_a0[SSF_WAVELENGTH_B0];
4964 if (wavelength == SFP_WAVELENGTH_LC1310)
4965 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4966 if (wavelength == SFP_WAVELENGTH_LL1550)
4967 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4968 }
4969 /* check if its SFP+ */
4970 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4971 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4972 << SFP_FLAG_CT_SHIFT;
4973
4974 /* check if its OPTICAL */
4975 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4976 SFP_FLAG_IS_OPTICAL_PORT : 0)
4977 << SFP_FLAG_IS_OPTICAL_SHIFT;
4978
4979 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4980 page_a2[SFF_TEMPERATURE_B0]);
4981 vcc = (page_a2[SFF_VCC_B1] << 8 |
4982 page_a2[SFF_VCC_B0]);
4983 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4984 page_a2[SFF_TXPOWER_B0]);
4985 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4986 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4987 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4988 page_a2[SFF_RXPOWER_B0]);
4989 desc->sfp_info.temperature = cpu_to_be16(temperature);
4990 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4991 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4992 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4993 desc->sfp_info.vcc = cpu_to_be16(vcc);
4994
4995 desc->sfp_info.flags = cpu_to_be16(flag);
4996 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004997
4998 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04004999}
5000
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005001static uint32_t
James Smart86478872015-05-21 13:55:21 -04005002lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5003 READ_LNK_VAR *stat)
5004{
5005 uint32_t type;
5006
5007 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5008
5009 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5010
5011 desc->info.port_type = cpu_to_be32(type);
5012
5013 desc->info.link_status.link_failure_cnt =
5014 cpu_to_be32(stat->linkFailureCnt);
5015 desc->info.link_status.loss_of_synch_cnt =
5016 cpu_to_be32(stat->lossSyncCnt);
5017 desc->info.link_status.loss_of_signal_cnt =
5018 cpu_to_be32(stat->lossSignalCnt);
5019 desc->info.link_status.primitive_seq_proto_err =
5020 cpu_to_be32(stat->primSeqErrCnt);
5021 desc->info.link_status.invalid_trans_word =
5022 cpu_to_be32(stat->invalidXmitWord);
5023 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5024
5025 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005026
5027 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04005028}
5029
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005030static uint32_t
James Smart56204982016-03-31 14:12:32 -07005031lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5032 struct lpfc_vport *vport)
5033{
James Smart3aaaa312016-07-06 12:35:57 -07005034 uint32_t bbCredit;
5035
James Smart56204982016-03-31 14:12:32 -07005036 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5037
James Smart3aaaa312016-07-06 12:35:57 -07005038 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5039 (vport->fc_sparam.cmn.bbCreditMsb << 8);
5040 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5041 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5042 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5043 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5044 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5045 } else {
James Smart56204982016-03-31 14:12:32 -07005046 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07005047 }
James Smart56204982016-03-31 14:12:32 -07005048
5049 desc->bbc_info.rtt = 0;
5050 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005051
5052 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07005053}
5054
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005055static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005056lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5057 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07005058{
James Smart310429e2016-07-06 12:35:54 -07005059 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005060
5061 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5062
James Smart3aaaa312016-07-06 12:35:57 -07005063 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5064 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5065 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5066 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005067
5068 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5069 flags |= RDP_OET_HIGH_ALARM;
5070 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5071 flags |= RDP_OET_LOW_ALARM;
5072 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5073 flags |= RDP_OET_HIGH_WARNING;
5074 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5075 flags |= RDP_OET_LOW_WARNING;
5076
James Smart56204982016-03-31 14:12:32 -07005077 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5078 desc->oed_info.function_flags = cpu_to_be32(flags);
5079 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005080 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005081}
5082
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005083static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005084lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5085 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005086 uint8_t *page_a2)
5087{
James Smart310429e2016-07-06 12:35:54 -07005088 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005089
5090 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5091
James Smart3aaaa312016-07-06 12:35:57 -07005092 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5093 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5094 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5095 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005096
5097 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5098 flags |= RDP_OET_HIGH_ALARM;
5099 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5100 flags |= RDP_OET_LOW_ALARM;
5101 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5102 flags |= RDP_OET_HIGH_WARNING;
5103 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5104 flags |= RDP_OET_LOW_WARNING;
5105
James Smart56204982016-03-31 14:12:32 -07005106 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5107 desc->oed_info.function_flags = cpu_to_be32(flags);
5108 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005109 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005110}
5111
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005112static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005113lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5114 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005115 uint8_t *page_a2)
5116{
James Smart310429e2016-07-06 12:35:54 -07005117 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005118
5119 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5120
James Smart3aaaa312016-07-06 12:35:57 -07005121 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5122 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5123 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5124 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005125
5126 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5127 flags |= RDP_OET_HIGH_ALARM;
5128 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5129 flags |= RDP_OET_LOW_ALARM;
5130 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5131 flags |= RDP_OET_HIGH_WARNING;
5132 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5133 flags |= RDP_OET_LOW_WARNING;
5134
James Smart56204982016-03-31 14:12:32 -07005135 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5136 desc->oed_info.function_flags = cpu_to_be32(flags);
5137 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005138 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005139}
5140
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005141static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005142lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5143 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005144 uint8_t *page_a2)
5145{
James Smart310429e2016-07-06 12:35:54 -07005146 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005147
5148 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5149
James Smart3aaaa312016-07-06 12:35:57 -07005150 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5151 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5152 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5153 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005154
5155 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5156 flags |= RDP_OET_HIGH_ALARM;
5157 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5158 flags |= RDP_OET_LOW_ALARM;
5159 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5160 flags |= RDP_OET_HIGH_WARNING;
5161 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5162 flags |= RDP_OET_LOW_WARNING;
5163
James Smart56204982016-03-31 14:12:32 -07005164 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5165 desc->oed_info.function_flags = cpu_to_be32(flags);
5166 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005167 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005168}
5169
5170
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005171static uint32_t
James Smart310429e2016-07-06 12:35:54 -07005172lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5173 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07005174 uint8_t *page_a2)
5175{
James Smart310429e2016-07-06 12:35:54 -07005176 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07005177
5178 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5179
James Smart3aaaa312016-07-06 12:35:57 -07005180 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5181 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5182 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5183 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07005184
5185 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5186 flags |= RDP_OET_HIGH_ALARM;
5187 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5188 flags |= RDP_OET_LOW_ALARM;
5189 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5190 flags |= RDP_OET_HIGH_WARNING;
5191 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5192 flags |= RDP_OET_LOW_WARNING;
5193
James Smart56204982016-03-31 14:12:32 -07005194 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5195 desc->oed_info.function_flags = cpu_to_be32(flags);
5196 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005197 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005198}
5199
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005200static uint32_t
James Smart56204982016-03-31 14:12:32 -07005201lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5202 uint8_t *page_a0, struct lpfc_vport *vport)
5203{
5204 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5205 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5206 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5207 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
James Smarta0f2d3e2017-02-12 13:52:31 -08005208 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
James Smart56204982016-03-31 14:12:32 -07005209 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5210 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07005211 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07005212}
5213
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005214static uint32_t
James Smart4258e982015-12-16 18:11:58 -05005215lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5216{
5217 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5218 return 0;
5219 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5220
5221 desc->info.CorrectedBlocks =
5222 cpu_to_be32(stat->fecCorrBlkCount);
5223 desc->info.UncorrectableBlocks =
5224 cpu_to_be32(stat->fecUncorrBlkCount);
5225
5226 desc->length = cpu_to_be32(sizeof(desc->info));
5227
5228 return sizeof(struct fc_fec_rdp_desc);
5229}
5230
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005231static uint32_t
James Smart86478872015-05-21 13:55:21 -04005232lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5233{
5234 uint16_t rdp_cap = 0;
5235 uint16_t rdp_speed;
5236
5237 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5238
James Smart81e75172015-12-16 18:11:59 -05005239 switch (phba->fc_linkspeed) {
5240 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04005241 rdp_speed = RDP_PS_1GB;
5242 break;
James Smart81e75172015-12-16 18:11:59 -05005243 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04005244 rdp_speed = RDP_PS_2GB;
5245 break;
James Smart81e75172015-12-16 18:11:59 -05005246 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04005247 rdp_speed = RDP_PS_4GB;
5248 break;
James Smart81e75172015-12-16 18:11:59 -05005249 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04005250 rdp_speed = RDP_PS_8GB;
5251 break;
James Smart81e75172015-12-16 18:11:59 -05005252 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04005253 rdp_speed = RDP_PS_10GB;
5254 break;
James Smart81e75172015-12-16 18:11:59 -05005255 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04005256 rdp_speed = RDP_PS_16GB;
5257 break;
James Smarta085e872015-12-16 18:12:02 -05005258 case LPFC_LINK_SPEED_32GHZ:
5259 rdp_speed = RDP_PS_32GB;
5260 break;
James Smart86478872015-05-21 13:55:21 -04005261 default:
5262 rdp_speed = RDP_PS_UNKNOWN;
5263 break;
5264 }
5265
5266 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5267
James Smartd38dd522015-08-31 16:48:17 -04005268 if (phba->lmt & LMT_32Gb)
5269 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04005270 if (phba->lmt & LMT_16Gb)
5271 rdp_cap |= RDP_PS_16GB;
5272 if (phba->lmt & LMT_10Gb)
5273 rdp_cap |= RDP_PS_10GB;
5274 if (phba->lmt & LMT_8Gb)
5275 rdp_cap |= RDP_PS_8GB;
5276 if (phba->lmt & LMT_4Gb)
5277 rdp_cap |= RDP_PS_4GB;
5278 if (phba->lmt & LMT_2Gb)
5279 rdp_cap |= RDP_PS_2GB;
5280 if (phba->lmt & LMT_1Gb)
5281 rdp_cap |= RDP_PS_1GB;
5282
5283 if (rdp_cap == 0)
5284 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07005285 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5286 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04005287
5288 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5289 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07005290 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04005291}
5292
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005293static uint32_t
James Smart86478872015-05-21 13:55:21 -04005294lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
James Smartcd46cde2017-03-04 09:30:37 -08005295 struct lpfc_vport *vport)
James Smart86478872015-05-21 13:55:21 -04005296{
5297
5298 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5299
James Smartcd46cde2017-03-04 09:30:37 -08005300 memcpy(desc->port_names.wwnn, &vport->fc_nodename,
James Smart86478872015-05-21 13:55:21 -04005301 sizeof(desc->port_names.wwnn));
5302
James Smartcd46cde2017-03-04 09:30:37 -08005303 memcpy(desc->port_names.wwpn, &vport->fc_portname,
James Smart86478872015-05-21 13:55:21 -04005304 sizeof(desc->port_names.wwpn));
5305
5306 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005307 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005308}
5309
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005310static uint32_t
James Smart86478872015-05-21 13:55:21 -04005311lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5312 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5313{
5314
5315 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5316 if (vport->fc_flag & FC_FABRIC) {
5317 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5318 sizeof(desc->port_names.wwnn));
5319
5320 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5321 sizeof(desc->port_names.wwpn));
5322 } else { /* Point to Point */
5323 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5324 sizeof(desc->port_names.wwnn));
5325
5326 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5327 sizeof(desc->port_names.wwpn));
5328 }
5329
5330 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005331 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005332}
5333
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005334static void
James Smart86478872015-05-21 13:55:21 -04005335lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5336 int status)
5337{
5338 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5339 struct lpfc_vport *vport = ndlp->vport;
5340 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005341 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005342 IOCB_t *icmd;
5343 uint8_t *pcmd;
5344 struct ls_rjt *stat;
5345 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005346 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005347 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005348 int rc;
James Smart86478872015-05-21 13:55:21 -04005349
5350 if (status != SUCCESS)
5351 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005352
5353 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005354 cmdsize = sizeof(struct fc_rdp_res_frame);
5355
5356 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5357 lpfc_max_els_tries, rdp_context->ndlp,
5358 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5359 lpfc_nlp_put(ndlp);
5360 if (!elsiocb)
5361 goto free_rdp_context;
5362
5363 icmd = &elsiocb->iocb;
5364 icmd->ulpContext = rdp_context->rx_id;
5365 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5366
5367 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5368 "2171 Xmit RDP response tag x%x xri x%x, "
5369 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5370 elsiocb->iotag, elsiocb->iocb.ulpContext,
5371 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5372 ndlp->nlp_rpi);
5373 rdp_res = (struct fc_rdp_res_frame *)
5374 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5375 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5376 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5377 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5378
James Smart310429e2016-07-06 12:35:54 -07005379 /* Update Alarm and Warning */
5380 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5381 phba->sfp_alarm |= *flag_ptr;
5382 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5383 phba->sfp_warning |= *flag_ptr;
5384
James Smart86478872015-05-21 13:55:21 -04005385 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07005386 len = 8;
5387 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5388 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04005389
James Smart6c92d1d2016-07-06 12:35:55 -07005390 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04005391 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07005392 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5393 phba);
5394 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5395 (len + pcmd), &rdp_context->link_stat);
5396 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
James Smartcd46cde2017-03-04 09:30:37 -08005397 (len + pcmd), vport);
James Smart6c92d1d2016-07-06 12:35:55 -07005398 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5399 (len + pcmd), vport, ndlp);
5400 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05005401 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07005402 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5403 &rdp_context->link_stat, vport);
5404 len += lpfc_rdp_res_oed_temp_desc(phba,
5405 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5406 rdp_context->page_a2);
5407 len += lpfc_rdp_res_oed_voltage_desc(phba,
5408 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5409 rdp_context->page_a2);
5410 len += lpfc_rdp_res_oed_txbias_desc(phba,
5411 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5412 rdp_context->page_a2);
5413 len += lpfc_rdp_res_oed_txpower_desc(phba,
5414 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5415 rdp_context->page_a2);
5416 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5417 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5418 rdp_context->page_a2);
5419 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5420 rdp_context->page_a0, vport);
5421
James Smart6c92d1d2016-07-06 12:35:55 -07005422 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04005423 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5424
James Smarteb8d68c2015-12-16 18:12:00 -05005425 /* Now that we know the true size of the payload, update the BPL */
5426 bpl = (struct ulp_bde64 *)
5427 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07005428 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05005429 bpl->tus.f.bdeFlags = 0;
5430 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5431
James Smart86478872015-05-21 13:55:21 -04005432 phba->fc_stat.elsXmitACC++;
5433 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5434 if (rc == IOCB_ERROR)
5435 lpfc_els_free_iocb(phba, elsiocb);
5436
5437 kfree(rdp_context);
5438
5439 return;
5440error:
5441 cmdsize = 2 * sizeof(uint32_t);
5442 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5443 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5444 lpfc_nlp_put(ndlp);
5445 if (!elsiocb)
5446 goto free_rdp_context;
5447
5448 icmd = &elsiocb->iocb;
5449 icmd->ulpContext = rdp_context->rx_id;
5450 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5451 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5452
5453 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5454 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5455 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5456
5457 phba->fc_stat.elsXmitLSRJT++;
5458 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5459 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5460
5461 if (rc == IOCB_ERROR)
5462 lpfc_els_free_iocb(phba, elsiocb);
5463free_rdp_context:
5464 kfree(rdp_context);
5465}
5466
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005467static int
James Smart86478872015-05-21 13:55:21 -04005468lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5469{
5470 LPFC_MBOXQ_t *mbox = NULL;
5471 int rc;
5472
5473 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5474 if (!mbox) {
5475 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5476 "7105 failed to allocate mailbox memory");
5477 return 1;
5478 }
5479
5480 if (lpfc_sli4_dump_page_a0(phba, mbox))
5481 goto prep_mbox_fail;
5482 mbox->vport = rdp_context->ndlp->vport;
5483 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5484 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5485 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5486 if (rc == MBX_NOT_FINISHED)
5487 goto issue_mbox_fail;
5488
5489 return 0;
5490
5491prep_mbox_fail:
5492issue_mbox_fail:
5493 mempool_free(mbox, phba->mbox_mem_pool);
5494 return 1;
5495}
5496
5497/*
5498 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5499 * @vport: pointer to a host virtual N_Port data structure.
5500 * @cmdiocb: pointer to lpfc command iocb data structure.
5501 * @ndlp: pointer to a node-list data structure.
5502 *
5503 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5504 * IOCB. First, the payload of the unsolicited RDP is checked.
5505 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5506 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5507 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5508 * gather all data and send RDP response.
5509 *
5510 * Return code
5511 * 0 - Sent the acc response
5512 * 1 - Sent the reject response.
5513 */
5514static int
5515lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5516 struct lpfc_nodelist *ndlp)
5517{
5518 struct lpfc_hba *phba = vport->phba;
5519 struct lpfc_dmabuf *pcmd;
5520 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5521 struct fc_rdp_req_frame *rdp_req;
5522 struct lpfc_rdp_context *rdp_context;
5523 IOCB_t *cmd = NULL;
5524 struct ls_rjt stat;
5525
5526 if (phba->sli_rev < LPFC_SLI_REV4 ||
James Smarta0f2d3e2017-02-12 13:52:31 -08005527 bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5528 LPFC_SLI_INTF_IF_TYPE_2) {
James Smart86478872015-05-21 13:55:21 -04005529 rjt_err = LSRJT_UNABLE_TPC;
5530 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5531 goto error;
5532 }
5533
5534 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5535 rjt_err = LSRJT_UNABLE_TPC;
5536 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5537 goto error;
5538 }
5539
5540 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5541 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5542
James Smart86478872015-05-21 13:55:21 -04005543 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5544 "2422 ELS RDP Request "
5545 "dec len %d tag x%x port_id %d len %d\n",
5546 be32_to_cpu(rdp_req->rdp_des_length),
5547 be32_to_cpu(rdp_req->nport_id_desc.tag),
5548 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5549 be32_to_cpu(rdp_req->nport_id_desc.length));
5550
5551 if (sizeof(struct fc_rdp_nport_desc) !=
5552 be32_to_cpu(rdp_req->rdp_des_length))
5553 goto rjt_logerr;
5554 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5555 goto rjt_logerr;
5556 if (RDP_NPORT_ID_SIZE !=
5557 be32_to_cpu(rdp_req->nport_id_desc.length))
5558 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05005559 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04005560 if (!rdp_context) {
5561 rjt_err = LSRJT_UNABLE_TPC;
5562 goto error;
5563 }
5564
James Smart86478872015-05-21 13:55:21 -04005565 cmd = &cmdiocb->iocb;
5566 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5567 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5568 rdp_context->rx_id = cmd->ulpContext;
5569 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5570 if (lpfc_get_rdp_info(phba, rdp_context)) {
5571 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5572 "2423 Unable to send mailbox");
5573 kfree(rdp_context);
5574 rjt_err = LSRJT_UNABLE_TPC;
5575 lpfc_nlp_put(ndlp);
5576 goto error;
5577 }
5578
5579 return 0;
5580
5581rjt_logerr:
5582 rjt_err = LSRJT_LOGICAL_ERR;
5583
5584error:
5585 memset(&stat, 0, sizeof(stat));
5586 stat.un.b.lsRjtRsnCode = rjt_err;
5587 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5589 return 1;
5590}
5591
5592
James Smart8b017a32015-05-21 13:55:18 -04005593static void
5594lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5595{
5596 MAILBOX_t *mb;
5597 IOCB_t *icmd;
5598 uint8_t *pcmd;
5599 struct lpfc_iocbq *elsiocb;
5600 struct lpfc_nodelist *ndlp;
5601 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005602 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005603 struct lpfc_lcb_context *lcb_context;
5604 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005605 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005606 int rc;
5607
5608 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005609 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5610 ndlp = lcb_context->ndlp;
5611 pmb->context1 = NULL;
5612 pmb->context2 = NULL;
5613
James Smart481ad962015-05-22 10:42:35 -04005614 shdr = (union lpfc_sli4_cfg_shdr *)
5615 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5616 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5617 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5618
5619 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5620 "0194 SET_BEACON_CONFIG mailbox "
5621 "completed with status x%x add_status x%x,"
5622 " mbx status x%x\n",
5623 shdr_status, shdr_add_status, mb->mbxStatus);
5624
5625 if (mb->mbxStatus && !(shdr_status &&
5626 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005627 mempool_free(pmb, phba->mbox_mem_pool);
5628 goto error;
5629 }
5630
5631 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005632 cmdsize = sizeof(struct fc_lcb_res_frame);
5633 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5634 lpfc_max_els_tries, ndlp,
5635 ndlp->nlp_DID, ELS_CMD_ACC);
5636
5637 /* Decrement the ndlp reference count from previous mbox command */
5638 lpfc_nlp_put(ndlp);
5639
5640 if (!elsiocb)
5641 goto free_lcb_context;
5642
5643 lcb_res = (struct fc_lcb_res_frame *)
5644 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5645
5646 icmd = &elsiocb->iocb;
5647 icmd->ulpContext = lcb_context->rx_id;
5648 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5649
5650 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5651 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5652 lcb_res->lcb_sub_command = lcb_context->sub_command;
5653 lcb_res->lcb_type = lcb_context->type;
5654 lcb_res->lcb_frequency = lcb_context->frequency;
5655 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5656 phba->fc_stat.elsXmitACC++;
5657 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5658 if (rc == IOCB_ERROR)
5659 lpfc_els_free_iocb(phba, elsiocb);
5660
5661 kfree(lcb_context);
5662 return;
5663
5664error:
5665 cmdsize = sizeof(struct fc_lcb_res_frame);
5666 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5667 lpfc_max_els_tries, ndlp,
5668 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5669 lpfc_nlp_put(ndlp);
5670 if (!elsiocb)
5671 goto free_lcb_context;
5672
5673 icmd = &elsiocb->iocb;
5674 icmd->ulpContext = lcb_context->rx_id;
5675 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5676 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5677
5678 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5679 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5680 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5681
5682 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5683 phba->fc_stat.elsXmitLSRJT++;
5684 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5685 if (rc == IOCB_ERROR)
5686 lpfc_els_free_iocb(phba, elsiocb);
5687free_lcb_context:
5688 kfree(lcb_context);
5689}
5690
5691static int
5692lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5693 struct lpfc_lcb_context *lcb_context,
5694 uint32_t beacon_state)
5695{
5696 struct lpfc_hba *phba = vport->phba;
5697 LPFC_MBOXQ_t *mbox = NULL;
5698 uint32_t len;
5699 int rc;
5700
5701 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5702 if (!mbox)
5703 return 1;
5704
5705 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5706 sizeof(struct lpfc_sli4_cfg_mhdr);
5707 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5708 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5709 LPFC_SLI4_MBX_EMBED);
5710 mbox->context1 = (void *)lcb_context;
5711 mbox->vport = phba->pport;
5712 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5713 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5714 phba->sli4_hba.physical_port);
5715 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5716 beacon_state);
5717 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5718 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5719 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5720 if (rc == MBX_NOT_FINISHED) {
5721 mempool_free(mbox, phba->mbox_mem_pool);
5722 return 1;
5723 }
5724
5725 return 0;
5726}
5727
5728
5729/**
5730 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5731 * @vport: pointer to a host virtual N_Port data structure.
5732 * @cmdiocb: pointer to lpfc command iocb data structure.
5733 * @ndlp: pointer to a node-list data structure.
5734 *
5735 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5736 * First, the payload of the unsolicited LCB is checked.
5737 * Then based on Subcommand beacon will either turn on or off.
5738 *
5739 * Return code
5740 * 0 - Sent the acc response
5741 * 1 - Sent the reject response.
5742 **/
5743static int
5744lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5745 struct lpfc_nodelist *ndlp)
5746{
5747 struct lpfc_hba *phba = vport->phba;
5748 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04005749 uint8_t *lp;
5750 struct fc_lcb_request_frame *beacon;
5751 struct lpfc_lcb_context *lcb_context;
5752 uint8_t state, rjt_err;
5753 struct ls_rjt stat;
5754
James Smart8b017a32015-05-21 13:55:18 -04005755 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5756 lp = (uint8_t *)pcmd->virt;
5757 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5758
5759 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5760 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5761 "type x%x frequency %x duration x%x\n",
5762 lp[0], lp[1], lp[2],
5763 beacon->lcb_command,
5764 beacon->lcb_sub_command,
5765 beacon->lcb_type,
5766 beacon->lcb_frequency,
5767 be16_to_cpu(beacon->lcb_duration));
5768
5769 if (phba->sli_rev < LPFC_SLI_REV4 ||
5770 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5771 LPFC_SLI_INTF_IF_TYPE_2)) {
5772 rjt_err = LSRJT_CMD_UNSUPPORTED;
5773 goto rjt;
5774 }
James Smart8b017a32015-05-21 13:55:18 -04005775
5776 if (phba->hba_flag & HBA_FCOE_MODE) {
5777 rjt_err = LSRJT_CMD_UNSUPPORTED;
5778 goto rjt;
5779 }
James Smartd6564e52017-06-15 22:56:50 -07005780 if (beacon->lcb_sub_command != LPFC_LCB_ON &&
5781 beacon->lcb_sub_command != LPFC_LCB_OFF) {
James Smart8b017a32015-05-21 13:55:18 -04005782 rjt_err = LSRJT_CMD_UNSUPPORTED;
5783 goto rjt;
5784 }
James Smartd6564e52017-06-15 22:56:50 -07005785 if (beacon->lcb_sub_command == LPFC_LCB_ON &&
5786 be16_to_cpu(beacon->lcb_duration) != 0) {
James Smart8b017a32015-05-21 13:55:18 -04005787 rjt_err = LSRJT_CMD_UNSUPPORTED;
5788 goto rjt;
5789 }
5790
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305791 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5792 if (!lcb_context) {
5793 rjt_err = LSRJT_UNABLE_TPC;
5794 goto rjt;
5795 }
5796
James Smart8b017a32015-05-21 13:55:18 -04005797 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5798 lcb_context->sub_command = beacon->lcb_sub_command;
5799 lcb_context->type = beacon->lcb_type;
5800 lcb_context->frequency = beacon->lcb_frequency;
5801 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5802 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5803 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5804 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5805 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5806 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305807 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04005808 lpfc_nlp_put(ndlp);
5809 rjt_err = LSRJT_UNABLE_TPC;
5810 goto rjt;
5811 }
5812 return 0;
5813rjt:
5814 memset(&stat, 0, sizeof(stat));
5815 stat.un.b.lsRjtRsnCode = rjt_err;
5816 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5817 return 1;
5818}
5819
5820
James Smarte59058c2008-08-24 21:49:00 -04005821/**
James Smart3621a712009-04-06 18:47:14 -04005822 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005823 * @vport: pointer to a host virtual N_Port data structure.
5824 *
5825 * This routine cleans up any Registration State Change Notification
5826 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5827 * @vport together with the host_lock is used to prevent multiple thread
5828 * trying to access the RSCN array on a same @vport at the same time.
5829 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005830void
James Smart2e0fef82007-06-17 19:56:36 -05005831lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005832{
James Smart2e0fef82007-06-17 19:56:36 -05005833 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5834 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005835 int i;
5836
James Smart7f5f3d02008-02-08 18:50:14 -05005837 spin_lock_irq(shost->host_lock);
5838 if (vport->fc_rscn_flush) {
5839 /* Another thread is walking fc_rscn_id_list on this vport */
5840 spin_unlock_irq(shost->host_lock);
5841 return;
5842 }
5843 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5844 vport->fc_rscn_flush = 1;
5845 spin_unlock_irq(shost->host_lock);
5846
James Smart2e0fef82007-06-17 19:56:36 -05005847 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005848 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005849 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005850 }
James Smart2e0fef82007-06-17 19:56:36 -05005851 spin_lock_irq(shost->host_lock);
5852 vport->fc_rscn_id_cnt = 0;
5853 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5854 spin_unlock_irq(shost->host_lock);
5855 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005856 /* Indicate we are done walking this fc_rscn_id_list */
5857 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005858}
5859
James Smarte59058c2008-08-24 21:49:00 -04005860/**
James Smart3621a712009-04-06 18:47:14 -04005861 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005862 * @vport: pointer to a host virtual N_Port data structure.
5863 * @did: remote destination port identifier.
5864 *
5865 * This routine checks whether there is any pending Registration State
5866 * Configuration Notification (RSCN) to a @did on @vport.
5867 *
5868 * Return code
5869 * None zero - The @did matched with a pending rscn
5870 * 0 - not able to match @did with a pending rscn
5871 **/
dea31012005-04-17 16:05:31 -05005872int
James Smart2e0fef82007-06-17 19:56:36 -05005873lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005874{
5875 D_ID ns_did;
5876 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005877 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005878 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005879 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005880
5881 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005882
5883 /* Never match fabric nodes for RSCNs */
5884 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005885 return 0;
dea31012005-04-17 16:05:31 -05005886
5887 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005888 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005889 return did;
dea31012005-04-17 16:05:31 -05005890
James Smart7f5f3d02008-02-08 18:50:14 -05005891 spin_lock_irq(shost->host_lock);
5892 if (vport->fc_rscn_flush) {
5893 /* Another thread is walking fc_rscn_id_list on this vport */
5894 spin_unlock_irq(shost->host_lock);
5895 return 0;
5896 }
5897 /* Indicate we are walking fc_rscn_id_list on this vport */
5898 vport->fc_rscn_flush = 1;
5899 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005900 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005901 lp = vport->fc_rscn_id_list[i]->virt;
5902 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5903 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005904 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005905 rscn_did.un.word = be32_to_cpu(*lp++);
5906 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005907 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5908 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005909 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5910 && (ns_did.un.b.area == rscn_did.un.b.area)
5911 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005912 goto return_did_out;
dea31012005-04-17 16:05:31 -05005913 break;
James Smarteaf15d52008-12-04 22:39:29 -05005914 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005915 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5916 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005917 goto return_did_out;
dea31012005-04-17 16:05:31 -05005918 break;
James Smarteaf15d52008-12-04 22:39:29 -05005919 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005920 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005921 goto return_did_out;
dea31012005-04-17 16:05:31 -05005922 break;
James Smarteaf15d52008-12-04 22:39:29 -05005923 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005924 goto return_did_out;
dea31012005-04-17 16:05:31 -05005925 }
5926 }
James Smart92d7f7b2007-06-17 19:56:38 -05005927 }
James Smart7f5f3d02008-02-08 18:50:14 -05005928 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5929 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005930 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005931return_did_out:
5932 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5933 vport->fc_rscn_flush = 0;
5934 return did;
dea31012005-04-17 16:05:31 -05005935}
5936
James Smarte59058c2008-08-24 21:49:00 -04005937/**
James Smart3621a712009-04-06 18:47:14 -04005938 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005939 * @vport: pointer to a host virtual N_Port data structure.
5940 *
5941 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5942 * state machine for a @vport's nodes that are with pending RSCN (Registration
5943 * State Change Notification).
5944 *
5945 * Return code
5946 * 0 - Successful (currently alway return 0)
5947 **/
dea31012005-04-17 16:05:31 -05005948static int
James Smart2e0fef82007-06-17 19:56:36 -05005949lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005950{
James Smart685f0bf2007-04-25 09:53:08 -04005951 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005952
James Smart0d2b6b82008-06-14 22:52:47 -04005953 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005954 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005955 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005956 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5957 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005958 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07005959
5960 /* NVME Target mode does not do RSCN Recovery. */
James Smart8c258642017-02-12 13:52:36 -08005961 if (vport->phba->nvmet_support)
5962 continue;
James Smart1c5b12f2017-04-21 16:05:03 -07005963
James Smart2e0fef82007-06-17 19:56:36 -05005964 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005965 NLP_EVT_DEVICE_RECOVERY);
5966 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005967 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005968 return 0;
dea31012005-04-17 16:05:31 -05005969}
5970
James Smarte59058c2008-08-24 21:49:00 -04005971/**
James Smart3621a712009-04-06 18:47:14 -04005972 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005973 * @vport: pointer to a host virtual N_Port data structure.
5974 * @cmdiocb: pointer to lpfc command iocb data structure.
5975 *
5976 * lpfc_send_rscn_event sends an RSCN netlink event to management
5977 * applications.
5978 */
5979static void
5980lpfc_send_rscn_event(struct lpfc_vport *vport,
5981 struct lpfc_iocbq *cmdiocb)
5982{
5983 struct lpfc_dmabuf *pcmd;
5984 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5985 uint32_t *payload_ptr;
5986 uint32_t payload_len;
5987 struct lpfc_rscn_event_header *rscn_event_data;
5988
5989 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5990 payload_ptr = (uint32_t *) pcmd->virt;
5991 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5992
5993 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5994 payload_len, GFP_KERNEL);
5995 if (!rscn_event_data) {
5996 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5997 "0147 Failed to allocate memory for RSCN event\n");
5998 return;
5999 }
6000 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6001 rscn_event_data->payload_length = payload_len;
6002 memcpy(rscn_event_data->rscn_payload, payload_ptr,
6003 payload_len);
6004
6005 fc_host_post_vendor_event(shost,
6006 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04006007 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05006008 (char *)rscn_event_data,
6009 LPFC_NL_VENDOR_ID);
6010
6011 kfree(rscn_event_data);
6012}
6013
6014/**
James Smart3621a712009-04-06 18:47:14 -04006015 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04006016 * @vport: pointer to a host virtual N_Port data structure.
6017 * @cmdiocb: pointer to lpfc command iocb data structure.
6018 * @ndlp: pointer to a node-list data structure.
6019 *
6020 * This routine processes an unsolicited RSCN (Registration State Change
6021 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6022 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6023 * discover state machine is about to begin discovery, it just accepts the
6024 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6025 * contains N_Port IDs for other vports on this HBA, it just accepts the
6026 * RSCN and ignore processing it. If the state machine is in the recovery
6027 * state, the fc_rscn_id_list of this @vport is walked and the
6028 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6029 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6030 * routine is invoked to handle the RSCN event.
6031 *
6032 * Return code
6033 * 0 - Just sent the acc response
6034 * 1 - Sent the acc response and waited for name server completion
6035 **/
dea31012005-04-17 16:05:31 -05006036static int
James Smart2e0fef82007-06-17 19:56:36 -05006037lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006038 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006039{
James Smart2e0fef82007-06-17 19:56:36 -05006040 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6041 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006042 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05006043 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05006044 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006045 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05006046 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04006047 int i;
dea31012005-04-17 16:05:31 -05006048
dea31012005-04-17 16:05:31 -05006049 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6050 lp = (uint32_t *) pcmd->virt;
6051
James Smart92d7f7b2007-06-17 19:56:38 -05006052 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6053 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05006054 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04006055 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6056 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05006057 vport->fc_flag, payload_len, *lp,
6058 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05006059
6060 /* Send an RSCN event to the management application */
6061 lpfc_send_rscn_event(vport, cmdiocb);
6062
James Smartd2873e42006-08-18 17:46:43 -04006063 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05006064 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04006065 FCH_EVT_RSCN, lp[i]);
6066
dea31012005-04-17 16:05:31 -05006067 /* If we are about to begin discovery, just ACC the RSCN.
6068 * Discovery processing will satisfy it.
6069 */
James Smart2e0fef82007-06-17 19:56:36 -05006070 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05006071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6072 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6073 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6074
James Smart51ef4c22007-08-02 11:10:31 -04006075 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006076 return 0;
dea31012005-04-17 16:05:31 -05006077 }
6078
James Smart92d7f7b2007-06-17 19:56:38 -05006079 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6080 * just ACC and ignore it.
6081 */
6082 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04006083 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05006084 i = payload_len;
6085 datap = lp;
6086 while (i > 0) {
6087 nportid = *datap++;
6088 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6089 i -= sizeof(uint32_t);
6090 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04006091 if (lpfc_find_vport_by_did(phba, nportid))
6092 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05006093 }
6094 if (rscn_id == hba_id) {
6095 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04006096 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04006097 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04006098 "Data: x%x x%x x%x x%x\n",
6099 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05006100 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05006101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6102 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6103 ndlp->nlp_DID, vport->port_state,
6104 ndlp->nlp_flag);
6105
James Smart92d7f7b2007-06-17 19:56:38 -05006106 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006107 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05006108 return 0;
6109 }
6110 }
6111
James Smart7f5f3d02008-02-08 18:50:14 -05006112 spin_lock_irq(shost->host_lock);
6113 if (vport->fc_rscn_flush) {
6114 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05006115 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05006116 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04006117 /* Send back ACC */
6118 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05006119 return 0;
6120 }
6121 /* Indicate we are walking fc_rscn_id_list on this vport */
6122 vport->fc_rscn_flush = 1;
6123 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02006124 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05006125 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05006126 /* If we are already processing an RSCN, save the received
6127 * RSCN payload buffer, cmdiocb->context2 to process later.
6128 */
James Smart2e0fef82007-06-17 19:56:36 -05006129 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05006130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6131 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6132 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6133
James Smart09372822008-01-11 01:52:54 -05006134 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006135 vport->fc_flag |= FC_RSCN_DEFERRED;
6136 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05006137 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05006138 vport->fc_flag |= FC_RSCN_MODE;
6139 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006140 if (rscn_cnt) {
6141 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6142 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6143 }
6144 if ((rscn_cnt) &&
6145 (payload_len + length <= LPFC_BPL_SIZE)) {
6146 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05006147 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05006148 memcpy(((uint8_t *)cmd) + length, lp,
6149 payload_len);
6150 } else {
6151 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6152 vport->fc_rscn_id_cnt++;
6153 /* If we zero, cmdiocb->context2, the calling
6154 * routine will not try to free it.
6155 */
6156 cmdiocb->context2 = NULL;
6157 }
dea31012005-04-17 16:05:31 -05006158 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006159 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6160 "0235 Deferred RSCN "
6161 "Data: x%x x%x x%x\n",
6162 vport->fc_rscn_id_cnt, vport->fc_flag,
6163 vport->port_state);
dea31012005-04-17 16:05:31 -05006164 } else {
James Smart2e0fef82007-06-17 19:56:36 -05006165 vport->fc_flag |= FC_RSCN_DISCOVERY;
6166 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05006167 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04006168 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6169 "0234 ReDiscovery RSCN "
6170 "Data: x%x x%x x%x\n",
6171 vport->fc_rscn_id_cnt, vport->fc_flag,
6172 vport->port_state);
dea31012005-04-17 16:05:31 -05006173 }
James Smart7f5f3d02008-02-08 18:50:14 -05006174 /* Indicate we are done walking fc_rscn_id_list on this vport */
6175 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006176 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006177 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006178 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006179 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05006180 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006181 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05006182 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006183 return 0;
dea31012005-04-17 16:05:31 -05006184 }
James Smart858c9f62007-06-17 19:56:39 -05006185 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6186 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6187 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6188
James Smart2e0fef82007-06-17 19:56:36 -05006189 spin_lock_irq(shost->host_lock);
6190 vport->fc_flag |= FC_RSCN_MODE;
6191 spin_unlock_irq(shost->host_lock);
6192 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05006193 /* Indicate we are done walking fc_rscn_id_list on this vport */
6194 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05006195 /*
6196 * If we zero, cmdiocb->context2, the calling routine will
6197 * not try to free it.
6198 */
6199 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05006200 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006201 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04006202 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006203 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05006204 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05006205 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05006206}
6207
James Smarte59058c2008-08-24 21:49:00 -04006208/**
James Smart3621a712009-04-06 18:47:14 -04006209 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04006210 * @vport: pointer to a host virtual N_Port data structure.
6211 *
6212 * This routine handles the Registration State Configuration Notification
6213 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6214 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6215 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6216 * NameServer shall be issued. If CT command to the NameServer fails to be
6217 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6218 * RSCN activities with the @vport.
6219 *
6220 * Return code
6221 * 0 - Cleaned up rscn on the @vport
6222 * 1 - Wait for plogi to name server before proceed
6223 **/
dea31012005-04-17 16:05:31 -05006224int
James Smart2e0fef82007-06-17 19:56:36 -05006225lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006226{
6227 struct lpfc_nodelist *ndlp;
6228
James Smart92d7f7b2007-06-17 19:56:38 -05006229 /* Ignore RSCN if the port is being torn down. */
6230 if (vport->load_flag & FC_UNLOADING) {
6231 lpfc_els_flush_rscn(vport);
6232 return 0;
6233 }
6234
dea31012005-04-17 16:05:31 -05006235 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05006236 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006237
6238 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04006239 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6240 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6241 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6242 vport->port_state);
dea31012005-04-17 16:05:31 -05006243
6244 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05006245 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05006246 vport->num_disc_nodes = 0;
6247
James Smart2e0fef82007-06-17 19:56:36 -05006248 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006249 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6250 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart1c5b12f2017-04-21 16:05:03 -07006251 /* Good ndlp, issue CT Request to NameServer. Need to
6252 * know how many gidfts were issued. If none, then just
6253 * flush the RSCN. Otherwise, the outstanding requests
6254 * need to complete.
6255 */
James Smarta0f2d3e2017-02-12 13:52:31 -08006256 vport->gidft_inp = 0;
James Smart1c5b12f2017-04-21 16:05:03 -07006257 if (lpfc_issue_gidft(vport) > 0)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006258 return 1;
dea31012005-04-17 16:05:31 -05006259 } else {
James Smart1c5b12f2017-04-21 16:05:03 -07006260 /* Nameserver login in question. Revalidate. */
James Smarte47c9092008-02-08 18:49:26 -05006261 if (ndlp) {
6262 ndlp = lpfc_enable_node(vport, ndlp,
6263 NLP_STE_PLOGI_ISSUE);
6264 if (!ndlp) {
6265 lpfc_els_flush_rscn(vport);
6266 return 0;
6267 }
6268 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05006269 } else {
James Smart9d3d3402017-04-21 16:05:00 -07006270 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006271 if (!ndlp) {
6272 lpfc_els_flush_rscn(vport);
6273 return 0;
6274 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006275 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05006277 }
James Smarte47c9092008-02-08 18:49:26 -05006278 ndlp->nlp_type |= NLP_FABRIC;
6279 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6280 /* Wait for NameServer login cmpl before we can
6281 * continue
6282 */
6283 return 1;
dea31012005-04-17 16:05:31 -05006284 }
6285
James Smart2e0fef82007-06-17 19:56:36 -05006286 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006287 return 0;
dea31012005-04-17 16:05:31 -05006288}
6289
James Smarte59058c2008-08-24 21:49:00 -04006290/**
James Smart3621a712009-04-06 18:47:14 -04006291 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04006292 * @vport: pointer to a host virtual N_Port data structure.
6293 * @cmdiocb: pointer to lpfc command iocb data structure.
6294 * @ndlp: pointer to a node-list data structure.
6295 *
6296 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6297 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6298 * point topology. As an unsolicited FLOGI should not be received in a loop
6299 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6300 * lpfc_check_sparm() routine is invoked to check the parameters in the
6301 * unsolicited FLOGI. If parameters validation failed, the routine
6302 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6303 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6304 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6305 * will initiate PLOGI. The higher lexicographical value party shall has
6306 * higher priority (as the winning port) and will initiate PLOGI and
6307 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6308 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6309 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6310 *
6311 * Return code
6312 * 0 - Successfully processed the unsolicited flogi
6313 * 1 - Failed to process the unsolicited flogi
6314 **/
dea31012005-04-17 16:05:31 -05006315static int
James Smart2e0fef82007-06-17 19:56:36 -05006316lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006317 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006318{
James Smart2e0fef82007-06-17 19:56:36 -05006319 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6320 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006321 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6322 uint32_t *lp = (uint32_t *) pcmd->virt;
6323 IOCB_t *icmd = &cmdiocb->iocb;
6324 struct serv_parm *sp;
6325 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05006326 uint32_t cmd, did;
6327 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04006328 uint32_t fc_flag = 0;
6329 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05006330
6331 cmd = *lp++;
6332 sp = (struct serv_parm *) lp;
6333
6334 /* FLOGI received */
6335
James Smart2e0fef82007-06-17 19:56:36 -05006336 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006337
James Smart76a95d72010-11-20 23:11:48 -05006338 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006339 /* We should never receive a FLOGI in loop mode, ignore it */
6340 did = icmd->un.elsreq64.remoteID;
6341
6342 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6343 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04006344 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6345 "0113 An FLOGI ELS command x%x was "
6346 "received from DID x%x in Loop Mode\n",
6347 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006348 return 1;
dea31012005-04-17 16:05:31 -05006349 }
6350
James Smartd6de08c2015-12-16 18:11:53 -05006351 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05006352
James Smartd6de08c2015-12-16 18:11:53 -05006353 /*
6354 * If our portname is greater than the remote portname,
6355 * then we initiate Nport login.
6356 */
6357
6358 rc = memcmp(&vport->fc_portname, &sp->portName,
6359 sizeof(struct lpfc_name));
6360
6361 if (!rc) {
6362 if (phba->sli_rev < LPFC_SLI_REV4) {
6363 mbox = mempool_alloc(phba->mbox_mem_pool,
6364 GFP_KERNEL);
6365 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006366 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05006367 lpfc_linkdown(phba);
6368 lpfc_init_link(phba, mbox,
6369 phba->cfg_topology,
6370 phba->cfg_link_speed);
6371 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6372 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6373 mbox->vport = vport;
6374 rc = lpfc_sli_issue_mbox(phba, mbox,
6375 MBX_NOWAIT);
6376 lpfc_set_loopback_flag(phba);
6377 if (rc == MBX_NOT_FINISHED)
6378 mempool_free(mbox, phba->mbox_mem_pool);
6379 return 1;
6380 }
James Smart939723a2012-05-09 21:19:03 -04006381
James Smartd6de08c2015-12-16 18:11:53 -05006382 /* abort the flogi coming back to ourselves
6383 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04006384 */
James Smartd6de08c2015-12-16 18:11:53 -05006385 lpfc_els_abort_flogi(phba);
6386 return 0;
6387
6388 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05006389 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05006390 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05006391 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04006392
James Smartd6de08c2015-12-16 18:11:53 -05006393 /* If we have the high WWPN we can assign our own
6394 * myDID; otherwise, we have to WAIT for a PLOGI
6395 * from the remote NPort to find out what it
6396 * will be.
James Smart939723a2012-05-09 21:19:03 -04006397 */
James Smartd6de08c2015-12-16 18:11:53 -05006398 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05006399 } else {
James Smartd6de08c2015-12-16 18:11:53 -05006400 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05006401 }
6402
James Smartd6de08c2015-12-16 18:11:53 -05006403 /*
6404 * The vport state should go to LPFC_FLOGI only
6405 * AFTER we issue a FLOGI, not receive one.
6406 */
6407 spin_lock_irq(shost->host_lock);
6408 fc_flag = vport->fc_flag;
6409 port_state = vport->port_state;
6410 vport->fc_flag |= FC_PT2PT;
6411 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6412 spin_unlock_irq(shost->host_lock);
6413 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6414 "3311 Rcv Flogi PS x%x new PS x%x "
6415 "fc_flag x%x new fc_flag x%x\n",
6416 port_state, vport->port_state,
6417 fc_flag, vport->fc_flag);
6418
6419 /*
6420 * We temporarily set fc_myDID to make it look like we are
6421 * a Fabric. This is done just so we end up with the right
6422 * did / sid on the FLOGI ACC rsp.
6423 */
6424 did = vport->fc_myDID;
6425 vport->fc_myDID = Fabric_DID;
6426
6427 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04006428
dea31012005-04-17 16:05:31 -05006429 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05006430 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006431
James Smart939723a2012-05-09 21:19:03 -04006432 /* Now lets put fc_myDID back to what its supposed to be */
6433 vport->fc_myDID = did;
6434
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006435 return 0;
dea31012005-04-17 16:05:31 -05006436}
6437
James Smarte59058c2008-08-24 21:49:00 -04006438/**
James Smart3621a712009-04-06 18:47:14 -04006439 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04006440 * @vport: pointer to a host virtual N_Port data structure.
6441 * @cmdiocb: pointer to lpfc command iocb data structure.
6442 * @ndlp: pointer to a node-list data structure.
6443 *
6444 * This routine processes Request Node Identification Data (RNID) IOCB
6445 * received as an ELS unsolicited event. Only when the RNID specified format
6446 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6447 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6448 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6449 * rejected by invoking the lpfc_els_rsp_reject() routine.
6450 *
6451 * Return code
6452 * 0 - Successfully processed rnid iocb (currently always return 0)
6453 **/
dea31012005-04-17 16:05:31 -05006454static int
James Smart2e0fef82007-06-17 19:56:36 -05006455lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6456 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006457{
6458 struct lpfc_dmabuf *pcmd;
6459 uint32_t *lp;
dea31012005-04-17 16:05:31 -05006460 RNID *rn;
6461 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04006462 uint32_t cmd;
dea31012005-04-17 16:05:31 -05006463
dea31012005-04-17 16:05:31 -05006464 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6465 lp = (uint32_t *) pcmd->virt;
6466
6467 cmd = *lp++;
6468 rn = (RNID *) lp;
6469
6470 /* RNID received */
6471
6472 switch (rn->Format) {
6473 case 0:
6474 case RNID_TOPOLOGY_DISC:
6475 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05006476 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006477 break;
6478 default:
6479 /* Reject this request because format not supported */
6480 stat.un.b.lsRjtRsvd0 = 0;
6481 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6482 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6483 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006484 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6485 NULL);
dea31012005-04-17 16:05:31 -05006486 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006487 return 0;
dea31012005-04-17 16:05:31 -05006488}
6489
James Smarte59058c2008-08-24 21:49:00 -04006490/**
James Smart12265f62010-10-22 11:05:53 -04006491 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6492 * @vport: pointer to a host virtual N_Port data structure.
6493 * @cmdiocb: pointer to lpfc command iocb data structure.
6494 * @ndlp: pointer to a node-list data structure.
6495 *
6496 * Return code
6497 * 0 - Successfully processed echo iocb (currently always return 0)
6498 **/
6499static int
6500lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6501 struct lpfc_nodelist *ndlp)
6502{
6503 uint8_t *pcmd;
6504
6505 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6506
6507 /* skip over first word of echo command to find echo data */
6508 pcmd += sizeof(uint32_t);
6509
6510 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6511 return 0;
6512}
6513
6514/**
James Smart3621a712009-04-06 18:47:14 -04006515 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04006516 * @vport: pointer to a host virtual N_Port data structure.
6517 * @cmdiocb: pointer to lpfc command iocb data structure.
6518 * @ndlp: pointer to a node-list data structure.
6519 *
6520 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6521 * received as an ELS unsolicited event. Currently, this function just invokes
6522 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6523 *
6524 * Return code
6525 * 0 - Successfully processed lirr iocb (currently always return 0)
6526 **/
dea31012005-04-17 16:05:31 -05006527static int
James Smart2e0fef82007-06-17 19:56:36 -05006528lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6529 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006530{
6531 struct ls_rjt stat;
6532
6533 /* For now, unconditionally reject this command */
6534 stat.un.b.lsRjtRsvd0 = 0;
6535 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6536 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6537 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006538 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006539 return 0;
6540}
6541
James Smarte59058c2008-08-24 21:49:00 -04006542/**
James Smart5ffc2662009-11-18 15:39:44 -05006543 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6544 * @vport: pointer to a host virtual N_Port data structure.
6545 * @cmdiocb: pointer to lpfc command iocb data structure.
6546 * @ndlp: pointer to a node-list data structure.
6547 *
6548 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6549 * received as an ELS unsolicited event. A request to RRQ shall only
6550 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6551 * Nx_Port N_Port_ID of the target Exchange is the same as the
6552 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6553 * not accepted, an LS_RJT with reason code "Unable to perform
6554 * command request" and reason code explanation "Invalid Originator
6555 * S_ID" shall be returned. For now, we just unconditionally accept
6556 * RRQ from the target.
6557 **/
6558static void
6559lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6560 struct lpfc_nodelist *ndlp)
6561{
6562 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05006563 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6564 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05006565}
6566
6567/**
James Smart12265f62010-10-22 11:05:53 -04006568 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6569 * @phba: pointer to lpfc hba data structure.
6570 * @pmb: pointer to the driver internal queue element for mailbox command.
6571 *
6572 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6573 * mailbox command. This callback function is to actually send the Accept
6574 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6575 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6576 * mailbox command, constructs the RPS response with the link statistics
6577 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6578 * response to the RPS.
6579 *
6580 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6581 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6582 * will be stored into the context1 field of the IOCB for the completion
6583 * callback function to the RPS Accept Response ELS IOCB command.
6584 *
6585 **/
6586static void
6587lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6588{
6589 MAILBOX_t *mb;
6590 IOCB_t *icmd;
6591 struct RLS_RSP *rls_rsp;
6592 uint8_t *pcmd;
6593 struct lpfc_iocbq *elsiocb;
6594 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006595 uint16_t oxid;
6596 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006597 uint32_t cmdsize;
6598
6599 mb = &pmb->u.mb;
6600
6601 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006602 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6603 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006604 pmb->context1 = NULL;
6605 pmb->context2 = NULL;
6606
6607 if (mb->mbxStatus) {
6608 mempool_free(pmb, phba->mbox_mem_pool);
6609 return;
6610 }
6611
6612 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006613 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6614 lpfc_max_els_tries, ndlp,
6615 ndlp->nlp_DID, ELS_CMD_ACC);
6616
6617 /* Decrement the ndlp reference count from previous mbox command */
6618 lpfc_nlp_put(ndlp);
6619
James Smart37db57e2012-05-09 21:17:16 -04006620 if (!elsiocb) {
6621 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006622 return;
James Smart37db57e2012-05-09 21:17:16 -04006623 }
James Smart12265f62010-10-22 11:05:53 -04006624
6625 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006626 icmd->ulpContext = rxid;
6627 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006628
6629 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6630 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6631 pcmd += sizeof(uint32_t); /* Skip past command */
6632 rls_rsp = (struct RLS_RSP *)pcmd;
6633
6634 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6635 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6636 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6637 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6638 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6639 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006640 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006641 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6642 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6643 "2874 Xmit ELS RLS 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);
6648 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6649 phba->fc_stat.elsXmitACC++;
6650 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6651 lpfc_els_free_iocb(phba, elsiocb);
6652}
6653
6654/**
James Smart3621a712009-04-06 18:47:14 -04006655 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006656 * @phba: pointer to lpfc hba data structure.
6657 * @pmb: pointer to the driver internal queue element for mailbox command.
6658 *
6659 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6660 * mailbox command. This callback function is to actually send the Accept
6661 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6662 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6663 * mailbox command, constructs the RPS response with the link statistics
6664 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6665 * response to the RPS.
6666 *
6667 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6668 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6669 * will be stored into the context1 field of the IOCB for the completion
6670 * callback function to the RPS Accept Response ELS IOCB command.
6671 *
6672 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006673static void
James Smart329f9bc2007-04-25 09:53:01 -04006674lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006675{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006676 MAILBOX_t *mb;
6677 IOCB_t *icmd;
6678 RPS_RSP *rps_rsp;
6679 uint8_t *pcmd;
6680 struct lpfc_iocbq *elsiocb;
6681 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006682 uint16_t status;
6683 uint16_t oxid;
6684 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006685 uint32_t cmdsize;
6686
James Smart04c68492009-05-22 14:52:52 -04006687 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006688
6689 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006690 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6691 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006692 pmb->context1 = NULL;
6693 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006694
6695 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006696 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006697 return;
6698 }
6699
6700 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006701 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006702 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6703 lpfc_max_els_tries, ndlp,
6704 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006705
6706 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006707 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006708
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006709 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006710 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006711
6712 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006713 icmd->ulpContext = rxid;
6714 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006715
6716 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6717 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006718 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006719 rps_rsp = (RPS_RSP *)pcmd;
6720
James Smart76a95d72010-11-20 23:11:48 -05006721 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006722 status = 0x10;
6723 else
6724 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006725 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006726 status |= 0x4;
6727
6728 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006729 rps_rsp->portStatus = cpu_to_be16(status);
6730 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6731 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6732 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6733 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6734 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6735 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006736 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006737 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6738 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6739 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6740 elsiocb->iotag, elsiocb->iocb.ulpContext,
6741 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6742 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006743 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006744 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006745 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006746 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006747 return;
6748}
6749
James Smarte59058c2008-08-24 21:49:00 -04006750/**
James Smart12265f62010-10-22 11:05:53 -04006751 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6752 * @vport: pointer to a host virtual N_Port data structure.
6753 * @cmdiocb: pointer to lpfc command iocb data structure.
6754 * @ndlp: pointer to a node-list data structure.
6755 *
6756 * This routine processes Read Port Status (RPL) IOCB received as an
6757 * ELS unsolicited event. It first checks the remote port state. If the
6758 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6759 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6760 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6761 * for reading the HBA link statistics. It is for the callback function,
6762 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6763 * to actually sending out RPL Accept (ACC) response.
6764 *
6765 * Return codes
6766 * 0 - Successfully processed rls iocb (currently always return 0)
6767 **/
6768static int
6769lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6770 struct lpfc_nodelist *ndlp)
6771{
6772 struct lpfc_hba *phba = vport->phba;
6773 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04006774 struct ls_rjt stat;
6775
6776 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6777 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6778 /* reject the unsolicited RPS request and done with it */
6779 goto reject_out;
6780
James Smart12265f62010-10-22 11:05:53 -04006781 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6782 if (mbox) {
6783 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006784 mbox->context1 = (void *)((unsigned long)
6785 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6786 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006787 mbox->context2 = lpfc_nlp_get(ndlp);
6788 mbox->vport = vport;
6789 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6790 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6791 != MBX_NOT_FINISHED)
6792 /* Mbox completion will send ELS Response */
6793 return 0;
6794 /* Decrement reference count used for the failed mbox
6795 * command.
6796 */
6797 lpfc_nlp_put(ndlp);
6798 mempool_free(mbox, phba->mbox_mem_pool);
6799 }
6800reject_out:
6801 /* issue rejection response */
6802 stat.un.b.lsRjtRsvd0 = 0;
6803 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6804 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6805 stat.un.b.vendorUnique = 0;
6806 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6807 return 0;
6808}
6809
6810/**
6811 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6812 * @vport: pointer to a host virtual N_Port data structure.
6813 * @cmdiocb: pointer to lpfc command iocb data structure.
6814 * @ndlp: pointer to a node-list data structure.
6815 *
6816 * This routine processes Read Timout Value (RTV) IOCB received as an
6817 * ELS unsolicited event. It first checks the remote port state. If the
6818 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6819 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6820 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6821 * Value (RTV) unsolicited IOCB event.
6822 *
6823 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6824 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6825 * will be stored into the context1 field of the IOCB for the completion
6826 * callback function to the RPS Accept Response ELS IOCB command.
6827 *
6828 * Return codes
6829 * 0 - Successfully processed rtv iocb (currently always return 0)
6830 **/
6831static int
6832lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6833 struct lpfc_nodelist *ndlp)
6834{
6835 struct lpfc_hba *phba = vport->phba;
6836 struct ls_rjt stat;
6837 struct RTV_RSP *rtv_rsp;
6838 uint8_t *pcmd;
6839 struct lpfc_iocbq *elsiocb;
6840 uint32_t cmdsize;
6841
6842
6843 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6844 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6845 /* reject the unsolicited RPS request and done with it */
6846 goto reject_out;
6847
6848 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6849 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6850 lpfc_max_els_tries, ndlp,
6851 ndlp->nlp_DID, ELS_CMD_ACC);
6852
6853 if (!elsiocb)
6854 return 1;
6855
6856 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6857 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6858 pcmd += sizeof(uint32_t); /* Skip past command */
6859
6860 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006861 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6862 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006863
6864 rtv_rsp = (struct RTV_RSP *)pcmd;
6865
6866 /* populate RTV payload */
6867 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6868 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6869 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6870 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6871 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6872
6873 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6874 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6875 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6876 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6877 "Data: x%x x%x x%x\n",
6878 elsiocb->iotag, elsiocb->iocb.ulpContext,
6879 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6880 ndlp->nlp_rpi,
6881 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6882 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6883 phba->fc_stat.elsXmitACC++;
6884 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6885 lpfc_els_free_iocb(phba, elsiocb);
6886 return 0;
6887
6888reject_out:
6889 /* issue rejection response */
6890 stat.un.b.lsRjtRsvd0 = 0;
6891 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6892 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6893 stat.un.b.vendorUnique = 0;
6894 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6895 return 0;
6896}
6897
6898/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006899 * @vport: pointer to a host virtual N_Port data structure.
6900 * @cmdiocb: pointer to lpfc command iocb data structure.
6901 * @ndlp: pointer to a node-list data structure.
6902 *
6903 * This routine processes Read Port Status (RPS) IOCB received as an
6904 * ELS unsolicited event. It first checks the remote port state. If the
6905 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6906 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6907 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6908 * for reading the HBA link statistics. It is for the callback function,
6909 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6910 * to actually sending out RPS Accept (ACC) response.
6911 *
6912 * Return codes
6913 * 0 - Successfully processed rps iocb (currently always return 0)
6914 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006915static int
James Smart2e0fef82007-06-17 19:56:36 -05006916lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6917 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006918{
James Smart2e0fef82007-06-17 19:56:36 -05006919 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006920 uint32_t *lp;
6921 uint8_t flag;
6922 LPFC_MBOXQ_t *mbox;
6923 struct lpfc_dmabuf *pcmd;
6924 RPS *rps;
6925 struct ls_rjt stat;
6926
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006927 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006928 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6929 /* reject the unsolicited RPS request and done with it */
6930 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006931
6932 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6933 lp = (uint32_t *) pcmd->virt;
6934 flag = (be32_to_cpu(*lp++) & 0xf);
6935 rps = (RPS *) lp;
6936
6937 if ((flag == 0) ||
6938 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006939 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006940 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006941
James Smart92d7f7b2007-06-17 19:56:38 -05006942 printk("Fix me....\n");
6943 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006944 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6945 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006946 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006947 mbox->context1 = (void *)((unsigned long)
6948 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6949 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006950 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006951 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006952 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006953 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006954 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006955 /* Mbox completion will send ELS Response */
6956 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006957 /* Decrement reference count used for the failed mbox
6958 * command.
6959 */
James Smart329f9bc2007-04-25 09:53:01 -04006960 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006961 mempool_free(mbox, phba->mbox_mem_pool);
6962 }
6963 }
James Smart90160e02008-08-24 21:49:45 -04006964
6965reject_out:
6966 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006967 stat.un.b.lsRjtRsvd0 = 0;
6968 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6969 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6970 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006971 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006972 return 0;
6973}
6974
James Smart19ca7602010-11-20 23:11:55 -05006975/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6976 * @vport: pointer to a host virtual N_Port data structure.
6977 * @ndlp: pointer to a node-list data structure.
6978 * @did: DID of the target.
6979 * @rrq: Pointer to the rrq struct.
6980 *
6981 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6982 * Successful the the completion handler will clear the RRQ.
6983 *
6984 * Return codes
6985 * 0 - Successfully sent rrq els iocb.
6986 * 1 - Failed to send rrq els iocb.
6987 **/
6988static int
6989lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6990 uint32_t did, struct lpfc_node_rrq *rrq)
6991{
6992 struct lpfc_hba *phba = vport->phba;
6993 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05006994 struct lpfc_iocbq *elsiocb;
6995 uint8_t *pcmd;
6996 uint16_t cmdsize;
6997 int ret;
6998
6999
7000 if (ndlp != rrq->ndlp)
7001 ndlp = rrq->ndlp;
7002 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7003 return 1;
7004
7005 /* If ndlp is not NULL, we will bump the reference count on it */
7006 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7007 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7008 ELS_CMD_RRQ);
7009 if (!elsiocb)
7010 return 1;
7011
James Smart19ca7602010-11-20 23:11:55 -05007012 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7013
7014 /* For RRQ request, remainder of payload is Exchange IDs */
7015 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7016 pcmd += sizeof(uint32_t);
7017 els_rrq = (struct RRQ *) pcmd;
7018
James Smartee0f4fe2012-05-09 21:19:14 -04007019 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05007020 bf_set(rrq_rxid, els_rrq, rrq->rxid);
7021 bf_set(rrq_did, els_rrq, vport->fc_myDID);
7022 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7023 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7024
7025
7026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7027 "Issue RRQ: did:x%x",
7028 did, rrq->xritag, rrq->rxid);
7029 elsiocb->context_un.rrq = rrq;
7030 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7031 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7032
7033 if (ret == IOCB_ERROR) {
7034 lpfc_els_free_iocb(phba, elsiocb);
7035 return 1;
7036 }
7037 return 0;
7038}
7039
7040/**
7041 * lpfc_send_rrq - Sends ELS RRQ if needed.
7042 * @phba: pointer to lpfc hba data structure.
7043 * @rrq: pointer to the active rrq.
7044 *
7045 * This routine will call the lpfc_issue_els_rrq if the rrq is
7046 * still active for the xri. If this function returns a failure then
7047 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7048 *
7049 * Returns 0 Success.
7050 * 1 Failure.
7051 **/
7052int
7053lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7054{
7055 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7056 rrq->nlp_DID);
7057 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7058 return lpfc_issue_els_rrq(rrq->vport, ndlp,
7059 rrq->nlp_DID, rrq);
7060 else
7061 return 1;
7062}
7063
James Smarte59058c2008-08-24 21:49:00 -04007064/**
James Smart3621a712009-04-06 18:47:14 -04007065 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04007066 * @vport: pointer to a host virtual N_Port data structure.
7067 * @cmdsize: size of the ELS command.
7068 * @oldiocb: pointer to the original lpfc command iocb data structure.
7069 * @ndlp: pointer to a node-list data structure.
7070 *
7071 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7072 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7073 *
7074 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7075 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7076 * will be stored into the context1 field of the IOCB for the completion
7077 * callback function to the RPL Accept Response ELS command.
7078 *
7079 * Return code
7080 * 0 - Successfully issued ACC RPL ELS command
7081 * 1 - Failed to issue ACC RPL ELS command
7082 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05007083static int
James Smart2e0fef82007-06-17 19:56:36 -05007084lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7085 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007086{
James Smart2e0fef82007-06-17 19:56:36 -05007087 struct lpfc_hba *phba = vport->phba;
7088 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007089 RPL_RSP rpl_rsp;
7090 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007091 uint8_t *pcmd;
7092
James Smart2e0fef82007-06-17 19:56:36 -05007093 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7094 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007095
James Smart488d1462006-03-07 15:02:37 -05007096 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007097 return 1;
James Smart488d1462006-03-07 15:02:37 -05007098
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007099 icmd = &elsiocb->iocb;
7100 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04007101 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7102 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007103
7104 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7105 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05007106 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007107 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7108 pcmd += sizeof(uint16_t);
7109
7110 /* Setup the RPL ACC payload */
7111 rpl_rsp.listLen = be32_to_cpu(1);
7112 rpl_rsp.index = 0;
7113 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05007114 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7115 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007116 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007117 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007118 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04007119 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7120 "0120 Xmit ELS RPL ACC response tag x%x "
7121 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7122 "rpi x%x\n",
7123 elsiocb->iotag, elsiocb->iocb.ulpContext,
7124 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7125 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05007126 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007127 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04007128 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7129 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007130 lpfc_els_free_iocb(phba, elsiocb);
7131 return 1;
7132 }
7133 return 0;
7134}
7135
James Smarte59058c2008-08-24 21:49:00 -04007136/**
James Smart3621a712009-04-06 18:47:14 -04007137 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04007138 * @vport: pointer to a host virtual N_Port data structure.
7139 * @cmdiocb: pointer to lpfc command iocb data structure.
7140 * @ndlp: pointer to a node-list data structure.
7141 *
7142 * This routine processes Read Port List (RPL) IOCB received as an ELS
7143 * unsolicited event. It first checks the remote port state. If the remote
7144 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7145 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7146 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7147 * to accept the RPL.
7148 *
7149 * Return code
7150 * 0 - Successfully processed rpl iocb (currently always return 0)
7151 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007152static int
James Smart2e0fef82007-06-17 19:56:36 -05007153lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7154 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007155{
7156 struct lpfc_dmabuf *pcmd;
7157 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007158 uint32_t maxsize;
7159 uint16_t cmdsize;
7160 RPL *rpl;
7161 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05007162
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007163 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7164 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04007165 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007166 stat.un.b.lsRjtRsvd0 = 0;
7167 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7168 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7169 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05007170 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7171 NULL);
James Smart90160e02008-08-24 21:49:45 -04007172 /* rejected the unsolicited RPL request and done with it */
7173 return 0;
dea31012005-04-17 16:05:31 -05007174 }
7175
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007176 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7177 lp = (uint32_t *) pcmd->virt;
7178 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007179 maxsize = be32_to_cpu(rpl->maxsize);
7180
7181 /* We support only one port */
7182 if ((rpl->index == 0) &&
7183 ((maxsize == 0) ||
7184 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7185 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05007186 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007187 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7188 }
James Smart2e0fef82007-06-17 19:56:36 -05007189 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05007190
7191 return 0;
7192}
7193
James Smarte59058c2008-08-24 21:49:00 -04007194/**
James Smart3621a712009-04-06 18:47:14 -04007195 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04007196 * @vport: pointer to a virtual N_Port data structure.
7197 * @cmdiocb: pointer to lpfc command iocb data structure.
7198 * @ndlp: pointer to a node-list data structure.
7199 *
7200 * This routine processes Fibre Channel Address Resolution Protocol
7201 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7202 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7203 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7204 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7205 * remote PortName is compared against the FC PortName stored in the @vport
7206 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7207 * compared against the FC NodeName stored in the @vport data structure.
7208 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7209 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7210 * invoked to send out FARP Response to the remote node. Before sending the
7211 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7212 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7213 * routine is invoked to log into the remote port first.
7214 *
7215 * Return code
7216 * 0 - Either the FARP Match Mode not supported or successfully processed
7217 **/
dea31012005-04-17 16:05:31 -05007218static int
James Smart2e0fef82007-06-17 19:56:36 -05007219lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7220 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007221{
7222 struct lpfc_dmabuf *pcmd;
7223 uint32_t *lp;
7224 IOCB_t *icmd;
7225 FARP *fp;
7226 uint32_t cmd, cnt, did;
7227
7228 icmd = &cmdiocb->iocb;
7229 did = icmd->un.elsreq64.remoteID;
7230 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7231 lp = (uint32_t *) pcmd->virt;
7232
7233 cmd = *lp++;
7234 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05007235 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007236 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7237 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007238 /* We will only support match on WWPN or WWNN */
7239 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007240 return 0;
dea31012005-04-17 16:05:31 -05007241 }
7242
7243 cnt = 0;
7244 /* If this FARP command is searching for my portname */
7245 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05007246 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05007247 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007248 cnt = 1;
7249 }
7250
7251 /* If this FARP command is searching for my nodename */
7252 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05007253 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05007254 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05007255 cnt = 1;
7256 }
7257
7258 if (cnt) {
7259 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7260 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7261 /* Log back into the node before sending the FARP. */
7262 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007263 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007264 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007265 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007266 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007267 }
7268
7269 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007270 if (fp->Rflags & FARP_REQUEST_FARPR)
7271 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007272 }
7273 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007274 return 0;
dea31012005-04-17 16:05:31 -05007275}
7276
James Smarte59058c2008-08-24 21:49:00 -04007277/**
James Smart3621a712009-04-06 18:47:14 -04007278 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007279 * @vport: pointer to a host virtual N_Port data structure.
7280 * @cmdiocb: pointer to lpfc command iocb data structure.
7281 * @ndlp: pointer to a node-list data structure.
7282 *
7283 * This routine processes Fibre Channel Address Resolution Protocol
7284 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7285 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7286 * the FARP response request.
7287 *
7288 * Return code
7289 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7290 **/
dea31012005-04-17 16:05:31 -05007291static int
James Smart2e0fef82007-06-17 19:56:36 -05007292lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7293 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007294{
7295 struct lpfc_dmabuf *pcmd;
7296 uint32_t *lp;
7297 IOCB_t *icmd;
7298 uint32_t cmd, did;
7299
7300 icmd = &cmdiocb->iocb;
7301 did = icmd->un.elsreq64.remoteID;
7302 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7303 lp = (uint32_t *) pcmd->virt;
7304
7305 cmd = *lp++;
7306 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007307 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7308 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007309 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007310 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007311
7312 return 0;
7313}
7314
James Smarte59058c2008-08-24 21:49:00 -04007315/**
James Smart3621a712009-04-06 18:47:14 -04007316 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007317 * @vport: pointer to a host virtual N_Port data structure.
7318 * @cmdiocb: pointer to lpfc command iocb data structure.
7319 * @fan_ndlp: pointer to a node-list data structure.
7320 *
7321 * This routine processes a Fabric Address Notification (FAN) IOCB
7322 * command received as an ELS unsolicited event. The FAN ELS command will
7323 * only be processed on a physical port (i.e., the @vport represents the
7324 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7325 * compared against those in the phba data structure. If any of those is
7326 * different, the lpfc_initial_flogi() routine is invoked to initialize
7327 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7328 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7329 * is invoked to register login to the fabric.
7330 *
7331 * Return code
7332 * 0 - Successfully processed fan iocb (currently always return 0).
7333 **/
dea31012005-04-17 16:05:31 -05007334static int
James Smart2e0fef82007-06-17 19:56:36 -05007335lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7336 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007337{
James Smart2e0fef82007-06-17 19:56:36 -05007338 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007339 uint32_t *lp;
7340 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007341
James Smart0d2b6b82008-06-14 22:52:47 -04007342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7343 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7344 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007345 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007346 if ((vport == phba->pport) &&
7347 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007348 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007349 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007350 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007351 sizeof(struct lpfc_name)))) {
7352 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007353 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007354 } else {
7355 /* FAN verified - skip FLOGI */
7356 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007357 if (phba->sli_rev < LPFC_SLI_REV4)
7358 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007359 else {
7360 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7361 "3138 Need register VFI: (x%x/%x)\n",
7362 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04007363 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05007364 }
dea31012005-04-17 16:05:31 -05007365 }
dea31012005-04-17 16:05:31 -05007366 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007367 return 0;
dea31012005-04-17 16:05:31 -05007368}
7369
James Smarte59058c2008-08-24 21:49:00 -04007370/**
James Smart3621a712009-04-06 18:47:14 -04007371 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04007372 * @ptr: holder for the timer function associated data.
7373 *
7374 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7375 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7376 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7377 * up the worker thread. It is for the worker thread to invoke the routine
7378 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7379 **/
dea31012005-04-17 16:05:31 -05007380void
Kees Cookf22eb4d2017-09-06 20:24:26 -07007381lpfc_els_timeout(struct timer_list *t)
dea31012005-04-17 16:05:31 -05007382{
Kees Cookf22eb4d2017-09-06 20:24:26 -07007383 struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
James Smart2e0fef82007-06-17 19:56:36 -05007384 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04007385 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05007386 unsigned long iflag;
7387
James Smart2e0fef82007-06-17 19:56:36 -05007388 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04007389 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05007390 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05007391 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04007392 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05007393
James Smart06918ac2014-02-20 09:57:57 -05007394 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04007395 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05007396 return;
7397}
7398
James Smart2a9bf3d2010-06-07 15:24:45 -04007399
James Smarte59058c2008-08-24 21:49:00 -04007400/**
James Smart3621a712009-04-06 18:47:14 -04007401 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04007402 * @vport: pointer to a virtual N_Port data structure.
7403 *
7404 * This routine is the actual handler function that processes an ELS timeout
7405 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7406 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7407 * invoking the lpfc_sli_issue_abort_iotag() routine.
7408 **/
dea31012005-04-17 16:05:31 -05007409void
James Smart2e0fef82007-06-17 19:56:36 -05007410lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007411{
James Smart2e0fef82007-06-17 19:56:36 -05007412 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007413 struct lpfc_sli_ring *pring;
7414 struct lpfc_iocbq *tmp_iocb, *piocb;
7415 IOCB_t *cmd = NULL;
7416 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05007417 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05007418 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05007419 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04007420 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05007421
James Smart2a9bf3d2010-06-07 15:24:45 -04007422
dea31012005-04-17 16:05:31 -05007423 timeout = (uint32_t)(phba->fc_ratov << 1);
7424
James Smart895427b2017-02-12 13:52:30 -08007425 pring = lpfc_phba_elsring(phba);
Dick Kennedy1234a6d2017-09-29 17:34:29 -07007426 if (unlikely(!pring))
7427 return;
James Smart895427b2017-02-12 13:52:30 -08007428
James Smart06918ac2014-02-20 09:57:57 -05007429 if ((phba->pport->load_flag & FC_UNLOADING))
7430 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04007431 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007432 if (phba->sli_rev == LPFC_SLI_REV4)
7433 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04007434
James Smart06918ac2014-02-20 09:57:57 -05007435 if ((phba->pport->load_flag & FC_UNLOADING)) {
7436 if (phba->sli_rev == LPFC_SLI_REV4)
7437 spin_unlock(&pring->ring_lock);
7438 spin_unlock_irq(&phba->hbalock);
7439 return;
7440 }
7441
James Smart0976e1a2013-12-17 20:29:36 -05007442 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05007443 cmd = &piocb->iocb;
7444
James Smart2e0fef82007-06-17 19:56:36 -05007445 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7446 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7447 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05007448 continue;
James Smart2e0fef82007-06-17 19:56:36 -05007449
7450 if (piocb->vport != vport)
7451 continue;
7452
dea31012005-04-17 16:05:31 -05007453 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05007454 if (pcmd)
7455 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05007456
James Smart92d7f7b2007-06-17 19:56:38 -05007457 if (els_command == ELS_CMD_FARP ||
7458 els_command == ELS_CMD_FARPR ||
7459 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05007460 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05007461
dea31012005-04-17 16:05:31 -05007462 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05007463 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05007464 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05007465 else
dea31012005-04-17 16:05:31 -05007466 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05007467 continue;
7468 }
7469
James Smart2e0fef82007-06-17 19:56:36 -05007470 remote_ID = 0xffffffff;
7471 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05007472 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05007473 else {
7474 struct lpfc_nodelist *ndlp;
7475 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04007476 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05007477 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05007478 }
James Smart2a9bf3d2010-06-07 15:24:45 -04007479 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05007480 }
James Smart0976e1a2013-12-17 20:29:36 -05007481 if (phba->sli_rev == LPFC_SLI_REV4)
7482 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007483 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04007484
James Smart2a9bf3d2010-06-07 15:24:45 -04007485 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05007486 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04007487 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7488 "0127 ELS timeout Data: x%x x%x x%x "
7489 "x%x\n", els_command,
7490 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7491 spin_lock_irq(&phba->hbalock);
7492 list_del_init(&piocb->dlist);
7493 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7494 spin_unlock_irq(&phba->hbalock);
7495 }
7496
James Smart895427b2017-02-12 13:52:30 -08007497 if (!list_empty(&pring->txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05007498 if (!(phba->pport->load_flag & FC_UNLOADING))
7499 mod_timer(&vport->els_tmofunc,
7500 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05007501}
7502
James Smarte59058c2008-08-24 21:49:00 -04007503/**
James Smart3621a712009-04-06 18:47:14 -04007504 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04007505 * @vport: pointer to a host virtual N_Port data structure.
7506 *
7507 * This routine is used to clean up all the outstanding ELS commands on a
7508 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7509 * routine. After that, it walks the ELS transmit queue to remove all the
7510 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7511 * the IOCBs with a non-NULL completion callback function, the callback
7512 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7513 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7514 * callback function, the IOCB will simply be released. Finally, it walks
7515 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7516 * completion queue IOCB that is associated with the @vport and is not
7517 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7518 * part of the discovery state machine) out to HBA by invoking the
7519 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7520 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7521 * the IOCBs are aborted when this function returns.
7522 **/
dea31012005-04-17 16:05:31 -05007523void
James Smart2e0fef82007-06-17 19:56:36 -05007524lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007525{
James Smart0976e1a2013-12-17 20:29:36 -05007526 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05007527 struct lpfc_hba *phba = vport->phba;
James Smart895427b2017-02-12 13:52:30 -08007528 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05007529 struct lpfc_iocbq *tmp_iocb, *piocb;
7530 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007531
7532 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05007533 /*
7534 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7535 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7536 * ultimately grabs the ring_lock, the driver must splice the list into
7537 * a working list and release the locks before calling the abort.
7538 */
7539 spin_lock_irq(&phba->hbalock);
James Smart895427b2017-02-12 13:52:30 -08007540 pring = lpfc_phba_elsring(phba);
Guilherme G. Piccoli53cf29d2017-05-17 19:02:17 -03007541
7542 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7543 if (unlikely(!pring)) {
7544 spin_unlock_irq(&phba->hbalock);
7545 return;
7546 }
7547
James Smart0976e1a2013-12-17 20:29:36 -05007548 if (phba->sli_rev == LPFC_SLI_REV4)
7549 spin_lock(&pring->ring_lock);
7550
7551 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7552 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7553 continue;
7554
7555 if (piocb->vport != vport)
7556 continue;
7557 list_add_tail(&piocb->dlist, &abort_list);
7558 }
7559 if (phba->sli_rev == LPFC_SLI_REV4)
7560 spin_unlock(&pring->ring_lock);
7561 spin_unlock_irq(&phba->hbalock);
7562 /* Abort each iocb on the aborted list and remove the dlist links. */
7563 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7564 spin_lock_irq(&phba->hbalock);
7565 list_del_init(&piocb->dlist);
7566 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7567 spin_unlock_irq(&phba->hbalock);
7568 }
7569 if (!list_empty(&abort_list))
7570 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7571 "3387 abort list for txq not empty\n");
7572 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05007573
James Smart2e0fef82007-06-17 19:56:36 -05007574 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007575 if (phba->sli_rev == LPFC_SLI_REV4)
7576 spin_lock(&pring->ring_lock);
7577
dea31012005-04-17 16:05:31 -05007578 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7579 cmd = &piocb->iocb;
7580
7581 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7582 continue;
7583 }
7584
7585 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007586 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7587 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7588 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7589 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007590 continue;
dea31012005-04-17 16:05:31 -05007591
James Smart2e0fef82007-06-17 19:56:36 -05007592 if (piocb->vport != vport)
7593 continue;
7594
James Smart0976e1a2013-12-17 20:29:36 -05007595 list_del_init(&piocb->list);
7596 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007597 }
James Smart0976e1a2013-12-17 20:29:36 -05007598 if (phba->sli_rev == LPFC_SLI_REV4)
7599 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007600 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007601
James Smarta257bf92009-04-06 18:48:10 -04007602 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007603 lpfc_sli_cancel_iocbs(phba, &abort_list,
7604 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007605
dea31012005-04-17 16:05:31 -05007606 return;
7607}
7608
James Smarte59058c2008-08-24 21:49:00 -04007609/**
James Smart3621a712009-04-06 18:47:14 -04007610 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007611 * @phba: pointer to lpfc hba data structure.
7612 *
7613 * This routine is used to clean up all the outstanding ELS commands on a
7614 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7615 * routine. After that, it walks the ELS transmit queue to remove all the
7616 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7617 * the IOCBs with the completion callback function associated, the callback
7618 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7619 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7620 * callback function associated, the IOCB will simply be released. Finally,
7621 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7622 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7623 * management plane IOCBs that are not part of the discovery state machine)
7624 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7625 **/
James Smart549e55c2007-08-02 11:09:51 -04007626void
7627lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7628{
James Smart0976e1a2013-12-17 20:29:36 -05007629 struct lpfc_vport *vport;
7630 list_for_each_entry(vport, &phba->port_list, listentry)
7631 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007632
James Smart549e55c2007-08-02 11:09:51 -04007633 return;
7634}
7635
James Smarte59058c2008-08-24 21:49:00 -04007636/**
James Smart3621a712009-04-06 18:47:14 -04007637 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007638 * @phba: Pointer to hba context object.
7639 * @cmdiocbp: Pointer to command iocb which reported error.
7640 * @rspiocbp: Pointer to response iocb which reported error.
7641 *
7642 * This function sends an event when there is an ELS command
7643 * failure.
7644 **/
7645void
7646lpfc_send_els_failure_event(struct lpfc_hba *phba,
7647 struct lpfc_iocbq *cmdiocbp,
7648 struct lpfc_iocbq *rspiocbp)
7649{
7650 struct lpfc_vport *vport = cmdiocbp->vport;
7651 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7652 struct lpfc_lsrjt_event lsrjt_event;
7653 struct lpfc_fabric_event_header fabric_event;
7654 struct ls_rjt stat;
7655 struct lpfc_nodelist *ndlp;
7656 uint32_t *pcmd;
7657
7658 ndlp = cmdiocbp->context1;
7659 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7660 return;
7661
7662 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7663 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7664 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7665 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7666 sizeof(struct lpfc_name));
7667 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7668 sizeof(struct lpfc_name));
7669 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7670 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007671 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007672 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7673 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7674 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7675 fc_host_post_vendor_event(shost,
7676 fc_get_event_number(),
7677 sizeof(lsrjt_event),
7678 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007679 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007680 return;
7681 }
7682 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7683 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7684 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7685 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7686 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7687 else
7688 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7689 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7690 sizeof(struct lpfc_name));
7691 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7692 sizeof(struct lpfc_name));
7693 fc_host_post_vendor_event(shost,
7694 fc_get_event_number(),
7695 sizeof(fabric_event),
7696 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007697 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007698 return;
7699 }
7700
7701}
7702
7703/**
James Smart3621a712009-04-06 18:47:14 -04007704 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007705 * @vport: Pointer to vport object.
7706 * @ndlp: Pointer FC node object.
7707 * @cmd: ELS command code.
7708 *
7709 * This function posts an event when there is an incoming
7710 * unsolicited ELS command.
7711 **/
7712static void
7713lpfc_send_els_event(struct lpfc_vport *vport,
7714 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007715 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007716{
James Smartddcc50f2008-12-04 22:38:46 -05007717 struct lpfc_els_event_header *els_data = NULL;
7718 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007719 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7720
James Smartddcc50f2008-12-04 22:38:46 -05007721 if (*payload == ELS_CMD_LOGO) {
7722 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7723 if (!logo_data) {
7724 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7725 "0148 Failed to allocate memory "
7726 "for LOGO event\n");
7727 return;
7728 }
7729 els_data = &logo_data->header;
7730 } else {
7731 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7732 GFP_KERNEL);
7733 if (!els_data) {
7734 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7735 "0149 Failed to allocate memory "
7736 "for ELS event\n");
7737 return;
7738 }
7739 }
7740 els_data->event_type = FC_REG_ELS_EVENT;
7741 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007742 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007743 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007744 break;
7745 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007746 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007747 break;
7748 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007749 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7750 break;
7751 case ELS_CMD_LOGO:
7752 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7753 /* Copy the WWPN in the LOGO payload */
7754 memcpy(logo_data->logo_wwpn, &payload[2],
7755 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007756 break;
7757 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007758 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007759 return;
7760 }
James Smartddcc50f2008-12-04 22:38:46 -05007761 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7762 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7763 if (*payload == ELS_CMD_LOGO) {
7764 fc_host_post_vendor_event(shost,
7765 fc_get_event_number(),
7766 sizeof(struct lpfc_logo_event),
7767 (char *)logo_data,
7768 LPFC_NL_VENDOR_ID);
7769 kfree(logo_data);
7770 } else {
7771 fc_host_post_vendor_event(shost,
7772 fc_get_event_number(),
7773 sizeof(struct lpfc_els_event_header),
7774 (char *)els_data,
7775 LPFC_NL_VENDOR_ID);
7776 kfree(els_data);
7777 }
James Smartea2151b2008-09-07 11:52:10 -04007778
7779 return;
7780}
7781
7782
7783/**
James Smart3621a712009-04-06 18:47:14 -04007784 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007785 * @phba: pointer to lpfc hba data structure.
7786 * @pring: pointer to a SLI ring.
7787 * @vport: pointer to a host virtual N_Port data structure.
7788 * @elsiocb: pointer to lpfc els command iocb data structure.
7789 *
7790 * This routine is used for processing the IOCB associated with a unsolicited
7791 * event. It first determines whether there is an existing ndlp that matches
7792 * the DID from the unsolicited IOCB. If not, it will create a new one with
7793 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7794 * IOCB is then used to invoke the proper routine and to set up proper state
7795 * of the discovery state machine.
7796 **/
James Smarted957682007-06-17 19:56:37 -05007797static void
7798lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007799 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007800{
James Smart87af33f2007-10-27 13:37:43 -04007801 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007802 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007803 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007804 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007805 uint32_t cmd, did, newnode;
7806 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007807 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007808
James Smarte47c9092008-02-08 18:49:26 -05007809 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007810 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007811
dea31012005-04-17 16:05:31 -05007812 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007813 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7814 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007815 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007816 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007817
James Smart858c9f62007-06-17 19:56:39 -05007818 did = icmd->un.rcvels.remoteID;
7819 if (icmd->ulpStatus) {
7820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7821 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7822 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007823 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007824 }
dea31012005-04-17 16:05:31 -05007825
7826 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007827 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007828 goto dropit;
dea31012005-04-17 16:05:31 -05007829
James Smartc8685952009-11-18 15:39:16 -05007830 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007831 if (vport->load_flag & FC_UNLOADING)
7832 goto dropit;
7833
James Smart92494142011-02-16 12:39:44 -05007834 /* If NPort discovery is delayed drop incoming ELS */
7835 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7836 (cmd != ELS_CMD_PLOGI))
7837 goto dropit;
7838
James Smart2e0fef82007-06-17 19:56:36 -05007839 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007840 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007841 /* Cannot find existing Fabric ndlp, so allocate a new one */
James Smart9d3d3402017-04-21 16:05:00 -07007842 ndlp = lpfc_nlp_init(vport, did);
James Smarted957682007-06-17 19:56:37 -05007843 if (!ndlp)
dea31012005-04-17 16:05:31 -05007844 goto dropit;
James Smart98c9ea52007-10-27 13:37:33 -04007845 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007846 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007847 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007848 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007849 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7850 ndlp = lpfc_enable_node(vport, ndlp,
7851 NLP_STE_UNUSED_NODE);
7852 if (!ndlp)
7853 goto dropit;
7854 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7855 newnode = 1;
7856 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7857 ndlp->nlp_type |= NLP_FABRIC;
7858 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7859 /* This is similar to the new node path */
7860 ndlp = lpfc_nlp_get(ndlp);
7861 if (!ndlp)
7862 goto dropit;
7863 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7864 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007865 }
dea31012005-04-17 16:05:31 -05007866
7867 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007868
James Smart12838e72014-09-03 12:57:19 -04007869 /*
7870 * Do not process any unsolicited ELS commands
7871 * if the ndlp is in DEV_LOSS
7872 */
James Smart466e8402015-05-21 13:55:28 -04007873 shost = lpfc_shost_from_vport(vport);
7874 spin_lock_irq(shost->host_lock);
7875 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7876 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007877 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007878 }
7879 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007880
James Smart329f9bc2007-04-25 09:53:01 -04007881 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007882 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007883
7884 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7885 cmd &= ELS_CMD_MASK;
7886 }
7887 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007888 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7889 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007890 "Data: x%x x%x x%x x%x\n",
7891 cmd, did, vport->port_state, vport->fc_flag,
7892 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04007893
7894 /* reject till our FLOGI completes */
7895 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smartd6de08c2015-12-16 18:11:53 -05007896 (cmd != ELS_CMD_FLOGI)) {
James Smart401304c2016-10-13 15:06:14 -07007897 rjt_err = LSRJT_LOGICAL_BSY;
James Smarteec3d312015-08-31 16:48:18 -04007898 rjt_exp = LSEXP_NOTHING_MORE;
7899 goto lsrjt;
7900 }
7901
dea31012005-04-17 16:05:31 -05007902 switch (cmd) {
7903 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007904 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7905 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7906 did, vport->port_state, ndlp->nlp_flag);
7907
dea31012005-04-17 16:05:31 -05007908 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007909 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007910 if (phba->sli_rev == LPFC_SLI_REV4 &&
7911 (phba->pport->fc_flag & FC_PT2PT)) {
7912 vport->fc_prevDID = vport->fc_myDID;
7913 /* Our DID needs to be updated before registering
7914 * the vfi. This is done in lpfc_rcv_plogi but
7915 * that is called after the reg_vfi.
7916 */
7917 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7918 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7919 "3312 Remote port assigned DID x%x "
7920 "%x\n", vport->fc_myDID,
7921 vport->fc_prevDID);
7922 }
James Smart858c9f62007-06-17 19:56:39 -05007923
James Smartddcc50f2008-12-04 22:38:46 -05007924 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007925
7926 /* If Nport discovery is delayed, reject PLOGIs */
7927 if (vport->fc_flag & FC_DISC_DELAYED) {
7928 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007929 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007930 break;
7931 }
James Smartd6de08c2015-12-16 18:11:53 -05007932
James Smart858c9f62007-06-17 19:56:39 -05007933 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007934 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7935 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7936 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007937 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007938 break;
7939 }
dea31012005-04-17 16:05:31 -05007940 }
James Smart87af33f2007-10-27 13:37:43 -04007941
James Smart87af33f2007-10-27 13:37:43 -04007942 spin_lock_irq(shost->host_lock);
7943 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7944 spin_unlock_irq(shost->host_lock);
7945
James Smart2e0fef82007-06-17 19:56:36 -05007946 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7947 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007948
dea31012005-04-17 16:05:31 -05007949 break;
7950 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007951 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7952 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7953 did, vport->port_state, ndlp->nlp_flag);
7954
dea31012005-04-17 16:05:31 -05007955 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007956 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007957 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007958 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007959 break;
7960 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007961 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7962 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7963 did, vport->port_state, ndlp->nlp_flag);
7964
dea31012005-04-17 16:05:31 -05007965 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007966 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007967 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007968 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007969 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007970 break;
7971 }
James Smart2e0fef82007-06-17 19:56:36 -05007972 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007973 break;
7974 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007975 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7976 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7977 did, vport->port_state, ndlp->nlp_flag);
7978
dea31012005-04-17 16:05:31 -05007979 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007980 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007981 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007982 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007983 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007984 break;
7985 }
James Smart2e0fef82007-06-17 19:56:36 -05007986 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05007987 break;
James Smart8b017a32015-05-21 13:55:18 -04007988 case ELS_CMD_LCB:
7989 phba->fc_stat.elsRcvLCB++;
7990 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7991 break;
James Smart86478872015-05-21 13:55:21 -04007992 case ELS_CMD_RDP:
7993 phba->fc_stat.elsRcvRDP++;
7994 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7995 break;
dea31012005-04-17 16:05:31 -05007996 case ELS_CMD_RSCN:
7997 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04007998 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007999 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008000 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008001 break;
8002 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05008003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8004 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8005 did, vport->port_state, ndlp->nlp_flag);
8006
James Smartddcc50f2008-12-04 22:38:46 -05008007 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05008008 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008009 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008010 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008011 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008012 break;
8013 }
James Smart2e0fef82007-06-17 19:56:36 -05008014 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8015 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05008016 break;
8017 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05008018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8019 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8020 did, vport->port_state, ndlp->nlp_flag);
8021
dea31012005-04-17 16:05:31 -05008022 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05008023 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05008024 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008025 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008026 break;
8027 }
James Smart2e0fef82007-06-17 19:56:36 -05008028 lpfc_disc_state_machine(vport, ndlp, elsiocb,
8029 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05008030 break;
8031 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05008032 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8033 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8034 did, vport->port_state, ndlp->nlp_flag);
8035
dea31012005-04-17 16:05:31 -05008036 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05008037 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008038 break;
8039 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05008040 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8041 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8042 did, vport->port_state, ndlp->nlp_flag);
8043
dea31012005-04-17 16:05:31 -05008044 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05008045 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008046 break;
8047 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05008048 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8049 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8050 did, vport->port_state, ndlp->nlp_flag);
8051
dea31012005-04-17 16:05:31 -05008052 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05008053 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05008054 break;
dea31012005-04-17 16:05:31 -05008055 case ELS_CMD_PRLI:
James Smarta0f2d3e2017-02-12 13:52:31 -08008056 case ELS_CMD_NVMEPRLI:
James Smart858c9f62007-06-17 19:56:39 -05008057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8058 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8059 did, vport->port_state, ndlp->nlp_flag);
8060
dea31012005-04-17 16:05:31 -05008061 phba->fc_stat.elsRcvPRLI++;
Dick Kennedya71e3cd2017-03-23 08:47:18 -04008062 if ((vport->port_state < LPFC_DISC_AUTH) &&
8063 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05008064 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05008065 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008066 break;
8067 }
Dick Kennedy8db1c2b2017-08-23 16:55:36 -07008068
8069 /* NVMET accepts NVME PRLI only. Reject FCP PRLI */
8070 if (cmd == ELS_CMD_PRLI && phba->nvmet_support) {
8071 rjt_err = LSRJT_CMD_UNSUPPORTED;
8072 rjt_exp = LSEXP_REQ_UNSUPPORTED;
8073 break;
8074 }
James Smart2e0fef82007-06-17 19:56:36 -05008075 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05008076 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008077 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05008078 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8079 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8080 did, vport->port_state, ndlp->nlp_flag);
8081
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008082 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05008083 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008084 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008085 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008086 break;
James Smart12265f62010-10-22 11:05:53 -04008087 case ELS_CMD_RLS:
8088 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8089 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8090 did, vport->port_state, ndlp->nlp_flag);
8091
8092 phba->fc_stat.elsRcvRLS++;
8093 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8094 if (newnode)
8095 lpfc_nlp_put(ndlp);
8096 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008097 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05008098 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8099 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8100 did, vport->port_state, ndlp->nlp_flag);
8101
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008102 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05008103 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008104 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008105 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008106 break;
8107 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05008108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8109 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8110 did, vport->port_state, ndlp->nlp_flag);
8111
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008112 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05008113 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008114 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008115 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05008116 break;
dea31012005-04-17 16:05:31 -05008117 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05008118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8119 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8120 did, vport->port_state, ndlp->nlp_flag);
8121
dea31012005-04-17 16:05:31 -05008122 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05008123 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04008124 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008125 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008126 break;
James Smart12265f62010-10-22 11:05:53 -04008127 case ELS_CMD_RTV:
8128 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8129 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8130 did, vport->port_state, ndlp->nlp_flag);
8131 phba->fc_stat.elsRcvRTV++;
8132 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8133 if (newnode)
8134 lpfc_nlp_put(ndlp);
8135 break;
James Smart5ffc2662009-11-18 15:39:44 -05008136 case ELS_CMD_RRQ:
8137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8138 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8139 did, vport->port_state, ndlp->nlp_flag);
8140
8141 phba->fc_stat.elsRcvRRQ++;
8142 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8143 if (newnode)
8144 lpfc_nlp_put(ndlp);
8145 break;
James Smart12265f62010-10-22 11:05:53 -04008146 case ELS_CMD_ECHO:
8147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8148 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8149 did, vport->port_state, ndlp->nlp_flag);
8150
8151 phba->fc_stat.elsRcvECHO++;
8152 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8153 if (newnode)
8154 lpfc_nlp_put(ndlp);
8155 break;
James Smart303f2f92013-01-03 15:43:11 -05008156 case ELS_CMD_REC:
8157 /* receive this due to exchange closed */
8158 rjt_err = LSRJT_UNABLE_TPC;
8159 rjt_exp = LSEXP_INVALID_OX_RX;
8160 break;
dea31012005-04-17 16:05:31 -05008161 default:
James Smart858c9f62007-06-17 19:56:39 -05008162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8163 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8164 cmd, did, vport->port_state);
8165
dea31012005-04-17 16:05:31 -05008166 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05008167 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05008168 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05008169
8170 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04008171 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8172 "0115 Unknown ELS command x%x "
8173 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04008174 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04008175 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05008176 break;
8177 }
8178
James Smarteec3d312015-08-31 16:48:18 -04008179lsrjt:
dea31012005-04-17 16:05:31 -05008180 /* check if need to LS_RJT received ELS cmd */
8181 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05008182 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05008183 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05008184 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05008185 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8186 NULL);
dea31012005-04-17 16:05:31 -05008187 }
8188
James Smartd7c255b2008-08-24 21:50:00 -04008189 lpfc_nlp_put(elsiocb->context1);
8190 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05008191 return;
8192
8193dropit:
James Smart98c9ea52007-10-27 13:37:33 -04008194 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04008195 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8196 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05008197 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04008198 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05008199 phba->fc_stat.elsRcvDrop++;
8200}
8201
James Smarte59058c2008-08-24 21:49:00 -04008202/**
James Smart3621a712009-04-06 18:47:14 -04008203 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04008204 * @phba: pointer to lpfc hba data structure.
8205 * @pring: pointer to a SLI ring.
8206 * @elsiocb: pointer to lpfc els iocb data structure.
8207 *
8208 * This routine is used to process an unsolicited event received from a SLI
8209 * (Service Level Interface) ring. The actual processing of the data buffer
8210 * associated with the unsolicited event is done by invoking the routine
8211 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8212 * SLI ring on which the unsolicited event was received.
8213 **/
James Smarted957682007-06-17 19:56:37 -05008214void
8215lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8216 struct lpfc_iocbq *elsiocb)
8217{
8218 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05008219 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05008220 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05008221 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8222 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05008223
James Smartd7c255b2008-08-24 21:50:00 -04008224 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05008225 elsiocb->context2 = NULL;
8226 elsiocb->context3 = NULL;
8227
8228 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8229 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8230 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04008231 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8232 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05008233 phba->fc_stat.NoRcvBuf++;
8234 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05008235 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04008236 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05008237 return;
8238 }
8239
James Smart92d7f7b2007-06-17 19:56:38 -05008240 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8241 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8242 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8243 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8244 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04008245 else
8246 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04008247 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05008248 }
James Smart6d368e52011-05-24 11:44:12 -04008249
James Smart7f5f3d02008-02-08 18:50:14 -05008250 /* If there are no BDEs associated
8251 * with this IOCB, there is nothing to do.
8252 */
James Smarted957682007-06-17 19:56:37 -05008253 if (icmd->ulpBdeCount == 0)
8254 return;
8255
James Smart7f5f3d02008-02-08 18:50:14 -05008256 /* type of ELS cmd is first 32bit word
8257 * in packet
8258 */
James Smarted957682007-06-17 19:56:37 -05008259 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05008260 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05008261 } else {
8262 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8263 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05008264 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8265 paddr);
James Smarted957682007-06-17 19:56:37 -05008266 }
8267
James Smart92d7f7b2007-06-17 19:56:38 -05008268 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8269 /*
8270 * The different unsolicited event handlers would tell us
8271 * if they are done with "mp" by setting context2 to NULL.
8272 */
dea31012005-04-17 16:05:31 -05008273 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008274 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8275 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05008276 }
James Smarted957682007-06-17 19:56:37 -05008277
8278 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05008279 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05008280 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008281 elsiocb->context2 = bdeBuf2;
8282 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05008283 /* free mp if we are done with it */
8284 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008285 lpfc_in_buf_free(phba, elsiocb->context2);
8286 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05008287 }
dea31012005-04-17 16:05:31 -05008288 }
dea31012005-04-17 16:05:31 -05008289}
James Smart92d7f7b2007-06-17 19:56:38 -05008290
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08008291static void
James Smart4258e982015-12-16 18:11:58 -05008292lpfc_start_fdmi(struct lpfc_vport *vport)
8293{
James Smart4258e982015-12-16 18:11:58 -05008294 struct lpfc_nodelist *ndlp;
8295
8296 /* If this is the first time, allocate an ndlp and initialize
8297 * it. Otherwise, make sure the node is enabled and then do the
8298 * login.
8299 */
8300 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8301 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008302 ndlp = lpfc_nlp_init(vport, FDMI_DID);
James Smart4258e982015-12-16 18:11:58 -05008303 if (ndlp) {
James Smart4258e982015-12-16 18:11:58 -05008304 ndlp->nlp_type |= NLP_FABRIC;
8305 } else {
8306 return;
8307 }
8308 }
8309 if (!NLP_CHK_NODE_ACT(ndlp))
8310 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8311
8312 if (ndlp) {
8313 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8314 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8315 }
8316}
8317
James Smarte59058c2008-08-24 21:49:00 -04008318/**
James Smart3621a712009-04-06 18:47:14 -04008319 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04008320 * @phba: pointer to lpfc hba data structure.
8321 * @vport: pointer to a virtual N_Port data structure.
8322 *
8323 * This routine issues a Port Login (PLOGI) to the Name Server with
8324 * State Change Request (SCR) for a @vport. This routine will create an
8325 * ndlp for the Name Server associated to the @vport if such node does
8326 * not already exist. The PLOGI to Name Server is issued by invoking the
8327 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8328 * (FDMI) is configured to the @vport, a FDMI node will be created and
8329 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8330 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008331void
8332lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8333{
James Smart4258e982015-12-16 18:11:58 -05008334 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05008335 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8336
8337 /*
8338 * If lpfc_delay_discovery parameter is set and the clean address
8339 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8340 * discovery.
8341 */
8342 spin_lock_irq(shost->host_lock);
8343 if (vport->fc_flag & FC_DISC_DELAYED) {
8344 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04008345 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8346 "3334 Delay fc port discovery for %d seconds\n",
8347 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05008348 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04008349 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05008350 return;
8351 }
8352 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008353
8354 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8355 if (!ndlp) {
James Smart9d3d3402017-04-21 16:05:00 -07008356 ndlp = lpfc_nlp_init(vport, NameServer_DID);
James Smart92d7f7b2007-06-17 19:56:38 -05008357 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008358 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05008359 lpfc_disc_start(vport);
8360 return;
8361 }
8362 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008363 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8364 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008365 return;
8366 }
James Smarte47c9092008-02-08 18:49:26 -05008367 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8368 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8369 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008370 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05008371 lpfc_disc_start(vport);
8372 return;
8373 }
8374 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8375 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8376 "0348 NameServer login: node freed\n");
8377 return;
8378 }
James Smart92d7f7b2007-06-17 19:56:38 -05008379 }
James Smart58da1ff2008-04-07 10:15:56 -04008380 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05008381
8382 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8383
8384 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8385 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008386 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8387 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008388 return;
8389 }
8390
James Smart8663cbb2016-03-31 14:12:33 -07008391 if ((phba->cfg_enable_SmartSAN ||
8392 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8393 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05008394 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008395}
8396
James Smarte59058c2008-08-24 21:49:00 -04008397/**
James Smart3621a712009-04-06 18:47:14 -04008398 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04008399 * @phba: pointer to lpfc hba data structure.
8400 * @pmb: pointer to the driver internal queue element for mailbox command.
8401 *
8402 * This routine is the completion callback function to register new vport
8403 * mailbox command. If the new vport mailbox command completes successfully,
8404 * the fabric registration login shall be performed on physical port (the
8405 * new vport created is actually a physical port, with VPI 0) or the port
8406 * login to Name Server for State Change Request (SCR) will be performed
8407 * on virtual port (real virtual port, with VPI greater than 0).
8408 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008409static void
8410lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8411{
8412 struct lpfc_vport *vport = pmb->vport;
8413 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8414 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04008415 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05008416 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008417
James Smart09372822008-01-11 01:52:54 -05008418 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008419 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008420 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008421
8422 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04008423 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04008424 "0915 Register VPI failed : Status: x%x"
8425 " upd bit: x%x \n", mb->mbxStatus,
8426 mb->un.varRegVpi.upd);
8427 if (phba->sli_rev == LPFC_SLI_REV4 &&
8428 mb->un.varRegVpi.upd)
8429 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05008430
8431 switch (mb->mbxStatus) {
8432 case 0x11: /* unsupported feature */
8433 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05008434 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05008435 /* giving up on vport registration */
8436 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8437 spin_lock_irq(shost->host_lock);
8438 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8439 spin_unlock_irq(shost->host_lock);
8440 lpfc_can_disctmo(vport);
8441 break;
James Smart695a8142010-01-26 23:08:03 -05008442 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8443 case 0x20:
8444 spin_lock_irq(shost->host_lock);
8445 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8446 spin_unlock_irq(shost->host_lock);
8447 lpfc_init_vpi(phba, pmb, vport->vpi);
8448 pmb->vport = vport;
8449 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8450 rc = lpfc_sli_issue_mbox(phba, pmb,
8451 MBX_NOWAIT);
8452 if (rc == MBX_NOT_FINISHED) {
8453 lpfc_printf_vlog(vport,
8454 KERN_ERR, LOG_MBOX,
8455 "2732 Failed to issue INIT_VPI"
8456 " mailbox command\n");
8457 } else {
8458 lpfc_nlp_put(ndlp);
8459 return;
8460 }
8461
James Smart92d7f7b2007-06-17 19:56:38 -05008462 default:
8463 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04008464 if (phba->sli_rev == LPFC_SLI_REV4)
8465 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008466 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05008467 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008468 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008469 spin_unlock_irq(shost->host_lock);
James Smart5d181532017-03-04 09:30:25 -08008470 if (mb->mbxStatus == MBX_NOT_FINISHED)
8471 break;
8472 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8473 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8474 if (phba->sli_rev == LPFC_SLI_REV4)
8475 lpfc_issue_init_vfi(vport);
8476 else
8477 lpfc_initial_flogi(vport);
8478 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05008479 lpfc_initial_fdisc(vport);
James Smart5d181532017-03-04 09:30:25 -08008480 }
James Smart92d7f7b2007-06-17 19:56:38 -05008481 break;
8482 }
James Smart92d7f7b2007-06-17 19:56:38 -05008483 } else {
James Smart695a8142010-01-26 23:08:03 -05008484 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05008485 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05008486 spin_unlock_irq(shost->host_lock);
8487 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04008488 if (phba->sli_rev < LPFC_SLI_REV4)
8489 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05008490 else {
James Smartfc2b9892010-02-26 14:15:29 -05008491 /*
8492 * If the physical port is instantiated using
8493 * FDISC, do not start vport discovery.
8494 */
8495 if (vport->port_state != LPFC_FDISC)
8496 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05008497 lpfc_do_scr_ns_plogi(phba, vport);
8498 }
8499 } else
James Smart92d7f7b2007-06-17 19:56:38 -05008500 lpfc_do_scr_ns_plogi(phba, vport);
8501 }
James Smart38b92ef2010-08-04 16:11:39 -04008502mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05008503 /* Now, we decrement the ndlp reference count held for this
8504 * callback function
8505 */
8506 lpfc_nlp_put(ndlp);
8507
James Smart92d7f7b2007-06-17 19:56:38 -05008508 mempool_free(pmb, phba->mbox_mem_pool);
8509 return;
8510}
8511
James Smarte59058c2008-08-24 21:49:00 -04008512/**
James Smart3621a712009-04-06 18:47:14 -04008513 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04008514 * @phba: pointer to lpfc hba data structure.
8515 * @vport: pointer to a host virtual N_Port data structure.
8516 * @ndlp: pointer to a node-list data structure.
8517 *
8518 * This routine registers the @vport as a new virtual port with a HBA.
8519 * It is done through a registering vpi mailbox command.
8520 **/
James Smart695a8142010-01-26 23:08:03 -05008521void
James Smart92d7f7b2007-06-17 19:56:38 -05008522lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8523 struct lpfc_nodelist *ndlp)
8524{
James Smart09372822008-01-11 01:52:54 -05008525 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008526 LPFC_MBOXQ_t *mbox;
8527
8528 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8529 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04008530 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05008531 mbox->vport = vport;
8532 mbox->context2 = lpfc_nlp_get(ndlp);
8533 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04008534 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05008535 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05008536 /* mailbox command not success, decrement ndlp
8537 * reference count for this command
8538 */
8539 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008540 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05008541
James Smarte8b62012007-08-02 11:10:09 -04008542 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8543 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05008544 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008545 }
8546 } else {
James Smarte8b62012007-08-02 11:10:09 -04008547 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8548 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05008549 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008550 }
James Smartfa4066b2008-01-11 01:53:27 -05008551 return;
8552
8553mbox_err_exit:
8554 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8555 spin_lock_irq(shost->host_lock);
8556 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8557 spin_unlock_irq(shost->host_lock);
8558 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008559}
8560
James Smarte59058c2008-08-24 21:49:00 -04008561/**
James Smart0c9ab6f2010-02-26 14:15:57 -05008562 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05008563 * @phba: pointer to lpfc hba data structure.
8564 *
James Smart0c9ab6f2010-02-26 14:15:57 -05008565 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05008566 **/
8567void
James Smart0c9ab6f2010-02-26 14:15:57 -05008568lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05008569{
8570 struct lpfc_vport **vports;
8571 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05008572 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05008573 int i;
James Smart695a8142010-01-26 23:08:03 -05008574
8575 /* Treat this failure as linkdown for all vports */
8576 link_state = phba->link_state;
8577 lpfc_linkdown(phba);
8578 phba->link_state = link_state;
8579
8580 vports = lpfc_create_vport_work_array(phba);
8581
8582 if (vports) {
8583 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8584 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8585 if (ndlp)
8586 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8587 lpfc_els_flush_cmd(vports[i]);
8588 }
8589 lpfc_destroy_vport_work_array(phba, vports);
8590 }
James Smart0c9ab6f2010-02-26 14:15:57 -05008591}
8592
8593/**
8594 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8595 * @phba: pointer to lpfc hba data structure.
8596 *
8597 * This routine abort all pending discovery commands and
8598 * start a timer to retry FLOGI for the physical port
8599 * discovery.
8600 **/
8601void
8602lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8603{
8604 struct lpfc_nodelist *ndlp;
8605 struct Scsi_Host *shost;
8606
8607 /* Cancel the all vports retry delay retry timers */
8608 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008609
8610 /* If fabric require FLOGI, then re-instantiate physical login */
8611 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8612 if (!ndlp)
8613 return;
8614
James Smart695a8142010-01-26 23:08:03 -05008615 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008616 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008617 spin_lock_irq(shost->host_lock);
8618 ndlp->nlp_flag |= NLP_DELAY_TMO;
8619 spin_unlock_irq(shost->host_lock);
8620 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8621 phba->pport->port_state = LPFC_FLOGI;
8622 return;
8623}
8624
8625/**
8626 * lpfc_fabric_login_reqd - Check if FLOGI required.
8627 * @phba: pointer to lpfc hba data structure.
8628 * @cmdiocb: pointer to FDISC command iocb.
8629 * @rspiocb: pointer to FDISC response iocb.
8630 *
8631 * This routine checks if a FLOGI is reguired for FDISC
8632 * to succeed.
8633 **/
8634static int
8635lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8636 struct lpfc_iocbq *cmdiocb,
8637 struct lpfc_iocbq *rspiocb)
8638{
8639
8640 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8641 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8642 return 0;
8643 else
8644 return 1;
8645}
8646
8647/**
James Smart3621a712009-04-06 18:47:14 -04008648 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008649 * @phba: pointer to lpfc hba data structure.
8650 * @cmdiocb: pointer to lpfc command iocb data structure.
8651 * @rspiocb: pointer to lpfc response iocb data structure.
8652 *
8653 * This routine is the completion callback function to a Fabric Discover
8654 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8655 * single threaded, each FDISC completion callback function will reset
8656 * the discovery timer for all vports such that the timers will not get
8657 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8658 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8659 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8660 * assigned to the vport has been changed with the completion of the FDISC
8661 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8662 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8663 * routine is invoked to register new vport with the HBA. Otherwise, the
8664 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8665 * Server for State Change Request (SCR).
8666 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008667static void
8668lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8669 struct lpfc_iocbq *rspiocb)
8670{
8671 struct lpfc_vport *vport = cmdiocb->vport;
8672 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8673 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8674 struct lpfc_nodelist *np;
8675 struct lpfc_nodelist *next_np;
8676 IOCB_t *irsp = &rspiocb->iocb;
8677 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008678 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8679 struct serv_parm *sp;
8680 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008681
James Smarte8b62012007-08-02 11:10:09 -04008682 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8683 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8684 irsp->ulpStatus, irsp->un.ulpWord[4],
8685 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008686 /* Since all FDISCs are being single threaded, we
8687 * must reset the discovery timer for ALL vports
8688 * waiting to send FDISC when one completes.
8689 */
8690 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8691 lpfc_set_disctmo(piocb->vport);
8692 }
8693
James Smart858c9f62007-06-17 19:56:39 -05008694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8695 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8696 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8697
James Smart92d7f7b2007-06-17 19:56:38 -05008698 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008699
8700 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8701 lpfc_retry_pport_discovery(phba);
8702 goto out;
8703 }
8704
James Smart92d7f7b2007-06-17 19:56:38 -05008705 /* Check for retry */
8706 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8707 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008708 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008709 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008710 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008711 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008712 goto fdisc_failed;
8713 }
James Smartd7c255b2008-08-24 21:50:00 -04008714 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008715 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008716 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008717 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008718 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008719 vport->fc_flag |= FC_PUBLIC_LOOP;
8720 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008721
James Smartd7c255b2008-08-24 21:50:00 -04008722 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8723 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008724 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008725 if (!prsp)
8726 goto out;
James Smart92494142011-02-16 12:39:44 -05008727 sp = prsp->virt + sizeof(uint32_t);
8728 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8729 memcpy(&vport->fabric_portname, &sp->portName,
8730 sizeof(struct lpfc_name));
8731 memcpy(&vport->fabric_nodename, &sp->nodeName,
8732 sizeof(struct lpfc_name));
8733 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008734 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8735 /* If our NportID changed, we need to ensure all
8736 * remaining NPORTs get unreg_login'ed so we can
8737 * issue unreg_vpi.
8738 */
8739 list_for_each_entry_safe(np, next_np,
8740 &vport->fc_nodes, nlp_listp) {
8741 if (!NLP_CHK_NODE_ACT(ndlp) ||
8742 (np->nlp_state != NLP_STE_NPR_NODE) ||
8743 !(np->nlp_flag & NLP_NPR_ADISC))
8744 continue;
James Smart09372822008-01-11 01:52:54 -05008745 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008746 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008747 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008748 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008749 }
James Smart78730cf2010-04-06 15:06:30 -04008750 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008751
8752 if (phba->sli_rev == LPFC_SLI_REV4)
8753 lpfc_sli4_unreg_all_rpis(vport);
8754
James Smartd7c255b2008-08-24 21:50:00 -04008755 lpfc_mbx_unreg_vpi(vport);
8756 spin_lock_irq(shost->host_lock);
8757 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008758 if (phba->sli_rev == LPFC_SLI_REV4)
8759 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008760 else
8761 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008762 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008763 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8764 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8765 /*
8766 * Driver needs to re-reg VPI in order for f/w
8767 * to update the MAC address.
8768 */
8769 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008770 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008771 }
8772
James Smartecfd03c2010-02-12 14:41:27 -05008773 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8774 lpfc_issue_init_vpi(vport);
8775 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008776 lpfc_register_new_vport(phba, vport, ndlp);
8777 else
8778 lpfc_do_scr_ns_plogi(phba, vport);
8779 goto out;
8780fdisc_failed:
James Smart845d9e82017-05-15 15:20:38 -07008781 if (vport->fc_vport &&
8782 (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
James Smartc84163d2015-05-21 13:55:22 -04008783 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008784 /* Cancel discovery timer */
8785 lpfc_can_disctmo(vport);
8786 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008787out:
8788 lpfc_els_free_iocb(phba, cmdiocb);
8789}
8790
James Smarte59058c2008-08-24 21:49:00 -04008791/**
James Smart3621a712009-04-06 18:47:14 -04008792 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008793 * @vport: pointer to a virtual N_Port data structure.
8794 * @ndlp: pointer to a node-list data structure.
8795 * @retry: number of retries to the command IOCB.
8796 *
8797 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8798 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8799 * routine to issue the IOCB, which makes sure only one outstanding fabric
8800 * IOCB will be sent off HBA at any given time.
8801 *
8802 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8803 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8804 * will be stored into the context1 field of the IOCB for the completion
8805 * callback function to the FDISC ELS command.
8806 *
8807 * Return code
8808 * 0 - Successfully issued fdisc iocb command
8809 * 1 - Failed to issue fdisc iocb command
8810 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008811static int
James Smart92d7f7b2007-06-17 19:56:38 -05008812lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8813 uint8_t retry)
8814{
8815 struct lpfc_hba *phba = vport->phba;
8816 IOCB_t *icmd;
8817 struct lpfc_iocbq *elsiocb;
8818 struct serv_parm *sp;
8819 uint8_t *pcmd;
8820 uint16_t cmdsize;
8821 int did = ndlp->nlp_DID;
8822 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008823
James Smart5ffc2662009-11-18 15:39:44 -05008824 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008825 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008826 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8827 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8828 ELS_CMD_FDISC);
8829 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008830 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008831 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8832 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008833 return 1;
8834 }
8835
8836 icmd = &elsiocb->iocb;
8837 icmd->un.elsreq64.myID = 0;
8838 icmd->un.elsreq64.fl = 1;
8839
James Smart73d91e52011-10-10 21:32:10 -04008840 /*
8841 * SLI3 ports require a different context type value than SLI4.
8842 * Catch SLI3 ports here and override the prep.
8843 */
8844 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008845 icmd->ulpCt_h = 1;
8846 icmd->ulpCt_l = 0;
8847 }
James Smart92d7f7b2007-06-17 19:56:38 -05008848
8849 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8850 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8851 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8852 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8853 sp = (struct serv_parm *) pcmd;
8854 /* Setup CSPs accordingly for Fabric */
8855 sp->cmn.e_d_tov = 0;
8856 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008857 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008858 sp->cls1.classValid = 0;
8859 sp->cls2.seqDelivery = 1;
8860 sp->cls3.seqDelivery = 1;
8861
8862 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8863 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8864 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8865 pcmd += sizeof(uint32_t); /* Port Name */
8866 memcpy(pcmd, &vport->fc_portname, 8);
8867 pcmd += sizeof(uint32_t); /* Node Name */
8868 pcmd += sizeof(uint32_t); /* Node Name */
8869 memcpy(pcmd, &vport->fc_nodename, 8);
Dick Kennedy176de5b2017-08-23 16:55:40 -07008870 sp->cmn.valid_vendor_ver_level = 0;
James Smartaeb3c812017-04-21 16:05:02 -07008871 memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
James Smart92d7f7b2007-06-17 19:56:38 -05008872 lpfc_set_disctmo(vport);
8873
8874 phba->fc_stat.elsXmitFDISC++;
8875 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8876
James Smart858c9f62007-06-17 19:56:39 -05008877 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8878 "Issue FDISC: did:x%x",
8879 did, 0, 0);
8880
James Smart92d7f7b2007-06-17 19:56:38 -05008881 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8882 if (rc == IOCB_ERROR) {
8883 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008884 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008885 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8886 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008887 return 1;
8888 }
8889 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008890 return 0;
8891}
8892
James Smarte59058c2008-08-24 21:49:00 -04008893/**
James Smart3621a712009-04-06 18:47:14 -04008894 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008895 * @phba: pointer to lpfc hba data structure.
8896 * @cmdiocb: pointer to lpfc command iocb data structure.
8897 * @rspiocb: pointer to lpfc response iocb data structure.
8898 *
8899 * This routine is the completion callback function to the issuing of a LOGO
8900 * ELS command off a vport. It frees the command IOCB and then decrement the
8901 * reference count held on ndlp for this completion function, indicating that
8902 * the reference to the ndlp is no long needed. Note that the
8903 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8904 * callback function and an additional explicit ndlp reference decrementation
8905 * will trigger the actual release of the ndlp.
8906 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008907static void
8908lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8909 struct lpfc_iocbq *rspiocb)
8910{
8911 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008912 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008913 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008915
James Smart9589b0622011-04-16 11:03:17 -04008916 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008917 irsp = &rspiocb->iocb;
8918 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8919 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8920 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008921
8922 lpfc_els_free_iocb(phba, cmdiocb);
8923 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008924
8925 /* Trigger the release of the ndlp after logo */
8926 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008927
8928 /* NPIV LOGO completes to NPort <nlp_DID> */
8929 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8930 "2928 NPIV LOGO completes to NPort x%x "
8931 "Data: x%x x%x x%x x%x\n",
8932 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8933 irsp->ulpTimeout, vport->num_disc_nodes);
8934
8935 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8936 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008937 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008938 vport->fc_flag &= ~FC_FABRIC;
8939 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008940 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008941 }
James Smart92d7f7b2007-06-17 19:56:38 -05008942}
8943
James Smarte59058c2008-08-24 21:49:00 -04008944/**
James Smart3621a712009-04-06 18:47:14 -04008945 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008946 * @vport: pointer to a virtual N_Port data structure.
8947 * @ndlp: pointer to a node-list data structure.
8948 *
8949 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8950 *
8951 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8952 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8953 * will be stored into the context1 field of the IOCB for the completion
8954 * callback function to the LOGO ELS command.
8955 *
8956 * Return codes
8957 * 0 - Successfully issued logo off the @vport
8958 * 1 - Failed to issue logo off the @vport
8959 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008960int
8961lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8962{
8963 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8964 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008965 struct lpfc_iocbq *elsiocb;
8966 uint8_t *pcmd;
8967 uint16_t cmdsize;
8968
8969 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8970 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8971 ELS_CMD_LOGO);
8972 if (!elsiocb)
8973 return 1;
8974
James Smart92d7f7b2007-06-17 19:56:38 -05008975 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8976 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8977 pcmd += sizeof(uint32_t);
8978
8979 /* Fill in LOGO payload */
8980 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8981 pcmd += sizeof(uint32_t);
8982 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8983
James Smart858c9f62007-06-17 19:56:39 -05008984 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8985 "Issue LOGO npiv did:x%x flg:x%x",
8986 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8987
James Smart92d7f7b2007-06-17 19:56:38 -05008988 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8989 spin_lock_irq(shost->host_lock);
8990 ndlp->nlp_flag |= NLP_LOGO_SND;
8991 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008992 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8993 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05008994 spin_lock_irq(shost->host_lock);
8995 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8996 spin_unlock_irq(shost->host_lock);
8997 lpfc_els_free_iocb(phba, elsiocb);
8998 return 1;
8999 }
9000 return 0;
9001}
9002
James Smarte59058c2008-08-24 21:49:00 -04009003/**
James Smart3621a712009-04-06 18:47:14 -04009004 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04009005 * @ptr: holder for the timer function associated data.
9006 *
9007 * This routine is invoked by the fabric iocb block timer after
9008 * timeout. It posts the fabric iocb block timeout event by setting the
9009 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9010 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9011 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9012 * posted event WORKER_FABRIC_BLOCK_TMO.
9013 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009014void
Kees Cookf22eb4d2017-09-06 20:24:26 -07009015lpfc_fabric_block_timeout(struct timer_list *t)
James Smart92d7f7b2007-06-17 19:56:38 -05009016{
Kees Cookf22eb4d2017-09-06 20:24:26 -07009017 struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
James Smart92d7f7b2007-06-17 19:56:38 -05009018 unsigned long iflags;
9019 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04009020
James Smart92d7f7b2007-06-17 19:56:38 -05009021 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9022 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9023 if (!tmo_posted)
9024 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9025 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9026
James Smart5e9d9b82008-06-14 22:52:53 -04009027 if (!tmo_posted)
9028 lpfc_worker_wake_up(phba);
9029 return;
James Smart92d7f7b2007-06-17 19:56:38 -05009030}
9031
James Smarte59058c2008-08-24 21:49:00 -04009032/**
James Smart3621a712009-04-06 18:47:14 -04009033 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04009034 * @phba: pointer to lpfc hba data structure.
9035 *
9036 * This routine issues one fabric iocb from the driver internal list to
9037 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9038 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9039 * remove one pending fabric iocb from the driver internal list and invokes
9040 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9041 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009042static void
9043lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9044{
9045 struct lpfc_iocbq *iocb;
9046 unsigned long iflags;
9047 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05009048 IOCB_t *cmd;
9049
9050repeat:
9051 iocb = NULL;
9052 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05009053 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05009054 if (atomic_read(&phba->fabric_iocb_count) == 0) {
9055 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9056 list);
9057 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05009058 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05009059 atomic_inc(&phba->fabric_iocb_count);
9060 }
9061 spin_unlock_irqrestore(&phba->hbalock, iflags);
9062 if (iocb) {
9063 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9064 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9065 iocb->iocb_flag |= LPFC_IO_FABRIC;
9066
James Smart858c9f62007-06-17 19:56:39 -05009067 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9068 "Fabric sched1: ste:x%x",
9069 iocb->vport->port_state, 0, 0);
9070
James Smart3772a992009-05-22 14:50:54 -04009071 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009072
9073 if (ret == IOCB_ERROR) {
9074 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9075 iocb->fabric_iocb_cmpl = NULL;
9076 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9077 cmd = &iocb->iocb;
9078 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9079 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9080 iocb->iocb_cmpl(phba, iocb, iocb);
9081
9082 atomic_dec(&phba->fabric_iocb_count);
9083 goto repeat;
9084 }
9085 }
9086
9087 return;
9088}
9089
James Smarte59058c2008-08-24 21:49:00 -04009090/**
James Smart3621a712009-04-06 18:47:14 -04009091 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009092 * @phba: pointer to lpfc hba data structure.
9093 *
9094 * This routine unblocks the issuing fabric iocb command. The function
9095 * will clear the fabric iocb block bit and then invoke the routine
9096 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9097 * from the driver internal fabric iocb list.
9098 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009099void
9100lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9101{
9102 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9103
9104 lpfc_resume_fabric_iocbs(phba);
9105 return;
9106}
9107
James Smarte59058c2008-08-24 21:49:00 -04009108/**
James Smart3621a712009-04-06 18:47:14 -04009109 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009110 * @phba: pointer to lpfc hba data structure.
9111 *
9112 * This routine blocks the issuing fabric iocb for a specified amount of
9113 * time (currently 100 ms). This is done by set the fabric iocb block bit
9114 * and set up a timeout timer for 100ms. When the block bit is set, no more
9115 * fabric iocb will be issued out of the HBA.
9116 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009117static void
9118lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9119{
9120 int blocked;
9121
9122 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05009123 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05009124 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04009125 mod_timer(&phba->fabric_block_timer,
9126 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05009127
9128 return;
9129}
9130
James Smarte59058c2008-08-24 21:49:00 -04009131/**
James Smart3621a712009-04-06 18:47:14 -04009132 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04009133 * @phba: pointer to lpfc hba data structure.
9134 * @cmdiocb: pointer to lpfc command iocb data structure.
9135 * @rspiocb: pointer to lpfc response iocb data structure.
9136 *
9137 * This routine is the callback function that is put to the fabric iocb's
9138 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9139 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9140 * function first restores and invokes the original iocb's callback function
9141 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9142 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9143 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009144static void
9145lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9146 struct lpfc_iocbq *rspiocb)
9147{
9148 struct ls_rjt stat;
9149
Shyam Sainie01ea5e2016-12-24 16:21:07 +05309150 BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
James Smart92d7f7b2007-06-17 19:56:38 -05009151
9152 switch (rspiocb->iocb.ulpStatus) {
9153 case IOSTAT_NPORT_RJT:
9154 case IOSTAT_FABRIC_RJT:
9155 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9156 lpfc_block_fabric_iocbs(phba);
9157 }
9158 break;
9159
9160 case IOSTAT_NPORT_BSY:
9161 case IOSTAT_FABRIC_BSY:
9162 lpfc_block_fabric_iocbs(phba);
9163 break;
9164
9165 case IOSTAT_LS_RJT:
9166 stat.un.lsRjtError =
9167 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9168 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9169 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9170 lpfc_block_fabric_iocbs(phba);
9171 break;
9172 }
9173
James Smarta0f2d3e2017-02-12 13:52:31 -08009174 BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009175
9176 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9177 cmdiocb->fabric_iocb_cmpl = NULL;
9178 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9179 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9180
9181 atomic_dec(&phba->fabric_iocb_count);
9182 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05009183 /* Post any pending iocbs to HBA */
9184 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009185 }
9186}
9187
James Smarte59058c2008-08-24 21:49:00 -04009188/**
James Smart3621a712009-04-06 18:47:14 -04009189 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04009190 * @phba: pointer to lpfc hba data structure.
9191 * @iocb: pointer to lpfc command iocb data structure.
9192 *
9193 * This routine is used as the top-level API for issuing a fabric iocb command
9194 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9195 * function makes sure that only one fabric bound iocb will be outstanding at
9196 * any given time. As such, this function will first check to see whether there
9197 * is already an outstanding fabric iocb on the wire. If so, it will put the
9198 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9199 * issued later. Otherwise, it will issue the iocb on the wire and update the
9200 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9201 *
9202 * Note, this implementation has a potential sending out fabric IOCBs out of
9203 * order. The problem is caused by the construction of the "ready" boolen does
9204 * not include the condition that the internal fabric IOCB list is empty. As
9205 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9206 * ahead of the fabric IOCBs in the internal list.
9207 *
9208 * Return code
9209 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9210 * IOCB_ERROR - failed to issue fabric iocb
9211 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009212static int
James Smart92d7f7b2007-06-17 19:56:38 -05009213lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9214{
9215 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05009216 int ready;
9217 int ret;
9218
James Smarta0f2d3e2017-02-12 13:52:31 -08009219 BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
James Smart92d7f7b2007-06-17 19:56:38 -05009220
9221 spin_lock_irqsave(&phba->hbalock, iflags);
9222 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9223 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9224
James Smart7f5f3d02008-02-08 18:50:14 -05009225 if (ready)
9226 /* Increment fabric iocb count to hold the position */
9227 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05009228 spin_unlock_irqrestore(&phba->hbalock, iflags);
9229 if (ready) {
9230 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9231 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9232 iocb->iocb_flag |= LPFC_IO_FABRIC;
9233
James Smart858c9f62007-06-17 19:56:39 -05009234 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9235 "Fabric sched2: ste:x%x",
9236 iocb->vport->port_state, 0, 0);
9237
James Smart3772a992009-05-22 14:50:54 -04009238 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05009239
9240 if (ret == IOCB_ERROR) {
9241 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9242 iocb->fabric_iocb_cmpl = NULL;
9243 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9244 atomic_dec(&phba->fabric_iocb_count);
9245 }
9246 } else {
9247 spin_lock_irqsave(&phba->hbalock, iflags);
9248 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9249 spin_unlock_irqrestore(&phba->hbalock, iflags);
9250 ret = IOCB_SUCCESS;
9251 }
9252 return ret;
9253}
9254
James Smarte59058c2008-08-24 21:49:00 -04009255/**
James Smart3621a712009-04-06 18:47:14 -04009256 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009257 * @vport: pointer to a virtual N_Port data structure.
9258 *
9259 * This routine aborts all the IOCBs associated with a @vport from the
9260 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9261 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9262 * list, removes each IOCB associated with the @vport off the list, set the
9263 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9264 * associated with the IOCB.
9265 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01009266static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05009267{
9268 LIST_HEAD(completions);
9269 struct lpfc_hba *phba = vport->phba;
9270 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05009271
9272 spin_lock_irq(&phba->hbalock);
9273 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9274 list) {
9275
9276 if (piocb->vport != vport)
9277 continue;
9278
9279 list_move_tail(&piocb->list, &completions);
9280 }
9281 spin_unlock_irq(&phba->hbalock);
9282
James Smarta257bf92009-04-06 18:48:10 -04009283 /* Cancel all the IOCBs from the completions list */
9284 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9285 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009286}
9287
James Smarte59058c2008-08-24 21:49:00 -04009288/**
James Smart3621a712009-04-06 18:47:14 -04009289 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009290 * @ndlp: pointer to a node-list data structure.
9291 *
9292 * This routine aborts all the IOCBs associated with an @ndlp from the
9293 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9294 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9295 * list, removes each IOCB associated with the @ndlp off the list, set the
9296 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9297 * associated with the IOCB.
9298 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009299void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9300{
9301 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04009302 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009303 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart895427b2017-02-12 13:52:30 -08009304 struct lpfc_sli_ring *pring;
9305
9306 pring = lpfc_phba_elsring(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05009307
Dick Kennedy1234a6d2017-09-29 17:34:29 -07009308 if (unlikely(!pring))
9309 return;
9310
James Smart92d7f7b2007-06-17 19:56:38 -05009311 spin_lock_irq(&phba->hbalock);
9312 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9313 list) {
9314 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9315
9316 list_move_tail(&piocb->list, &completions);
9317 }
9318 }
9319 spin_unlock_irq(&phba->hbalock);
9320
James Smarta257bf92009-04-06 18:48:10 -04009321 /* Cancel all the IOCBs from the completions list */
9322 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9323 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009324}
9325
James Smarte59058c2008-08-24 21:49:00 -04009326/**
James Smart3621a712009-04-06 18:47:14 -04009327 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009328 * @phba: pointer to lpfc hba data structure.
9329 *
9330 * This routine aborts all the IOCBs currently on the driver internal
9331 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9332 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9333 * list, removes IOCBs off the list, set the status feild to
9334 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9335 * the IOCB.
9336 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009337void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9338{
9339 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009340
9341 spin_lock_irq(&phba->hbalock);
9342 list_splice_init(&phba->fabric_iocb_list, &completions);
9343 spin_unlock_irq(&phba->hbalock);
9344
James Smarta257bf92009-04-06 18:48:10 -04009345 /* Cancel all the IOCBs from the completions list */
9346 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9347 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009348}
James Smart6fb120a2009-05-22 14:52:59 -04009349
9350/**
James Smart1151e3e2011-02-16 12:39:35 -05009351 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9352 * @vport: pointer to lpfc vport data structure.
9353 *
9354 * This routine is invoked by the vport cleanup for deletions and the cleanup
9355 * for an ndlp on removal.
9356 **/
9357void
9358lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9359{
9360 struct lpfc_hba *phba = vport->phba;
9361 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9362 unsigned long iflag = 0;
9363
9364 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -08009365 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -05009366 list_for_each_entry_safe(sglq_entry, sglq_next,
9367 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9368 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9369 sglq_entry->ndlp = NULL;
9370 }
James Smart895427b2017-02-12 13:52:30 -08009371 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart1151e3e2011-02-16 12:39:35 -05009372 spin_unlock_irqrestore(&phba->hbalock, iflag);
9373 return;
9374}
9375
9376/**
James Smart6fb120a2009-05-22 14:52:59 -04009377 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9378 * @phba: pointer to lpfc hba data structure.
9379 * @axri: pointer to the els xri abort wcqe structure.
9380 *
9381 * This routine is invoked by the worker thread to process a SLI4 slow-path
9382 * ELS aborted xri.
9383 **/
9384void
9385lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9386 struct sli4_wcqe_xri_aborted *axri)
9387{
9388 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05009389 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04009390 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05009391
James Smart6fb120a2009-05-22 14:52:59 -04009392 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9393 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05009394 struct lpfc_nodelist *ndlp;
James Smart895427b2017-02-12 13:52:30 -08009395 struct lpfc_sli_ring *pring;
9396
9397 pring = lpfc_phba_elsring(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009398
James Smart0f65ff62010-02-26 14:14:23 -05009399 spin_lock_irqsave(&phba->hbalock, iflag);
James Smart895427b2017-02-12 13:52:30 -08009400 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009401 list_for_each_entry_safe(sglq_entry, sglq_next,
9402 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9403 if (sglq_entry->sli4_xritag == xri) {
9404 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05009405 ndlp = sglq_entry->ndlp;
9406 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04009407 list_add_tail(&sglq_entry->list,
James Smart895427b2017-02-12 13:52:30 -08009408 &phba->sli4_hba.lpfc_els_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05009409 sglq_entry->state = SGL_FREED;
James Smart895427b2017-02-12 13:52:30 -08009410 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009411 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04009412 lpfc_set_rrq_active(phba, ndlp,
9413 sglq_entry->sli4_lxritag,
9414 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04009415
9416 /* Check if TXQ queue needs to be serviced */
Dick Kennedy1234a6d2017-09-29 17:34:29 -07009417 if (pring && !list_empty(&pring->txq))
James Smart589a52d2010-07-14 15:30:54 -04009418 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009419 return;
9420 }
9421 }
James Smart895427b2017-02-12 13:52:30 -08009422 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009423 lxri = lpfc_sli4_xri_inrange(phba, xri);
9424 if (lxri == NO_XRI) {
9425 spin_unlock_irqrestore(&phba->hbalock, iflag);
9426 return;
9427 }
James Smart895427b2017-02-12 13:52:30 -08009428 spin_lock(&phba->sli4_hba.sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009429 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05009430 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smart895427b2017-02-12 13:52:30 -08009431 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009432 spin_unlock_irqrestore(&phba->hbalock, iflag);
9433 return;
9434 }
9435 sglq_entry->state = SGL_XRI_ABORTED;
James Smart895427b2017-02-12 13:52:30 -08009436 spin_unlock(&phba->sli4_hba.sgl_list_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009437 spin_unlock_irqrestore(&phba->hbalock, iflag);
9438 return;
James Smart6fb120a2009-05-22 14:52:59 -04009439}
James Smart086a3452012-08-14 14:25:21 -04009440
9441/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9442 * @vport: pointer to virtual port object.
9443 * @ndlp: nodelist pointer for the impacted node.
9444 *
9445 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9446 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9447 * the driver is required to send a LOGO to the remote node before it
9448 * attempts to recover its login to the remote node.
9449 */
9450void
9451lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9452 struct lpfc_nodelist *ndlp)
9453{
9454 struct Scsi_Host *shost;
9455 struct lpfc_hba *phba;
9456 unsigned long flags = 0;
9457
9458 shost = lpfc_shost_from_vport(vport);
9459 phba = vport->phba;
9460 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9461 lpfc_printf_log(phba, KERN_INFO,
9462 LOG_SLI, "3093 No rport recovery needed. "
9463 "rport in state 0x%x\n", ndlp->nlp_state);
9464 return;
9465 }
9466 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9467 "3094 Start rport recovery on shost id 0x%x "
9468 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9469 "flags 0x%x\n",
9470 shost->host_no, ndlp->nlp_DID,
9471 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9472 ndlp->nlp_flag);
9473 /*
9474 * The rport is not responding. Remove the FCP-2 flag to prevent
9475 * an ADISC in the follow-up recovery code.
9476 */
9477 spin_lock_irqsave(shost->host_lock, flags);
9478 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9479 spin_unlock_irqrestore(shost->host_lock, flags);
9480 lpfc_issue_els_logo(vport, ndlp, 0);
9481 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
9482}
9483