blob: b5be4df05733fcc9d549f9af707fbb7a23564473 [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 Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smarte74c03c2013-04-17 20:15:19 -040032
James Smartda0436e2009-05-22 14:51:39 -040033#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_hw.h"
35#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040037#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050044#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050045
46static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
47 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050048static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
49 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010050static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
51static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp, uint8_t retry);
53static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
54 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050055
dea31012005-04-17 16:05:31 -050056static int lpfc_max_els_tries = 3;
57
James Smarte59058c2008-08-24 21:49:00 -040058/**
James Smart3621a712009-04-06 18:47:14 -040059 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040060 * @vport: pointer to a host virtual N_Port data structure.
61 *
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
69 * had happened.
70 *
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
75 *
76 * Return codes
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
79 **/
James Smart858c9f62007-06-17 19:56:39 -050080int
James Smart2e0fef82007-06-17 19:56:36 -050081lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050082{
James Smart2e0fef82007-06-17 19:56:36 -050083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
84 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050085 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050086
James Smart2e0fef82007-06-17 19:56:36 -050087 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040088 phba->link_state == LPFC_LINK_DOWN ||
89 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050090 return 0;
91
92 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050093 if (lpfc_readl(phba->HAregaddr, &ha_copy))
94 return 1;
dea31012005-04-17 16:05:31 -050095
96 if (!(ha_copy & HA_LATT))
97 return 0;
98
99 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500104
105 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300106 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
109 * events.
110 */
James Smart2e0fef82007-06-17 19:56:36 -0500111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500114
James Smart92d7f7b2007-06-17 19:56:38 -0500115 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500117
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500118 return 1;
dea31012005-04-17 16:05:31 -0500119}
120
James Smarte59058c2008-08-24 21:49:00 -0400121/**
James Smart3621a712009-04-06 18:47:14 -0400122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
130 *
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
144 *
145 * Return code
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
148 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400149struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500150lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
153 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500154{
James Smart2e0fef82007-06-17 19:56:36 -0500155 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400156 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
159 IOCB_t *icmd;
160
dea31012005-04-17 16:05:31 -0500161
James Smart2e0fef82007-06-17 19:56:36 -0500162 if (!lpfc_is_link_up(phba))
163 return NULL;
dea31012005-04-17 16:05:31 -0500164
dea31012005-04-17 16:05:31 -0500165 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400166 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500167
168 if (elsiocb == NULL)
169 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500170
James Smart0c287582009-06-10 17:22:56 -0400171 /*
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
174 */
175 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400176 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400177 ((elscmd == ELS_CMD_FLOGI) ||
178 (elscmd == ELS_CMD_FDISC) ||
179 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500180 switch (elscmd) {
181 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400182 elsiocb->iocb_flag |=
183 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500184 & LPFC_FIP_ELS_ID_MASK);
185 break;
186 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400187 elsiocb->iocb_flag |=
188 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400192 elsiocb->iocb_flag |=
193 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500194 & LPFC_FIP_ELS_ID_MASK);
195 break;
196 }
James Smart0c287582009-06-10 17:22:56 -0400197 else
James Smartc8685952009-11-18 15:39:16 -0500198 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400199
dea31012005-04-17 16:05:31 -0500200 icmd = &elsiocb->iocb;
201
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400204 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
205 if (pcmd)
206 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500207 if (!pcmd || !pcmd->virt)
208 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500209
210 INIT_LIST_HEAD(&pcmd->list);
211
212 /* Allocate buffer for response payload */
213 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500214 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500215 if (prsp)
216 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
217 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500218 if (!prsp || !prsp->virt)
219 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500220 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500221 } else
dea31012005-04-17 16:05:31 -0500222 prsp = NULL;
dea31012005-04-17 16:05:31 -0500223
224 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500225 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500226 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500227 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
228 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500229 if (!pbuflist || !pbuflist->virt)
230 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500231
232 INIT_LIST_HEAD(&pbuflist->list);
233
dea31012005-04-17 16:05:31 -0500234 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400235 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
236 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
237 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400239
240 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500241 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400242 if (elscmd == ELS_CMD_FLOGI)
243 icmd->ulpTimeout = FF_DEF_RATOV * 2;
244 else
245 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500246 } else {
James Smart939723a2012-05-09 21:19:03 -0400247 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
248 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
249 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
250 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
251 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500252 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
253 }
dea31012005-04-17 16:05:31 -0500254 icmd->ulpBdeCount = 1;
255 icmd->ulpLe = 1;
256 icmd->ulpClass = CLASS3;
257
James Smart939723a2012-05-09 21:19:03 -0400258 /*
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
262 */
263 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
264 ((phba->sli_rev == LPFC_SLI_REV4) &&
265 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500266
James Smart939723a2012-05-09 21:19:03 -0400267 if (expectRsp) {
268 icmd->un.elsreq64.myID = vport->fc_myDID;
269
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd->ulpContext = phba->vpi_ids[vport->vpi];
272 }
273
James Smart92d7f7b2007-06-17 19:56:38 -0500274 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd == ELS_CMD_ECHO)
277 icmd->ulpCt_l = 0; /* context = invalid RPI */
278 else
279 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500280 }
281
dea31012005-04-17 16:05:31 -0500282 bpl = (struct ulp_bde64 *) pbuflist->virt;
283 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
284 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
285 bpl->tus.f.bdeSize = cmdSize;
286 bpl->tus.f.bdeFlags = 0;
287 bpl->tus.w = le32_to_cpu(bpl->tus.w);
288
289 if (expectRsp) {
290 bpl++;
291 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
292 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
293 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400294 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500295 bpl->tus.w = le32_to_cpu(bpl->tus.w);
296 }
297
James Smartfa4066b2008-01-11 01:53:27 -0500298 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400299 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500300 if (!elsiocb->context1)
301 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400302 elsiocb->context2 = pcmd;
303 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500304 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500305 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500306 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
307
308 if (prsp) {
309 list_add(&prsp->list, &pcmd->list);
310 }
dea31012005-04-17 16:05:31 -0500311 if (expectRsp) {
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400313 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
314 "0116 Xmit ELS command x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400315 "NPORT x%x I/O tag: x%x, port state:x%x"
316 " fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400317 elscmd, did, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400318 vport->port_state,
319 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500320 } else {
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
323 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400326 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400327 cmdSize, vport->port_state,
328 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500329 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500330 return elsiocb;
dea31012005-04-17 16:05:31 -0500331
James Smartfa4066b2008-01-11 01:53:27 -0500332els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500333 if (expectRsp)
334 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500335 kfree(pbuflist);
336
337els_iocb_free_prsp_exit:
338 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
339 kfree(prsp);
340
341els_iocb_free_pcmb_exit:
342 kfree(pcmd);
343 lpfc_sli_release_iocbq(phba, elsiocb);
344 return NULL;
345}
dea31012005-04-17 16:05:31 -0500346
James Smarte59058c2008-08-24 21:49:00 -0400347/**
James Smart3621a712009-04-06 18:47:14 -0400348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400349 * @vport: pointer to a host virtual N_Port data structure.
350 *
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
357 * with the @vport.
358 *
359 * Return code
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
362 **/
James Smart3772a992009-05-22 14:50:54 -0400363int
James Smart92d7f7b2007-06-17 19:56:38 -0500364lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
365{
366 struct lpfc_hba *phba = vport->phba;
367 LPFC_MBOXQ_t *mbox;
368 struct lpfc_dmabuf *mp;
369 struct lpfc_nodelist *ndlp;
370 struct serv_parm *sp;
371 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400372 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 sp = &phba->fc_fabparam;
375 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500376 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400377 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400382 if (!mbox) {
383 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500384 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400385 }
James Smart92d7f7b2007-06-17 19:56:38 -0500386
387 vport->port_state = LPFC_FABRIC_CFG_LINK;
388 lpfc_config_link(phba, mbox);
389 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
390 mbox->vport = vport;
391
James Smart0b727fe2007-10-27 13:37:25 -0400392 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400393 if (rc == MBX_NOT_FINISHED) {
394 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500395 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400396 }
James Smart92d7f7b2007-06-17 19:56:38 -0500397
398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400399 if (!mbox) {
400 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500401 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400402 }
James Smart40426292010-12-15 17:58:10 -0500403 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
404 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400405 if (rc) {
406 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500407 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400408 }
James Smart92d7f7b2007-06-17 19:56:38 -0500409
410 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
411 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
414 */
James Smart92d7f7b2007-06-17 19:56:38 -0500415 mbox->context2 = lpfc_nlp_get(ndlp);
416
James Smart0b727fe2007-10-27 13:37:25 -0400417 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400418 if (rc == MBX_NOT_FINISHED) {
419 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500420 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400421 }
James Smart92d7f7b2007-06-17 19:56:38 -0500422
423 return 0;
424
425fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
428 */
James Smart92d7f7b2007-06-17 19:56:38 -0500429 lpfc_nlp_put(ndlp);
430 mp = (struct lpfc_dmabuf *) mbox->context1;
431 lpfc_mbuf_free(phba, mp->virt, mp->phys);
432 kfree(mp);
433fail_free_mbox:
434 mempool_free(mbox, phba->mbox_mem_pool);
435
436fail:
437 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400439 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500440 return -ENXIO;
441}
442
James Smarte59058c2008-08-24 21:49:00 -0400443/**
James Smart6fb120a2009-05-22 14:52:59 -0400444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
446 *
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500448 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400449 *
450 * Return code
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
453 **/
James Smart1b511972011-12-13 13:23:09 -0500454int
James Smart6fb120a2009-05-22 14:52:59 -0400455lpfc_issue_reg_vfi(struct lpfc_vport *vport)
456{
457 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500458 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400459 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500460 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400461 int rc = 0;
462
James Smart939723a2012-05-09 21:19:03 -0400463 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500464 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400465 !(phba->link_flag & LS_LOOPBACK_MODE) &&
466 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500467 ndlp = lpfc_findnode_did(vport, Fabric_DID);
468 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
469 rc = -ENODEV;
470 goto fail;
471 }
James Smart6fb120a2009-05-22 14:52:59 -0400472 }
473
James Smart6fb120a2009-05-22 14:52:59 -0400474 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
475 if (!mboxq) {
476 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500477 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400478 }
James Smartd6de08c2015-12-16 18:11:53 -0500479
480 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
481 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
482 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
483 if (!dmabuf) {
484 rc = -ENOMEM;
485 goto fail;
486 }
487 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
488 if (!dmabuf->virt) {
489 rc = -ENOMEM;
490 goto fail;
491 }
492 memcpy(dmabuf->virt, &phba->fc_fabparam,
493 sizeof(struct serv_parm));
494 }
495
James Smart6fb120a2009-05-22 14:52:59 -0400496 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500497 if (dmabuf)
498 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
499 else
500 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500501
James Smart6fb120a2009-05-22 14:52:59 -0400502 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
503 mboxq->vport = vport;
504 mboxq->context1 = dmabuf;
505 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
506 if (rc == MBX_NOT_FINISHED) {
507 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500508 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400509 }
510 return 0;
511
James Smart6fb120a2009-05-22 14:52:59 -0400512fail:
James Smartd6de08c2015-12-16 18:11:53 -0500513 if (mboxq)
514 mempool_free(mboxq, phba->mbox_mem_pool);
515 if (dmabuf) {
516 if (dmabuf->virt)
517 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
518 kfree(dmabuf);
519 }
520
James Smart6fb120a2009-05-22 14:52:59 -0400521 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
522 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
523 "0289 Issue Register VFI failed: Err %d\n", rc);
524 return rc;
525}
526
527/**
James Smart1b511972011-12-13 13:23:09 -0500528 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
529 * @vport: pointer to a host virtual N_Port data structure.
530 *
531 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
532 * the @vport. This mailbox command is necessary for SLI4 port only.
533 *
534 * Return code
535 * 0 - successfully issued REG_VFI for @vport
536 * A failure code otherwise.
537 **/
538int
539lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
540{
541 struct lpfc_hba *phba = vport->phba;
542 struct Scsi_Host *shost;
543 LPFC_MBOXQ_t *mboxq;
544 int rc;
545
546 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
547 if (!mboxq) {
548 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
549 "2556 UNREG_VFI mbox allocation failed"
550 "HBA state x%x\n", phba->pport->port_state);
551 return -ENOMEM;
552 }
553
554 lpfc_unreg_vfi(mboxq, vport);
555 mboxq->vport = vport;
556 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
557
558 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
559 if (rc == MBX_NOT_FINISHED) {
560 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
561 "2557 UNREG_VFI issue mbox failed rc x%x "
562 "HBA state x%x\n",
563 rc, phba->pport->port_state);
564 mempool_free(mboxq, phba->mbox_mem_pool);
565 return -EIO;
566 }
567
568 shost = lpfc_shost_from_vport(vport);
569 spin_lock_irq(shost->host_lock);
570 vport->fc_flag &= ~FC_VFI_REGISTERED;
571 spin_unlock_irq(shost->host_lock);
572 return 0;
573}
574
575/**
James Smart92494142011-02-16 12:39:44 -0500576 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
577 * @vport: pointer to a host virtual N_Port data structure.
578 * @sp: pointer to service parameter data structure.
579 *
580 * This routine is called from FLOGI/FDISC completion handler functions.
581 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
582 * node nodename is changed in the completion service parameter else return
583 * 0. This function also set flag in the vport data structure to delay
584 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
585 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
586 * node nodename is changed in the completion service parameter.
587 *
588 * Return code
589 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
590 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
591 *
592 **/
593static uint8_t
594lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
595 struct serv_parm *sp)
596{
James Smart8eb8b962016-07-06 12:36:08 -0700597 struct lpfc_hba *phba = vport->phba;
James Smart92494142011-02-16 12:39:44 -0500598 uint8_t fabric_param_changed = 0;
599 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
600
601 if ((vport->fc_prevDID != vport->fc_myDID) ||
602 memcmp(&vport->fabric_portname, &sp->portName,
603 sizeof(struct lpfc_name)) ||
604 memcmp(&vport->fabric_nodename, &sp->nodeName,
605 sizeof(struct lpfc_name)))
606 fabric_param_changed = 1;
607
608 /*
609 * Word 1 Bit 31 in common service parameter is overloaded.
610 * Word 1 Bit 31 in FLOGI request is multiple NPort request
611 * Word 1 Bit 31 in FLOGI response is clean address bit
612 *
613 * If fabric parameter is changed and clean address bit is
614 * cleared delay nport discovery if
615 * - vport->fc_prevDID != 0 (not initial discovery) OR
616 * - lpfc_delay_discovery module parameter is set.
617 */
618 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
James Smart8eb8b962016-07-06 12:36:08 -0700619 (vport->fc_prevDID || phba->cfg_delay_discovery)) {
James Smart92494142011-02-16 12:39:44 -0500620 spin_lock_irq(shost->host_lock);
621 vport->fc_flag |= FC_DISC_DELAYED;
622 spin_unlock_irq(shost->host_lock);
623 }
624
625 return fabric_param_changed;
626}
627
628
629/**
James Smart3621a712009-04-06 18:47:14 -0400630 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400631 * @vport: pointer to a host virtual N_Port data structure.
632 * @ndlp: pointer to a node-list data structure.
633 * @sp: pointer to service parameter data structure.
634 * @irsp: pointer to the IOCB within the lpfc response IOCB.
635 *
636 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
637 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
638 * port in a fabric topology. It properly sets up the parameters to the @ndlp
639 * from the IOCB response. It also check the newly assigned N_Port ID to the
640 * @vport against the previously assigned N_Port ID. If it is different from
641 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
642 * is invoked on all the remaining nodes with the @vport to unregister the
643 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
644 * is invoked to register login to the fabric.
645 *
646 * Return code
647 * 0 - Success (currently, always return 0)
648 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500649static int
James Smart2e0fef82007-06-17 19:56:36 -0500650lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
651 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500652{
James Smart2e0fef82007-06-17 19:56:36 -0500653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
654 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500655 struct lpfc_nodelist *np;
656 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500657 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500658
James Smart2e0fef82007-06-17 19:56:36 -0500659 spin_lock_irq(shost->host_lock);
660 vport->fc_flag |= FC_FABRIC;
661 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500662
663 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
664 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
665 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
666
James Smart12265f62010-10-22 11:05:53 -0400667 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500668 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
669
James Smart76a95d72010-11-20 23:11:48 -0500670 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500671 spin_lock_irq(shost->host_lock);
672 vport->fc_flag |= FC_PUBLIC_LOOP;
673 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500674 }
675
James Smart2e0fef82007-06-17 19:56:36 -0500676 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500677 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500678 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500679 ndlp->nlp_class_sup = 0;
680 if (sp->cls1.classValid)
681 ndlp->nlp_class_sup |= FC_COS_CLASS1;
682 if (sp->cls2.classValid)
683 ndlp->nlp_class_sup |= FC_COS_CLASS2;
684 if (sp->cls3.classValid)
685 ndlp->nlp_class_sup |= FC_COS_CLASS3;
686 if (sp->cls4.classValid)
687 ndlp->nlp_class_sup |= FC_COS_CLASS4;
688 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
689 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500690
691 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500692 if (fabric_param_changed) {
693 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700694 if (phba->cfg_enable_SmartSAN ||
695 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500696 /* Setup appropriate attribute masks */
697 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700698 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500699 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
700 else
701 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700702 } else {
703 vport->fdmi_hba_mask = 0;
704 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500705 }
706
707 }
James Smart92494142011-02-16 12:39:44 -0500708 memcpy(&vport->fabric_portname, &sp->portName,
709 sizeof(struct lpfc_name));
710 memcpy(&vport->fabric_nodename, &sp->nodeName,
711 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500712 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
713
James Smart92d7f7b2007-06-17 19:56:38 -0500714 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
715 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400716 lpfc_printf_vlog(vport, KERN_WARNING,
717 LOG_ELS | LOG_VPORT,
718 "1816 FLOGI NPIV supported, "
719 "response data 0x%x\n",
720 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500721 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500722 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500723 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500724 } else {
725 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400726 to call reg_vnpid atleast for the physcial host */
727 lpfc_printf_vlog(vport, KERN_WARNING,
728 LOG_ELS | LOG_VPORT,
729 "1817 Fabric does not support NPIV "
730 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500731 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500732 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500733 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500734 }
735 }
736
James Smartae05ebe2013-03-01 16:35:38 -0500737 /*
738 * For FC we need to do some special processing because of the SLI
739 * Port's default settings of the Common Service Parameters.
740 */
James Smartd6de08c2015-12-16 18:11:53 -0500741 if ((phba->sli_rev == LPFC_SLI_REV4) &&
742 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500743 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500744 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500745 lpfc_unregister_fcf_prep(phba);
746
747 /* This should just update the VFI CSPs*/
748 if (vport->fc_flag & FC_VFI_REGISTERED)
749 lpfc_issue_reg_vfi(vport);
750 }
751
James Smart92494142011-02-16 12:39:44 -0500752 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500753 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
754
755 /* If our NportID changed, we need to ensure all
756 * remaining NPORTs get unreg_login'ed.
757 */
758 list_for_each_entry_safe(np, next_np,
759 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400760 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500761 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500762 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
763 !(np->nlp_flag & NLP_NPR_ADISC))
764 continue;
765 spin_lock_irq(shost->host_lock);
766 np->nlp_flag &= ~NLP_NPR_ADISC;
767 spin_unlock_irq(shost->host_lock);
768 lpfc_unreg_rpi(vport, np);
769 }
James Smart78730cf2010-04-06 15:06:30 -0400770 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400771
James Smart5248a742011-07-22 18:37:06 -0400772 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400773 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500774 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500775 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500776 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
777 spin_unlock_irq(shost->host_lock);
778 }
James Smart27aa1b72012-05-09 21:18:49 -0400779
780 /*
781 * For SLI3 and SLI4, the VPI needs to be reregistered in
782 * response to this fabric parameter change event.
783 */
784 spin_lock_irq(shost->host_lock);
785 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
786 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400787 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
788 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
789 /*
790 * Driver needs to re-reg VPI in order for f/w
791 * to update the MAC address.
792 */
James Smart9589b0622011-04-16 11:03:17 -0400793 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400794 lpfc_register_new_vport(phba, vport, ndlp);
795 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500796 }
797
James Smart6fb120a2009-05-22 14:52:59 -0400798 if (phba->sli_rev < LPFC_SLI_REV4) {
799 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
800 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
801 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
802 lpfc_register_new_vport(phba, vport, ndlp);
803 else
804 lpfc_issue_fabric_reglogin(vport);
805 } else {
806 ndlp->nlp_type |= NLP_FABRIC;
807 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500808 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
809 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400810 lpfc_start_fdiscs(phba);
811 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500812 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500813 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500814 else {
815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
816 "3135 Need register VFI: (x%x/%x)\n",
817 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400818 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500819 }
James Smart92d7f7b2007-06-17 19:56:38 -0500820 }
dea31012005-04-17 16:05:31 -0500821 return 0;
dea31012005-04-17 16:05:31 -0500822}
James Smart1b511972011-12-13 13:23:09 -0500823
James Smarte59058c2008-08-24 21:49:00 -0400824/**
James Smart3621a712009-04-06 18:47:14 -0400825 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400826 * @vport: pointer to a host virtual N_Port data structure.
827 * @ndlp: pointer to a node-list data structure.
828 * @sp: pointer to service parameter data structure.
829 *
830 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
831 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
832 * in a point-to-point topology. First, the @vport's N_Port Name is compared
833 * with the received N_Port Name: if the @vport's N_Port Name is greater than
834 * the received N_Port Name lexicographically, this node shall assign local
835 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
836 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
837 * this node shall just wait for the remote node to issue PLOGI and assign
838 * N_Port IDs.
839 *
840 * Return code
841 * 0 - Success
842 * -ENXIO - Fail
843 **/
dea31012005-04-17 16:05:31 -0500844static int
James Smart2e0fef82007-06-17 19:56:36 -0500845lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
846 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500847{
James Smart2e0fef82007-06-17 19:56:36 -0500848 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
849 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500850 LPFC_MBOXQ_t *mbox;
851 int rc;
852
James Smart2e0fef82007-06-17 19:56:36 -0500853 spin_lock_irq(shost->host_lock);
854 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500855 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500856 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500857
James Smartd6de08c2015-12-16 18:11:53 -0500858 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
859 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
860 lpfc_unregister_fcf_prep(phba);
861
862 spin_lock_irq(shost->host_lock);
863 vport->fc_flag &= ~FC_VFI_REGISTERED;
864 spin_unlock_irq(shost->host_lock);
865 phba->fc_topology_changed = 0;
866 }
867
James Smart2e0fef82007-06-17 19:56:36 -0500868 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500869 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400870
dea31012005-04-17 16:05:31 -0500871 if (rc >= 0) {
872 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500873 spin_lock_irq(shost->host_lock);
874 vport->fc_flag |= FC_PT2PT_PLOGI;
875 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500876
877 /*
James Smartd6de08c2015-12-16 18:11:53 -0500878 * N_Port ID cannot be 0, set our Id to LocalID
879 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500880 */
881
882 /* not equal */
883 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500884 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500885
James Smarte47c9092008-02-08 18:49:26 -0500886 /* Decrement ndlp reference count indicating that ndlp can be
887 * safely released when other references to it are done.
888 */
James Smart329f9bc2007-04-25 09:53:01 -0400889 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500890
James Smart2e0fef82007-06-17 19:56:36 -0500891 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500892 if (!ndlp) {
893 /*
894 * Cannot find existing Fabric ndlp, so allocate a
895 * new one
896 */
897 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
898 if (!ndlp)
899 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500900 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500901 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
902 ndlp = lpfc_enable_node(vport, ndlp,
903 NLP_STE_UNUSED_NODE);
904 if(!ndlp)
905 goto fail;
dea31012005-04-17 16:05:31 -0500906 }
907
908 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500909 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500910 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500911 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500912 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500913 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
914 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500915 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500916 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500917 } else
918 /* This side will wait for the PLOGI, decrement ndlp reference
919 * count indicating that ndlp can be released when other
920 * references to it are done.
921 */
James Smart329f9bc2007-04-25 09:53:01 -0400922 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500923
James Smart09372822008-01-11 01:52:54 -0500924 /* If we are pt2pt with another NPort, force NPIV off! */
925 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
926
James Smartd6de08c2015-12-16 18:11:53 -0500927 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
928 if (!mbox)
929 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400930
James Smartd6de08c2015-12-16 18:11:53 -0500931 lpfc_config_link(phba, mbox);
932
933 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
934 mbox->vport = vport;
935 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
936 if (rc == MBX_NOT_FINISHED) {
937 mempool_free(mbox, phba->mbox_mem_pool);
938 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400939 }
dea31012005-04-17 16:05:31 -0500940
dea31012005-04-17 16:05:31 -0500941 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500942fail:
dea31012005-04-17 16:05:31 -0500943 return -ENXIO;
944}
945
James Smarte59058c2008-08-24 21:49:00 -0400946/**
James Smart3621a712009-04-06 18:47:14 -0400947 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400948 * @phba: pointer to lpfc hba data structure.
949 * @cmdiocb: pointer to lpfc command iocb data structure.
950 * @rspiocb: pointer to lpfc response iocb data structure.
951 *
952 * This routine is the top-level completion callback function for issuing
953 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
954 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
955 * retry has been made (either immediately or delayed with lpfc_els_retry()
956 * returning 1), the command IOCB will be released and function returned.
957 * If the retry attempt has been given up (possibly reach the maximum
958 * number of retries), one additional decrement of ndlp reference shall be
959 * invoked before going out after releasing the command IOCB. This will
960 * actually release the remote node (Note, lpfc_els_free_iocb() will also
961 * invoke one decrement of ndlp reference count). If no error reported in
962 * the IOCB status, the command Port ID field is used to determine whether
963 * this is a point-to-point topology or a fabric topology: if the Port ID
964 * field is assigned, it is a fabric topology; otherwise, it is a
965 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
966 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
967 * specific topology completion conditions.
968 **/
dea31012005-04-17 16:05:31 -0500969static void
James Smart329f9bc2007-04-25 09:53:01 -0400970lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
971 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500972{
James Smart2e0fef82007-06-17 19:56:36 -0500973 struct lpfc_vport *vport = cmdiocb->vport;
974 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500975 IOCB_t *irsp = &rspiocb->iocb;
976 struct lpfc_nodelist *ndlp = cmdiocb->context1;
977 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
978 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500979 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500980 int rc;
981
982 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500983 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500984 /* One additional decrement on node reference count to
985 * trigger the release of the node
986 */
James Smart329f9bc2007-04-25 09:53:01 -0400987 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500988 goto out;
989 }
990
James Smart858c9f62007-06-17 19:56:39 -0500991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
992 "FLOGI cmpl: status:x%x/x%x state:x%x",
993 irsp->ulpStatus, irsp->un.ulpWord[4],
994 vport->port_state);
995
dea31012005-04-17 16:05:31 -0500996 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500997 /*
James Smarta93ff372010-10-22 11:06:08 -0400998 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500999 * due to new FCF discovery
1000 */
1001 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001002 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1003 if (phba->link_state < LPFC_LINK_UP)
1004 goto stop_rr_fcf_flogi;
1005 if ((phba->fcoe_cvl_eventtag_attn ==
1006 phba->fcoe_cvl_eventtag) &&
1007 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001008 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1009 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001010 goto stop_rr_fcf_flogi;
1011 else
1012 phba->fcoe_cvl_eventtag_attn =
1013 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001014 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001015 "2611 FLOGI failed on FCF (x%x), "
1016 "status:x%x/x%x, tmo:x%x, perform "
1017 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001018 phba->fcf.current_rec.fcf_indx,
1019 irsp->ulpStatus, irsp->un.ulpWord[4],
1020 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001021 lpfc_sli4_set_fcf_flogi_fail(phba,
1022 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001023 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001024 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1025 if (rc)
1026 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001027 }
1028
James Smart80c17842012-03-01 22:35:45 -05001029stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001030 /* FLOGI failure */
1031 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart8fe5c162015-08-31 16:48:19 -04001032 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1033 "Data x%x x%x\n",
James Smart38b92ef2010-08-04 16:11:39 -04001034 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart8fe5c162015-08-31 16:48:19 -04001035 irsp->ulpTimeout, phba->hba_flag,
1036 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001037
dea31012005-04-17 16:05:31 -05001038 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001039 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001040 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001041
James Smart76a95d72010-11-20 23:11:48 -05001042 /* FLOGI failure */
1043 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1044 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1045 irsp->ulpStatus, irsp->un.ulpWord[4],
1046 irsp->ulpTimeout);
1047
dea31012005-04-17 16:05:31 -05001048 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001049 spin_lock_irq(shost->host_lock);
1050 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1051 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001052
James Smart329f9bc2007-04-25 09:53:01 -04001053 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001054 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1055 * alpa map would take too long otherwise.
1056 */
James Smart1b511972011-12-13 13:23:09 -05001057 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001058 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001059 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1060 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001061 (vport->fc_prevDID != vport->fc_myDID) ||
1062 phba->fc_topology_changed)) {
1063 if (vport->fc_flag & FC_VFI_REGISTERED) {
1064 if (phba->fc_topology_changed) {
1065 lpfc_unregister_fcf_prep(phba);
1066 spin_lock_irq(shost->host_lock);
1067 vport->fc_flag &= ~FC_VFI_REGISTERED;
1068 spin_unlock_irq(shost->host_lock);
1069 phba->fc_topology_changed = 0;
1070 } else {
1071 lpfc_sli4_unreg_all_rpis(vport);
1072 }
1073 }
James Smart342b59c2016-03-31 14:12:31 -07001074
1075 /* Do not register VFI if the driver aborted FLOGI */
1076 if (!lpfc_error_lost_link(irsp))
1077 lpfc_issue_reg_vfi(vport);
James Smartff78d8f2011-12-13 13:21:35 -05001078 lpfc_nlp_put(ndlp);
1079 goto out;
dea31012005-04-17 16:05:31 -05001080 }
dea31012005-04-17 16:05:31 -05001081 goto flogifail;
1082 }
James Smart695a8142010-01-26 23:08:03 -05001083 spin_lock_irq(shost->host_lock);
1084 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001085 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001086 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001087
1088 /*
1089 * The FLogI succeeded. Sync the data for the CPU before
1090 * accessing it.
1091 */
1092 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001093 if (!prsp)
1094 goto out;
dea31012005-04-17 16:05:31 -05001095 sp = prsp->virt + sizeof(uint32_t);
1096
1097 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001098 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001099 "0101 FLOGI completes successfully, I/O tag:x%x, "
1100 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001101 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001102 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1103 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001104
James Smart2e0fef82007-06-17 19:56:36 -05001105 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001106 /*
1107 * If Common Service Parameters indicate Nport
1108 * we are point to point, if Fport we are Fabric.
1109 */
1110 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001111 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001112 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001113 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001114 else {
1115 lpfc_printf_vlog(vport, KERN_ERR,
1116 LOG_FIP | LOG_ELS,
1117 "2831 FLOGI response with cleared Fabric "
1118 "bit fcf_index 0x%x "
1119 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1120 "Fabric Name "
1121 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1122 phba->fcf.current_rec.fcf_indx,
1123 phba->fcf.current_rec.switch_name[0],
1124 phba->fcf.current_rec.switch_name[1],
1125 phba->fcf.current_rec.switch_name[2],
1126 phba->fcf.current_rec.switch_name[3],
1127 phba->fcf.current_rec.switch_name[4],
1128 phba->fcf.current_rec.switch_name[5],
1129 phba->fcf.current_rec.switch_name[6],
1130 phba->fcf.current_rec.switch_name[7],
1131 phba->fcf.current_rec.fabric_name[0],
1132 phba->fcf.current_rec.fabric_name[1],
1133 phba->fcf.current_rec.fabric_name[2],
1134 phba->fcf.current_rec.fabric_name[3],
1135 phba->fcf.current_rec.fabric_name[4],
1136 phba->fcf.current_rec.fabric_name[5],
1137 phba->fcf.current_rec.fabric_name[6],
1138 phba->fcf.current_rec.fabric_name[7]);
1139 lpfc_nlp_put(ndlp);
1140 spin_lock_irq(&phba->hbalock);
1141 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001142 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001143 spin_unlock_irq(&phba->hbalock);
1144 goto out;
1145 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001146 if (!rc) {
1147 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001148 if (phba->hba_flag & HBA_FIP_SUPPORT)
1149 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1150 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001151 "2769 FLOGI to FCF (x%x) "
1152 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001153 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001154 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 Smart0c9ab6f2010-02-26 14:15:57 -05001157 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001158 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001159 }
dea31012005-04-17 16:05:31 -05001160 }
1161
1162flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001163 spin_lock_irq(&phba->hbalock);
1164 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1165 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001166
James Smart329f9bc2007-04-25 09:53:01 -04001167 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001168
James Smart858c9f62007-06-17 19:56:39 -05001169 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001170 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001171 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001172
1173 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001174 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001175 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001176 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1177 IOERR_SLI_ABORTED) &&
1178 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1179 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001180 (phba->link_state != LPFC_CLEAR_LA)) {
1181 /* If FLOGI failed enable link interrupt. */
1182 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001183 }
dea31012005-04-17 16:05:31 -05001184out:
1185 lpfc_els_free_iocb(phba, cmdiocb);
1186}
1187
James Smarte59058c2008-08-24 21:49:00 -04001188/**
James Smart3621a712009-04-06 18:47:14 -04001189 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001190 * @vport: pointer to a host virtual N_Port data structure.
1191 * @ndlp: pointer to a node-list data structure.
1192 * @retry: number of retries to the command IOCB.
1193 *
1194 * This routine issues a Fabric Login (FLOGI) Request ELS command
1195 * for a @vport. The initiator service parameters are put into the payload
1196 * of the FLOGI Request IOCB and the top-level callback function pointer
1197 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1198 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1199 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1200 *
1201 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1202 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1203 * will be stored into the context1 field of the IOCB for the completion
1204 * callback function to the FLOGI ELS command.
1205 *
1206 * Return code
1207 * 0 - successfully issued flogi iocb for @vport
1208 * 1 - failed to issue flogi iocb for @vport
1209 **/
dea31012005-04-17 16:05:31 -05001210static int
James Smart2e0fef82007-06-17 19:56:36 -05001211lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001212 uint8_t retry)
1213{
James Smart2e0fef82007-06-17 19:56:36 -05001214 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001215 struct serv_parm *sp;
1216 IOCB_t *icmd;
1217 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001218 uint8_t *pcmd;
1219 uint16_t cmdsize;
1220 uint32_t tmo;
1221 int rc;
1222
James Smart92d7f7b2007-06-17 19:56:38 -05001223 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001224 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1225 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001226
James Smart488d1462006-03-07 15:02:37 -05001227 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001228 return 1;
dea31012005-04-17 16:05:31 -05001229
1230 icmd = &elsiocb->iocb;
1231 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1232
1233 /* For FLOGI request, remainder of payload is service parameters */
1234 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001235 pcmd += sizeof(uint32_t);
1236 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001237 sp = (struct serv_parm *) pcmd;
1238
1239 /* Setup CSPs accordingly for Fabric */
1240 sp->cmn.e_d_tov = 0;
1241 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001242 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001243 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001244 if (sp->cmn.fcphLow < FC_PH3)
1245 sp->cmn.fcphLow = FC_PH3;
1246 if (sp->cmn.fcphHigh < FC_PH3)
1247 sp->cmn.fcphHigh = FC_PH3;
1248
James Smartc31098c2011-04-16 11:03:33 -04001249 if (phba->sli_rev == LPFC_SLI_REV4) {
1250 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1251 LPFC_SLI_INTF_IF_TYPE_0) {
1252 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1253 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1254 /* FLOGI needs to be 3 for WQE FCFI */
1255 /* Set the fcfi to the fcfi we registered with */
1256 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1257 }
James Smart0f378872012-10-31 14:45:01 -04001258 /* Can't do SLI4 class2 without support sequence coalescing */
1259 sp->cls2.classValid = 0;
1260 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001261 } else {
James Smart0f378872012-10-31 14:45:01 -04001262 /* Historical, setting sequential-delivery bit for SLI3 */
1263 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1264 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001265 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1266 sp->cmn.request_multiple_Nport = 1;
1267 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1268 icmd->ulpCt_h = 1;
1269 icmd->ulpCt_l = 0;
1270 } else
1271 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001272 }
1273
James Smart76a95d72010-11-20 23:11:48 -05001274 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001275 icmd->un.elsreq64.myID = 0;
1276 icmd->un.elsreq64.fl = 1;
1277 }
1278
dea31012005-04-17 16:05:31 -05001279 tmo = phba->fc_ratov;
1280 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001281 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001282 phba->fc_ratov = tmo;
1283
1284 phba->fc_stat.elsXmitFLOGI++;
1285 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001286
1287 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1288 "Issue FLOGI: opt:x%x",
1289 phba->sli3_options, 0, 0);
1290
James Smart92d7f7b2007-06-17 19:56:38 -05001291 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001292 if (rc == IOCB_ERROR) {
1293 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001294 return 1;
dea31012005-04-17 16:05:31 -05001295 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001296 return 0;
dea31012005-04-17 16:05:31 -05001297}
1298
James Smarte59058c2008-08-24 21:49:00 -04001299/**
James Smart3621a712009-04-06 18:47:14 -04001300 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001301 * @phba: pointer to lpfc hba data structure.
1302 *
1303 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1304 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1305 * list and issues an abort IOCB commond on each outstanding IOCB that
1306 * contains a active Fabric_DID ndlp. Note that this function is to issue
1307 * the abort IOCB command on all the outstanding IOCBs, thus when this
1308 * function returns, it does not guarantee all the IOCBs are actually aborted.
1309 *
1310 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001311 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001312 **/
dea31012005-04-17 16:05:31 -05001313int
James Smart2e0fef82007-06-17 19:56:36 -05001314lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001315{
1316 struct lpfc_sli_ring *pring;
1317 struct lpfc_iocbq *iocb, *next_iocb;
1318 struct lpfc_nodelist *ndlp;
1319 IOCB_t *icmd;
1320
1321 /* Abort outstanding I/O on NPort <nlp_DID> */
1322 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001323 "0201 Abort outstanding I/O on NPort x%x\n",
1324 Fabric_DID);
dea31012005-04-17 16:05:31 -05001325
1326 pring = &phba->sli.ring[LPFC_ELS_RING];
1327
1328 /*
1329 * Check the txcmplq for an iocb that matches the nport the driver is
1330 * searching for.
1331 */
James Smart2e0fef82007-06-17 19:56:36 -05001332 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001333 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1334 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001335 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001336 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001337 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1338 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001339 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001340 }
1341 }
James Smart2e0fef82007-06-17 19:56:36 -05001342 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001343
1344 return 0;
1345}
1346
James Smarte59058c2008-08-24 21:49:00 -04001347/**
James Smart3621a712009-04-06 18:47:14 -04001348 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001349 * @vport: pointer to a host virtual N_Port data structure.
1350 *
1351 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1352 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1353 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1354 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1355 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1356 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1357 * @vport.
1358 *
1359 * Return code
1360 * 0 - failed to issue initial flogi for @vport
1361 * 1 - successfully issued initial flogi for @vport
1362 **/
dea31012005-04-17 16:05:31 -05001363int
James Smart2e0fef82007-06-17 19:56:36 -05001364lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001365{
James Smart2e0fef82007-06-17 19:56:36 -05001366 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001367 struct lpfc_nodelist *ndlp;
1368
James Smart98c9ea52007-10-27 13:37:33 -04001369 vport->port_state = LPFC_FLOGI;
1370 lpfc_set_disctmo(vport);
1371
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001372 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001373 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001374 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001375 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001376 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1377 if (!ndlp)
1378 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001379 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001380 /* Set the node type */
1381 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001382 /* Put ndlp onto node list */
1383 lpfc_enqueue_node(vport, ndlp);
1384 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1385 /* re-setup ndlp without removing from node list */
1386 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1387 if (!ndlp)
1388 return 0;
dea31012005-04-17 16:05:31 -05001389 }
James Smart87af33f2007-10-27 13:37:43 -04001390
James Smart5ac6b302010-10-22 11:05:36 -04001391 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001392 /* This decrement of reference count to node shall kick off
1393 * the release of the node.
1394 */
James Smart329f9bc2007-04-25 09:53:01 -04001395 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001396 return 0;
1397 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return 1;
dea31012005-04-17 16:05:31 -05001399}
1400
James Smarte59058c2008-08-24 21:49:00 -04001401/**
James Smart3621a712009-04-06 18:47:14 -04001402 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001403 * @vport: pointer to a host virtual N_Port data structure.
1404 *
1405 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1406 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1407 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1408 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1409 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1410 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1411 * @vport.
1412 *
1413 * Return code
1414 * 0 - failed to issue initial fdisc for @vport
1415 * 1 - successfully issued initial fdisc for @vport
1416 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001417int
1418lpfc_initial_fdisc(struct lpfc_vport *vport)
1419{
1420 struct lpfc_hba *phba = vport->phba;
1421 struct lpfc_nodelist *ndlp;
1422
1423 /* First look for the Fabric ndlp */
1424 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1425 if (!ndlp) {
1426 /* Cannot find existing Fabric ndlp, so allocate a new one */
1427 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1428 if (!ndlp)
1429 return 0;
1430 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001431 /* Put ndlp onto node list */
1432 lpfc_enqueue_node(vport, ndlp);
1433 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1434 /* re-setup ndlp without removing from node list */
1435 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1436 if (!ndlp)
1437 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001438 }
James Smarte47c9092008-02-08 18:49:26 -05001439
James Smart92d7f7b2007-06-17 19:56:38 -05001440 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001441 /* decrement node reference count to trigger the release of
1442 * the node.
1443 */
James Smart92d7f7b2007-06-17 19:56:38 -05001444 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001445 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001446 }
1447 return 1;
1448}
James Smart87af33f2007-10-27 13:37:43 -04001449
James Smarte59058c2008-08-24 21:49:00 -04001450/**
James Smart3621a712009-04-06 18:47:14 -04001451 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001452 * @vport: pointer to a host virtual N_Port data structure.
1453 *
1454 * This routine checks whether there are more remaining Port Logins
1455 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1456 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1457 * to issue ELS PLOGIs up to the configured discover threads with the
1458 * @vport (@vport->cfg_discovery_threads). The function also decrement
1459 * the @vport's num_disc_node by 1 if it is not already 0.
1460 **/
James Smart87af33f2007-10-27 13:37:43 -04001461void
James Smart2e0fef82007-06-17 19:56:36 -05001462lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001463{
James Smart2e0fef82007-06-17 19:56:36 -05001464 if (vport->num_disc_nodes)
1465 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001466
1467 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001468 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1469 "0232 Continue discovery with %d PLOGIs to go "
1470 "Data: x%x x%x x%x\n",
1471 vport->num_disc_nodes, vport->fc_plogi_cnt,
1472 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001473 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001474 if (vport->fc_flag & FC_NLP_MORE)
1475 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001476 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001477
dea31012005-04-17 16:05:31 -05001478 return;
1479}
1480
James Smarte59058c2008-08-24 21:49:00 -04001481/**
James Smart3621a712009-04-06 18:47:14 -04001482 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001483 * @phba: pointer to lpfc hba data structure.
1484 * @prsp: pointer to response IOCB payload.
1485 * @ndlp: pointer to a node-list data structure.
1486 *
1487 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1488 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1489 * The following cases are considered N_Port confirmed:
1490 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1491 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1492 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1493 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1494 * 1) if there is a node on vport list other than the @ndlp with the same
1495 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1496 * on that node to release the RPI associated with the node; 2) if there is
1497 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1498 * into, a new node shall be allocated (or activated). In either case, the
1499 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1500 * be released and the new_ndlp shall be put on to the vport node list and
1501 * its pointer returned as the confirmed node.
1502 *
1503 * Note that before the @ndlp got "released", the keepDID from not-matching
1504 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1505 * of the @ndlp. This is because the release of @ndlp is actually to put it
1506 * into an inactive state on the vport node list and the vport node list
1507 * management algorithm does not allow two node with a same DID.
1508 *
1509 * Return code
1510 * pointer to the PLOGI N_Port @ndlp
1511 **/
James Smart488d1462006-03-07 15:02:37 -05001512static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001513lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001514 struct lpfc_nodelist *ndlp)
1515{
James Smart2e0fef82007-06-17 19:56:36 -05001516 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001518 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001519 struct lpfc_rport_data *rdata;
1520 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001521 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001522 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001523 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001524 uint16_t keep_nlp_state;
James Smart38b92ef2010-08-04 16:11:39 -04001525 int put_node;
1526 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001527 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001528
James Smart2fb9bd82006-12-02 13:33:57 -05001529 /* Fabric nodes can have the same WWPN so we don't bother searching
1530 * by WWPN. Just return the ndlp that was given to us.
1531 */
1532 if (ndlp->nlp_type & NLP_FABRIC)
1533 return ndlp;
1534
James Smart92d7f7b2007-06-17 19:56:38 -05001535 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001536 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001537
James Smart685f0bf2007-04-25 09:53:08 -04001538 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001539 * we have for that ndlp. If not, we have some work to do.
1540 */
James Smart2e0fef82007-06-17 19:56:36 -05001541 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001542
James Smarte47c9092008-02-08 18:49:26 -05001543 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001544 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001545 if (phba->sli_rev == LPFC_SLI_REV4) {
1546 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1547 GFP_KERNEL);
1548 if (active_rrqs_xri_bitmap)
1549 memset(active_rrqs_xri_bitmap, 0,
1550 phba->cfg_rrq_xri_bitmap_sz);
1551 }
James Smart488d1462006-03-07 15:02:37 -05001552
James Smart34f5ad82012-08-03 12:35:03 -04001553 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1554 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1555 ndlp, ndlp->nlp_DID, new_ndlp);
1556
James Smart488d1462006-03-07 15:02:37 -05001557 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001558 rc = memcmp(&ndlp->nlp_portname, name,
1559 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001560 if (!rc) {
1561 if (active_rrqs_xri_bitmap)
1562 mempool_free(active_rrqs_xri_bitmap,
1563 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001564 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001565 }
James Smart488d1462006-03-07 15:02:37 -05001566 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
James Smartcff261f2013-12-17 20:29:47 -05001567 if (!new_ndlp) {
1568 if (active_rrqs_xri_bitmap)
1569 mempool_free(active_rrqs_xri_bitmap,
1570 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001571 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001572 }
James Smart2e0fef82007-06-17 19:56:36 -05001573 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001574 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001575 rc = memcmp(&ndlp->nlp_portname, name,
1576 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001577 if (!rc) {
1578 if (active_rrqs_xri_bitmap)
1579 mempool_free(active_rrqs_xri_bitmap,
1580 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001581 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001582 }
James Smarte47c9092008-02-08 18:49:26 -05001583 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1584 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001585 if (!new_ndlp) {
1586 if (active_rrqs_xri_bitmap)
1587 mempool_free(active_rrqs_xri_bitmap,
1588 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001589 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001590 }
James Smart58da1ff2008-04-07 10:15:56 -04001591 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001592 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1593 memcpy(active_rrqs_xri_bitmap,
1594 new_ndlp->active_rrqs_xri_bitmap,
1595 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001596 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001597 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001598 if (phba->sli_rev == LPFC_SLI_REV4 &&
1599 active_rrqs_xri_bitmap)
1600 memcpy(active_rrqs_xri_bitmap,
1601 new_ndlp->active_rrqs_xri_bitmap,
1602 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001603 }
James Smart488d1462006-03-07 15:02:37 -05001604
James Smart2e0fef82007-06-17 19:56:36 -05001605 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001606 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001607 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001608 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001609 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1610 ndlp->active_rrqs_xri_bitmap,
1611 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001612
James Smart953ceed2015-05-22 10:42:37 -04001613 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001614 keep_nlp_flag = new_ndlp->nlp_flag;
1615 new_ndlp->nlp_flag = ndlp->nlp_flag;
1616 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001617 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001618
James Smart953ceed2015-05-22 10:42:37 -04001619 /* Set nlp_states accordingly */
1620 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001621 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001622
James Smart2e0fef82007-06-17 19:56:36 -05001623 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001624 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1625 /* The new_ndlp is replacing ndlp totally, so we need
1626 * to put ndlp on UNUSED list and try to free it.
1627 */
James Smart34f5ad82012-08-03 12:35:03 -04001628 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1629 "3179 PLOGI confirm NEW: %x %x\n",
1630 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001631
1632 /* Fix up the rport accordingly */
1633 rport = ndlp->rport;
1634 if (rport) {
1635 rdata = rport->dd_data;
1636 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001637 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001638 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001639 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001640 rdata->pnode = lpfc_nlp_get(new_ndlp);
1641 new_ndlp->rport = rport;
1642 }
1643 new_ndlp->nlp_type = ndlp->nlp_type;
1644 }
James Smart58da1ff2008-04-07 10:15:56 -04001645 /* We shall actually free the ndlp with both nlp_DID and
1646 * nlp_portname fields equals 0 to avoid any ndlp on the
1647 * nodelist never to be used.
1648 */
1649 if (ndlp->nlp_DID == 0) {
1650 spin_lock_irq(&phba->ndlp_lock);
1651 NLP_SET_FREE_REQ(ndlp);
1652 spin_unlock_irq(&phba->ndlp_lock);
1653 }
James Smart0ff10d42008-01-11 01:52:36 -05001654
James Smart58da1ff2008-04-07 10:15:56 -04001655 /* Two ndlps cannot have the same did on the nodelist */
1656 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001657 if (phba->sli_rev == LPFC_SLI_REV4 &&
1658 active_rrqs_xri_bitmap)
1659 memcpy(ndlp->active_rrqs_xri_bitmap,
1660 active_rrqs_xri_bitmap,
1661 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001662
1663 if (!NLP_CHK_NODE_ACT(ndlp))
1664 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001665 }
James Smart92795652006-07-06 15:50:02 -04001666 else {
James Smart34f5ad82012-08-03 12:35:03 -04001667 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1668 "3180 PLOGI confirm SWAP: %x %x\n",
1669 new_ndlp->nlp_DID, keepDID);
1670
James Smart2e0fef82007-06-17 19:56:36 -05001671 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001672
James Smart58da1ff2008-04-07 10:15:56 -04001673 /* Two ndlps cannot have the same did */
1674 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001675 if (phba->sli_rev == LPFC_SLI_REV4 &&
1676 active_rrqs_xri_bitmap)
1677 memcpy(ndlp->active_rrqs_xri_bitmap,
1678 active_rrqs_xri_bitmap,
1679 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001680
James Smart953ceed2015-05-22 10:42:37 -04001681 /* Since we are switching over to the new_ndlp,
1682 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001683 */
1684 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1685 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001686 keep_nlp_state = NLP_STE_NPR_NODE;
1687 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001688
James Smart38b92ef2010-08-04 16:11:39 -04001689 /* Fix up the rport accordingly */
1690 rport = ndlp->rport;
1691 if (rport) {
1692 rdata = rport->dd_data;
1693 put_node = rdata->pnode != NULL;
1694 put_rport = ndlp->rport != NULL;
1695 rdata->pnode = NULL;
1696 ndlp->rport = NULL;
1697 if (put_node)
1698 lpfc_nlp_put(ndlp);
1699 if (put_rport)
1700 put_device(&rport->dev);
1701 }
James Smart92795652006-07-06 15:50:02 -04001702 }
James Smartcff261f2013-12-17 20:29:47 -05001703 if (phba->sli_rev == LPFC_SLI_REV4 &&
1704 active_rrqs_xri_bitmap)
1705 mempool_free(active_rrqs_xri_bitmap,
1706 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001707 return new_ndlp;
1708}
1709
James Smarte59058c2008-08-24 21:49:00 -04001710/**
James Smart3621a712009-04-06 18:47:14 -04001711 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001712 * @vport: pointer to a host virtual N_Port data structure.
1713 *
1714 * This routine checks whether more Registration State Change
1715 * Notifications (RSCNs) came in while the discovery state machine was in
1716 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1717 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1718 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1719 * handling the RSCNs.
1720 **/
James Smart87af33f2007-10-27 13:37:43 -04001721void
1722lpfc_end_rscn(struct lpfc_vport *vport)
1723{
1724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1725
1726 if (vport->fc_flag & FC_RSCN_MODE) {
1727 /*
1728 * Check to see if more RSCNs came in while we were
1729 * processing this one.
1730 */
1731 if (vport->fc_rscn_id_cnt ||
1732 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1733 lpfc_els_handle_rscn(vport);
1734 else {
1735 spin_lock_irq(shost->host_lock);
1736 vport->fc_flag &= ~FC_RSCN_MODE;
1737 spin_unlock_irq(shost->host_lock);
1738 }
1739 }
1740}
1741
James Smarte59058c2008-08-24 21:49:00 -04001742/**
James Smart19ca7602010-11-20 23:11:55 -05001743 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1744 * @phba: pointer to lpfc hba data structure.
1745 * @cmdiocb: pointer to lpfc command iocb data structure.
1746 * @rspiocb: pointer to lpfc response iocb data structure.
1747 *
1748 * This routine will call the clear rrq function to free the rrq and
1749 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1750 * exist then the clear_rrq is still called because the rrq needs to
1751 * be freed.
1752 **/
1753
1754static void
1755lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1756 struct lpfc_iocbq *rspiocb)
1757{
1758 struct lpfc_vport *vport = cmdiocb->vport;
1759 IOCB_t *irsp;
1760 struct lpfc_nodelist *ndlp;
1761 struct lpfc_node_rrq *rrq;
1762
1763 /* we pass cmdiocb to state machine which needs rspiocb as well */
1764 rrq = cmdiocb->context_un.rrq;
1765 cmdiocb->context_un.rsp_iocb = rspiocb;
1766
1767 irsp = &rspiocb->iocb;
1768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1769 "RRQ cmpl: status:x%x/x%x did:x%x",
1770 irsp->ulpStatus, irsp->un.ulpWord[4],
1771 irsp->un.elsreq64.remoteID);
1772
1773 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1774 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1775 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1776 "2882 RRQ completes to NPort x%x "
1777 "with no ndlp. Data: x%x x%x x%x\n",
1778 irsp->un.elsreq64.remoteID,
1779 irsp->ulpStatus, irsp->un.ulpWord[4],
1780 irsp->ulpIoTag);
1781 goto out;
1782 }
1783
1784 /* rrq completes to NPort <nlp_DID> */
1785 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1786 "2880 RRQ completes to NPort x%x "
1787 "Data: x%x x%x x%x x%x x%x\n",
1788 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1789 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1790
1791 if (irsp->ulpStatus) {
1792 /* Check for retry */
1793 /* RRQ failed Don't print the vport to vport rjts */
1794 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1795 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1796 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1797 (phba)->pport->cfg_log_verbose & LOG_ELS)
1798 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1799 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1800 ndlp->nlp_DID, irsp->ulpStatus,
1801 irsp->un.ulpWord[4]);
1802 }
1803out:
1804 if (rrq)
1805 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1806 lpfc_els_free_iocb(phba, cmdiocb);
1807 return;
1808}
1809/**
James Smart3621a712009-04-06 18:47:14 -04001810 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001811 * @phba: pointer to lpfc hba data structure.
1812 * @cmdiocb: pointer to lpfc command iocb data structure.
1813 * @rspiocb: pointer to lpfc response iocb data structure.
1814 *
1815 * This routine is the completion callback function for issuing the Port
1816 * Login (PLOGI) command. For PLOGI completion, there must be an active
1817 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001818 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001819 * ignored and command IOCB released. The PLOGI response IOCB status is
1820 * checked for error conditons. If there is error status reported, PLOGI
1821 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1822 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1823 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1824 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1825 * there are additional N_Port nodes with the vport that need to perform
1826 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1827 * PLOGIs.
1828 **/
dea31012005-04-17 16:05:31 -05001829static void
James Smart2e0fef82007-06-17 19:56:36 -05001830lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1831 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001832{
James Smart2e0fef82007-06-17 19:56:36 -05001833 struct lpfc_vport *vport = cmdiocb->vport;
1834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001835 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001836 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001837 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001838 int disc, rc;
dea31012005-04-17 16:05:31 -05001839
dea31012005-04-17 16:05:31 -05001840 /* we pass cmdiocb to state machine which needs rspiocb as well */
1841 cmdiocb->context_un.rsp_iocb = rspiocb;
1842
1843 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001844 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1845 "PLOGI cmpl: status:x%x/x%x did:x%x",
1846 irsp->ulpStatus, irsp->un.ulpWord[4],
1847 irsp->un.elsreq64.remoteID);
1848
James Smart2e0fef82007-06-17 19:56:36 -05001849 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001850 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001851 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1852 "0136 PLOGI completes to NPort x%x "
1853 "with no ndlp. Data: x%x x%x x%x\n",
1854 irsp->un.elsreq64.remoteID,
1855 irsp->ulpStatus, irsp->un.ulpWord[4],
1856 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001857 goto out;
James Smarted957682007-06-17 19:56:37 -05001858 }
dea31012005-04-17 16:05:31 -05001859
1860 /* Since ndlp can be freed in the disc state machine, note if this node
1861 * is being used during discovery.
1862 */
James Smart2e0fef82007-06-17 19:56:36 -05001863 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001864 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001865 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001866 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001867 rc = 0;
1868
1869 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001870 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1871 "0102 PLOGI completes to NPort x%x "
1872 "Data: x%x x%x x%x x%x x%x\n",
1873 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1874 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001875 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001876 if (lpfc_els_chk_latt(vport)) {
1877 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001878 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001879 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001880 goto out;
1881 }
1882
dea31012005-04-17 16:05:31 -05001883 if (irsp->ulpStatus) {
1884 /* Check for retry */
1885 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1886 /* ELS command is being retried */
1887 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001888 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001889 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001890 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001891 }
1892 goto out;
1893 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001894 /* PLOGI failed Don't print the vport to vport rjts */
1895 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1896 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1897 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1898 (phba)->pport->cfg_log_verbose & LOG_ELS)
1899 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001900 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1901 ndlp->nlp_DID, irsp->ulpStatus,
1902 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001903 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001904 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001905 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001906 else
James Smart2e0fef82007-06-17 19:56:36 -05001907 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001908 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001909 } else {
1910 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001911 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001912 cmdiocb->context2)->list.next,
1913 struct lpfc_dmabuf, list);
1914 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001915 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001916 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001917 }
1918
James Smart2e0fef82007-06-17 19:56:36 -05001919 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001920 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001921 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001922
James Smart2e0fef82007-06-17 19:56:36 -05001923 if (vport->num_disc_nodes == 0) {
1924 spin_lock_irq(shost->host_lock);
1925 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1926 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001927
James Smart2e0fef82007-06-17 19:56:36 -05001928 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001929 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001930 }
1931 }
1932
1933out:
1934 lpfc_els_free_iocb(phba, cmdiocb);
1935 return;
1936}
1937
James Smarte59058c2008-08-24 21:49:00 -04001938/**
James Smart3621a712009-04-06 18:47:14 -04001939 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001940 * @vport: pointer to a host virtual N_Port data structure.
1941 * @did: destination port identifier.
1942 * @retry: number of retries to the command IOCB.
1943 *
1944 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1945 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1946 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1947 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1948 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1949 *
1950 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1951 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1952 * will be stored into the context1 field of the IOCB for the completion
1953 * callback function to the PLOGI ELS command.
1954 *
1955 * Return code
1956 * 0 - Successfully issued a plogi for @vport
1957 * 1 - failed to issue a plogi for @vport
1958 **/
dea31012005-04-17 16:05:31 -05001959int
James Smart2e0fef82007-06-17 19:56:36 -05001960lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001961{
James Smart2e0fef82007-06-17 19:56:36 -05001962 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001963 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04001964 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001965 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001966 uint8_t *pcmd;
1967 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001968 int ret;
dea31012005-04-17 16:05:31 -05001969
James Smart98c9ea52007-10-27 13:37:33 -04001970 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001971 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1972 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001973
James Smarte47c9092008-02-08 18:49:26 -05001974 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001975 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001976 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001977 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001978 if (!elsiocb)
1979 return 1;
dea31012005-04-17 16:05:31 -05001980
dea31012005-04-17 16:05:31 -05001981 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1982
1983 /* For PLOGI request, remainder of payload is service parameters */
1984 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001985 pcmd += sizeof(uint32_t);
1986 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001987 sp = (struct serv_parm *) pcmd;
1988
James Smart5ac6b302010-10-22 11:05:36 -04001989 /*
1990 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1991 * to device on remote loops work.
1992 */
1993 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1994 sp->cmn.altBbCredit = 1;
1995
dea31012005-04-17 16:05:31 -05001996 if (sp->cmn.fcphLow < FC_PH_4_3)
1997 sp->cmn.fcphLow = FC_PH_4_3;
1998
1999 if (sp->cmn.fcphHigh < FC_PH3)
2000 sp->cmn.fcphHigh = FC_PH3;
2001
James Smartcb341672016-12-19 15:07:20 -08002002 sp->cmn.valid_vendor_ver_level = 0;
2003 memset(sp->vendorVersion, 0, sizeof(sp->vendorVersion));
2004
James Smart858c9f62007-06-17 19:56:39 -05002005 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2006 "Issue PLOGI: did:x%x",
2007 did, 0, 0);
2008
dea31012005-04-17 16:05:31 -05002009 phba->fc_stat.elsXmitPLOGI++;
2010 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002011 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002012
2013 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002014 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002015 return 1;
dea31012005-04-17 16:05:31 -05002016 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002017 return 0;
dea31012005-04-17 16:05:31 -05002018}
2019
James Smarte59058c2008-08-24 21:49:00 -04002020/**
James Smart3621a712009-04-06 18:47:14 -04002021 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002022 * @phba: pointer to lpfc hba data structure.
2023 * @cmdiocb: pointer to lpfc command iocb data structure.
2024 * @rspiocb: pointer to lpfc response iocb data structure.
2025 *
2026 * This routine is the completion callback function for a Process Login
2027 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2028 * status. If there is error status reported, PRLI retry shall be attempted
2029 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2030 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2031 * ndlp to mark the PRLI completion.
2032 **/
dea31012005-04-17 16:05:31 -05002033static void
James Smart2e0fef82007-06-17 19:56:36 -05002034lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2035 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002036{
James Smart2e0fef82007-06-17 19:56:36 -05002037 struct lpfc_vport *vport = cmdiocb->vport;
2038 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002039 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002040 struct lpfc_nodelist *ndlp;
2041
dea31012005-04-17 16:05:31 -05002042 /* we pass cmdiocb to state machine which needs rspiocb as well */
2043 cmdiocb->context_un.rsp_iocb = rspiocb;
2044
2045 irsp = &(rspiocb->iocb);
2046 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002047 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002048 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002049 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002050
James Smart858c9f62007-06-17 19:56:39 -05002051 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2052 "PRLI cmpl: status:x%x/x%x did:x%x",
2053 irsp->ulpStatus, irsp->un.ulpWord[4],
2054 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002055 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002056 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2057 "0103 PRLI completes to NPort x%x "
2058 "Data: x%x x%x x%x x%x\n",
2059 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2060 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002061
James Smart2e0fef82007-06-17 19:56:36 -05002062 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05002063 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002064 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002065 goto out;
2066
2067 if (irsp->ulpStatus) {
2068 /* Check for retry */
2069 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2070 /* ELS command is being retried */
2071 goto out;
2072 }
2073 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002074 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2075 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2076 ndlp->nlp_DID, irsp->ulpStatus,
2077 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002078 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002079 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002080 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002081 else
James Smart2e0fef82007-06-17 19:56:36 -05002082 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002083 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002084 } else
dea31012005-04-17 16:05:31 -05002085 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002086 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002087 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002088out:
2089 lpfc_els_free_iocb(phba, cmdiocb);
2090 return;
2091}
2092
James Smarte59058c2008-08-24 21:49:00 -04002093/**
James Smart3621a712009-04-06 18:47:14 -04002094 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002095 * @vport: pointer to a host virtual N_Port data structure.
2096 * @ndlp: pointer to a node-list data structure.
2097 * @retry: number of retries to the command IOCB.
2098 *
2099 * This routine issues a Process Login (PRLI) ELS command for the
2100 * @vport. The PRLI service parameters are set up in the payload of the
2101 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2102 * is put to the IOCB completion callback func field before invoking the
2103 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2104 *
2105 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2106 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2107 * will be stored into the context1 field of the IOCB for the completion
2108 * callback function to the PRLI ELS command.
2109 *
2110 * Return code
2111 * 0 - successfully issued prli iocb command for @vport
2112 * 1 - failed to issue prli iocb command for @vport
2113 **/
dea31012005-04-17 16:05:31 -05002114int
James Smart2e0fef82007-06-17 19:56:36 -05002115lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002116 uint8_t retry)
2117{
James Smart2e0fef82007-06-17 19:56:36 -05002118 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2119 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002120 PRLI *npr;
dea31012005-04-17 16:05:31 -05002121 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002122 uint8_t *pcmd;
2123 uint16_t cmdsize;
2124
James Smart92d7f7b2007-06-17 19:56:38 -05002125 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002126 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2127 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002128 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002129 return 1;
dea31012005-04-17 16:05:31 -05002130
dea31012005-04-17 16:05:31 -05002131 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2132
2133 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002134 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002135 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002136 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002137
2138 /* For PRLI, remainder of payload is PRLI parameter page */
2139 npr = (PRLI *) pcmd;
2140 /*
2141 * If our firmware version is 3.20 or later,
2142 * set the following bits for FC-TAPE support.
2143 */
2144 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2145 npr->ConfmComplAllowed = 1;
2146 npr->Retry = 1;
2147 npr->TaskRetryIdReq = 1;
2148 }
2149 npr->estabImagePair = 1;
2150 npr->readXferRdyDis = 1;
James Smart3cb01c52013-07-15 18:35:04 -04002151 if (vport->cfg_first_burst_size)
2152 npr->writeXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05002153
2154 /* For FCP support */
2155 npr->prliType = PRLI_FCP_TYPE;
2156 npr->initiatorFunc = 1;
2157
James Smart858c9f62007-06-17 19:56:39 -05002158 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2159 "Issue PRLI: did:x%x",
2160 ndlp->nlp_DID, 0, 0);
2161
dea31012005-04-17 16:05:31 -05002162 phba->fc_stat.elsXmitPRLI++;
2163 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002164 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002165 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002166 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002167 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2168 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002169 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002170 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002171 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002172 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002173 return 1;
dea31012005-04-17 16:05:31 -05002174 }
James Smart2e0fef82007-06-17 19:56:36 -05002175 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002176 return 0;
dea31012005-04-17 16:05:31 -05002177}
2178
James Smarte59058c2008-08-24 21:49:00 -04002179/**
James Smart3621a712009-04-06 18:47:14 -04002180 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002181 * @vport: pointer to a host virtual N_Port data structure.
2182 *
2183 * This routine performs Registration State Change Notification (RSCN)
2184 * discovery for a @vport. If the @vport's node port recovery count is not
2185 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2186 * the nodes that need recovery. If none of the PLOGI were needed through
2187 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2188 * invoked to check and handle possible more RSCN came in during the period
2189 * of processing the current ones.
2190 **/
2191static void
2192lpfc_rscn_disc(struct lpfc_vport *vport)
2193{
2194 lpfc_can_disctmo(vport);
2195
2196 /* RSCN discovery */
2197 /* go thru NPR nodes and issue ELS PLOGIs */
2198 if (vport->fc_npr_cnt)
2199 if (lpfc_els_disc_plogi(vport))
2200 return;
2201
2202 lpfc_end_rscn(vport);
2203}
2204
2205/**
James Smart3621a712009-04-06 18:47:14 -04002206 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002207 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2208 *
2209 * This function is called when the final ADISC is completed during discovery.
2210 * This function handles clearing link attention or issuing reg_vpi depending
2211 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2212 * discovery.
2213 * This function is called with no locks held.
2214 **/
2215static void
2216lpfc_adisc_done(struct lpfc_vport *vport)
2217{
2218 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2219 struct lpfc_hba *phba = vport->phba;
2220
2221 /*
2222 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2223 * and continue discovery.
2224 */
2225 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002226 !(vport->fc_flag & FC_RSCN_MODE) &&
2227 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002228 /* The ADISCs are complete. Doesn't matter if they
2229 * succeeded or failed because the ADISC completion
2230 * routine guarantees to call the state machine and
2231 * the RPI is either unregistered (failed ADISC response)
2232 * or the RPI is still valid and the node is marked
2233 * mapped for a target. The exchanges should be in the
2234 * correct state. This code is specific to SLI3.
2235 */
2236 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002237 lpfc_issue_reg_vpi(phba, vport);
2238 return;
2239 }
2240 /*
2241 * For SLI2, we need to set port_state to READY
2242 * and continue discovery.
2243 */
2244 if (vport->port_state < LPFC_VPORT_READY) {
2245 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002246 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002247 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2248 vport->num_disc_nodes = 0;
2249 /* go thru NPR list, issue ELS PLOGIs */
2250 if (vport->fc_npr_cnt)
2251 lpfc_els_disc_plogi(vport);
2252 if (!vport->num_disc_nodes) {
2253 spin_lock_irq(shost->host_lock);
2254 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2255 spin_unlock_irq(shost->host_lock);
2256 lpfc_can_disctmo(vport);
2257 lpfc_end_rscn(vport);
2258 }
2259 }
2260 vport->port_state = LPFC_VPORT_READY;
2261 } else
2262 lpfc_rscn_disc(vport);
2263}
2264
2265/**
James Smart3621a712009-04-06 18:47:14 -04002266 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002267 * @vport: pointer to a host virtual N_Port data structure.
2268 *
2269 * This routine determines whether there are more ndlps on a @vport
2270 * node list need to have Address Discover (ADISC) issued. If so, it will
2271 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2272 * remaining nodes which need to have ADISC sent.
2273 **/
James Smart0ff10d42008-01-11 01:52:36 -05002274void
James Smart2e0fef82007-06-17 19:56:36 -05002275lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002276{
James Smart2e0fef82007-06-17 19:56:36 -05002277 if (vport->num_disc_nodes)
2278 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002279 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002280 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2281 "0210 Continue discovery with %d ADISCs to go "
2282 "Data: x%x x%x x%x\n",
2283 vport->num_disc_nodes, vport->fc_adisc_cnt,
2284 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002285 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002286 if (vport->fc_flag & FC_NLP_MORE) {
2287 lpfc_set_disctmo(vport);
2288 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002289 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002290 }
James Smart90160e02008-08-24 21:49:45 -04002291 if (!vport->num_disc_nodes)
2292 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002293 return;
2294}
2295
James Smarte59058c2008-08-24 21:49:00 -04002296/**
James Smart3621a712009-04-06 18:47:14 -04002297 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002298 * @phba: pointer to lpfc hba data structure.
2299 * @cmdiocb: pointer to lpfc command iocb data structure.
2300 * @rspiocb: pointer to lpfc response iocb data structure.
2301 *
2302 * This routine is the completion function for issuing the Address Discover
2303 * (ADISC) command. It first checks to see whether link went down during
2304 * the discovery process. If so, the node will be marked as node port
2305 * recovery for issuing discover IOCB by the link attention handler and
2306 * exit. Otherwise, the response status is checked. If error was reported
2307 * in the response status, the ADISC command shall be retried by invoking
2308 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2309 * the response status, the state machine is invoked to set transition
2310 * with respect to NLP_EVT_CMPL_ADISC event.
2311 **/
dea31012005-04-17 16:05:31 -05002312static void
James Smart2e0fef82007-06-17 19:56:36 -05002313lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2314 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002315{
James Smart2e0fef82007-06-17 19:56:36 -05002316 struct lpfc_vport *vport = cmdiocb->vport;
2317 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002318 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002319 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002320 int disc;
dea31012005-04-17 16:05:31 -05002321
2322 /* we pass cmdiocb to state machine which needs rspiocb as well */
2323 cmdiocb->context_un.rsp_iocb = rspiocb;
2324
2325 irsp = &(rspiocb->iocb);
2326 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002327
James Smart858c9f62007-06-17 19:56:39 -05002328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2329 "ADISC cmpl: status:x%x/x%x did:x%x",
2330 irsp->ulpStatus, irsp->un.ulpWord[4],
2331 ndlp->nlp_DID);
2332
dea31012005-04-17 16:05:31 -05002333 /* Since ndlp can be freed in the disc state machine, note if this node
2334 * is being used during discovery.
2335 */
James Smart2e0fef82007-06-17 19:56:36 -05002336 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002337 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002338 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002339 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002340 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002341 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2342 "0104 ADISC completes to NPort x%x "
2343 "Data: x%x x%x x%x x%x x%x\n",
2344 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2345 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002346 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002347 if (lpfc_els_chk_latt(vport)) {
2348 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002349 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002350 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002351 goto out;
2352 }
2353
2354 if (irsp->ulpStatus) {
2355 /* Check for retry */
2356 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2357 /* ELS command is being retried */
2358 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002359 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002360 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002361 spin_unlock_irq(shost->host_lock);
2362 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002363 }
2364 goto out;
2365 }
2366 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002367 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2368 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2369 ndlp->nlp_DID, irsp->ulpStatus,
2370 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002371 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002372 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002373 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002374 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002375 } else
dea31012005-04-17 16:05:31 -05002376 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002377 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002378 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002379
James Smart90160e02008-08-24 21:49:45 -04002380 /* Check to see if there are more ADISCs to be sent */
2381 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002382 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002383out:
2384 lpfc_els_free_iocb(phba, cmdiocb);
2385 return;
2386}
2387
James Smarte59058c2008-08-24 21:49:00 -04002388/**
James Smart3621a712009-04-06 18:47:14 -04002389 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002390 * @vport: pointer to a virtual N_Port data structure.
2391 * @ndlp: pointer to a node-list data structure.
2392 * @retry: number of retries to the command IOCB.
2393 *
2394 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2395 * @vport. It prepares the payload of the ADISC ELS command, updates the
2396 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2397 * to issue the ADISC ELS command.
2398 *
2399 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2400 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2401 * will be stored into the context1 field of the IOCB for the completion
2402 * callback function to the ADISC ELS command.
2403 *
2404 * Return code
2405 * 0 - successfully issued adisc
2406 * 1 - failed to issue adisc
2407 **/
dea31012005-04-17 16:05:31 -05002408int
James Smart2e0fef82007-06-17 19:56:36 -05002409lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002410 uint8_t retry)
2411{
James Smart2e0fef82007-06-17 19:56:36 -05002412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2413 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002414 ADISC *ap;
dea31012005-04-17 16:05:31 -05002415 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002416 uint8_t *pcmd;
2417 uint16_t cmdsize;
2418
James Smart92d7f7b2007-06-17 19:56:38 -05002419 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002420 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2421 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002422 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002423 return 1;
dea31012005-04-17 16:05:31 -05002424
dea31012005-04-17 16:05:31 -05002425 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2426
2427 /* For ADISC request, remainder of payload is service parameters */
2428 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002429 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002430
2431 /* Fill in ADISC payload */
2432 ap = (ADISC *) pcmd;
2433 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002434 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2435 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002436 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002437
James Smart858c9f62007-06-17 19:56:39 -05002438 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2439 "Issue ADISC: did:x%x",
2440 ndlp->nlp_DID, 0, 0);
2441
dea31012005-04-17 16:05:31 -05002442 phba->fc_stat.elsXmitADISC++;
2443 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002444 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002445 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002446 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002447 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2448 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002449 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002450 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002451 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002452 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002453 return 1;
dea31012005-04-17 16:05:31 -05002454 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002455 return 0;
dea31012005-04-17 16:05:31 -05002456}
2457
James Smarte59058c2008-08-24 21:49:00 -04002458/**
James Smart3621a712009-04-06 18:47:14 -04002459 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002460 * @phba: pointer to lpfc hba data structure.
2461 * @cmdiocb: pointer to lpfc command iocb data structure.
2462 * @rspiocb: pointer to lpfc response iocb data structure.
2463 *
2464 * This routine is the completion function for issuing the ELS Logout (LOGO)
2465 * command. If no error status was reported from the LOGO response, the
2466 * state machine of the associated ndlp shall be invoked for transition with
2467 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2468 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2469 **/
dea31012005-04-17 16:05:31 -05002470static void
James Smart2e0fef82007-06-17 19:56:36 -05002471lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2472 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002473{
James Smart2e0fef82007-06-17 19:56:36 -05002474 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2475 struct lpfc_vport *vport = ndlp->vport;
2476 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002477 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002478 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002479 unsigned long flags;
2480 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002481
dea31012005-04-17 16:05:31 -05002482 /* we pass cmdiocb to state machine which needs rspiocb as well */
2483 cmdiocb->context_un.rsp_iocb = rspiocb;
2484
2485 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002486 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002487 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002488 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002489
James Smart858c9f62007-06-17 19:56:39 -05002490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2491 "LOGO cmpl: status:x%x/x%x did:x%x",
2492 irsp->ulpStatus, irsp->un.ulpWord[4],
2493 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002494
dea31012005-04-17 16:05:31 -05002495 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002496 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2497 "0105 LOGO completes to NPort x%x "
2498 "Data: x%x x%x x%x x%x\n",
2499 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2500 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002501
James Smart086a3452012-08-14 14:25:21 -04002502 if (lpfc_els_chk_latt(vport)) {
2503 skip_recovery = 1;
2504 goto out;
2505 }
2506
2507 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002508 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2509 /* NLP_EVT_DEVICE_RM should unregister the RPI
2510 * which should abort all outstanding IOs.
2511 */
2512 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2513 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002514 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002515 goto out;
2516 }
2517
dea31012005-04-17 16:05:31 -05002518 if (irsp->ulpStatus) {
2519 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002520 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002521 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002522 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002523 goto out;
James Smart086a3452012-08-14 14:25:21 -04002524 }
dea31012005-04-17 16:05:31 -05002525 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002526 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2527 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2528 ndlp->nlp_DID, irsp->ulpStatus,
2529 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002530 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002531 if (lpfc_error_lost_link(irsp)) {
2532 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002533 goto out;
James Smart086a3452012-08-14 14:25:21 -04002534 }
2535 }
2536
2537 /* Call state machine. This will unregister the rpi if needed. */
2538 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2539
dea31012005-04-17 16:05:31 -05002540out:
2541 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002542 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2543 if ((vport->fc_flag & FC_PT2PT) &&
2544 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2545 phba->pport->fc_myDID = 0;
2546 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2547 if (mbox) {
2548 lpfc_config_link(phba, mbox);
2549 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2550 mbox->vport = vport;
2551 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2552 MBX_NOT_FINISHED) {
2553 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002554 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002555 }
2556 }
2557 }
James Smart086a3452012-08-14 14:25:21 -04002558
2559 /*
2560 * If the node is a target, the handling attempts to recover the port.
2561 * For any other port type, the rpi is unregistered as an implicit
2562 * LOGO.
2563 */
2564 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2565 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2566 spin_lock_irqsave(shost->host_lock, flags);
2567 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2568 spin_unlock_irqrestore(shost->host_lock, flags);
2569
2570 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2571 "3187 LOGO completes to NPort x%x: Start "
2572 "Recovery Data: x%x x%x x%x x%x\n",
2573 ndlp->nlp_DID, irsp->ulpStatus,
2574 irsp->un.ulpWord[4], irsp->ulpTimeout,
2575 vport->num_disc_nodes);
2576 lpfc_disc_start(vport);
2577 }
dea31012005-04-17 16:05:31 -05002578 return;
2579}
2580
James Smarte59058c2008-08-24 21:49:00 -04002581/**
James Smart3621a712009-04-06 18:47:14 -04002582 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002583 * @vport: pointer to a virtual N_Port data structure.
2584 * @ndlp: pointer to a node-list data structure.
2585 * @retry: number of retries to the command IOCB.
2586 *
2587 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2588 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2589 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2590 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2591 *
2592 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2593 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2594 * will be stored into the context1 field of the IOCB for the completion
2595 * callback function to the LOGO ELS command.
2596 *
2597 * Return code
2598 * 0 - successfully issued logo
2599 * 1 - failed to issue logo
2600 **/
dea31012005-04-17 16:05:31 -05002601int
James Smart2e0fef82007-06-17 19:56:36 -05002602lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002603 uint8_t retry)
2604{
James Smart2e0fef82007-06-17 19:56:36 -05002605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2606 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002607 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002608 uint8_t *pcmd;
2609 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002610 int rc;
dea31012005-04-17 16:05:31 -05002611
James Smart98c9ea52007-10-27 13:37:33 -04002612 spin_lock_irq(shost->host_lock);
2613 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2614 spin_unlock_irq(shost->host_lock);
2615 return 0;
2616 }
2617 spin_unlock_irq(shost->host_lock);
2618
James Smart92d7f7b2007-06-17 19:56:38 -05002619 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002620 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2621 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002622 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002623 return 1;
dea31012005-04-17 16:05:31 -05002624
dea31012005-04-17 16:05:31 -05002625 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2626 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002627 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002628
2629 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002630 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002631 pcmd += sizeof(uint32_t);
2632 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002633
James Smart858c9f62007-06-17 19:56:39 -05002634 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2635 "Issue LOGO: did:x%x",
2636 ndlp->nlp_DID, 0, 0);
2637
James Smart086a3452012-08-14 14:25:21 -04002638 /*
2639 * If we are issuing a LOGO, we may try to recover the remote NPort
2640 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2641 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2642 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2643 * for that ELS cmd. To avoid this situation, lets get rid of the
2644 * RPI right now, before any ELS cmds are sent.
2645 */
2646 spin_lock_irq(shost->host_lock);
2647 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2648 spin_unlock_irq(shost->host_lock);
2649 if (lpfc_unreg_rpi(vport, ndlp)) {
2650 lpfc_els_free_iocb(phba, elsiocb);
2651 return 0;
2652 }
2653
dea31012005-04-17 16:05:31 -05002654 phba->fc_stat.elsXmitLOGO++;
2655 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002656 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002657 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002658 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002659 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002660 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002661
2662 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002663 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002664 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002666 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002667 return 1;
dea31012005-04-17 16:05:31 -05002668 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002669 return 0;
dea31012005-04-17 16:05:31 -05002670}
2671
James Smarte59058c2008-08-24 21:49:00 -04002672/**
James Smart3621a712009-04-06 18:47:14 -04002673 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002674 * @phba: pointer to lpfc hba data structure.
2675 * @cmdiocb: pointer to lpfc command iocb data structure.
2676 * @rspiocb: pointer to lpfc response iocb data structure.
2677 *
2678 * This routine is a generic completion callback function for ELS commands.
2679 * Specifically, it is the callback function which does not need to perform
2680 * any command specific operations. It is currently used by the ELS command
2681 * issuing routines for the ELS State Change Request (SCR),
2682 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2683 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2684 * certain debug loggings, this callback function simply invokes the
2685 * lpfc_els_chk_latt() routine to check whether link went down during the
2686 * discovery process.
2687 **/
dea31012005-04-17 16:05:31 -05002688static void
James Smart2e0fef82007-06-17 19:56:36 -05002689lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2690 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002691{
James Smart2e0fef82007-06-17 19:56:36 -05002692 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002693 IOCB_t *irsp;
2694
2695 irsp = &rspiocb->iocb;
2696
James Smart858c9f62007-06-17 19:56:39 -05002697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2698 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2699 irsp->ulpStatus, irsp->un.ulpWord[4],
2700 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002701 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002702 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2703 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2704 irsp->ulpIoTag, irsp->ulpStatus,
2705 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002706 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002707 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002708 lpfc_els_free_iocb(phba, cmdiocb);
2709 return;
2710}
2711
James Smarte59058c2008-08-24 21:49:00 -04002712/**
James Smart3621a712009-04-06 18:47:14 -04002713 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002714 * @vport: pointer to a host virtual N_Port data structure.
2715 * @nportid: N_Port identifier to the remote node.
2716 * @retry: number of retries to the command IOCB.
2717 *
2718 * This routine issues a State Change Request (SCR) to a fabric node
2719 * on a @vport. The remote node @nportid is passed into the function. It
2720 * first search the @vport node list to find the matching ndlp. If no such
2721 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2722 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2723 * routine is invoked to send the SCR IOCB.
2724 *
2725 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2726 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2727 * will be stored into the context1 field of the IOCB for the completion
2728 * callback function to the SCR ELS command.
2729 *
2730 * Return code
2731 * 0 - Successfully issued scr command
2732 * 1 - Failed to issue scr command
2733 **/
dea31012005-04-17 16:05:31 -05002734int
James Smart2e0fef82007-06-17 19:56:36 -05002735lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002736{
James Smart2e0fef82007-06-17 19:56:36 -05002737 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002738 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002739 uint8_t *pcmd;
2740 uint16_t cmdsize;
2741 struct lpfc_nodelist *ndlp;
2742
James Smart92d7f7b2007-06-17 19:56:38 -05002743 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002744
James Smarte47c9092008-02-08 18:49:26 -05002745 ndlp = lpfc_findnode_did(vport, nportid);
2746 if (!ndlp) {
2747 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2748 if (!ndlp)
2749 return 1;
2750 lpfc_nlp_init(vport, ndlp, nportid);
2751 lpfc_enqueue_node(vport, ndlp);
2752 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2753 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2754 if (!ndlp)
2755 return 1;
2756 }
dea31012005-04-17 16:05:31 -05002757
James Smart2e0fef82007-06-17 19:56:36 -05002758 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2759 ndlp->nlp_DID, ELS_CMD_SCR);
2760
James Smart488d1462006-03-07 15:02:37 -05002761 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002762 /* This will trigger the release of the node just
2763 * allocated
2764 */
James Smart329f9bc2007-04-25 09:53:01 -04002765 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002766 return 1;
dea31012005-04-17 16:05:31 -05002767 }
2768
dea31012005-04-17 16:05:31 -05002769 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2770
2771 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002772 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002773
2774 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002775 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002776 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2777
James Smart858c9f62007-06-17 19:56:39 -05002778 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2779 "Issue SCR: did:x%x",
2780 ndlp->nlp_DID, 0, 0);
2781
dea31012005-04-17 16:05:31 -05002782 phba->fc_stat.elsXmitSCR++;
2783 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002784 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2785 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002786 /* The additional lpfc_nlp_put will cause the following
2787 * lpfc_els_free_iocb routine to trigger the rlease of
2788 * the node.
2789 */
James Smart329f9bc2007-04-25 09:53:01 -04002790 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002791 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002792 return 1;
dea31012005-04-17 16:05:31 -05002793 }
James Smartfa4066b2008-01-11 01:53:27 -05002794 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2795 * trigger the release of node.
2796 */
James Smartcff261f2013-12-17 20:29:47 -05002797
James Smart329f9bc2007-04-25 09:53:01 -04002798 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002799 return 0;
dea31012005-04-17 16:05:31 -05002800}
2801
James Smarte59058c2008-08-24 21:49:00 -04002802/**
James Smart3621a712009-04-06 18:47:14 -04002803 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002804 * @vport: pointer to a host virtual N_Port data structure.
2805 * @nportid: N_Port identifier to the remote node.
2806 * @retry: number of retries to the command IOCB.
2807 *
2808 * This routine issues a Fibre Channel Address Resolution Response
2809 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2810 * is passed into the function. It first search the @vport node list to find
2811 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2812 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2813 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2814 *
2815 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2816 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2817 * will be stored into the context1 field of the IOCB for the completion
2818 * callback function to the PARPR ELS command.
2819 *
2820 * Return code
2821 * 0 - Successfully issued farpr command
2822 * 1 - Failed to issue farpr command
2823 **/
dea31012005-04-17 16:05:31 -05002824static int
James Smart2e0fef82007-06-17 19:56:36 -05002825lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002826{
James Smart2e0fef82007-06-17 19:56:36 -05002827 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002828 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002829 FARP *fp;
2830 uint8_t *pcmd;
2831 uint32_t *lp;
2832 uint16_t cmdsize;
2833 struct lpfc_nodelist *ondlp;
2834 struct lpfc_nodelist *ndlp;
2835
James Smart92d7f7b2007-06-17 19:56:38 -05002836 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002837
James Smarte47c9092008-02-08 18:49:26 -05002838 ndlp = lpfc_findnode_did(vport, nportid);
2839 if (!ndlp) {
2840 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2841 if (!ndlp)
2842 return 1;
2843 lpfc_nlp_init(vport, ndlp, nportid);
2844 lpfc_enqueue_node(vport, ndlp);
2845 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2846 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2847 if (!ndlp)
2848 return 1;
2849 }
James Smart2e0fef82007-06-17 19:56:36 -05002850
2851 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2852 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002853 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002854 /* This will trigger the release of the node just
2855 * allocated
2856 */
James Smart329f9bc2007-04-25 09:53:01 -04002857 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002858 return 1;
dea31012005-04-17 16:05:31 -05002859 }
2860
dea31012005-04-17 16:05:31 -05002861 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2862
2863 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002864 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002865
2866 /* Fill in FARPR payload */
2867 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002868 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002869 lp = (uint32_t *) pcmd;
2870 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002871 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002872 fp->Rflags = 0;
2873 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2874
James Smart92d7f7b2007-06-17 19:56:38 -05002875 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2876 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002877 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002878 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002879 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002880 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002881 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002882 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002883 }
2884
James Smart858c9f62007-06-17 19:56:39 -05002885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2886 "Issue FARPR: did:x%x",
2887 ndlp->nlp_DID, 0, 0);
2888
dea31012005-04-17 16:05:31 -05002889 phba->fc_stat.elsXmitFARPR++;
2890 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002891 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2892 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002893 /* The additional lpfc_nlp_put will cause the following
2894 * lpfc_els_free_iocb routine to trigger the release of
2895 * the node.
2896 */
James Smart329f9bc2007-04-25 09:53:01 -04002897 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002898 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002899 return 1;
dea31012005-04-17 16:05:31 -05002900 }
James Smartfa4066b2008-01-11 01:53:27 -05002901 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2902 * trigger the release of the node.
2903 */
James Smart329f9bc2007-04-25 09:53:01 -04002904 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002905 return 0;
dea31012005-04-17 16:05:31 -05002906}
2907
James Smarte59058c2008-08-24 21:49:00 -04002908/**
James Smart3621a712009-04-06 18:47:14 -04002909 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002910 * @vport: pointer to a host virtual N_Port data structure.
2911 * @nlp: pointer to a node-list data structure.
2912 *
2913 * This routine cancels the timer with a delayed IOCB-command retry for
2914 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2915 * removes the ELS retry event if it presents. In addition, if the
2916 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2917 * commands are sent for the @vport's nodes that require issuing discovery
2918 * ADISC.
2919 **/
dea31012005-04-17 16:05:31 -05002920void
James Smart2e0fef82007-06-17 19:56:36 -05002921lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002922{
James Smart2e0fef82007-06-17 19:56:36 -05002923 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002924 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002925
James Smart0d2b6b82008-06-14 22:52:47 -04002926 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2927 return;
James Smart2e0fef82007-06-17 19:56:36 -05002928 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002929 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002930 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002931 del_timer_sync(&nlp->nlp_delayfunc);
2932 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002933 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002934 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002935 /* Decrement nlp reference count held for the delayed retry */
2936 evtp = &nlp->els_retry_evt;
2937 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2938 }
James Smartfdcebe22006-03-07 15:04:01 -05002939 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002940 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002941 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002942 spin_unlock_irq(shost->host_lock);
2943 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002944 if (vport->port_state < LPFC_VPORT_READY) {
2945 /* Check if there are more ADISCs to be sent */
2946 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002947 } else {
2948 /* Check if there are more PLOGIs to be sent */
2949 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002950 if (vport->num_disc_nodes == 0) {
2951 spin_lock_irq(shost->host_lock);
2952 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2953 spin_unlock_irq(shost->host_lock);
2954 lpfc_can_disctmo(vport);
2955 lpfc_end_rscn(vport);
2956 }
James Smartfdcebe22006-03-07 15:04:01 -05002957 }
2958 }
2959 }
2960 return;
2961}
2962
James Smarte59058c2008-08-24 21:49:00 -04002963/**
James Smart3621a712009-04-06 18:47:14 -04002964 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002965 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2966 *
2967 * This routine is invoked by the ndlp delayed-function timer to check
2968 * whether there is any pending ELS retry event(s) with the node. If not, it
2969 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2970 * adds the delayed events to the HBA work list and invokes the
2971 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2972 * event. Note that lpfc_nlp_get() is called before posting the event to
2973 * the work list to hold reference count of ndlp so that it guarantees the
2974 * reference to ndlp will still be available when the worker thread gets
2975 * to the event associated with the ndlp.
2976 **/
James Smartfdcebe22006-03-07 15:04:01 -05002977void
dea31012005-04-17 16:05:31 -05002978lpfc_els_retry_delay(unsigned long ptr)
2979{
James Smart2e0fef82007-06-17 19:56:36 -05002980 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2981 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002982 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002983 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002984 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002985
James Smart92d7f7b2007-06-17 19:56:38 -05002986 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002987 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002988 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002989 return;
2990 }
2991
James Smartfa4066b2008-01-11 01:53:27 -05002992 /* We need to hold the node by incrementing the reference
2993 * count until the queued work is done
2994 */
2995 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002996 if (evtp->evt_arg1) {
2997 evtp->evt = LPFC_EVT_ELS_RETRY;
2998 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002999 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04003000 }
James Smart92d7f7b2007-06-17 19:56:38 -05003001 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05003002 return;
3003}
3004
James Smarte59058c2008-08-24 21:49:00 -04003005/**
James Smart3621a712009-04-06 18:47:14 -04003006 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003007 * @ndlp: pointer to a node-list data structure.
3008 *
3009 * This routine is the worker-thread handler for processing the @ndlp delayed
3010 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3011 * the last ELS command from the associated ndlp and invokes the proper ELS
3012 * function according to the delayed ELS command to retry the command.
3013 **/
dea31012005-04-17 16:05:31 -05003014void
3015lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3016{
James Smart2e0fef82007-06-17 19:56:36 -05003017 struct lpfc_vport *vport = ndlp->vport;
3018 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003019 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003020
James Smart2e0fef82007-06-17 19:56:36 -05003021 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003022 cmd = ndlp->nlp_last_elscmd;
3023 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003024
3025 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003026 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003027 return;
3028 }
3029
3030 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003031 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003032 /*
3033 * If a discovery event readded nlp_delayfunc after timer
3034 * firing and before processing the timer, cancel the
3035 * nlp_delayfunc.
3036 */
3037 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003038 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003039 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003040
3041 switch (cmd) {
3042 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003043 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003044 break;
3045 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003046 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003047 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003048 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003049 }
dea31012005-04-17 16:05:31 -05003050 break;
3051 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003052 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003053 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003054 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003055 }
dea31012005-04-17 16:05:31 -05003056 break;
3057 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003058 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003059 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003060 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003061 }
dea31012005-04-17 16:05:31 -05003062 break;
3063 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003064 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003065 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003066 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003067 }
dea31012005-04-17 16:05:31 -05003068 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003069 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003070 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3071 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003072 break;
dea31012005-04-17 16:05:31 -05003073 }
3074 return;
3075}
3076
James Smarte59058c2008-08-24 21:49:00 -04003077/**
James Smart3621a712009-04-06 18:47:14 -04003078 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003079 * @phba: pointer to lpfc hba data structure.
3080 * @cmdiocb: pointer to lpfc command iocb data structure.
3081 * @rspiocb: pointer to lpfc response iocb data structure.
3082 *
3083 * This routine makes a retry decision on an ELS command IOCB, which has
3084 * failed. The following ELS IOCBs use this function for retrying the command
3085 * when previously issued command responsed with error status: FLOGI, PLOGI,
3086 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3087 * returned error status, it makes the decision whether a retry shall be
3088 * issued for the command, and whether a retry shall be made immediately or
3089 * delayed. In the former case, the corresponding ELS command issuing-function
3090 * is called to retry the command. In the later case, the ELS command shall
3091 * be posted to the ndlp delayed event and delayed function timer set to the
3092 * ndlp for the delayed command issusing.
3093 *
3094 * Return code
3095 * 0 - No retry of els command is made
3096 * 1 - Immediate or delayed retry of els command is made
3097 **/
dea31012005-04-17 16:05:31 -05003098static int
James Smart2e0fef82007-06-17 19:56:36 -05003099lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3100 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003101{
James Smart2e0fef82007-06-17 19:56:36 -05003102 struct lpfc_vport *vport = cmdiocb->vport;
3103 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3104 IOCB_t *irsp = &rspiocb->iocb;
3105 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3106 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003107 uint32_t *elscmd;
3108 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003109 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003110 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003111 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003112 uint32_t did;
dea31012005-04-17 16:05:31 -05003113
James Smart488d1462006-03-07 15:02:37 -05003114
dea31012005-04-17 16:05:31 -05003115 /* Note: context2 may be 0 for internal driver abort
3116 * of delays ELS command.
3117 */
3118
3119 if (pcmd && pcmd->virt) {
3120 elscmd = (uint32_t *) (pcmd->virt);
3121 cmd = *elscmd++;
3122 }
3123
James Smarte47c9092008-02-08 18:49:26 -05003124 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003125 did = ndlp->nlp_DID;
3126 else {
3127 /* We should only hit this case for retrying PLOGI */
3128 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003129 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003130 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3131 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003132 return 1;
3133 }
3134
James Smart858c9f62007-06-17 19:56:39 -05003135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3136 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3137 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3138
dea31012005-04-17 16:05:31 -05003139 switch (irsp->ulpStatus) {
3140 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003141 break;
James Smart1151e3e2011-02-16 12:39:35 -05003142 case IOSTAT_REMOTE_STOP:
3143 if (phba->sli_rev == LPFC_SLI_REV4) {
3144 /* This IO was aborted by the target, we don't
3145 * know the rxid and because we did not send the
3146 * ABTS we cannot generate and RRQ.
3147 */
3148 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003149 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003150 }
3151 break;
dea31012005-04-17 16:05:31 -05003152 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003153 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003154 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003155 if (cmd == ELS_CMD_FLOGI) {
3156 if (PCI_DEVICE_ID_HORNET ==
3157 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003158 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003159 phba->pport->fc_myDID = 0;
3160 phba->alpa_map[0] = 0;
3161 phba->alpa_map[1] = 0;
3162 }
3163 }
James Smart2e0fef82007-06-17 19:56:36 -05003164 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003165 delay = 1000;
dea31012005-04-17 16:05:31 -05003166 retry = 1;
3167 break;
3168
James Smart92d7f7b2007-06-17 19:56:38 -05003169 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003170 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3171 "0124 Retry illegal cmd x%x "
3172 "retry:x%x delay:x%x\n",
3173 cmd, cmdiocb->retry, delay);
3174 retry = 1;
3175 /* All command's retry policy */
3176 maxretry = 8;
3177 if (cmdiocb->retry > 2)
3178 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003179 break;
3180
dea31012005-04-17 16:05:31 -05003181 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003182 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003183 retry = 1;
3184 if (cmdiocb->retry > 100)
3185 delay = 100;
3186 maxretry = 250;
3187 break;
3188
3189 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003190 delay = 100;
dea31012005-04-17 16:05:31 -05003191 retry = 1;
3192 break;
3193
James Smart858c9f62007-06-17 19:56:39 -05003194 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003195 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003196 if (cmd == ELS_CMD_PLOGI &&
3197 did == NameServer_DID) {
3198 /* Continue forever if plogi to */
3199 /* the nameserver fails */
3200 maxretry = 0;
3201 delay = 100;
3202 }
dea31012005-04-17 16:05:31 -05003203 retry = 1;
3204 break;
3205 }
3206 break;
3207
3208 case IOSTAT_NPORT_RJT:
3209 case IOSTAT_FABRIC_RJT:
3210 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3211 retry = 1;
3212 break;
3213 }
3214 break;
3215
3216 case IOSTAT_NPORT_BSY:
3217 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003218 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003219 retry = 1;
3220 break;
3221
3222 case IOSTAT_LS_RJT:
3223 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3224 /* Added for Vendor specifc support
3225 * Just keep retrying for these Rsn / Exp codes
3226 */
3227 switch (stat.un.b.lsRjtRsnCode) {
3228 case LSRJT_UNABLE_TPC:
3229 if (stat.un.b.lsRjtRsnCodeExp ==
3230 LSEXP_CMD_IN_PROGRESS) {
3231 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003232 delay = 1000;
dea31012005-04-17 16:05:31 -05003233 maxretry = 48;
3234 }
3235 retry = 1;
3236 break;
3237 }
James Smartffc95492010-06-07 15:23:17 -04003238 if (stat.un.b.lsRjtRsnCodeExp ==
3239 LSEXP_CANT_GIVE_DATA) {
3240 if (cmd == ELS_CMD_PLOGI) {
3241 delay = 1000;
3242 maxretry = 48;
3243 }
3244 retry = 1;
3245 break;
3246 }
James Smart4c1b64b2012-09-29 11:31:11 -04003247 if ((cmd == ELS_CMD_PLOGI) ||
3248 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003249 delay = 1000;
dea31012005-04-17 16:05:31 -05003250 maxretry = lpfc_max_els_tries + 1;
3251 retry = 1;
3252 break;
3253 }
James Smart92d7f7b2007-06-17 19:56:38 -05003254 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3255 (cmd == ELS_CMD_FDISC) &&
3256 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003257 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3258 "0125 FDISC Failed (x%x). "
3259 "Fabric out of resources\n",
3260 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003261 lpfc_vport_set_state(vport,
3262 FC_VPORT_NO_FABRIC_RSCS);
3263 }
dea31012005-04-17 16:05:31 -05003264 break;
3265
3266 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003267 if ((cmd == ELS_CMD_PLOGI) ||
3268 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003269 delay = 1000;
dea31012005-04-17 16:05:31 -05003270 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003271 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003272 /* FDISC retry policy */
3273 maxretry = 48;
3274 if (cmdiocb->retry >= 32)
3275 delay = 1000;
dea31012005-04-17 16:05:31 -05003276 }
3277 retry = 1;
3278 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003279
3280 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003281 /* There are some cases where switches return this
3282 * error when they are not ready and should be returning
3283 * Logical Busy. We should delay every time.
3284 */
3285 if (cmd == ELS_CMD_FDISC &&
3286 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3287 maxretry = 3;
3288 delay = 1000;
3289 retry = 1;
3290 break;
3291 }
James Smart92d7f7b2007-06-17 19:56:38 -05003292 case LSRJT_PROTOCOL_ERR:
3293 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3294 (cmd == ELS_CMD_FDISC) &&
3295 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3296 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3297 ) {
James Smarte8b62012007-08-02 11:10:09 -04003298 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003299 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003300 "Fabric Detected Bad WWN\n",
3301 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003302 lpfc_vport_set_state(vport,
3303 FC_VPORT_FABRIC_REJ_WWN);
3304 }
3305 break;
James Smart7bdedb32016-07-06 12:36:00 -07003306 case LSRJT_VENDOR_UNIQUE:
3307 if ((stat.un.b.vendorUnique == 0x45) &&
3308 (cmd == ELS_CMD_FLOGI)) {
3309 goto out_retry;
3310 }
3311 break;
dea31012005-04-17 16:05:31 -05003312 }
3313 break;
3314
3315 case IOSTAT_INTERMED_RSP:
3316 case IOSTAT_BA_RJT:
3317 break;
3318
3319 default:
3320 break;
3321 }
3322
James Smart488d1462006-03-07 15:02:37 -05003323 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003324 retry = 1;
dea31012005-04-17 16:05:31 -05003325
James Smartdf9e1b52011-12-13 13:22:17 -05003326 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003327 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003328 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003329 /* FLOGI retry policy */
3330 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003331 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003332 if (phba->link_flag != LS_LOOPBACK_MODE)
3333 maxretry = 0;
3334 else
3335 maxretry = 2;
3336
James Smart6669f9b2009-10-02 15:16:45 -04003337 if (cmdiocb->retry >= 100)
3338 delay = 5000;
3339 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003340 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003341 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3342 /* retry FDISCs every second up to devloss */
3343 retry = 1;
3344 maxretry = vport->cfg_devloss_tmo;
3345 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003346 }
3347
James Smart6669f9b2009-10-02 15:16:45 -04003348 cmdiocb->retry++;
3349 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003350 phba->fc_stat.elsRetryExceeded++;
3351 retry = 0;
3352 }
3353
James Smarted957682007-06-17 19:56:37 -05003354 if ((vport->load_flag & FC_UNLOADING) != 0)
3355 retry = 0;
3356
James Smart7bdedb32016-07-06 12:36:00 -07003357out_retry:
dea31012005-04-17 16:05:31 -05003358 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003359 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3360 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3361 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3362 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3363 "2849 Stop retry ELS command "
3364 "x%x to remote NPORT x%x, "
3365 "Data: x%x x%x\n", cmd, did,
3366 cmdiocb->retry, delay);
3367 return 0;
3368 }
3369 }
dea31012005-04-17 16:05:31 -05003370
3371 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3373 "0107 Retry ELS command x%x to remote "
3374 "NPORT x%x Data: x%x x%x\n",
3375 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003376
James Smart858c9f62007-06-17 19:56:39 -05003377 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3378 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003379 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3380 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003381 /* Don't reset timer for no resources */
3382
dea31012005-04-17 16:05:31 -05003383 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003384 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003385 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003386 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003387 }
3388
3389 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003390 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003391 phba->fc_stat.elsDelayRetry++;
3392 ndlp->nlp_retry = cmdiocb->retry;
3393
James Smart92d7f7b2007-06-17 19:56:38 -05003394 /* delay is specified in milliseconds */
3395 mod_timer(&ndlp->nlp_delayfunc,
3396 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003397 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003398 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003399 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003400
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003401 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003402 if (cmd == ELS_CMD_PRLI)
3403 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003404 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003405 else
3406 lpfc_nlp_set_state(vport, ndlp,
3407 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003408 ndlp->nlp_last_elscmd = cmd;
3409
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003410 return 1;
dea31012005-04-17 16:05:31 -05003411 }
3412 switch (cmd) {
3413 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003414 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003415 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003416 case ELS_CMD_FDISC:
3417 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3418 return 1;
dea31012005-04-17 16:05:31 -05003419 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003420 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003421 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003422 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003423 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003424 }
James Smart2e0fef82007-06-17 19:56:36 -05003425 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003426 return 1;
dea31012005-04-17 16:05:31 -05003427 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003428 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003429 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3430 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003431 return 1;
dea31012005-04-17 16:05:31 -05003432 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003433 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003434 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3435 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003436 return 1;
dea31012005-04-17 16:05:31 -05003437 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003438 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003439 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003440 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003441 return 1;
dea31012005-04-17 16:05:31 -05003442 }
3443 }
dea31012005-04-17 16:05:31 -05003444 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003445 if (logerr) {
3446 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3447 "0137 No retry ELS command x%x to remote "
3448 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3449 cmd, did, irsp->ulpStatus,
3450 irsp->un.ulpWord[4]);
3451 }
3452 else {
3453 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003454 "0108 No retry ELS command x%x to remote "
3455 "NPORT x%x Retried:%d Error:x%x/%x\n",
3456 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3457 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003458 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003459 return 0;
dea31012005-04-17 16:05:31 -05003460}
3461
James Smarte59058c2008-08-24 21:49:00 -04003462/**
James Smart3621a712009-04-06 18:47:14 -04003463 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003464 * @phba: pointer to lpfc hba data structure.
3465 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3466 *
3467 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3468 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3469 * checks to see whether there is a lpfc DMA buffer associated with the
3470 * response of the command IOCB. If so, it will be released before releasing
3471 * the lpfc DMA buffer associated with the IOCB itself.
3472 *
3473 * Return code
3474 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3475 **/
James Smart09372822008-01-11 01:52:54 -05003476static int
James Smart87af33f2007-10-27 13:37:43 -04003477lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3478{
3479 struct lpfc_dmabuf *buf_ptr;
3480
James Smarte59058c2008-08-24 21:49:00 -04003481 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003482 if (!list_empty(&buf_ptr1->list)) {
3483 list_remove_head(&buf_ptr1->list, buf_ptr,
3484 struct lpfc_dmabuf,
3485 list);
3486 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3487 kfree(buf_ptr);
3488 }
3489 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3490 kfree(buf_ptr1);
3491 return 0;
3492}
3493
James Smarte59058c2008-08-24 21:49:00 -04003494/**
James Smart3621a712009-04-06 18:47:14 -04003495 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003496 * @phba: pointer to lpfc hba data structure.
3497 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3498 *
3499 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3500 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3501 * pool.
3502 *
3503 * Return code
3504 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3505 **/
James Smart09372822008-01-11 01:52:54 -05003506static int
James Smart87af33f2007-10-27 13:37:43 -04003507lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3508{
3509 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3510 kfree(buf_ptr);
3511 return 0;
3512}
3513
James Smarte59058c2008-08-24 21:49:00 -04003514/**
James Smart3621a712009-04-06 18:47:14 -04003515 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003516 * @phba: pointer to lpfc hba data structure.
3517 * @elsiocb: pointer to lpfc els command iocb data structure.
3518 *
3519 * This routine frees a command IOCB and its associated resources. The
3520 * command IOCB data structure contains the reference to various associated
3521 * resources, these fields must be set to NULL if the associated reference
3522 * not present:
3523 * context1 - reference to ndlp
3524 * context2 - reference to cmd
3525 * context2->next - reference to rsp
3526 * context3 - reference to bpl
3527 *
3528 * It first properly decrements the reference count held on ndlp for the
3529 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3530 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3531 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3532 * adds the DMA buffer the @phba data structure for the delayed release.
3533 * If reference to the Buffer Pointer List (BPL) is present, the
3534 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3535 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3536 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3537 *
3538 * Return code
3539 * 0 - Success (currently, always return 0)
3540 **/
James Smart87af33f2007-10-27 13:37:43 -04003541int
James Smart329f9bc2007-04-25 09:53:01 -04003542lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003543{
3544 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003545 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003546
James Smarta8adb832007-10-27 13:37:53 -04003547 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3548 if (ndlp) {
3549 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3550 lpfc_nlp_put(ndlp);
3551
3552 /* If the ndlp is not being used by another discovery
3553 * thread, free it.
3554 */
3555 if (!lpfc_nlp_not_used(ndlp)) {
3556 /* If ndlp is being used by another discovery
3557 * thread, just clear NLP_DEFER_RM
3558 */
3559 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3560 }
3561 }
3562 else
3563 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003564 elsiocb->context1 = NULL;
3565 }
dea31012005-04-17 16:05:31 -05003566 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3567 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003568 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3569 /* Firmware could still be in progress of DMAing
3570 * payload, so don't free data buffer till after
3571 * a hbeat.
3572 */
3573 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3574 buf_ptr = elsiocb->context2;
3575 elsiocb->context2 = NULL;
3576 if (buf_ptr) {
3577 buf_ptr1 = NULL;
3578 spin_lock_irq(&phba->hbalock);
3579 if (!list_empty(&buf_ptr->list)) {
3580 list_remove_head(&buf_ptr->list,
3581 buf_ptr1, struct lpfc_dmabuf,
3582 list);
3583 INIT_LIST_HEAD(&buf_ptr1->list);
3584 list_add_tail(&buf_ptr1->list,
3585 &phba->elsbuf);
3586 phba->elsbuf_cnt++;
3587 }
3588 INIT_LIST_HEAD(&buf_ptr->list);
3589 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3590 phba->elsbuf_cnt++;
3591 spin_unlock_irq(&phba->hbalock);
3592 }
3593 } else {
3594 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3595 lpfc_els_free_data(phba, buf_ptr1);
Johannes Thumshirn42a1d5b42017-01-10 12:05:54 +01003596 elsiocb->context2 = NULL;
James Smart0ff10d42008-01-11 01:52:36 -05003597 }
dea31012005-04-17 16:05:31 -05003598 }
3599
3600 if (elsiocb->context3) {
3601 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003602 lpfc_els_free_bpl(phba, buf_ptr);
Johannes Thumshirn42a1d5b42017-01-10 12:05:54 +01003603 elsiocb->context3 = NULL;
dea31012005-04-17 16:05:31 -05003604 }
James Bottomley604a3e32005-10-29 10:28:33 -05003605 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003606 return 0;
3607}
3608
James Smarte59058c2008-08-24 21:49:00 -04003609/**
James Smart3621a712009-04-06 18:47:14 -04003610 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003611 * @phba: pointer to lpfc hba data structure.
3612 * @cmdiocb: pointer to lpfc command iocb data structure.
3613 * @rspiocb: pointer to lpfc response iocb data structure.
3614 *
3615 * This routine is the completion callback function to the Logout (LOGO)
3616 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3617 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3618 * release the ndlp if it has the last reference remaining (reference count
3619 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3620 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3621 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3622 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3623 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3624 * IOCB data structure.
3625 **/
dea31012005-04-17 16:05:31 -05003626static void
James Smart2e0fef82007-06-17 19:56:36 -05003627lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3628 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003629{
James Smart2e0fef82007-06-17 19:56:36 -05003630 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3631 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003632 IOCB_t *irsp;
3633
3634 irsp = &rspiocb->iocb;
3635 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3636 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3637 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003638 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003639 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3640 "0109 ACC to LOGO completes to NPort x%x "
3641 "Data: x%x x%x x%x\n",
3642 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3643 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003644
3645 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3646 /* NPort Recovery mode or node is just allocated */
3647 if (!lpfc_nlp_not_used(ndlp)) {
3648 /* If the ndlp is being used by another discovery
3649 * thread, just unregister the RPI.
3650 */
3651 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003652 } else {
3653 /* Indicate the node has already released, should
3654 * not reference to it from within lpfc_els_free_iocb.
3655 */
3656 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003657 }
dea31012005-04-17 16:05:31 -05003658 }
James Smart73d91e52011-10-10 21:32:10 -04003659
3660 /*
3661 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003662 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003663 */
dea31012005-04-17 16:05:31 -05003664 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003665}
3666
James Smarte59058c2008-08-24 21:49:00 -04003667/**
James Smart3621a712009-04-06 18:47:14 -04003668 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003669 * @phba: pointer to lpfc hba data structure.
3670 * @pmb: pointer to the driver internal queue element for mailbox command.
3671 *
3672 * This routine is the completion callback function for unregister default
3673 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3674 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3675 * decrements the ndlp reference count held for this completion callback
3676 * function. After that, it invokes the lpfc_nlp_not_used() to check
3677 * whether there is only one reference left on the ndlp. If so, it will
3678 * perform one more decrement and trigger the release of the ndlp.
3679 **/
James Smart858c9f62007-06-17 19:56:39 -05003680void
3681lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3682{
3683 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3684 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3685
3686 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003687 pmb->context2 = NULL;
3688
James Smart858c9f62007-06-17 19:56:39 -05003689 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3690 kfree(mp);
3691 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003692 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003693 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3694 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3695 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3696 atomic_read(&ndlp->kref.refcount),
3697 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003698 if (NLP_CHK_NODE_ACT(ndlp)) {
3699 lpfc_nlp_put(ndlp);
3700 /* This is the end of the default RPI cleanup logic for
3701 * this ndlp. If no other discovery threads are using
3702 * this ndlp, free all resources associated with it.
3703 */
3704 lpfc_nlp_not_used(ndlp);
3705 } else {
3706 lpfc_drop_node(ndlp->vport, ndlp);
3707 }
James Smarta8adb832007-10-27 13:37:53 -04003708 }
James Smart3772a992009-05-22 14:50:54 -04003709
James Smart858c9f62007-06-17 19:56:39 -05003710 return;
3711}
3712
James Smarte59058c2008-08-24 21:49:00 -04003713/**
James Smart3621a712009-04-06 18:47:14 -04003714 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003715 * @phba: pointer to lpfc hba data structure.
3716 * @cmdiocb: pointer to lpfc command iocb data structure.
3717 * @rspiocb: pointer to lpfc response iocb data structure.
3718 *
3719 * This routine is the completion callback function for ELS Response IOCB
3720 * command. In normal case, this callback function just properly sets the
3721 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3722 * field in the command IOCB is not NULL, the referred mailbox command will
3723 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3724 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3725 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3726 * routine shall be invoked trying to release the ndlp if no other threads
3727 * are currently referring it.
3728 **/
dea31012005-04-17 16:05:31 -05003729static void
James Smart858c9f62007-06-17 19:56:39 -05003730lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003731 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003732{
James Smart2e0fef82007-06-17 19:56:36 -05003733 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3734 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3735 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003736 IOCB_t *irsp;
3737 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003738 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003739 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003740 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003741
James Smart33ccf8d2006-08-17 11:57:58 -04003742 irsp = &rspiocb->iocb;
3743
dea31012005-04-17 16:05:31 -05003744 if (cmdiocb->context_un.mbox)
3745 mbox = cmdiocb->context_un.mbox;
3746
James Smartfa4066b2008-01-11 01:53:27 -05003747 /* First determine if this is a LS_RJT cmpl. Note, this callback
3748 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3749 */
James Smart87af33f2007-10-27 13:37:43 -04003750 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003751 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3752 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003753 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003754 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003755 */
3756 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3757 ls_rjt = 1;
3758 }
3759
dea31012005-04-17 16:05:31 -05003760 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003761 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003762 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003763 mp = (struct lpfc_dmabuf *) mbox->context1;
3764 if (mp) {
3765 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3766 kfree(mp);
3767 }
James Smart329f9bc2007-04-25 09:53:01 -04003768 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003769 }
James Smart58da1ff2008-04-07 10:15:56 -04003770 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3771 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003772 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003773 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003774 /* Indicate the node has already released,
3775 * should not reference to it from within
3776 * the routine lpfc_els_free_iocb.
3777 */
3778 cmdiocb->context1 = NULL;
3779 }
dea31012005-04-17 16:05:31 -05003780 goto out;
3781 }
3782
James Smart858c9f62007-06-17 19:56:39 -05003783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003784 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003785 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003786 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003787 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003788 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3789 "0110 ELS response tag x%x completes "
3790 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3791 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3792 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3793 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3794 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003795 if (mbox) {
3796 if ((rspiocb->iocb.ulpStatus == 0)
3797 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003798 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003799 /* Increment reference count to ndlp to hold the
3800 * reference to ndlp for the callback function.
3801 */
James Smart329f9bc2007-04-25 09:53:01 -04003802 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003803 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003804 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3805 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3806 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3807 }
3808 else {
3809 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3810 ndlp->nlp_prev_state = ndlp->nlp_state;
3811 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003812 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003813 }
James Smart4b7789b2015-12-16 18:11:55 -05003814
3815 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04003816 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003817 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003818 goto out;
James Smart4b7789b2015-12-16 18:11:55 -05003819
3820 /* Decrement the ndlp reference count we
3821 * set for this failed mailbox command.
3822 */
3823 lpfc_nlp_put(ndlp);
3824 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04003825
3826 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3827 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3828 "0138 ELS rsp: Cannot issue reg_login for x%x "
3829 "Data: x%x x%x x%x\n",
3830 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3831 ndlp->nlp_rpi);
3832
James Smartfa4066b2008-01-11 01:53:27 -05003833 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003834 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003835 /* Indicate node has already been released,
3836 * should not reference to it from within
3837 * the routine lpfc_els_free_iocb.
3838 */
3839 cmdiocb->context1 = NULL;
3840 }
dea31012005-04-17 16:05:31 -05003841 } else {
James Smart858c9f62007-06-17 19:56:39 -05003842 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3843 if (!lpfc_error_lost_link(irsp) &&
3844 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003845 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003846 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003847 /* Indicate node has already been
3848 * released, should not reference
3849 * to it from within the routine
3850 * lpfc_els_free_iocb.
3851 */
3852 cmdiocb->context1 = NULL;
3853 }
dea31012005-04-17 16:05:31 -05003854 }
3855 }
James Smart14691152006-12-02 13:34:28 -05003856 mp = (struct lpfc_dmabuf *) mbox->context1;
3857 if (mp) {
3858 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3859 kfree(mp);
3860 }
3861 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003862 }
3863out:
James Smart58da1ff2008-04-07 10:15:56 -04003864 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003865 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003866 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003867 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003868
3869 /* If the node is not being used by another discovery thread,
3870 * and we are sending a reject, we are done with it.
3871 * Release driver reference count here and free associated
3872 * resources.
3873 */
3874 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003875 if (lpfc_nlp_not_used(ndlp))
3876 /* Indicate node has already been released,
3877 * should not reference to it from within
3878 * the routine lpfc_els_free_iocb.
3879 */
3880 cmdiocb->context1 = NULL;
James Smart4b7789b2015-12-16 18:11:55 -05003881
dea31012005-04-17 16:05:31 -05003882 }
James Smart87af33f2007-10-27 13:37:43 -04003883
dea31012005-04-17 16:05:31 -05003884 lpfc_els_free_iocb(phba, cmdiocb);
3885 return;
3886}
3887
James Smarte59058c2008-08-24 21:49:00 -04003888/**
James Smart3621a712009-04-06 18:47:14 -04003889 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003890 * @vport: pointer to a host virtual N_Port data structure.
3891 * @flag: the els command code to be accepted.
3892 * @oldiocb: pointer to the original lpfc command iocb data structure.
3893 * @ndlp: pointer to a node-list data structure.
3894 * @mbox: pointer to the driver internal queue element for mailbox command.
3895 *
3896 * This routine prepares and issues an Accept (ACC) response IOCB
3897 * command. It uses the @flag to properly set up the IOCB field for the
3898 * specific ACC response command to be issued and invokes the
3899 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3900 * @mbox pointer is passed in, it will be put into the context_un.mbox
3901 * field of the IOCB for the completion callback function to issue the
3902 * mailbox command to the HBA later when callback is invoked.
3903 *
3904 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3905 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3906 * will be stored into the context1 field of the IOCB for the completion
3907 * callback function to the corresponding response ELS IOCB command.
3908 *
3909 * Return code
3910 * 0 - Successfully issued acc response
3911 * 1 - Failed to issue acc response
3912 **/
dea31012005-04-17 16:05:31 -05003913int
James Smart2e0fef82007-06-17 19:56:36 -05003914lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3915 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003916 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003917{
James Smart2e0fef82007-06-17 19:56:36 -05003918 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3919 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003920 IOCB_t *icmd;
3921 IOCB_t *oldcmd;
3922 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003923 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05003924 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05003925 uint16_t cmdsize;
3926 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003927 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003928
dea31012005-04-17 16:05:31 -05003929 oldcmd = &oldiocb->iocb;
3930
3931 switch (flag) {
3932 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003933 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003934 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3935 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003936 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003937 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003938 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003939 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003940 return 1;
dea31012005-04-17 16:05:31 -05003941 }
James Smart2e0fef82007-06-17 19:56:36 -05003942
dea31012005-04-17 16:05:31 -05003943 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003944 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3945 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003946 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3947 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003948 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003949
3950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3951 "Issue ACC: did:x%x flg:x%x",
3952 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003953 break;
James Smartd6de08c2015-12-16 18:11:53 -05003954 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05003955 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003956 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003957 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3958 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003959 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003960 return 1;
James Smart488d1462006-03-07 15:02:37 -05003961
dea31012005-04-17 16:05:31 -05003962 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003963 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3964 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003965 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3966
3967 if (mbox)
3968 elsiocb->context_un.mbox = mbox;
3969
3970 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003971 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05003972 sp = (struct serv_parm *)pcmd;
3973
3974 if (flag == ELS_CMD_FLOGI) {
3975 /* Copy the received service parameters back */
3976 memcpy(sp, &phba->fc_fabparam,
3977 sizeof(struct serv_parm));
3978
3979 /* Clear the F_Port bit */
3980 sp->cmn.fPort = 0;
3981
3982 /* Mark all class service parameters as invalid */
3983 sp->cls1.classValid = 0;
3984 sp->cls2.classValid = 0;
3985 sp->cls3.classValid = 0;
3986 sp->cls4.classValid = 0;
3987
3988 /* Copy our worldwide names */
3989 memcpy(&sp->portName, &vport->fc_sparam.portName,
3990 sizeof(struct lpfc_name));
3991 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
3992 sizeof(struct lpfc_name));
3993 } else {
3994 memcpy(pcmd, &vport->fc_sparam,
3995 sizeof(struct serv_parm));
James Smartcb341672016-12-19 15:07:20 -08003996
3997 sp->cmn.valid_vendor_ver_level = 0;
3998 memset(sp->vendorVersion, 0, sizeof(sp->vendorVersion));
James Smartd6de08c2015-12-16 18:11:53 -05003999 }
James Smart858c9f62007-06-17 19:56:39 -05004000
4001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05004002 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05004003 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05004004 break;
James Smart82d9a2a2006-04-15 11:53:05 -04004005 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05004006 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05004007 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04004008 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4009 if (!elsiocb)
4010 return 1;
4011
4012 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004013 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4014 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04004015 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4016
4017 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004018 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004019 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4020 els_pkt_ptr = (ELS_PKT *) pcmd;
4021 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004022
4023 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4024 "Issue ACC PRLO: did:x%x flg:x%x",
4025 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004026 break;
dea31012005-04-17 16:05:31 -05004027 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004028 return 1;
dea31012005-04-17 16:05:31 -05004029 }
dea31012005-04-17 16:05:31 -05004030 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4032 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04004033 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4034 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004035 elsiocb->iotag, elsiocb->iocb.ulpContext,
4036 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04004037 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05004038 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004039 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004040 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4041 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4042 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004043 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004044 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4045 } else {
James Smart858c9f62007-06-17 19:56:39 -05004046 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004047 }
4048
4049 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004050 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004051 if (rc == IOCB_ERROR) {
4052 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004053 return 1;
dea31012005-04-17 16:05:31 -05004054 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004055 return 0;
dea31012005-04-17 16:05:31 -05004056}
4057
James Smarte59058c2008-08-24 21:49:00 -04004058/**
James Smart3621a712009-04-06 18:47:14 -04004059 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004060 * @vport: pointer to a virtual N_Port data structure.
4061 * @rejectError:
4062 * @oldiocb: pointer to the original lpfc command iocb data structure.
4063 * @ndlp: pointer to a node-list data structure.
4064 * @mbox: pointer to the driver internal queue element for mailbox command.
4065 *
4066 * This routine prepares and issue an Reject (RJT) response IOCB
4067 * command. If a @mbox pointer is passed in, it will be put into the
4068 * context_un.mbox field of the IOCB for the completion callback function
4069 * to issue to the HBA later.
4070 *
4071 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4072 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4073 * will be stored into the context1 field of the IOCB for the completion
4074 * callback function to the reject response ELS IOCB command.
4075 *
4076 * Return code
4077 * 0 - Successfully issued reject response
4078 * 1 - Failed to issue reject response
4079 **/
dea31012005-04-17 16:05:31 -05004080int
James Smart2e0fef82007-06-17 19:56:36 -05004081lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004082 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4083 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004084{
James Smart2e0fef82007-06-17 19:56:36 -05004085 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004086 IOCB_t *icmd;
4087 IOCB_t *oldcmd;
4088 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004089 uint8_t *pcmd;
4090 uint16_t cmdsize;
4091 int rc;
4092
James Smart92d7f7b2007-06-17 19:56:38 -05004093 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004094 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4095 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004096 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004097 return 1;
dea31012005-04-17 16:05:31 -05004098
4099 icmd = &elsiocb->iocb;
4100 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004101 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4102 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004103 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4104
4105 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004106 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004107 *((uint32_t *) (pcmd)) = rejectError;
4108
James Smart51ef4c22007-08-02 11:10:31 -04004109 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004110 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004111
dea31012005-04-17 16:05:31 -05004112 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004113 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4114 "0129 Xmit ELS RJT x%x response tag x%x "
4115 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4116 "rpi x%x\n",
4117 rejectError, elsiocb->iotag,
4118 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4119 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4121 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4122 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4123
dea31012005-04-17 16:05:31 -05004124 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004125 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004126 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004127
dea31012005-04-17 16:05:31 -05004128 if (rc == IOCB_ERROR) {
4129 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004130 return 1;
dea31012005-04-17 16:05:31 -05004131 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004132 return 0;
dea31012005-04-17 16:05:31 -05004133}
4134
James Smarte59058c2008-08-24 21:49:00 -04004135/**
James Smart3621a712009-04-06 18:47:14 -04004136 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004137 * @vport: pointer to a virtual N_Port data structure.
4138 * @oldiocb: pointer to the original lpfc command iocb data structure.
4139 * @ndlp: pointer to a node-list data structure.
4140 *
4141 * This routine prepares and issues an Accept (ACC) response to Address
4142 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4143 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4144 *
4145 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4146 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4147 * will be stored into the context1 field of the IOCB for the completion
4148 * callback function to the ADISC Accept response ELS IOCB command.
4149 *
4150 * Return code
4151 * 0 - Successfully issued acc adisc response
4152 * 1 - Failed to issue adisc acc response
4153 **/
dea31012005-04-17 16:05:31 -05004154int
James Smart2e0fef82007-06-17 19:56:36 -05004155lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4156 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004157{
James Smart2e0fef82007-06-17 19:56:36 -05004158 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004159 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004160 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004161 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004162 uint8_t *pcmd;
4163 uint16_t cmdsize;
4164 int rc;
4165
James Smart92d7f7b2007-06-17 19:56:38 -05004166 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004167 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4168 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004169 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004170 return 1;
dea31012005-04-17 16:05:31 -05004171
dea31012005-04-17 16:05:31 -05004172 icmd = &elsiocb->iocb;
4173 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004174 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4175 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004176
4177 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004178 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4179 "0130 Xmit ADISC ACC response iotag x%x xri: "
4180 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4181 elsiocb->iotag, elsiocb->iocb.ulpContext,
4182 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4183 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004184 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4185
4186 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004187 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004188
4189 ap = (ADISC *) (pcmd);
4190 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004191 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4192 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004193 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004194
James Smart858c9f62007-06-17 19:56:39 -05004195 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4196 "Issue ACC ADISC: did:x%x flg:x%x",
4197 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4198
dea31012005-04-17 16:05:31 -05004199 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004200 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004201 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004202 if (rc == IOCB_ERROR) {
4203 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004204 return 1;
dea31012005-04-17 16:05:31 -05004205 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004206 return 0;
dea31012005-04-17 16:05:31 -05004207}
4208
James Smarte59058c2008-08-24 21:49:00 -04004209/**
James Smart3621a712009-04-06 18:47:14 -04004210 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004211 * @vport: pointer to a virtual N_Port data structure.
4212 * @oldiocb: pointer to the original lpfc command iocb data structure.
4213 * @ndlp: pointer to a node-list data structure.
4214 *
4215 * This routine prepares and issues an Accept (ACC) response to Process
4216 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4217 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4218 *
4219 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4220 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4221 * will be stored into the context1 field of the IOCB for the completion
4222 * callback function to the PRLI Accept response ELS IOCB command.
4223 *
4224 * Return code
4225 * 0 - Successfully issued acc prli response
4226 * 1 - Failed to issue acc prli response
4227 **/
dea31012005-04-17 16:05:31 -05004228int
James Smart2e0fef82007-06-17 19:56:36 -05004229lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004230 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004231{
James Smart2e0fef82007-06-17 19:56:36 -05004232 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004233 PRLI *npr;
4234 lpfc_vpd_t *vpd;
4235 IOCB_t *icmd;
4236 IOCB_t *oldcmd;
4237 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004238 uint8_t *pcmd;
4239 uint16_t cmdsize;
4240 int rc;
4241
James Smart92d7f7b2007-06-17 19:56:38 -05004242 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004243 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004244 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004245 if (!elsiocb)
4246 return 1;
dea31012005-04-17 16:05:31 -05004247
dea31012005-04-17 16:05:31 -05004248 icmd = &elsiocb->iocb;
4249 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004250 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4251 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4252
James Smart5b8bd0c2007-04-25 09:52:49 -04004253 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004254 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4255 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4256 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4257 elsiocb->iotag, elsiocb->iocb.ulpContext,
4258 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4259 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004260 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4261
4262 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004263 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004264
4265 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004266 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004267
4268 npr = (PRLI *) pcmd;
4269 vpd = &phba->vpd;
4270 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004271 * If the remote port is a target and our firmware version is 3.20 or
4272 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004273 */
James Smart0d2b6b82008-06-14 22:52:47 -04004274 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4275 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004276 npr->ConfmComplAllowed = 1;
4277 npr->Retry = 1;
4278 npr->TaskRetryIdReq = 1;
4279 }
4280
4281 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4282 npr->estabImagePair = 1;
4283 npr->readXferRdyDis = 1;
4284 npr->ConfmComplAllowed = 1;
4285
4286 npr->prliType = PRLI_FCP_TYPE;
4287 npr->initiatorFunc = 1;
4288
James Smart858c9f62007-06-17 19:56:39 -05004289 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4290 "Issue ACC PRLI: did:x%x flg:x%x",
4291 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4292
dea31012005-04-17 16:05:31 -05004293 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004294 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004295
James Smart3772a992009-05-22 14:50:54 -04004296 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004297 if (rc == IOCB_ERROR) {
4298 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004299 return 1;
dea31012005-04-17 16:05:31 -05004300 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004301 return 0;
dea31012005-04-17 16:05:31 -05004302}
4303
James Smarte59058c2008-08-24 21:49:00 -04004304/**
James Smart3621a712009-04-06 18:47:14 -04004305 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004306 * @vport: pointer to a virtual N_Port data structure.
4307 * @format: rnid command format.
4308 * @oldiocb: pointer to the original lpfc command iocb data structure.
4309 * @ndlp: pointer to a node-list data structure.
4310 *
4311 * This routine issues a Request Node Identification Data (RNID) Accept
4312 * (ACC) response. It constructs the RNID ACC response command according to
4313 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4314 * issue the response. Note that this command does not need to hold the ndlp
4315 * reference count for the callback. So, the ndlp reference count taken by
4316 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4317 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4318 * there is no ndlp reference available.
4319 *
4320 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4321 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4322 * will be stored into the context1 field of the IOCB for the completion
4323 * callback function. However, for the RNID Accept Response ELS command,
4324 * this is undone later by this routine after the IOCB is allocated.
4325 *
4326 * Return code
4327 * 0 - Successfully issued acc rnid response
4328 * 1 - Failed to issue acc rnid response
4329 **/
dea31012005-04-17 16:05:31 -05004330static int
James Smart2e0fef82007-06-17 19:56:36 -05004331lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004332 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004333{
James Smart2e0fef82007-06-17 19:56:36 -05004334 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004335 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004336 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004337 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004338 uint8_t *pcmd;
4339 uint16_t cmdsize;
4340 int rc;
4341
James Smart92d7f7b2007-06-17 19:56:38 -05004342 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4343 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004344 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004345 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004346
James Smart2e0fef82007-06-17 19:56:36 -05004347 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4348 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004349 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004350 return 1;
dea31012005-04-17 16:05:31 -05004351
dea31012005-04-17 16:05:31 -05004352 icmd = &elsiocb->iocb;
4353 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004354 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4355 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4356
James Smart5b8bd0c2007-04-25 09:52:49 -04004357 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004358 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4359 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4360 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004361 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004362 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004363 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004364
James Smart92d7f7b2007-06-17 19:56:38 -05004365 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004366 rn = (RNID *) (pcmd);
4367 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004368 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4369 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4370 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004371 switch (format) {
4372 case 0:
4373 rn->SpecificLen = 0;
4374 break;
4375 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004376 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004377 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004378 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004379 rn->un.topologyDisc.unitType = RNID_HBA;
4380 rn->un.topologyDisc.physPort = 0;
4381 rn->un.topologyDisc.attachedNodes = 0;
4382 break;
4383 default:
4384 rn->CommonLen = 0;
4385 rn->SpecificLen = 0;
4386 break;
4387 }
4388
James Smart858c9f62007-06-17 19:56:39 -05004389 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4390 "Issue ACC RNID: did:x%x flg:x%x",
4391 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4392
dea31012005-04-17 16:05:31 -05004393 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004394 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004395
James Smart3772a992009-05-22 14:50:54 -04004396 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004397 if (rc == IOCB_ERROR) {
4398 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004399 return 1;
dea31012005-04-17 16:05:31 -05004400 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004401 return 0;
dea31012005-04-17 16:05:31 -05004402}
4403
James Smarte59058c2008-08-24 21:49:00 -04004404/**
James Smart19ca7602010-11-20 23:11:55 -05004405 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4406 * @vport: pointer to a virtual N_Port data structure.
4407 * @iocb: pointer to the lpfc command iocb data structure.
4408 * @ndlp: pointer to a node-list data structure.
4409 *
4410 * Return
4411 **/
4412static void
4413lpfc_els_clear_rrq(struct lpfc_vport *vport,
4414 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4415{
4416 struct lpfc_hba *phba = vport->phba;
4417 uint8_t *pcmd;
4418 struct RRQ *rrq;
4419 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004420 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004421 struct lpfc_node_rrq *prrq;
4422
4423
4424 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4425 pcmd += sizeof(uint32_t);
4426 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004427 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004428 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004429
4430 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4431 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4432 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004433 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004434 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004435 rxid,
4436 iocb->iotag, iocb->iocb.ulpContext);
4437
4438 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4439 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4440 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004441 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004442 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004443 else
4444 xri = rxid;
4445 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004446 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004447 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004448 return;
4449}
4450
4451/**
James Smart12265f62010-10-22 11:05:53 -04004452 * lpfc_els_rsp_echo_acc - Issue echo acc response
4453 * @vport: pointer to a virtual N_Port data structure.
4454 * @data: pointer to echo data to return in the accept.
4455 * @oldiocb: pointer to the original lpfc command iocb data structure.
4456 * @ndlp: pointer to a node-list data structure.
4457 *
4458 * Return code
4459 * 0 - Successfully issued acc echo response
4460 * 1 - Failed to issue acc echo response
4461 **/
4462static int
4463lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4464 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4465{
4466 struct lpfc_hba *phba = vport->phba;
4467 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04004468 uint8_t *pcmd;
4469 uint16_t cmdsize;
4470 int rc;
4471
James Smart12265f62010-10-22 11:05:53 -04004472 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4473
James Smartbf086112011-08-21 21:48:13 -04004474 /* The accumulated length can exceed the BPL_SIZE. For
4475 * now, use this as the limit
4476 */
4477 if (cmdsize > LPFC_BPL_SIZE)
4478 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004479 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4480 ndlp->nlp_DID, ELS_CMD_ACC);
4481 if (!elsiocb)
4482 return 1;
4483
James Smart7851fe22011-07-22 18:36:52 -04004484 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4485 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4486
James Smart12265f62010-10-22 11:05:53 -04004487 /* Xmit ECHO ACC response tag <ulpIoTag> */
4488 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4489 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4490 elsiocb->iotag, elsiocb->iocb.ulpContext);
4491 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4492 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4493 pcmd += sizeof(uint32_t);
4494 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4495
4496 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4497 "Issue ACC ECHO: did:x%x flg:x%x",
4498 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4499
4500 phba->fc_stat.elsXmitACC++;
4501 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004502
4503 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4504 if (rc == IOCB_ERROR) {
4505 lpfc_els_free_iocb(phba, elsiocb);
4506 return 1;
4507 }
4508 return 0;
4509}
4510
4511/**
James Smart3621a712009-04-06 18:47:14 -04004512 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004513 * @vport: pointer to a host virtual N_Port data structure.
4514 *
4515 * This routine issues Address Discover (ADISC) ELS commands to those
4516 * N_Ports which are in node port recovery state and ADISC has not been issued
4517 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4518 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4519 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4520 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4521 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4522 * IOCBs quit for later pick up. On the other hand, after walking through
4523 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4524 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4525 * no more ADISC need to be sent.
4526 *
4527 * Return code
4528 * The number of N_Ports with adisc issued.
4529 **/
dea31012005-04-17 16:05:31 -05004530int
James Smart2e0fef82007-06-17 19:56:36 -05004531lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004532{
James Smart2e0fef82007-06-17 19:56:36 -05004533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004534 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004535 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004536
James Smart685f0bf2007-04-25 09:53:08 -04004537 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004538 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004539 if (!NLP_CHK_NODE_ACT(ndlp))
4540 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004541 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4542 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4543 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004544 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004545 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004546 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004547 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4549 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004550 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004551 vport->num_disc_nodes++;
4552 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004553 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004554 spin_lock_irq(shost->host_lock);
4555 vport->fc_flag |= FC_NLP_MORE;
4556 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004557 break;
dea31012005-04-17 16:05:31 -05004558 }
4559 }
4560 }
4561 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004562 spin_lock_irq(shost->host_lock);
4563 vport->fc_flag &= ~FC_NLP_MORE;
4564 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004565 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004566 return sentadisc;
dea31012005-04-17 16:05:31 -05004567}
4568
James Smarte59058c2008-08-24 21:49:00 -04004569/**
James Smart3621a712009-04-06 18:47:14 -04004570 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004571 * @vport: pointer to a host virtual N_Port data structure.
4572 *
4573 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4574 * which are in node port recovery state, with a @vport. Each time an ELS
4575 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4576 * the per @vport number of discover count (num_disc_nodes) shall be
4577 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4578 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4579 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4580 * later pick up. On the other hand, after walking through all the ndlps with
4581 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4582 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4583 * PLOGI need to be sent.
4584 *
4585 * Return code
4586 * The number of N_Ports with plogi issued.
4587 **/
dea31012005-04-17 16:05:31 -05004588int
James Smart2e0fef82007-06-17 19:56:36 -05004589lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004590{
James Smart2e0fef82007-06-17 19:56:36 -05004591 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004592 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004593 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004594
James Smart2e0fef82007-06-17 19:56:36 -05004595 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4596 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004597 if (!NLP_CHK_NODE_ACT(ndlp))
4598 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004599 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004600 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4601 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4602 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004603 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4605 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004606 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004607 vport->num_disc_nodes++;
4608 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004609 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004610 spin_lock_irq(shost->host_lock);
4611 vport->fc_flag |= FC_NLP_MORE;
4612 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004613 break;
dea31012005-04-17 16:05:31 -05004614 }
4615 }
4616 }
James Smart87af33f2007-10-27 13:37:43 -04004617 if (sentplogi) {
4618 lpfc_set_disctmo(vport);
4619 }
4620 else {
James Smart2e0fef82007-06-17 19:56:36 -05004621 spin_lock_irq(shost->host_lock);
4622 vport->fc_flag &= ~FC_NLP_MORE;
4623 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004624 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004625 return sentplogi;
dea31012005-04-17 16:05:31 -05004626}
4627
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004628static uint32_t
James Smart86478872015-05-21 13:55:21 -04004629lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4630 uint32_t word0)
4631{
4632
4633 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4634 desc->payload.els_req = word0;
4635 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07004636
4637 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04004638}
4639
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004640static uint32_t
James Smart86478872015-05-21 13:55:21 -04004641lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4642 uint8_t *page_a0, uint8_t *page_a2)
4643{
4644 uint16_t wavelength;
4645 uint16_t temperature;
4646 uint16_t rx_power;
4647 uint16_t tx_bias;
4648 uint16_t tx_power;
4649 uint16_t vcc;
4650 uint16_t flag = 0;
4651 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4652 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4653
4654 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4655
4656 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4657 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4658 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4659 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4660
4661 if ((trasn_code_byte4->fc_sw_laser) ||
4662 (trasn_code_byte5->fc_sw_laser_sl) ||
4663 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4664 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4665 } else if (trasn_code_byte4->fc_lw_laser) {
4666 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4667 page_a0[SSF_WAVELENGTH_B0];
4668 if (wavelength == SFP_WAVELENGTH_LC1310)
4669 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4670 if (wavelength == SFP_WAVELENGTH_LL1550)
4671 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4672 }
4673 /* check if its SFP+ */
4674 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4675 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4676 << SFP_FLAG_CT_SHIFT;
4677
4678 /* check if its OPTICAL */
4679 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4680 SFP_FLAG_IS_OPTICAL_PORT : 0)
4681 << SFP_FLAG_IS_OPTICAL_SHIFT;
4682
4683 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4684 page_a2[SFF_TEMPERATURE_B0]);
4685 vcc = (page_a2[SFF_VCC_B1] << 8 |
4686 page_a2[SFF_VCC_B0]);
4687 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4688 page_a2[SFF_TXPOWER_B0]);
4689 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4690 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4691 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4692 page_a2[SFF_RXPOWER_B0]);
4693 desc->sfp_info.temperature = cpu_to_be16(temperature);
4694 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4695 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4696 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4697 desc->sfp_info.vcc = cpu_to_be16(vcc);
4698
4699 desc->sfp_info.flags = cpu_to_be16(flag);
4700 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004701
4702 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04004703}
4704
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004705static uint32_t
James Smart86478872015-05-21 13:55:21 -04004706lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4707 READ_LNK_VAR *stat)
4708{
4709 uint32_t type;
4710
4711 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4712
4713 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4714
4715 desc->info.port_type = cpu_to_be32(type);
4716
4717 desc->info.link_status.link_failure_cnt =
4718 cpu_to_be32(stat->linkFailureCnt);
4719 desc->info.link_status.loss_of_synch_cnt =
4720 cpu_to_be32(stat->lossSyncCnt);
4721 desc->info.link_status.loss_of_signal_cnt =
4722 cpu_to_be32(stat->lossSignalCnt);
4723 desc->info.link_status.primitive_seq_proto_err =
4724 cpu_to_be32(stat->primSeqErrCnt);
4725 desc->info.link_status.invalid_trans_word =
4726 cpu_to_be32(stat->invalidXmitWord);
4727 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4728
4729 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07004730
4731 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04004732}
4733
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004734static uint32_t
James Smart56204982016-03-31 14:12:32 -07004735lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4736 struct lpfc_vport *vport)
4737{
James Smart3aaaa312016-07-06 12:35:57 -07004738 uint32_t bbCredit;
4739
James Smart56204982016-03-31 14:12:32 -07004740 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4741
James Smart3aaaa312016-07-06 12:35:57 -07004742 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4743 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4744 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4745 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4746 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4747 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4748 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4749 } else {
James Smart56204982016-03-31 14:12:32 -07004750 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07004751 }
James Smart56204982016-03-31 14:12:32 -07004752
4753 desc->bbc_info.rtt = 0;
4754 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004755
4756 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07004757}
4758
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004759static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004760lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4761 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07004762{
James Smart310429e2016-07-06 12:35:54 -07004763 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004764
4765 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4766
James Smart3aaaa312016-07-06 12:35:57 -07004767 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4768 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4769 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4770 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004771
4772 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4773 flags |= RDP_OET_HIGH_ALARM;
4774 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4775 flags |= RDP_OET_LOW_ALARM;
4776 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4777 flags |= RDP_OET_HIGH_WARNING;
4778 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4779 flags |= RDP_OET_LOW_WARNING;
4780
James Smart56204982016-03-31 14:12:32 -07004781 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4782 desc->oed_info.function_flags = cpu_to_be32(flags);
4783 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004784 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004785}
4786
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004787static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004788lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4789 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004790 uint8_t *page_a2)
4791{
James Smart310429e2016-07-06 12:35:54 -07004792 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004793
4794 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4795
James Smart3aaaa312016-07-06 12:35:57 -07004796 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4797 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4798 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4799 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004800
4801 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4802 flags |= RDP_OET_HIGH_ALARM;
4803 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4804 flags |= RDP_OET_LOW_ALARM;
4805 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4806 flags |= RDP_OET_HIGH_WARNING;
4807 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4808 flags |= RDP_OET_LOW_WARNING;
4809
James Smart56204982016-03-31 14:12:32 -07004810 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4811 desc->oed_info.function_flags = cpu_to_be32(flags);
4812 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004813 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004814}
4815
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004816static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004817lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4818 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004819 uint8_t *page_a2)
4820{
James Smart310429e2016-07-06 12:35:54 -07004821 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004822
4823 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4824
James Smart3aaaa312016-07-06 12:35:57 -07004825 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
4826 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
4827 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
4828 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004829
4830 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
4831 flags |= RDP_OET_HIGH_ALARM;
4832 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
4833 flags |= RDP_OET_LOW_ALARM;
4834 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
4835 flags |= RDP_OET_HIGH_WARNING;
4836 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
4837 flags |= RDP_OET_LOW_WARNING;
4838
James Smart56204982016-03-31 14:12:32 -07004839 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
4840 desc->oed_info.function_flags = cpu_to_be32(flags);
4841 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004842 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004843}
4844
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004845static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004846lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
4847 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004848 uint8_t *page_a2)
4849{
James Smart310429e2016-07-06 12:35:54 -07004850 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004851
4852 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4853
James Smart3aaaa312016-07-06 12:35:57 -07004854 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
4855 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
4856 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
4857 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004858
4859 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
4860 flags |= RDP_OET_HIGH_ALARM;
4861 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
4862 flags |= RDP_OET_LOW_ALARM;
4863 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
4864 flags |= RDP_OET_HIGH_WARNING;
4865 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
4866 flags |= RDP_OET_LOW_WARNING;
4867
James Smart56204982016-03-31 14:12:32 -07004868 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
4869 desc->oed_info.function_flags = cpu_to_be32(flags);
4870 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004871 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004872}
4873
4874
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004875static uint32_t
James Smart310429e2016-07-06 12:35:54 -07004876lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
4877 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004878 uint8_t *page_a2)
4879{
James Smart310429e2016-07-06 12:35:54 -07004880 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004881
4882 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4883
James Smart3aaaa312016-07-06 12:35:57 -07004884 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
4885 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
4886 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
4887 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004888
4889 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
4890 flags |= RDP_OET_HIGH_ALARM;
4891 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
4892 flags |= RDP_OET_LOW_ALARM;
4893 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
4894 flags |= RDP_OET_HIGH_WARNING;
4895 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
4896 flags |= RDP_OET_LOW_WARNING;
4897
James Smart56204982016-03-31 14:12:32 -07004898 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
4899 desc->oed_info.function_flags = cpu_to_be32(flags);
4900 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004901 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004902}
4903
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004904static uint32_t
James Smart56204982016-03-31 14:12:32 -07004905lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
4906 uint8_t *page_a0, struct lpfc_vport *vport)
4907{
4908 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
4909 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
4910 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
4911 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
4912 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 2);
4913 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
4914 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004915 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004916}
4917
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004918static uint32_t
James Smart4258e982015-12-16 18:11:58 -05004919lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
4920{
4921 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
4922 return 0;
4923 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
4924
4925 desc->info.CorrectedBlocks =
4926 cpu_to_be32(stat->fecCorrBlkCount);
4927 desc->info.UncorrectableBlocks =
4928 cpu_to_be32(stat->fecUncorrBlkCount);
4929
4930 desc->length = cpu_to_be32(sizeof(desc->info));
4931
4932 return sizeof(struct fc_fec_rdp_desc);
4933}
4934
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004935static uint32_t
James Smart86478872015-05-21 13:55:21 -04004936lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
4937{
4938 uint16_t rdp_cap = 0;
4939 uint16_t rdp_speed;
4940
4941 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
4942
James Smart81e75172015-12-16 18:11:59 -05004943 switch (phba->fc_linkspeed) {
4944 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04004945 rdp_speed = RDP_PS_1GB;
4946 break;
James Smart81e75172015-12-16 18:11:59 -05004947 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04004948 rdp_speed = RDP_PS_2GB;
4949 break;
James Smart81e75172015-12-16 18:11:59 -05004950 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04004951 rdp_speed = RDP_PS_4GB;
4952 break;
James Smart81e75172015-12-16 18:11:59 -05004953 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04004954 rdp_speed = RDP_PS_8GB;
4955 break;
James Smart81e75172015-12-16 18:11:59 -05004956 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04004957 rdp_speed = RDP_PS_10GB;
4958 break;
James Smart81e75172015-12-16 18:11:59 -05004959 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04004960 rdp_speed = RDP_PS_16GB;
4961 break;
James Smarta085e872015-12-16 18:12:02 -05004962 case LPFC_LINK_SPEED_32GHZ:
4963 rdp_speed = RDP_PS_32GB;
4964 break;
James Smart86478872015-05-21 13:55:21 -04004965 default:
4966 rdp_speed = RDP_PS_UNKNOWN;
4967 break;
4968 }
4969
4970 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
4971
James Smartd38dd522015-08-31 16:48:17 -04004972 if (phba->lmt & LMT_32Gb)
4973 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04004974 if (phba->lmt & LMT_16Gb)
4975 rdp_cap |= RDP_PS_16GB;
4976 if (phba->lmt & LMT_10Gb)
4977 rdp_cap |= RDP_PS_10GB;
4978 if (phba->lmt & LMT_8Gb)
4979 rdp_cap |= RDP_PS_8GB;
4980 if (phba->lmt & LMT_4Gb)
4981 rdp_cap |= RDP_PS_4GB;
4982 if (phba->lmt & LMT_2Gb)
4983 rdp_cap |= RDP_PS_2GB;
4984 if (phba->lmt & LMT_1Gb)
4985 rdp_cap |= RDP_PS_1GB;
4986
4987 if (rdp_cap == 0)
4988 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07004989 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
4990 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04004991
4992 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
4993 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07004994 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04004995}
4996
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08004997static uint32_t
James Smart86478872015-05-21 13:55:21 -04004998lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
4999 struct lpfc_hba *phba)
5000{
5001
5002 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5003
5004 memcpy(desc->port_names.wwnn, phba->wwnn,
5005 sizeof(desc->port_names.wwnn));
5006
5007 memcpy(desc->port_names.wwpn, &phba->wwpn,
5008 sizeof(desc->port_names.wwpn));
5009
5010 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005011 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005012}
5013
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005014static uint32_t
James Smart86478872015-05-21 13:55:21 -04005015lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5016 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5017{
5018
5019 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5020 if (vport->fc_flag & FC_FABRIC) {
5021 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5022 sizeof(desc->port_names.wwnn));
5023
5024 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5025 sizeof(desc->port_names.wwpn));
5026 } else { /* Point to Point */
5027 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5028 sizeof(desc->port_names.wwnn));
5029
5030 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5031 sizeof(desc->port_names.wwpn));
5032 }
5033
5034 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005035 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005036}
5037
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005038static void
James Smart86478872015-05-21 13:55:21 -04005039lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5040 int status)
5041{
5042 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5043 struct lpfc_vport *vport = ndlp->vport;
5044 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005045 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005046 IOCB_t *icmd;
5047 uint8_t *pcmd;
5048 struct ls_rjt *stat;
5049 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005050 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005051 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005052 int rc;
James Smart86478872015-05-21 13:55:21 -04005053
5054 if (status != SUCCESS)
5055 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005056
5057 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005058 cmdsize = sizeof(struct fc_rdp_res_frame);
5059
5060 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5061 lpfc_max_els_tries, rdp_context->ndlp,
5062 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5063 lpfc_nlp_put(ndlp);
5064 if (!elsiocb)
5065 goto free_rdp_context;
5066
5067 icmd = &elsiocb->iocb;
5068 icmd->ulpContext = rdp_context->rx_id;
5069 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5070
5071 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5072 "2171 Xmit RDP response tag x%x xri x%x, "
5073 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5074 elsiocb->iotag, elsiocb->iocb.ulpContext,
5075 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5076 ndlp->nlp_rpi);
5077 rdp_res = (struct fc_rdp_res_frame *)
5078 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5079 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5080 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5081 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5082
James Smart310429e2016-07-06 12:35:54 -07005083 /* Update Alarm and Warning */
5084 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5085 phba->sfp_alarm |= *flag_ptr;
5086 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5087 phba->sfp_warning |= *flag_ptr;
5088
James Smart86478872015-05-21 13:55:21 -04005089 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07005090 len = 8;
5091 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5092 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04005093
James Smart6c92d1d2016-07-06 12:35:55 -07005094 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04005095 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07005096 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5097 phba);
5098 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5099 (len + pcmd), &rdp_context->link_stat);
5100 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5101 (len + pcmd), phba);
5102 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5103 (len + pcmd), vport, ndlp);
5104 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05005105 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07005106 /* Check if nport is logged, BZ190632 */
5107 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5108 goto lpfc_skip_descriptor;
5109
5110 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5111 &rdp_context->link_stat, vport);
5112 len += lpfc_rdp_res_oed_temp_desc(phba,
5113 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5114 rdp_context->page_a2);
5115 len += lpfc_rdp_res_oed_voltage_desc(phba,
5116 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5117 rdp_context->page_a2);
5118 len += lpfc_rdp_res_oed_txbias_desc(phba,
5119 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5120 rdp_context->page_a2);
5121 len += lpfc_rdp_res_oed_txpower_desc(phba,
5122 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5123 rdp_context->page_a2);
5124 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5125 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5126 rdp_context->page_a2);
5127 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5128 rdp_context->page_a0, vport);
5129
5130lpfc_skip_descriptor:
5131 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04005132 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5133
James Smarteb8d68c2015-12-16 18:12:00 -05005134 /* Now that we know the true size of the payload, update the BPL */
5135 bpl = (struct ulp_bde64 *)
5136 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07005137 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05005138 bpl->tus.f.bdeFlags = 0;
5139 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5140
James Smart86478872015-05-21 13:55:21 -04005141 phba->fc_stat.elsXmitACC++;
5142 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5143 if (rc == IOCB_ERROR)
5144 lpfc_els_free_iocb(phba, elsiocb);
5145
5146 kfree(rdp_context);
5147
5148 return;
5149error:
5150 cmdsize = 2 * sizeof(uint32_t);
5151 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5152 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5153 lpfc_nlp_put(ndlp);
5154 if (!elsiocb)
5155 goto free_rdp_context;
5156
5157 icmd = &elsiocb->iocb;
5158 icmd->ulpContext = rdp_context->rx_id;
5159 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5160 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5161
5162 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5163 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5164 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5165
5166 phba->fc_stat.elsXmitLSRJT++;
5167 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5168 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5169
5170 if (rc == IOCB_ERROR)
5171 lpfc_els_free_iocb(phba, elsiocb);
5172free_rdp_context:
5173 kfree(rdp_context);
5174}
5175
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08005176static int
James Smart86478872015-05-21 13:55:21 -04005177lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5178{
5179 LPFC_MBOXQ_t *mbox = NULL;
5180 int rc;
5181
5182 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5183 if (!mbox) {
5184 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5185 "7105 failed to allocate mailbox memory");
5186 return 1;
5187 }
5188
5189 if (lpfc_sli4_dump_page_a0(phba, mbox))
5190 goto prep_mbox_fail;
5191 mbox->vport = rdp_context->ndlp->vport;
5192 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5193 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5194 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5195 if (rc == MBX_NOT_FINISHED)
5196 goto issue_mbox_fail;
5197
5198 return 0;
5199
5200prep_mbox_fail:
5201issue_mbox_fail:
5202 mempool_free(mbox, phba->mbox_mem_pool);
5203 return 1;
5204}
5205
5206/*
5207 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5208 * @vport: pointer to a host virtual N_Port data structure.
5209 * @cmdiocb: pointer to lpfc command iocb data structure.
5210 * @ndlp: pointer to a node-list data structure.
5211 *
5212 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5213 * IOCB. First, the payload of the unsolicited RDP is checked.
5214 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5215 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5216 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5217 * gather all data and send RDP response.
5218 *
5219 * Return code
5220 * 0 - Sent the acc response
5221 * 1 - Sent the reject response.
5222 */
5223static int
5224lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5225 struct lpfc_nodelist *ndlp)
5226{
5227 struct lpfc_hba *phba = vport->phba;
5228 struct lpfc_dmabuf *pcmd;
5229 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5230 struct fc_rdp_req_frame *rdp_req;
5231 struct lpfc_rdp_context *rdp_context;
5232 IOCB_t *cmd = NULL;
5233 struct ls_rjt stat;
5234
5235 if (phba->sli_rev < LPFC_SLI_REV4 ||
5236 (bf_get(lpfc_sli_intf_if_type,
5237 &phba->sli4_hba.sli_intf) !=
5238 LPFC_SLI_INTF_IF_TYPE_2)) {
5239 rjt_err = LSRJT_UNABLE_TPC;
5240 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5241 goto error;
5242 }
5243
5244 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5245 rjt_err = LSRJT_UNABLE_TPC;
5246 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5247 goto error;
5248 }
5249
5250 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5251 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5252
5253
5254 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5255 "2422 ELS RDP Request "
5256 "dec len %d tag x%x port_id %d len %d\n",
5257 be32_to_cpu(rdp_req->rdp_des_length),
5258 be32_to_cpu(rdp_req->nport_id_desc.tag),
5259 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5260 be32_to_cpu(rdp_req->nport_id_desc.length));
5261
James Smart7d933312016-07-06 12:35:58 -07005262 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5263 !phba->cfg_enable_SmartSAN) {
5264 rjt_err = LSRJT_UNABLE_TPC;
5265 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5266 goto error;
5267 }
James Smart86478872015-05-21 13:55:21 -04005268 if (sizeof(struct fc_rdp_nport_desc) !=
5269 be32_to_cpu(rdp_req->rdp_des_length))
5270 goto rjt_logerr;
5271 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5272 goto rjt_logerr;
5273 if (RDP_NPORT_ID_SIZE !=
5274 be32_to_cpu(rdp_req->nport_id_desc.length))
5275 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05005276 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04005277 if (!rdp_context) {
5278 rjt_err = LSRJT_UNABLE_TPC;
5279 goto error;
5280 }
5281
James Smart86478872015-05-21 13:55:21 -04005282 cmd = &cmdiocb->iocb;
5283 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5284 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5285 rdp_context->rx_id = cmd->ulpContext;
5286 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5287 if (lpfc_get_rdp_info(phba, rdp_context)) {
5288 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5289 "2423 Unable to send mailbox");
5290 kfree(rdp_context);
5291 rjt_err = LSRJT_UNABLE_TPC;
5292 lpfc_nlp_put(ndlp);
5293 goto error;
5294 }
5295
5296 return 0;
5297
5298rjt_logerr:
5299 rjt_err = LSRJT_LOGICAL_ERR;
5300
5301error:
5302 memset(&stat, 0, sizeof(stat));
5303 stat.un.b.lsRjtRsnCode = rjt_err;
5304 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5306 return 1;
5307}
5308
5309
James Smart8b017a32015-05-21 13:55:18 -04005310static void
5311lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5312{
5313 MAILBOX_t *mb;
5314 IOCB_t *icmd;
5315 uint8_t *pcmd;
5316 struct lpfc_iocbq *elsiocb;
5317 struct lpfc_nodelist *ndlp;
5318 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005319 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005320 struct lpfc_lcb_context *lcb_context;
5321 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005322 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005323 int rc;
5324
5325 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005326 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5327 ndlp = lcb_context->ndlp;
5328 pmb->context1 = NULL;
5329 pmb->context2 = NULL;
5330
James Smart481ad962015-05-22 10:42:35 -04005331 shdr = (union lpfc_sli4_cfg_shdr *)
5332 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5333 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5334 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5335
5336 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5337 "0194 SET_BEACON_CONFIG mailbox "
5338 "completed with status x%x add_status x%x,"
5339 " mbx status x%x\n",
5340 shdr_status, shdr_add_status, mb->mbxStatus);
5341
5342 if (mb->mbxStatus && !(shdr_status &&
5343 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005344 mempool_free(pmb, phba->mbox_mem_pool);
5345 goto error;
5346 }
5347
5348 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005349 cmdsize = sizeof(struct fc_lcb_res_frame);
5350 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5351 lpfc_max_els_tries, ndlp,
5352 ndlp->nlp_DID, ELS_CMD_ACC);
5353
5354 /* Decrement the ndlp reference count from previous mbox command */
5355 lpfc_nlp_put(ndlp);
5356
5357 if (!elsiocb)
5358 goto free_lcb_context;
5359
5360 lcb_res = (struct fc_lcb_res_frame *)
5361 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5362
5363 icmd = &elsiocb->iocb;
5364 icmd->ulpContext = lcb_context->rx_id;
5365 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5366
5367 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5368 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5369 lcb_res->lcb_sub_command = lcb_context->sub_command;
5370 lcb_res->lcb_type = lcb_context->type;
5371 lcb_res->lcb_frequency = lcb_context->frequency;
5372 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5373 phba->fc_stat.elsXmitACC++;
5374 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5375 if (rc == IOCB_ERROR)
5376 lpfc_els_free_iocb(phba, elsiocb);
5377
5378 kfree(lcb_context);
5379 return;
5380
5381error:
5382 cmdsize = sizeof(struct fc_lcb_res_frame);
5383 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5384 lpfc_max_els_tries, ndlp,
5385 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5386 lpfc_nlp_put(ndlp);
5387 if (!elsiocb)
5388 goto free_lcb_context;
5389
5390 icmd = &elsiocb->iocb;
5391 icmd->ulpContext = lcb_context->rx_id;
5392 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5393 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5394
5395 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5396 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5397 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5398
James Smart77850882018-10-23 13:41:07 -07005399 if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
5400 stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
5401
James Smart8b017a32015-05-21 13:55:18 -04005402 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5403 phba->fc_stat.elsXmitLSRJT++;
5404 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5405 if (rc == IOCB_ERROR)
5406 lpfc_els_free_iocb(phba, elsiocb);
5407free_lcb_context:
5408 kfree(lcb_context);
5409}
5410
5411static int
5412lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5413 struct lpfc_lcb_context *lcb_context,
5414 uint32_t beacon_state)
5415{
5416 struct lpfc_hba *phba = vport->phba;
5417 LPFC_MBOXQ_t *mbox = NULL;
5418 uint32_t len;
5419 int rc;
5420
5421 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5422 if (!mbox)
5423 return 1;
5424
5425 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5426 sizeof(struct lpfc_sli4_cfg_mhdr);
5427 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5428 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5429 LPFC_SLI4_MBX_EMBED);
5430 mbox->context1 = (void *)lcb_context;
5431 mbox->vport = phba->pport;
5432 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5433 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5434 phba->sli4_hba.physical_port);
5435 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5436 beacon_state);
5437 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5438 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5439 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5440 if (rc == MBX_NOT_FINISHED) {
5441 mempool_free(mbox, phba->mbox_mem_pool);
5442 return 1;
5443 }
5444
5445 return 0;
5446}
5447
5448
5449/**
5450 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5451 * @vport: pointer to a host virtual N_Port data structure.
5452 * @cmdiocb: pointer to lpfc command iocb data structure.
5453 * @ndlp: pointer to a node-list data structure.
5454 *
5455 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5456 * First, the payload of the unsolicited LCB is checked.
5457 * Then based on Subcommand beacon will either turn on or off.
5458 *
5459 * Return code
5460 * 0 - Sent the acc response
5461 * 1 - Sent the reject response.
5462 **/
5463static int
5464lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5465 struct lpfc_nodelist *ndlp)
5466{
5467 struct lpfc_hba *phba = vport->phba;
5468 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04005469 uint8_t *lp;
5470 struct fc_lcb_request_frame *beacon;
5471 struct lpfc_lcb_context *lcb_context;
5472 uint8_t state, rjt_err;
5473 struct ls_rjt stat;
5474
James Smart8b017a32015-05-21 13:55:18 -04005475 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5476 lp = (uint8_t *)pcmd->virt;
5477 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5478
5479 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5480 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5481 "type x%x frequency %x duration x%x\n",
5482 lp[0], lp[1], lp[2],
5483 beacon->lcb_command,
5484 beacon->lcb_sub_command,
5485 beacon->lcb_type,
5486 beacon->lcb_frequency,
5487 be16_to_cpu(beacon->lcb_duration));
5488
5489 if (phba->sli_rev < LPFC_SLI_REV4 ||
5490 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5491 LPFC_SLI_INTF_IF_TYPE_2)) {
5492 rjt_err = LSRJT_CMD_UNSUPPORTED;
5493 goto rjt;
5494 }
James Smart8b017a32015-05-21 13:55:18 -04005495
5496 if (phba->hba_flag & HBA_FCOE_MODE) {
5497 rjt_err = LSRJT_CMD_UNSUPPORTED;
5498 goto rjt;
5499 }
5500 if (beacon->lcb_frequency == 0) {
5501 rjt_err = LSRJT_CMD_UNSUPPORTED;
5502 goto rjt;
5503 }
5504 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5505 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5506 rjt_err = LSRJT_CMD_UNSUPPORTED;
5507 goto rjt;
5508 }
5509 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5510 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5511 rjt_err = LSRJT_CMD_UNSUPPORTED;
5512 goto rjt;
5513 }
5514 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5515 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5516 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5517 rjt_err = LSRJT_CMD_UNSUPPORTED;
5518 goto rjt;
5519 }
5520 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5521 rjt_err = LSRJT_CMD_UNSUPPORTED;
5522 goto rjt;
5523 }
5524
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305525 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5526 if (!lcb_context) {
5527 rjt_err = LSRJT_UNABLE_TPC;
5528 goto rjt;
5529 }
5530
James Smart8b017a32015-05-21 13:55:18 -04005531 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5532 lcb_context->sub_command = beacon->lcb_sub_command;
5533 lcb_context->type = beacon->lcb_type;
5534 lcb_context->frequency = beacon->lcb_frequency;
5535 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5536 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5537 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5538 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5539 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5540 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305541 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04005542 lpfc_nlp_put(ndlp);
5543 rjt_err = LSRJT_UNABLE_TPC;
5544 goto rjt;
5545 }
5546 return 0;
5547rjt:
5548 memset(&stat, 0, sizeof(stat));
5549 stat.un.b.lsRjtRsnCode = rjt_err;
5550 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5551 return 1;
5552}
5553
5554
James Smarte59058c2008-08-24 21:49:00 -04005555/**
James Smart3621a712009-04-06 18:47:14 -04005556 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005557 * @vport: pointer to a host virtual N_Port data structure.
5558 *
5559 * This routine cleans up any Registration State Change Notification
5560 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5561 * @vport together with the host_lock is used to prevent multiple thread
5562 * trying to access the RSCN array on a same @vport at the same time.
5563 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005564void
James Smart2e0fef82007-06-17 19:56:36 -05005565lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005566{
James Smart2e0fef82007-06-17 19:56:36 -05005567 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5568 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005569 int i;
5570
James Smart7f5f3d02008-02-08 18:50:14 -05005571 spin_lock_irq(shost->host_lock);
5572 if (vport->fc_rscn_flush) {
5573 /* Another thread is walking fc_rscn_id_list on this vport */
5574 spin_unlock_irq(shost->host_lock);
5575 return;
5576 }
5577 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5578 vport->fc_rscn_flush = 1;
5579 spin_unlock_irq(shost->host_lock);
5580
James Smart2e0fef82007-06-17 19:56:36 -05005581 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005582 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005583 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005584 }
James Smart2e0fef82007-06-17 19:56:36 -05005585 spin_lock_irq(shost->host_lock);
5586 vport->fc_rscn_id_cnt = 0;
5587 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5588 spin_unlock_irq(shost->host_lock);
5589 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005590 /* Indicate we are done walking this fc_rscn_id_list */
5591 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005592}
5593
James Smarte59058c2008-08-24 21:49:00 -04005594/**
James Smart3621a712009-04-06 18:47:14 -04005595 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005596 * @vport: pointer to a host virtual N_Port data structure.
5597 * @did: remote destination port identifier.
5598 *
5599 * This routine checks whether there is any pending Registration State
5600 * Configuration Notification (RSCN) to a @did on @vport.
5601 *
5602 * Return code
5603 * None zero - The @did matched with a pending rscn
5604 * 0 - not able to match @did with a pending rscn
5605 **/
dea31012005-04-17 16:05:31 -05005606int
James Smart2e0fef82007-06-17 19:56:36 -05005607lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005608{
5609 D_ID ns_did;
5610 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005611 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005612 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005613 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005614
5615 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005616
5617 /* Never match fabric nodes for RSCNs */
5618 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005619 return 0;
dea31012005-04-17 16:05:31 -05005620
5621 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005622 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005623 return did;
dea31012005-04-17 16:05:31 -05005624
James Smart7f5f3d02008-02-08 18:50:14 -05005625 spin_lock_irq(shost->host_lock);
5626 if (vport->fc_rscn_flush) {
5627 /* Another thread is walking fc_rscn_id_list on this vport */
5628 spin_unlock_irq(shost->host_lock);
5629 return 0;
5630 }
5631 /* Indicate we are walking fc_rscn_id_list on this vport */
5632 vport->fc_rscn_flush = 1;
5633 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005634 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005635 lp = vport->fc_rscn_id_list[i]->virt;
5636 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5637 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005638 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005639 rscn_did.un.word = be32_to_cpu(*lp++);
5640 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005641 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5642 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005643 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5644 && (ns_did.un.b.area == rscn_did.un.b.area)
5645 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005646 goto return_did_out;
dea31012005-04-17 16:05:31 -05005647 break;
James Smarteaf15d52008-12-04 22:39:29 -05005648 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005649 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5650 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005651 goto return_did_out;
dea31012005-04-17 16:05:31 -05005652 break;
James Smarteaf15d52008-12-04 22:39:29 -05005653 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005654 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005655 goto return_did_out;
dea31012005-04-17 16:05:31 -05005656 break;
James Smarteaf15d52008-12-04 22:39:29 -05005657 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005658 goto return_did_out;
dea31012005-04-17 16:05:31 -05005659 }
5660 }
James Smart92d7f7b2007-06-17 19:56:38 -05005661 }
James Smart7f5f3d02008-02-08 18:50:14 -05005662 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5663 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005664 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005665return_did_out:
5666 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5667 vport->fc_rscn_flush = 0;
5668 return did;
dea31012005-04-17 16:05:31 -05005669}
5670
James Smarte59058c2008-08-24 21:49:00 -04005671/**
James Smart3621a712009-04-06 18:47:14 -04005672 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005673 * @vport: pointer to a host virtual N_Port data structure.
5674 *
5675 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5676 * state machine for a @vport's nodes that are with pending RSCN (Registration
5677 * State Change Notification).
5678 *
5679 * Return code
5680 * 0 - Successful (currently alway return 0)
5681 **/
dea31012005-04-17 16:05:31 -05005682static int
James Smart2e0fef82007-06-17 19:56:36 -05005683lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005684{
James Smart685f0bf2007-04-25 09:53:08 -04005685 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005686
James Smart0d2b6b82008-06-14 22:52:47 -04005687 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005688 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005689 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005690 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5691 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005692 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005693 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005694 NLP_EVT_DEVICE_RECOVERY);
5695 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005696 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005697 return 0;
dea31012005-04-17 16:05:31 -05005698}
5699
James Smarte59058c2008-08-24 21:49:00 -04005700/**
James Smart3621a712009-04-06 18:47:14 -04005701 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005702 * @vport: pointer to a host virtual N_Port data structure.
5703 * @cmdiocb: pointer to lpfc command iocb data structure.
5704 *
5705 * lpfc_send_rscn_event sends an RSCN netlink event to management
5706 * applications.
5707 */
5708static void
5709lpfc_send_rscn_event(struct lpfc_vport *vport,
5710 struct lpfc_iocbq *cmdiocb)
5711{
5712 struct lpfc_dmabuf *pcmd;
5713 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5714 uint32_t *payload_ptr;
5715 uint32_t payload_len;
5716 struct lpfc_rscn_event_header *rscn_event_data;
5717
5718 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5719 payload_ptr = (uint32_t *) pcmd->virt;
5720 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5721
5722 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5723 payload_len, GFP_KERNEL);
5724 if (!rscn_event_data) {
5725 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5726 "0147 Failed to allocate memory for RSCN event\n");
5727 return;
5728 }
5729 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5730 rscn_event_data->payload_length = payload_len;
5731 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5732 payload_len);
5733
5734 fc_host_post_vendor_event(shost,
5735 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04005736 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05005737 (char *)rscn_event_data,
5738 LPFC_NL_VENDOR_ID);
5739
5740 kfree(rscn_event_data);
5741}
5742
5743/**
James Smart3621a712009-04-06 18:47:14 -04005744 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04005745 * @vport: pointer to a host virtual N_Port data structure.
5746 * @cmdiocb: pointer to lpfc command iocb data structure.
5747 * @ndlp: pointer to a node-list data structure.
5748 *
5749 * This routine processes an unsolicited RSCN (Registration State Change
5750 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5751 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5752 * discover state machine is about to begin discovery, it just accepts the
5753 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5754 * contains N_Port IDs for other vports on this HBA, it just accepts the
5755 * RSCN and ignore processing it. If the state machine is in the recovery
5756 * state, the fc_rscn_id_list of this @vport is walked and the
5757 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5758 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5759 * routine is invoked to handle the RSCN event.
5760 *
5761 * Return code
5762 * 0 - Just sent the acc response
5763 * 1 - Sent the acc response and waited for name server completion
5764 **/
dea31012005-04-17 16:05:31 -05005765static int
James Smart2e0fef82007-06-17 19:56:36 -05005766lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005767 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005768{
James Smart2e0fef82007-06-17 19:56:36 -05005769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5770 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005771 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005772 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05005773 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005774 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05005775 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04005776 int i;
dea31012005-04-17 16:05:31 -05005777
dea31012005-04-17 16:05:31 -05005778 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5779 lp = (uint32_t *) pcmd->virt;
5780
James Smart92d7f7b2007-06-17 19:56:38 -05005781 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5782 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005783 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04005784 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5785 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05005786 vport->fc_flag, payload_len, *lp,
5787 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05005788
5789 /* Send an RSCN event to the management application */
5790 lpfc_send_rscn_event(vport, cmdiocb);
5791
James Smartd2873e42006-08-18 17:46:43 -04005792 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05005793 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04005794 FCH_EVT_RSCN, lp[i]);
5795
dea31012005-04-17 16:05:31 -05005796 /* If we are about to begin discovery, just ACC the RSCN.
5797 * Discovery processing will satisfy it.
5798 */
James Smart2e0fef82007-06-17 19:56:36 -05005799 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05005800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5801 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5802 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5803
James Smart51ef4c22007-08-02 11:10:31 -04005804 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005805 return 0;
dea31012005-04-17 16:05:31 -05005806 }
5807
James Smart92d7f7b2007-06-17 19:56:38 -05005808 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5809 * just ACC and ignore it.
5810 */
5811 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04005812 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05005813 i = payload_len;
5814 datap = lp;
5815 while (i > 0) {
5816 nportid = *datap++;
5817 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5818 i -= sizeof(uint32_t);
5819 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04005820 if (lpfc_find_vport_by_did(phba, nportid))
5821 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05005822 }
5823 if (rscn_id == hba_id) {
5824 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04005825 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005826 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04005827 "Data: x%x x%x x%x x%x\n",
5828 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05005829 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05005830 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5831 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5832 ndlp->nlp_DID, vport->port_state,
5833 ndlp->nlp_flag);
5834
James Smart92d7f7b2007-06-17 19:56:38 -05005835 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005836 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05005837 return 0;
5838 }
5839 }
5840
James Smart7f5f3d02008-02-08 18:50:14 -05005841 spin_lock_irq(shost->host_lock);
5842 if (vport->fc_rscn_flush) {
5843 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05005844 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05005845 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04005846 /* Send back ACC */
5847 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05005848 return 0;
5849 }
5850 /* Indicate we are walking fc_rscn_id_list on this vport */
5851 vport->fc_rscn_flush = 1;
5852 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005853 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05005854 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05005855 /* If we are already processing an RSCN, save the received
5856 * RSCN payload buffer, cmdiocb->context2 to process later.
5857 */
James Smart2e0fef82007-06-17 19:56:36 -05005858 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05005859 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5860 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5861 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5862
James Smart09372822008-01-11 01:52:54 -05005863 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005864 vport->fc_flag |= FC_RSCN_DEFERRED;
5865 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05005866 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005867 vport->fc_flag |= FC_RSCN_MODE;
5868 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005869 if (rscn_cnt) {
5870 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
5871 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
5872 }
5873 if ((rscn_cnt) &&
5874 (payload_len + length <= LPFC_BPL_SIZE)) {
5875 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05005876 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05005877 memcpy(((uint8_t *)cmd) + length, lp,
5878 payload_len);
5879 } else {
5880 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
5881 vport->fc_rscn_id_cnt++;
5882 /* If we zero, cmdiocb->context2, the calling
5883 * routine will not try to free it.
5884 */
5885 cmdiocb->context2 = NULL;
5886 }
dea31012005-04-17 16:05:31 -05005887 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005888 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5889 "0235 Deferred RSCN "
5890 "Data: x%x x%x x%x\n",
5891 vport->fc_rscn_id_cnt, vport->fc_flag,
5892 vport->port_state);
dea31012005-04-17 16:05:31 -05005893 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005894 vport->fc_flag |= FC_RSCN_DISCOVERY;
5895 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005896 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005897 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5898 "0234 ReDiscovery RSCN "
5899 "Data: x%x x%x x%x\n",
5900 vport->fc_rscn_id_cnt, vport->fc_flag,
5901 vport->port_state);
dea31012005-04-17 16:05:31 -05005902 }
James Smart7f5f3d02008-02-08 18:50:14 -05005903 /* Indicate we are done walking fc_rscn_id_list on this vport */
5904 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005905 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005906 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005907 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005908 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05005909 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005910 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05005911 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005912 return 0;
dea31012005-04-17 16:05:31 -05005913 }
James Smart858c9f62007-06-17 19:56:39 -05005914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5915 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5916 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5917
James Smart2e0fef82007-06-17 19:56:36 -05005918 spin_lock_irq(shost->host_lock);
5919 vport->fc_flag |= FC_RSCN_MODE;
5920 spin_unlock_irq(shost->host_lock);
5921 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005922 /* Indicate we are done walking fc_rscn_id_list on this vport */
5923 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005924 /*
5925 * If we zero, cmdiocb->context2, the calling routine will
5926 * not try to free it.
5927 */
5928 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005929 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005930 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005931 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005932 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005933 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005934 return lpfc_els_handle_rscn(vport);
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_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04005939 * @vport: pointer to a host virtual N_Port data structure.
5940 *
5941 * This routine handles the Registration State Configuration Notification
5942 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5943 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5944 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5945 * NameServer shall be issued. If CT command to the NameServer fails to be
5946 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5947 * RSCN activities with the @vport.
5948 *
5949 * Return code
5950 * 0 - Cleaned up rscn on the @vport
5951 * 1 - Wait for plogi to name server before proceed
5952 **/
dea31012005-04-17 16:05:31 -05005953int
James Smart2e0fef82007-06-17 19:56:36 -05005954lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005955{
5956 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005957 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005958
James Smart92d7f7b2007-06-17 19:56:38 -05005959 /* Ignore RSCN if the port is being torn down. */
5960 if (vport->load_flag & FC_UNLOADING) {
5961 lpfc_els_flush_rscn(vport);
5962 return 0;
5963 }
5964
dea31012005-04-17 16:05:31 -05005965 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05005966 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005967
5968 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04005969 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5970 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5971 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
5972 vport->port_state);
dea31012005-04-17 16:05:31 -05005973
5974 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005975 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05005976 vport->num_disc_nodes = 0;
5977
James Smart2e0fef82007-06-17 19:56:36 -05005978 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005979 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
5980 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05005981 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05005982 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05005983 /* Wait for NameServer query cmpl before we can
5984 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005985 return 1;
dea31012005-04-17 16:05:31 -05005986 } else {
5987 /* If login to NameServer does not exist, issue one */
5988 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005989 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005990 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05005991 /* Wait for NameServer login cmpl before we can
5992 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005993 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05005994
James Smarte47c9092008-02-08 18:49:26 -05005995 if (ndlp) {
5996 ndlp = lpfc_enable_node(vport, ndlp,
5997 NLP_STE_PLOGI_ISSUE);
5998 if (!ndlp) {
5999 lpfc_els_flush_rscn(vport);
6000 return 0;
6001 }
6002 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05006003 } else {
James Smarte47c9092008-02-08 18:49:26 -05006004 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6005 if (!ndlp) {
6006 lpfc_els_flush_rscn(vport);
6007 return 0;
6008 }
James Smart2e0fef82007-06-17 19:56:36 -05006009 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006010 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006011 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05006012 }
James Smarte47c9092008-02-08 18:49:26 -05006013 ndlp->nlp_type |= NLP_FABRIC;
6014 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6015 /* Wait for NameServer login cmpl before we can
6016 * continue
6017 */
6018 return 1;
dea31012005-04-17 16:05:31 -05006019 }
6020
James Smart2e0fef82007-06-17 19:56:36 -05006021 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006022 return 0;
dea31012005-04-17 16:05:31 -05006023}
6024
James Smarte59058c2008-08-24 21:49:00 -04006025/**
James Smart3621a712009-04-06 18:47:14 -04006026 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04006027 * @vport: pointer to a host virtual N_Port data structure.
6028 * @cmdiocb: pointer to lpfc command iocb data structure.
6029 * @ndlp: pointer to a node-list data structure.
6030 *
6031 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6032 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6033 * point topology. As an unsolicited FLOGI should not be received in a loop
6034 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6035 * lpfc_check_sparm() routine is invoked to check the parameters in the
6036 * unsolicited FLOGI. If parameters validation failed, the routine
6037 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6038 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6039 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6040 * will initiate PLOGI. The higher lexicographical value party shall has
6041 * higher priority (as the winning port) and will initiate PLOGI and
6042 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6043 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6044 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6045 *
6046 * Return code
6047 * 0 - Successfully processed the unsolicited flogi
6048 * 1 - Failed to process the unsolicited flogi
6049 **/
dea31012005-04-17 16:05:31 -05006050static int
James Smart2e0fef82007-06-17 19:56:36 -05006051lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006052 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006053{
James Smart2e0fef82007-06-17 19:56:36 -05006054 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6055 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006056 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6057 uint32_t *lp = (uint32_t *) pcmd->virt;
6058 IOCB_t *icmd = &cmdiocb->iocb;
6059 struct serv_parm *sp;
6060 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05006061 uint32_t cmd, did;
6062 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04006063 uint32_t fc_flag = 0;
6064 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05006065
6066 cmd = *lp++;
6067 sp = (struct serv_parm *) lp;
6068
6069 /* FLOGI received */
6070
James Smart2e0fef82007-06-17 19:56:36 -05006071 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006072
James Smart76a95d72010-11-20 23:11:48 -05006073 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006074 /* We should never receive a FLOGI in loop mode, ignore it */
6075 did = icmd->un.elsreq64.remoteID;
6076
6077 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6078 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04006079 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6080 "0113 An FLOGI ELS command x%x was "
6081 "received from DID x%x in Loop Mode\n",
6082 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006083 return 1;
dea31012005-04-17 16:05:31 -05006084 }
6085
James Smartd6de08c2015-12-16 18:11:53 -05006086 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05006087
dea31012005-04-17 16:05:31 -05006088
James Smartd6de08c2015-12-16 18:11:53 -05006089 /*
6090 * If our portname is greater than the remote portname,
6091 * then we initiate Nport login.
6092 */
6093
6094 rc = memcmp(&vport->fc_portname, &sp->portName,
6095 sizeof(struct lpfc_name));
6096
6097 if (!rc) {
6098 if (phba->sli_rev < LPFC_SLI_REV4) {
6099 mbox = mempool_alloc(phba->mbox_mem_pool,
6100 GFP_KERNEL);
6101 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006102 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05006103 lpfc_linkdown(phba);
6104 lpfc_init_link(phba, mbox,
6105 phba->cfg_topology,
6106 phba->cfg_link_speed);
6107 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6108 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6109 mbox->vport = vport;
6110 rc = lpfc_sli_issue_mbox(phba, mbox,
6111 MBX_NOWAIT);
6112 lpfc_set_loopback_flag(phba);
6113 if (rc == MBX_NOT_FINISHED)
6114 mempool_free(mbox, phba->mbox_mem_pool);
6115 return 1;
6116 }
James Smart939723a2012-05-09 21:19:03 -04006117
James Smartd6de08c2015-12-16 18:11:53 -05006118 /* abort the flogi coming back to ourselves
6119 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04006120 */
James Smartd6de08c2015-12-16 18:11:53 -05006121 lpfc_els_abort_flogi(phba);
6122 return 0;
6123
6124 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05006125 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05006126 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05006127 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04006128
James Smartd6de08c2015-12-16 18:11:53 -05006129 /* If we have the high WWPN we can assign our own
6130 * myDID; otherwise, we have to WAIT for a PLOGI
6131 * from the remote NPort to find out what it
6132 * will be.
James Smart939723a2012-05-09 21:19:03 -04006133 */
James Smartd6de08c2015-12-16 18:11:53 -05006134 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05006135 } else {
James Smartd6de08c2015-12-16 18:11:53 -05006136 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05006137 }
6138
James Smartd6de08c2015-12-16 18:11:53 -05006139 /*
6140 * The vport state should go to LPFC_FLOGI only
6141 * AFTER we issue a FLOGI, not receive one.
6142 */
6143 spin_lock_irq(shost->host_lock);
6144 fc_flag = vport->fc_flag;
6145 port_state = vport->port_state;
6146 vport->fc_flag |= FC_PT2PT;
6147 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6148 spin_unlock_irq(shost->host_lock);
6149 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6150 "3311 Rcv Flogi PS x%x new PS x%x "
6151 "fc_flag x%x new fc_flag x%x\n",
6152 port_state, vport->port_state,
6153 fc_flag, vport->fc_flag);
6154
6155 /*
6156 * We temporarily set fc_myDID to make it look like we are
6157 * a Fabric. This is done just so we end up with the right
6158 * did / sid on the FLOGI ACC rsp.
6159 */
6160 did = vport->fc_myDID;
6161 vport->fc_myDID = Fabric_DID;
6162
6163 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04006164
dea31012005-04-17 16:05:31 -05006165 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05006166 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006167
James Smart939723a2012-05-09 21:19:03 -04006168 /* Now lets put fc_myDID back to what its supposed to be */
6169 vport->fc_myDID = did;
6170
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006171 return 0;
dea31012005-04-17 16:05:31 -05006172}
6173
James Smarte59058c2008-08-24 21:49:00 -04006174/**
James Smart3621a712009-04-06 18:47:14 -04006175 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04006176 * @vport: pointer to a host virtual N_Port data structure.
6177 * @cmdiocb: pointer to lpfc command iocb data structure.
6178 * @ndlp: pointer to a node-list data structure.
6179 *
6180 * This routine processes Request Node Identification Data (RNID) IOCB
6181 * received as an ELS unsolicited event. Only when the RNID specified format
6182 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6183 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6184 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6185 * rejected by invoking the lpfc_els_rsp_reject() routine.
6186 *
6187 * Return code
6188 * 0 - Successfully processed rnid iocb (currently always return 0)
6189 **/
dea31012005-04-17 16:05:31 -05006190static int
James Smart2e0fef82007-06-17 19:56:36 -05006191lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6192 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006193{
6194 struct lpfc_dmabuf *pcmd;
6195 uint32_t *lp;
dea31012005-04-17 16:05:31 -05006196 RNID *rn;
6197 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04006198 uint32_t cmd;
dea31012005-04-17 16:05:31 -05006199
dea31012005-04-17 16:05:31 -05006200 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6201 lp = (uint32_t *) pcmd->virt;
6202
6203 cmd = *lp++;
6204 rn = (RNID *) lp;
6205
6206 /* RNID received */
6207
6208 switch (rn->Format) {
6209 case 0:
6210 case RNID_TOPOLOGY_DISC:
6211 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05006212 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006213 break;
6214 default:
6215 /* Reject this request because format not supported */
6216 stat.un.b.lsRjtRsvd0 = 0;
6217 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6218 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6219 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006220 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6221 NULL);
dea31012005-04-17 16:05:31 -05006222 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006223 return 0;
dea31012005-04-17 16:05:31 -05006224}
6225
James Smarte59058c2008-08-24 21:49:00 -04006226/**
James Smart12265f62010-10-22 11:05:53 -04006227 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6228 * @vport: pointer to a host virtual N_Port data structure.
6229 * @cmdiocb: pointer to lpfc command iocb data structure.
6230 * @ndlp: pointer to a node-list data structure.
6231 *
6232 * Return code
6233 * 0 - Successfully processed echo iocb (currently always return 0)
6234 **/
6235static int
6236lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6237 struct lpfc_nodelist *ndlp)
6238{
6239 uint8_t *pcmd;
6240
6241 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6242
6243 /* skip over first word of echo command to find echo data */
6244 pcmd += sizeof(uint32_t);
6245
6246 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6247 return 0;
6248}
6249
6250/**
James Smart3621a712009-04-06 18:47:14 -04006251 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04006252 * @vport: pointer to a host virtual N_Port data structure.
6253 * @cmdiocb: pointer to lpfc command iocb data structure.
6254 * @ndlp: pointer to a node-list data structure.
6255 *
6256 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6257 * received as an ELS unsolicited event. Currently, this function just invokes
6258 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6259 *
6260 * Return code
6261 * 0 - Successfully processed lirr iocb (currently always return 0)
6262 **/
dea31012005-04-17 16:05:31 -05006263static int
James Smart2e0fef82007-06-17 19:56:36 -05006264lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6265 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006266{
6267 struct ls_rjt stat;
6268
6269 /* For now, unconditionally reject this command */
6270 stat.un.b.lsRjtRsvd0 = 0;
6271 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6272 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6273 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006274 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006275 return 0;
6276}
6277
James Smarte59058c2008-08-24 21:49:00 -04006278/**
James Smart5ffc2662009-11-18 15:39:44 -05006279 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6280 * @vport: pointer to a host virtual N_Port data structure.
6281 * @cmdiocb: pointer to lpfc command iocb data structure.
6282 * @ndlp: pointer to a node-list data structure.
6283 *
6284 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6285 * received as an ELS unsolicited event. A request to RRQ shall only
6286 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6287 * Nx_Port N_Port_ID of the target Exchange is the same as the
6288 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6289 * not accepted, an LS_RJT with reason code "Unable to perform
6290 * command request" and reason code explanation "Invalid Originator
6291 * S_ID" shall be returned. For now, we just unconditionally accept
6292 * RRQ from the target.
6293 **/
6294static void
6295lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6296 struct lpfc_nodelist *ndlp)
6297{
6298 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05006299 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6300 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05006301}
6302
6303/**
James Smart12265f62010-10-22 11:05:53 -04006304 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6305 * @phba: pointer to lpfc hba data structure.
6306 * @pmb: pointer to the driver internal queue element for mailbox command.
6307 *
6308 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6309 * mailbox command. This callback function is to actually send the Accept
6310 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6311 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6312 * mailbox command, constructs the RPS response with the link statistics
6313 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6314 * response to the RPS.
6315 *
6316 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6317 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6318 * will be stored into the context1 field of the IOCB for the completion
6319 * callback function to the RPS Accept Response ELS IOCB command.
6320 *
6321 **/
6322static void
6323lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6324{
6325 MAILBOX_t *mb;
6326 IOCB_t *icmd;
6327 struct RLS_RSP *rls_rsp;
6328 uint8_t *pcmd;
6329 struct lpfc_iocbq *elsiocb;
6330 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006331 uint16_t oxid;
6332 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006333 uint32_t cmdsize;
6334
6335 mb = &pmb->u.mb;
6336
6337 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006338 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6339 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006340 pmb->context1 = NULL;
6341 pmb->context2 = NULL;
6342
6343 if (mb->mbxStatus) {
6344 mempool_free(pmb, phba->mbox_mem_pool);
6345 return;
6346 }
6347
6348 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006349 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6350 lpfc_max_els_tries, ndlp,
6351 ndlp->nlp_DID, ELS_CMD_ACC);
6352
6353 /* Decrement the ndlp reference count from previous mbox command */
6354 lpfc_nlp_put(ndlp);
6355
James Smart37db57e2012-05-09 21:17:16 -04006356 if (!elsiocb) {
6357 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006358 return;
James Smart37db57e2012-05-09 21:17:16 -04006359 }
James Smart12265f62010-10-22 11:05:53 -04006360
6361 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006362 icmd->ulpContext = rxid;
6363 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006364
6365 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6366 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6367 pcmd += sizeof(uint32_t); /* Skip past command */
6368 rls_rsp = (struct RLS_RSP *)pcmd;
6369
6370 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6371 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6372 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6373 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6374 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6375 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006376 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006377 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6378 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6379 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6380 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6381 elsiocb->iotag, elsiocb->iocb.ulpContext,
6382 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6383 ndlp->nlp_rpi);
6384 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6385 phba->fc_stat.elsXmitACC++;
6386 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6387 lpfc_els_free_iocb(phba, elsiocb);
6388}
6389
6390/**
James Smart3621a712009-04-06 18:47:14 -04006391 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006392 * @phba: pointer to lpfc hba data structure.
6393 * @pmb: pointer to the driver internal queue element for mailbox command.
6394 *
6395 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6396 * mailbox command. This callback function is to actually send the Accept
6397 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6398 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6399 * mailbox command, constructs the RPS response with the link statistics
6400 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6401 * response to the RPS.
6402 *
6403 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6404 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6405 * will be stored into the context1 field of the IOCB for the completion
6406 * callback function to the RPS Accept Response ELS IOCB command.
6407 *
6408 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006409static void
James Smart329f9bc2007-04-25 09:53:01 -04006410lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006411{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006412 MAILBOX_t *mb;
6413 IOCB_t *icmd;
6414 RPS_RSP *rps_rsp;
6415 uint8_t *pcmd;
6416 struct lpfc_iocbq *elsiocb;
6417 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006418 uint16_t status;
6419 uint16_t oxid;
6420 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006421 uint32_t cmdsize;
6422
James Smart04c68492009-05-22 14:52:52 -04006423 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006424
6425 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006426 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6427 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006428 pmb->context1 = NULL;
6429 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006430
6431 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006432 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006433 return;
6434 }
6435
6436 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006437 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006438 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6439 lpfc_max_els_tries, ndlp,
6440 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006441
6442 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006443 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006444
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006445 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006446 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006447
6448 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006449 icmd->ulpContext = rxid;
6450 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006451
6452 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6453 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006454 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006455 rps_rsp = (RPS_RSP *)pcmd;
6456
James Smart76a95d72010-11-20 23:11:48 -05006457 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006458 status = 0x10;
6459 else
6460 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006461 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006462 status |= 0x4;
6463
6464 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006465 rps_rsp->portStatus = cpu_to_be16(status);
6466 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6467 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6468 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6469 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6470 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6471 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006472 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006473 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6474 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6475 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6476 elsiocb->iotag, elsiocb->iocb.ulpContext,
6477 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6478 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006479 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006480 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006481 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006482 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006483 return;
6484}
6485
James Smarte59058c2008-08-24 21:49:00 -04006486/**
James Smart12265f62010-10-22 11:05:53 -04006487 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6488 * @vport: pointer to a host virtual N_Port data structure.
6489 * @cmdiocb: pointer to lpfc command iocb data structure.
6490 * @ndlp: pointer to a node-list data structure.
6491 *
6492 * This routine processes Read Port Status (RPL) IOCB received as an
6493 * ELS unsolicited event. It first checks the remote port state. If the
6494 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6495 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6496 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6497 * for reading the HBA link statistics. It is for the callback function,
6498 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6499 * to actually sending out RPL Accept (ACC) response.
6500 *
6501 * Return codes
6502 * 0 - Successfully processed rls iocb (currently always return 0)
6503 **/
6504static int
6505lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6506 struct lpfc_nodelist *ndlp)
6507{
6508 struct lpfc_hba *phba = vport->phba;
6509 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04006510 struct ls_rjt stat;
6511
6512 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6513 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6514 /* reject the unsolicited RPS request and done with it */
6515 goto reject_out;
6516
James Smart12265f62010-10-22 11:05:53 -04006517 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6518 if (mbox) {
6519 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006520 mbox->context1 = (void *)((unsigned long)
6521 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6522 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006523 mbox->context2 = lpfc_nlp_get(ndlp);
6524 mbox->vport = vport;
6525 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6526 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6527 != MBX_NOT_FINISHED)
6528 /* Mbox completion will send ELS Response */
6529 return 0;
6530 /* Decrement reference count used for the failed mbox
6531 * command.
6532 */
6533 lpfc_nlp_put(ndlp);
6534 mempool_free(mbox, phba->mbox_mem_pool);
6535 }
6536reject_out:
6537 /* issue rejection response */
6538 stat.un.b.lsRjtRsvd0 = 0;
6539 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6540 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6541 stat.un.b.vendorUnique = 0;
6542 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6543 return 0;
6544}
6545
6546/**
6547 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6548 * @vport: pointer to a host virtual N_Port data structure.
6549 * @cmdiocb: pointer to lpfc command iocb data structure.
6550 * @ndlp: pointer to a node-list data structure.
6551 *
6552 * This routine processes Read Timout Value (RTV) IOCB received as an
6553 * ELS unsolicited event. It first checks the remote port state. If the
6554 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6555 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6556 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6557 * Value (RTV) unsolicited IOCB event.
6558 *
6559 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6560 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6561 * will be stored into the context1 field of the IOCB for the completion
6562 * callback function to the RPS Accept Response ELS IOCB command.
6563 *
6564 * Return codes
6565 * 0 - Successfully processed rtv iocb (currently always return 0)
6566 **/
6567static int
6568lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6569 struct lpfc_nodelist *ndlp)
6570{
6571 struct lpfc_hba *phba = vport->phba;
6572 struct ls_rjt stat;
6573 struct RTV_RSP *rtv_rsp;
6574 uint8_t *pcmd;
6575 struct lpfc_iocbq *elsiocb;
6576 uint32_t cmdsize;
6577
6578
6579 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6580 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6581 /* reject the unsolicited RPS request and done with it */
6582 goto reject_out;
6583
6584 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6585 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6586 lpfc_max_els_tries, ndlp,
6587 ndlp->nlp_DID, ELS_CMD_ACC);
6588
6589 if (!elsiocb)
6590 return 1;
6591
6592 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6593 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6594 pcmd += sizeof(uint32_t); /* Skip past command */
6595
6596 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006597 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6598 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006599
6600 rtv_rsp = (struct RTV_RSP *)pcmd;
6601
6602 /* populate RTV payload */
6603 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6604 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6605 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6606 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6607 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6608
6609 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6610 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6611 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6612 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6613 "Data: x%x x%x x%x\n",
6614 elsiocb->iotag, elsiocb->iocb.ulpContext,
6615 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6616 ndlp->nlp_rpi,
6617 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6618 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6619 phba->fc_stat.elsXmitACC++;
6620 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6621 lpfc_els_free_iocb(phba, elsiocb);
6622 return 0;
6623
6624reject_out:
6625 /* issue rejection response */
6626 stat.un.b.lsRjtRsvd0 = 0;
6627 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6628 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6629 stat.un.b.vendorUnique = 0;
6630 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6631 return 0;
6632}
6633
6634/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006635 * @vport: pointer to a host virtual N_Port data structure.
6636 * @cmdiocb: pointer to lpfc command iocb data structure.
6637 * @ndlp: pointer to a node-list data structure.
6638 *
6639 * This routine processes Read Port Status (RPS) IOCB received as an
6640 * ELS unsolicited event. It first checks the remote port state. If the
6641 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6642 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6643 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6644 * for reading the HBA link statistics. It is for the callback function,
6645 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6646 * to actually sending out RPS Accept (ACC) response.
6647 *
6648 * Return codes
6649 * 0 - Successfully processed rps iocb (currently always return 0)
6650 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006651static int
James Smart2e0fef82007-06-17 19:56:36 -05006652lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6653 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006654{
James Smart2e0fef82007-06-17 19:56:36 -05006655 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006656 uint32_t *lp;
6657 uint8_t flag;
6658 LPFC_MBOXQ_t *mbox;
6659 struct lpfc_dmabuf *pcmd;
6660 RPS *rps;
6661 struct ls_rjt stat;
6662
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006663 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006664 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6665 /* reject the unsolicited RPS request and done with it */
6666 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006667
6668 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6669 lp = (uint32_t *) pcmd->virt;
6670 flag = (be32_to_cpu(*lp++) & 0xf);
6671 rps = (RPS *) lp;
6672
6673 if ((flag == 0) ||
6674 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006675 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006676 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006677
James Smart92d7f7b2007-06-17 19:56:38 -05006678 printk("Fix me....\n");
6679 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006680 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6681 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006682 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006683 mbox->context1 = (void *)((unsigned long)
6684 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6685 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006686 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006687 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006688 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006689 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006690 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006691 /* Mbox completion will send ELS Response */
6692 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006693 /* Decrement reference count used for the failed mbox
6694 * command.
6695 */
James Smart329f9bc2007-04-25 09:53:01 -04006696 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006697 mempool_free(mbox, phba->mbox_mem_pool);
6698 }
6699 }
James Smart90160e02008-08-24 21:49:45 -04006700
6701reject_out:
6702 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006703 stat.un.b.lsRjtRsvd0 = 0;
6704 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6705 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6706 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006707 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006708 return 0;
6709}
6710
James Smart19ca7602010-11-20 23:11:55 -05006711/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6712 * @vport: pointer to a host virtual N_Port data structure.
6713 * @ndlp: pointer to a node-list data structure.
6714 * @did: DID of the target.
6715 * @rrq: Pointer to the rrq struct.
6716 *
6717 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6718 * Successful the the completion handler will clear the RRQ.
6719 *
6720 * Return codes
6721 * 0 - Successfully sent rrq els iocb.
6722 * 1 - Failed to send rrq els iocb.
6723 **/
6724static int
6725lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6726 uint32_t did, struct lpfc_node_rrq *rrq)
6727{
6728 struct lpfc_hba *phba = vport->phba;
6729 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05006730 struct lpfc_iocbq *elsiocb;
6731 uint8_t *pcmd;
6732 uint16_t cmdsize;
6733 int ret;
6734
6735
6736 if (ndlp != rrq->ndlp)
6737 ndlp = rrq->ndlp;
6738 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6739 return 1;
6740
6741 /* If ndlp is not NULL, we will bump the reference count on it */
6742 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6743 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6744 ELS_CMD_RRQ);
6745 if (!elsiocb)
6746 return 1;
6747
James Smart19ca7602010-11-20 23:11:55 -05006748 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6749
6750 /* For RRQ request, remainder of payload is Exchange IDs */
6751 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6752 pcmd += sizeof(uint32_t);
6753 els_rrq = (struct RRQ *) pcmd;
6754
James Smartee0f4fe2012-05-09 21:19:14 -04006755 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05006756 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6757 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6758 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6759 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6760
6761
6762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6763 "Issue RRQ: did:x%x",
6764 did, rrq->xritag, rrq->rxid);
6765 elsiocb->context_un.rrq = rrq;
6766 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6767 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6768
6769 if (ret == IOCB_ERROR) {
6770 lpfc_els_free_iocb(phba, elsiocb);
6771 return 1;
6772 }
6773 return 0;
6774}
6775
6776/**
6777 * lpfc_send_rrq - Sends ELS RRQ if needed.
6778 * @phba: pointer to lpfc hba data structure.
6779 * @rrq: pointer to the active rrq.
6780 *
6781 * This routine will call the lpfc_issue_els_rrq if the rrq is
6782 * still active for the xri. If this function returns a failure then
6783 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6784 *
6785 * Returns 0 Success.
6786 * 1 Failure.
6787 **/
6788int
6789lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6790{
6791 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
James Smart6eb60cf2019-05-06 17:26:49 -07006792 rrq->nlp_DID);
6793 if (!ndlp)
6794 return 1;
6795
James Smart19ca7602010-11-20 23:11:55 -05006796 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6797 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6798 rrq->nlp_DID, rrq);
6799 else
6800 return 1;
6801}
6802
James Smarte59058c2008-08-24 21:49:00 -04006803/**
James Smart3621a712009-04-06 18:47:14 -04006804 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04006805 * @vport: pointer to a host virtual N_Port data structure.
6806 * @cmdsize: size of the ELS command.
6807 * @oldiocb: pointer to the original lpfc command iocb data structure.
6808 * @ndlp: pointer to a node-list data structure.
6809 *
6810 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6811 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6812 *
6813 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6814 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6815 * will be stored into the context1 field of the IOCB for the completion
6816 * callback function to the RPL Accept Response ELS command.
6817 *
6818 * Return code
6819 * 0 - Successfully issued ACC RPL ELS command
6820 * 1 - Failed to issue ACC RPL ELS command
6821 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006822static int
James Smart2e0fef82007-06-17 19:56:36 -05006823lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6824 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006825{
James Smart2e0fef82007-06-17 19:56:36 -05006826 struct lpfc_hba *phba = vport->phba;
6827 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006828 RPL_RSP rpl_rsp;
6829 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006830 uint8_t *pcmd;
6831
James Smart2e0fef82007-06-17 19:56:36 -05006832 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6833 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006834
James Smart488d1462006-03-07 15:02:37 -05006835 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006836 return 1;
James Smart488d1462006-03-07 15:02:37 -05006837
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006838 icmd = &elsiocb->iocb;
6839 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006840 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6841 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006842
6843 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6844 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006845 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006846 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
6847 pcmd += sizeof(uint16_t);
6848
6849 /* Setup the RPL ACC payload */
6850 rpl_rsp.listLen = be32_to_cpu(1);
6851 rpl_rsp.index = 0;
6852 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05006853 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
6854 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006855 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006856 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006857 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006858 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6859 "0120 Xmit ELS RPL ACC response tag x%x "
6860 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6861 "rpi x%x\n",
6862 elsiocb->iotag, elsiocb->iocb.ulpContext,
6863 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6864 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006865 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006866 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006867 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6868 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006869 lpfc_els_free_iocb(phba, elsiocb);
6870 return 1;
6871 }
6872 return 0;
6873}
6874
James Smarte59058c2008-08-24 21:49:00 -04006875/**
James Smart3621a712009-04-06 18:47:14 -04006876 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04006877 * @vport: pointer to a host virtual N_Port data structure.
6878 * @cmdiocb: pointer to lpfc command iocb data structure.
6879 * @ndlp: pointer to a node-list data structure.
6880 *
6881 * This routine processes Read Port List (RPL) IOCB received as an ELS
6882 * unsolicited event. It first checks the remote port state. If the remote
6883 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6884 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6885 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6886 * to accept the RPL.
6887 *
6888 * Return code
6889 * 0 - Successfully processed rpl iocb (currently always return 0)
6890 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006891static int
James Smart2e0fef82007-06-17 19:56:36 -05006892lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6893 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006894{
6895 struct lpfc_dmabuf *pcmd;
6896 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006897 uint32_t maxsize;
6898 uint16_t cmdsize;
6899 RPL *rpl;
6900 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05006901
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006902 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6903 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04006904 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006905 stat.un.b.lsRjtRsvd0 = 0;
6906 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6907 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6908 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006909 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6910 NULL);
James Smart90160e02008-08-24 21:49:45 -04006911 /* rejected the unsolicited RPL request and done with it */
6912 return 0;
dea31012005-04-17 16:05:31 -05006913 }
6914
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006915 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6916 lp = (uint32_t *) pcmd->virt;
6917 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006918 maxsize = be32_to_cpu(rpl->maxsize);
6919
6920 /* We support only one port */
6921 if ((rpl->index == 0) &&
6922 ((maxsize == 0) ||
6923 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
6924 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006925 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006926 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
6927 }
James Smart2e0fef82007-06-17 19:56:36 -05006928 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006929
6930 return 0;
6931}
6932
James Smarte59058c2008-08-24 21:49:00 -04006933/**
James Smart3621a712009-04-06 18:47:14 -04006934 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04006935 * @vport: pointer to a virtual N_Port data structure.
6936 * @cmdiocb: pointer to lpfc command iocb data structure.
6937 * @ndlp: pointer to a node-list data structure.
6938 *
6939 * This routine processes Fibre Channel Address Resolution Protocol
6940 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6941 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6942 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6943 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6944 * remote PortName is compared against the FC PortName stored in the @vport
6945 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6946 * compared against the FC NodeName stored in the @vport data structure.
6947 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6948 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6949 * invoked to send out FARP Response to the remote node. Before sending the
6950 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6951 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6952 * routine is invoked to log into the remote port first.
6953 *
6954 * Return code
6955 * 0 - Either the FARP Match Mode not supported or successfully processed
6956 **/
dea31012005-04-17 16:05:31 -05006957static int
James Smart2e0fef82007-06-17 19:56:36 -05006958lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6959 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006960{
6961 struct lpfc_dmabuf *pcmd;
6962 uint32_t *lp;
6963 IOCB_t *icmd;
6964 FARP *fp;
6965 uint32_t cmd, cnt, did;
6966
6967 icmd = &cmdiocb->iocb;
6968 did = icmd->un.elsreq64.remoteID;
6969 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6970 lp = (uint32_t *) pcmd->virt;
6971
6972 cmd = *lp++;
6973 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05006974 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006975 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6976 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006977 /* We will only support match on WWPN or WWNN */
6978 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006979 return 0;
dea31012005-04-17 16:05:31 -05006980 }
6981
6982 cnt = 0;
6983 /* If this FARP command is searching for my portname */
6984 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05006985 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006986 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006987 cnt = 1;
6988 }
6989
6990 /* If this FARP command is searching for my nodename */
6991 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05006992 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05006993 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006994 cnt = 1;
6995 }
6996
6997 if (cnt) {
6998 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6999 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7000 /* Log back into the node before sending the FARP. */
7001 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007002 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05007003 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04007004 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05007005 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05007006 }
7007
7008 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05007009 if (fp->Rflags & FARP_REQUEST_FARPR)
7010 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05007011 }
7012 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007013 return 0;
dea31012005-04-17 16:05:31 -05007014}
7015
James Smarte59058c2008-08-24 21:49:00 -04007016/**
James Smart3621a712009-04-06 18:47:14 -04007017 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04007018 * @vport: pointer to a host virtual N_Port data structure.
7019 * @cmdiocb: pointer to lpfc command iocb data structure.
7020 * @ndlp: pointer to a node-list data structure.
7021 *
7022 * This routine processes Fibre Channel Address Resolution Protocol
7023 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7024 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7025 * the FARP response request.
7026 *
7027 * Return code
7028 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7029 **/
dea31012005-04-17 16:05:31 -05007030static int
James Smart2e0fef82007-06-17 19:56:36 -05007031lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7032 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007033{
7034 struct lpfc_dmabuf *pcmd;
7035 uint32_t *lp;
7036 IOCB_t *icmd;
7037 uint32_t cmd, did;
7038
7039 icmd = &cmdiocb->iocb;
7040 did = icmd->un.elsreq64.remoteID;
7041 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7042 lp = (uint32_t *) pcmd->virt;
7043
7044 cmd = *lp++;
7045 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007046 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7047 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007048 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007049 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007050
7051 return 0;
7052}
7053
James Smarte59058c2008-08-24 21:49:00 -04007054/**
James Smart3621a712009-04-06 18:47:14 -04007055 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007056 * @vport: pointer to a host virtual N_Port data structure.
7057 * @cmdiocb: pointer to lpfc command iocb data structure.
7058 * @fan_ndlp: pointer to a node-list data structure.
7059 *
7060 * This routine processes a Fabric Address Notification (FAN) IOCB
7061 * command received as an ELS unsolicited event. The FAN ELS command will
7062 * only be processed on a physical port (i.e., the @vport represents the
7063 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7064 * compared against those in the phba data structure. If any of those is
7065 * different, the lpfc_initial_flogi() routine is invoked to initialize
7066 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7067 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7068 * is invoked to register login to the fabric.
7069 *
7070 * Return code
7071 * 0 - Successfully processed fan iocb (currently always return 0).
7072 **/
dea31012005-04-17 16:05:31 -05007073static int
James Smart2e0fef82007-06-17 19:56:36 -05007074lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7075 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007076{
James Smart2e0fef82007-06-17 19:56:36 -05007077 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007078 uint32_t *lp;
7079 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007080
James Smart0d2b6b82008-06-14 22:52:47 -04007081 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7082 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7083 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007084 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007085 if ((vport == phba->pport) &&
7086 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007087 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007088 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007089 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007090 sizeof(struct lpfc_name)))) {
7091 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007092 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007093 } else {
7094 /* FAN verified - skip FLOGI */
7095 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007096 if (phba->sli_rev < LPFC_SLI_REV4)
7097 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007098 else {
7099 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7100 "3138 Need register VFI: (x%x/%x)\n",
7101 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04007102 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05007103 }
dea31012005-04-17 16:05:31 -05007104 }
dea31012005-04-17 16:05:31 -05007105 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007106 return 0;
dea31012005-04-17 16:05:31 -05007107}
7108
James Smarte59058c2008-08-24 21:49:00 -04007109/**
James Smart3621a712009-04-06 18:47:14 -04007110 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04007111 * @ptr: holder for the timer function associated data.
7112 *
7113 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7114 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7115 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7116 * up the worker thread. It is for the worker thread to invoke the routine
7117 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7118 **/
dea31012005-04-17 16:05:31 -05007119void
7120lpfc_els_timeout(unsigned long ptr)
7121{
James Smart2e0fef82007-06-17 19:56:36 -05007122 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7123 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04007124 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05007125 unsigned long iflag;
7126
James Smart2e0fef82007-06-17 19:56:36 -05007127 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04007128 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05007129 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05007130 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04007131 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05007132
James Smart06918ac2014-02-20 09:57:57 -05007133 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04007134 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05007135 return;
7136}
7137
James Smart2a9bf3d2010-06-07 15:24:45 -04007138
James Smarte59058c2008-08-24 21:49:00 -04007139/**
James Smart3621a712009-04-06 18:47:14 -04007140 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04007141 * @vport: pointer to a virtual N_Port data structure.
7142 *
7143 * This routine is the actual handler function that processes an ELS timeout
7144 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7145 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7146 * invoking the lpfc_sli_issue_abort_iotag() routine.
7147 **/
dea31012005-04-17 16:05:31 -05007148void
James Smart2e0fef82007-06-17 19:56:36 -05007149lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007150{
James Smart2e0fef82007-06-17 19:56:36 -05007151 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007152 struct lpfc_sli_ring *pring;
7153 struct lpfc_iocbq *tmp_iocb, *piocb;
7154 IOCB_t *cmd = NULL;
7155 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05007156 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05007157 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05007158 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04007159 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05007160
James Smart2a9bf3d2010-06-07 15:24:45 -04007161
dea31012005-04-17 16:05:31 -05007162 timeout = (uint32_t)(phba->fc_ratov << 1);
7163
7164 pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart06918ac2014-02-20 09:57:57 -05007165 if ((phba->pport->load_flag & FC_UNLOADING))
7166 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04007167 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007168 if (phba->sli_rev == LPFC_SLI_REV4)
7169 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04007170
James Smart06918ac2014-02-20 09:57:57 -05007171 if ((phba->pport->load_flag & FC_UNLOADING)) {
7172 if (phba->sli_rev == LPFC_SLI_REV4)
7173 spin_unlock(&pring->ring_lock);
7174 spin_unlock_irq(&phba->hbalock);
7175 return;
7176 }
7177
James Smart0976e1a2013-12-17 20:29:36 -05007178 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05007179 cmd = &piocb->iocb;
7180
James Smart2e0fef82007-06-17 19:56:36 -05007181 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7182 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7183 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05007184 continue;
James Smart2e0fef82007-06-17 19:56:36 -05007185
7186 if (piocb->vport != vport)
7187 continue;
7188
dea31012005-04-17 16:05:31 -05007189 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05007190 if (pcmd)
7191 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05007192
James Smart92d7f7b2007-06-17 19:56:38 -05007193 if (els_command == ELS_CMD_FARP ||
7194 els_command == ELS_CMD_FARPR ||
7195 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05007196 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05007197
dea31012005-04-17 16:05:31 -05007198 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05007199 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05007200 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05007201 else
dea31012005-04-17 16:05:31 -05007202 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05007203 continue;
7204 }
7205
James Smart2e0fef82007-06-17 19:56:36 -05007206 remote_ID = 0xffffffff;
7207 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05007208 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05007209 else {
7210 struct lpfc_nodelist *ndlp;
7211 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04007212 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05007213 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05007214 }
James Smart2a9bf3d2010-06-07 15:24:45 -04007215 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05007216 }
James Smart0976e1a2013-12-17 20:29:36 -05007217 if (phba->sli_rev == LPFC_SLI_REV4)
7218 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007219 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04007220
James Smart2a9bf3d2010-06-07 15:24:45 -04007221 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05007222 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04007223 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7224 "0127 ELS timeout Data: x%x x%x x%x "
7225 "x%x\n", els_command,
7226 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7227 spin_lock_irq(&phba->hbalock);
7228 list_del_init(&piocb->dlist);
7229 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7230 spin_unlock_irq(&phba->hbalock);
7231 }
7232
James Smart0e9bb8d2013-03-01 16:35:12 -05007233 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05007234 if (!(phba->pport->load_flag & FC_UNLOADING))
7235 mod_timer(&vport->els_tmofunc,
7236 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05007237}
7238
James Smarte59058c2008-08-24 21:49:00 -04007239/**
James Smart3621a712009-04-06 18:47:14 -04007240 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04007241 * @vport: pointer to a host virtual N_Port data structure.
7242 *
7243 * This routine is used to clean up all the outstanding ELS commands on a
7244 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7245 * routine. After that, it walks the ELS transmit queue to remove all the
7246 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7247 * the IOCBs with a non-NULL completion callback function, the callback
7248 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7249 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7250 * callback function, the IOCB will simply be released. Finally, it walks
7251 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7252 * completion queue IOCB that is associated with the @vport and is not
7253 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7254 * part of the discovery state machine) out to HBA by invoking the
7255 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7256 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7257 * the IOCBs are aborted when this function returns.
7258 **/
dea31012005-04-17 16:05:31 -05007259void
James Smart2e0fef82007-06-17 19:56:36 -05007260lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007261{
James Smart0976e1a2013-12-17 20:29:36 -05007262 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05007263 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04007264 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05007265 struct lpfc_iocbq *tmp_iocb, *piocb;
7266 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007267
7268 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05007269 /*
7270 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7271 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7272 * ultimately grabs the ring_lock, the driver must splice the list into
7273 * a working list and release the locks before calling the abort.
7274 */
7275 spin_lock_irq(&phba->hbalock);
7276 if (phba->sli_rev == LPFC_SLI_REV4)
7277 spin_lock(&pring->ring_lock);
7278
7279 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7280 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7281 continue;
7282
7283 if (piocb->vport != vport)
7284 continue;
7285 list_add_tail(&piocb->dlist, &abort_list);
7286 }
7287 if (phba->sli_rev == LPFC_SLI_REV4)
7288 spin_unlock(&pring->ring_lock);
7289 spin_unlock_irq(&phba->hbalock);
7290 /* Abort each iocb on the aborted list and remove the dlist links. */
7291 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7292 spin_lock_irq(&phba->hbalock);
7293 list_del_init(&piocb->dlist);
7294 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7295 spin_unlock_irq(&phba->hbalock);
7296 }
7297 if (!list_empty(&abort_list))
7298 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7299 "3387 abort list for txq not empty\n");
7300 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05007301
James Smart2e0fef82007-06-17 19:56:36 -05007302 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007303 if (phba->sli_rev == LPFC_SLI_REV4)
7304 spin_lock(&pring->ring_lock);
7305
dea31012005-04-17 16:05:31 -05007306 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7307 cmd = &piocb->iocb;
7308
7309 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7310 continue;
7311 }
7312
7313 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007314 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7315 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7316 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7317 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007318 continue;
dea31012005-04-17 16:05:31 -05007319
James Smart2e0fef82007-06-17 19:56:36 -05007320 if (piocb->vport != vport)
7321 continue;
7322
James Smart0976e1a2013-12-17 20:29:36 -05007323 list_del_init(&piocb->list);
7324 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007325 }
James Smart0976e1a2013-12-17 20:29:36 -05007326 if (phba->sli_rev == LPFC_SLI_REV4)
7327 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007328 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007329
James Smarta257bf92009-04-06 18:48:10 -04007330 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007331 lpfc_sli_cancel_iocbs(phba, &abort_list,
7332 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007333
dea31012005-04-17 16:05:31 -05007334 return;
7335}
7336
James Smarte59058c2008-08-24 21:49:00 -04007337/**
James Smart3621a712009-04-06 18:47:14 -04007338 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007339 * @phba: pointer to lpfc hba data structure.
7340 *
7341 * This routine is used to clean up all the outstanding ELS commands on a
7342 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7343 * routine. After that, it walks the ELS transmit queue to remove all the
7344 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7345 * the IOCBs with the completion callback function associated, the callback
7346 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7347 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7348 * callback function associated, the IOCB will simply be released. Finally,
7349 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7350 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7351 * management plane IOCBs that are not part of the discovery state machine)
7352 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7353 **/
James Smart549e55c2007-08-02 11:09:51 -04007354void
7355lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7356{
James Smart0976e1a2013-12-17 20:29:36 -05007357 struct lpfc_vport *vport;
7358 list_for_each_entry(vport, &phba->port_list, listentry)
7359 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007360
James Smart549e55c2007-08-02 11:09:51 -04007361 return;
7362}
7363
James Smarte59058c2008-08-24 21:49:00 -04007364/**
James Smart3621a712009-04-06 18:47:14 -04007365 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007366 * @phba: Pointer to hba context object.
7367 * @cmdiocbp: Pointer to command iocb which reported error.
7368 * @rspiocbp: Pointer to response iocb which reported error.
7369 *
7370 * This function sends an event when there is an ELS command
7371 * failure.
7372 **/
7373void
7374lpfc_send_els_failure_event(struct lpfc_hba *phba,
7375 struct lpfc_iocbq *cmdiocbp,
7376 struct lpfc_iocbq *rspiocbp)
7377{
7378 struct lpfc_vport *vport = cmdiocbp->vport;
7379 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7380 struct lpfc_lsrjt_event lsrjt_event;
7381 struct lpfc_fabric_event_header fabric_event;
7382 struct ls_rjt stat;
7383 struct lpfc_nodelist *ndlp;
7384 uint32_t *pcmd;
7385
7386 ndlp = cmdiocbp->context1;
7387 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7388 return;
7389
7390 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7391 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7392 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7393 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7394 sizeof(struct lpfc_name));
7395 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7396 sizeof(struct lpfc_name));
7397 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7398 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007399 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007400 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7401 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7402 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7403 fc_host_post_vendor_event(shost,
7404 fc_get_event_number(),
7405 sizeof(lsrjt_event),
7406 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007407 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007408 return;
7409 }
7410 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7411 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7412 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7413 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7414 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7415 else
7416 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7417 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7418 sizeof(struct lpfc_name));
7419 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7420 sizeof(struct lpfc_name));
7421 fc_host_post_vendor_event(shost,
7422 fc_get_event_number(),
7423 sizeof(fabric_event),
7424 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007425 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007426 return;
7427 }
7428
7429}
7430
7431/**
James Smart3621a712009-04-06 18:47:14 -04007432 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007433 * @vport: Pointer to vport object.
7434 * @ndlp: Pointer FC node object.
7435 * @cmd: ELS command code.
7436 *
7437 * This function posts an event when there is an incoming
7438 * unsolicited ELS command.
7439 **/
7440static void
7441lpfc_send_els_event(struct lpfc_vport *vport,
7442 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007443 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007444{
James Smartddcc50f2008-12-04 22:38:46 -05007445 struct lpfc_els_event_header *els_data = NULL;
7446 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7448
James Smartddcc50f2008-12-04 22:38:46 -05007449 if (*payload == ELS_CMD_LOGO) {
7450 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7451 if (!logo_data) {
7452 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7453 "0148 Failed to allocate memory "
7454 "for LOGO event\n");
7455 return;
7456 }
7457 els_data = &logo_data->header;
7458 } else {
7459 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7460 GFP_KERNEL);
7461 if (!els_data) {
7462 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7463 "0149 Failed to allocate memory "
7464 "for ELS event\n");
7465 return;
7466 }
7467 }
7468 els_data->event_type = FC_REG_ELS_EVENT;
7469 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007470 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007471 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007472 break;
7473 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007474 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007475 break;
7476 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007477 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7478 break;
7479 case ELS_CMD_LOGO:
7480 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7481 /* Copy the WWPN in the LOGO payload */
7482 memcpy(logo_data->logo_wwpn, &payload[2],
7483 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007484 break;
7485 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007486 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007487 return;
7488 }
James Smartddcc50f2008-12-04 22:38:46 -05007489 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7490 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7491 if (*payload == ELS_CMD_LOGO) {
7492 fc_host_post_vendor_event(shost,
7493 fc_get_event_number(),
7494 sizeof(struct lpfc_logo_event),
7495 (char *)logo_data,
7496 LPFC_NL_VENDOR_ID);
7497 kfree(logo_data);
7498 } else {
7499 fc_host_post_vendor_event(shost,
7500 fc_get_event_number(),
7501 sizeof(struct lpfc_els_event_header),
7502 (char *)els_data,
7503 LPFC_NL_VENDOR_ID);
7504 kfree(els_data);
7505 }
James Smartea2151b2008-09-07 11:52:10 -04007506
7507 return;
7508}
7509
7510
7511/**
James Smart3621a712009-04-06 18:47:14 -04007512 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007513 * @phba: pointer to lpfc hba data structure.
7514 * @pring: pointer to a SLI ring.
7515 * @vport: pointer to a host virtual N_Port data structure.
7516 * @elsiocb: pointer to lpfc els command iocb data structure.
7517 *
7518 * This routine is used for processing the IOCB associated with a unsolicited
7519 * event. It first determines whether there is an existing ndlp that matches
7520 * the DID from the unsolicited IOCB. If not, it will create a new one with
7521 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7522 * IOCB is then used to invoke the proper routine and to set up proper state
7523 * of the discovery state machine.
7524 **/
James Smarted957682007-06-17 19:56:37 -05007525static void
7526lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007527 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007528{
James Smart87af33f2007-10-27 13:37:43 -04007529 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007530 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007531 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007532 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007533 uint32_t cmd, did, newnode;
7534 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007535 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007536
James Smarte47c9092008-02-08 18:49:26 -05007537 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007538 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007539
dea31012005-04-17 16:05:31 -05007540 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007541 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7542 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007543 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007544 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007545
James Smart858c9f62007-06-17 19:56:39 -05007546 did = icmd->un.rcvels.remoteID;
7547 if (icmd->ulpStatus) {
7548 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7549 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7550 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007551 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007552 }
dea31012005-04-17 16:05:31 -05007553
7554 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007555 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007556 goto dropit;
dea31012005-04-17 16:05:31 -05007557
James Smartc8685952009-11-18 15:39:16 -05007558 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007559 if (vport->load_flag & FC_UNLOADING)
7560 goto dropit;
7561
James Smart92494142011-02-16 12:39:44 -05007562 /* If NPort discovery is delayed drop incoming ELS */
7563 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7564 (cmd != ELS_CMD_PLOGI))
7565 goto dropit;
7566
James Smart2e0fef82007-06-17 19:56:36 -05007567 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007568 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007569 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007570 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05007571 if (!ndlp)
dea31012005-04-17 16:05:31 -05007572 goto dropit;
dea31012005-04-17 16:05:31 -05007573
James Smart2e0fef82007-06-17 19:56:36 -05007574 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04007575 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007576 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007577 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007578 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007579 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7580 ndlp = lpfc_enable_node(vport, ndlp,
7581 NLP_STE_UNUSED_NODE);
7582 if (!ndlp)
7583 goto dropit;
7584 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7585 newnode = 1;
7586 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7587 ndlp->nlp_type |= NLP_FABRIC;
7588 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7589 /* This is similar to the new node path */
7590 ndlp = lpfc_nlp_get(ndlp);
7591 if (!ndlp)
7592 goto dropit;
7593 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7594 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007595 }
dea31012005-04-17 16:05:31 -05007596
7597 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007598
James Smart12838e72014-09-03 12:57:19 -04007599 /*
7600 * Do not process any unsolicited ELS commands
7601 * if the ndlp is in DEV_LOSS
7602 */
James Smart466e8402015-05-21 13:55:28 -04007603 shost = lpfc_shost_from_vport(vport);
7604 spin_lock_irq(shost->host_lock);
7605 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7606 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007607 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007608 }
7609 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007610
James Smart329f9bc2007-04-25 09:53:01 -04007611 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007612 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007613
7614 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7615 cmd &= ELS_CMD_MASK;
7616 }
7617 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007618 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7619 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007620 "Data: x%x x%x x%x x%x\n",
7621 cmd, did, vport->port_state, vport->fc_flag,
7622 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04007623
7624 /* reject till our FLOGI completes */
7625 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smartd6de08c2015-12-16 18:11:53 -05007626 (cmd != ELS_CMD_FLOGI)) {
James Smarteec3d312015-08-31 16:48:18 -04007627 rjt_err = LSRJT_UNABLE_TPC;
7628 rjt_exp = LSEXP_NOTHING_MORE;
7629 goto lsrjt;
7630 }
7631
dea31012005-04-17 16:05:31 -05007632 switch (cmd) {
7633 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007634 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7635 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7636 did, vport->port_state, ndlp->nlp_flag);
7637
dea31012005-04-17 16:05:31 -05007638 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007639 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007640 if (phba->sli_rev == LPFC_SLI_REV4 &&
7641 (phba->pport->fc_flag & FC_PT2PT)) {
7642 vport->fc_prevDID = vport->fc_myDID;
7643 /* Our DID needs to be updated before registering
7644 * the vfi. This is done in lpfc_rcv_plogi but
7645 * that is called after the reg_vfi.
7646 */
7647 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7648 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7649 "3312 Remote port assigned DID x%x "
7650 "%x\n", vport->fc_myDID,
7651 vport->fc_prevDID);
7652 }
James Smart858c9f62007-06-17 19:56:39 -05007653
James Smartddcc50f2008-12-04 22:38:46 -05007654 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007655
7656 /* If Nport discovery is delayed, reject PLOGIs */
7657 if (vport->fc_flag & FC_DISC_DELAYED) {
7658 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007659 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007660 break;
7661 }
James Smartd6de08c2015-12-16 18:11:53 -05007662
James Smart858c9f62007-06-17 19:56:39 -05007663 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007664 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7665 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7666 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007667 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007668 break;
7669 }
dea31012005-04-17 16:05:31 -05007670 }
James Smart87af33f2007-10-27 13:37:43 -04007671
James Smart87af33f2007-10-27 13:37:43 -04007672 spin_lock_irq(shost->host_lock);
7673 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7674 spin_unlock_irq(shost->host_lock);
7675
James Smart2e0fef82007-06-17 19:56:36 -05007676 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7677 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007678
dea31012005-04-17 16:05:31 -05007679 break;
7680 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7682 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7683 did, vport->port_state, ndlp->nlp_flag);
7684
dea31012005-04-17 16:05:31 -05007685 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007686 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007687 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007688 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007689 break;
7690 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007691 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7692 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7693 did, vport->port_state, ndlp->nlp_flag);
7694
dea31012005-04-17 16:05:31 -05007695 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007696 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007697 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007698 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007699 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007700 break;
7701 }
James Smart2e0fef82007-06-17 19:56:36 -05007702 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007703 break;
7704 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7706 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7707 did, vport->port_state, ndlp->nlp_flag);
7708
dea31012005-04-17 16:05:31 -05007709 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007710 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007711 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007712 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007713 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007714 break;
7715 }
James Smart2e0fef82007-06-17 19:56:36 -05007716 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05007717 break;
James Smart8b017a32015-05-21 13:55:18 -04007718 case ELS_CMD_LCB:
7719 phba->fc_stat.elsRcvLCB++;
7720 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7721 break;
James Smart86478872015-05-21 13:55:21 -04007722 case ELS_CMD_RDP:
7723 phba->fc_stat.elsRcvRDP++;
7724 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7725 break;
dea31012005-04-17 16:05:31 -05007726 case ELS_CMD_RSCN:
7727 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04007728 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007729 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007730 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007731 break;
7732 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05007733 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7734 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7735 did, vport->port_state, ndlp->nlp_flag);
7736
James Smartddcc50f2008-12-04 22:38:46 -05007737 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05007738 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007739 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007740 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007741 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007742 break;
7743 }
James Smart2e0fef82007-06-17 19:56:36 -05007744 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7745 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05007746 break;
7747 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05007748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7749 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7750 did, vport->port_state, ndlp->nlp_flag);
7751
dea31012005-04-17 16:05:31 -05007752 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007753 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007754 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007755 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007756 break;
7757 }
James Smart2e0fef82007-06-17 19:56:36 -05007758 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7759 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05007760 break;
7761 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05007762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7763 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7764 did, vport->port_state, ndlp->nlp_flag);
7765
dea31012005-04-17 16:05:31 -05007766 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05007767 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007768 break;
7769 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05007770 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7771 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7772 did, vport->port_state, ndlp->nlp_flag);
7773
dea31012005-04-17 16:05:31 -05007774 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05007775 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007776 break;
7777 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05007778 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7779 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7780 did, vport->port_state, ndlp->nlp_flag);
7781
dea31012005-04-17 16:05:31 -05007782 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05007783 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007784 break;
dea31012005-04-17 16:05:31 -05007785 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05007786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7787 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7788 did, vport->port_state, ndlp->nlp_flag);
7789
dea31012005-04-17 16:05:31 -05007790 phba->fc_stat.elsRcvPRLI++;
Dick Kennedy3bd20172017-03-23 08:47:18 -04007791 if ((vport->port_state < LPFC_DISC_AUTH) &&
7792 (vport->fc_flag & FC_FABRIC)) {
James Smart858c9f62007-06-17 19:56:39 -05007793 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007794 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007795 break;
7796 }
James Smart2e0fef82007-06-17 19:56:36 -05007797 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05007798 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007799 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05007800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7801 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7802 did, vport->port_state, ndlp->nlp_flag);
7803
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007804 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05007805 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007806 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007807 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007808 break;
James Smart12265f62010-10-22 11:05:53 -04007809 case ELS_CMD_RLS:
7810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7811 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7812 did, vport->port_state, ndlp->nlp_flag);
7813
7814 phba->fc_stat.elsRcvRLS++;
7815 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7816 if (newnode)
7817 lpfc_nlp_put(ndlp);
7818 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007819 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05007820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7821 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7822 did, vport->port_state, ndlp->nlp_flag);
7823
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007824 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05007825 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007826 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007827 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007828 break;
7829 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05007830 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7831 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7832 did, vport->port_state, ndlp->nlp_flag);
7833
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007834 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05007835 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007836 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007837 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007838 break;
dea31012005-04-17 16:05:31 -05007839 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05007840 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7841 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7842 did, vport->port_state, ndlp->nlp_flag);
7843
dea31012005-04-17 16:05:31 -05007844 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05007845 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007846 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007847 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007848 break;
James Smart12265f62010-10-22 11:05:53 -04007849 case ELS_CMD_RTV:
7850 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7851 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7852 did, vport->port_state, ndlp->nlp_flag);
7853 phba->fc_stat.elsRcvRTV++;
7854 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
7855 if (newnode)
7856 lpfc_nlp_put(ndlp);
7857 break;
James Smart5ffc2662009-11-18 15:39:44 -05007858 case ELS_CMD_RRQ:
7859 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7860 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7861 did, vport->port_state, ndlp->nlp_flag);
7862
7863 phba->fc_stat.elsRcvRRQ++;
7864 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
7865 if (newnode)
7866 lpfc_nlp_put(ndlp);
7867 break;
James Smart12265f62010-10-22 11:05:53 -04007868 case ELS_CMD_ECHO:
7869 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7870 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7871 did, vport->port_state, ndlp->nlp_flag);
7872
7873 phba->fc_stat.elsRcvECHO++;
7874 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
7875 if (newnode)
7876 lpfc_nlp_put(ndlp);
7877 break;
James Smart303f2f92013-01-03 15:43:11 -05007878 case ELS_CMD_REC:
7879 /* receive this due to exchange closed */
7880 rjt_err = LSRJT_UNABLE_TPC;
7881 rjt_exp = LSEXP_INVALID_OX_RX;
7882 break;
dea31012005-04-17 16:05:31 -05007883 default:
James Smart858c9f62007-06-17 19:56:39 -05007884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7885 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7886 cmd, did, vport->port_state);
7887
dea31012005-04-17 16:05:31 -05007888 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05007889 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05007890 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007891
7892 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007893 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7894 "0115 Unknown ELS command x%x "
7895 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04007896 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007897 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007898 break;
7899 }
7900
James Smarteec3d312015-08-31 16:48:18 -04007901lsrjt:
dea31012005-04-17 16:05:31 -05007902 /* check if need to LS_RJT received ELS cmd */
7903 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05007904 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05007905 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05007906 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05007907 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
7908 NULL);
dea31012005-04-17 16:05:31 -05007909 }
7910
James Smartd7c255b2008-08-24 21:50:00 -04007911 lpfc_nlp_put(elsiocb->context1);
7912 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05007913 return;
7914
7915dropit:
James Smart98c9ea52007-10-27 13:37:33 -04007916 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04007917 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7918 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05007919 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04007920 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05007921 phba->fc_stat.elsRcvDrop++;
7922}
7923
James Smarte59058c2008-08-24 21:49:00 -04007924/**
James Smart3621a712009-04-06 18:47:14 -04007925 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04007926 * @phba: pointer to lpfc hba data structure.
7927 * @pring: pointer to a SLI ring.
7928 * @elsiocb: pointer to lpfc els iocb data structure.
7929 *
7930 * This routine is used to process an unsolicited event received from a SLI
7931 * (Service Level Interface) ring. The actual processing of the data buffer
7932 * associated with the unsolicited event is done by invoking the routine
7933 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7934 * SLI ring on which the unsolicited event was received.
7935 **/
James Smarted957682007-06-17 19:56:37 -05007936void
7937lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7938 struct lpfc_iocbq *elsiocb)
7939{
7940 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05007941 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05007942 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05007943 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
7944 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05007945
James Smartd7c255b2008-08-24 21:50:00 -04007946 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007947 elsiocb->context2 = NULL;
7948 elsiocb->context3 = NULL;
7949
7950 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
7951 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
7952 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04007953 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
7954 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05007955 phba->fc_stat.NoRcvBuf++;
7956 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05007957 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04007958 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05007959 return;
7960 }
7961
James Smart92d7f7b2007-06-17 19:56:38 -05007962 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7963 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
7964 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7965 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7966 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04007967 else
7968 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04007969 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05007970 }
James Smart6d368e52011-05-24 11:44:12 -04007971
James Smart7f5f3d02008-02-08 18:50:14 -05007972 /* If there are no BDEs associated
7973 * with this IOCB, there is nothing to do.
7974 */
James Smarted957682007-06-17 19:56:37 -05007975 if (icmd->ulpBdeCount == 0)
7976 return;
7977
James Smart7f5f3d02008-02-08 18:50:14 -05007978 /* type of ELS cmd is first 32bit word
7979 * in packet
7980 */
James Smarted957682007-06-17 19:56:37 -05007981 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05007982 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05007983 } else {
7984 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7985 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05007986 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7987 paddr);
James Smarted957682007-06-17 19:56:37 -05007988 }
7989
James Smart92d7f7b2007-06-17 19:56:38 -05007990 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7991 /*
7992 * The different unsolicited event handlers would tell us
7993 * if they are done with "mp" by setting context2 to NULL.
7994 */
dea31012005-04-17 16:05:31 -05007995 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007996 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7997 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05007998 }
James Smarted957682007-06-17 19:56:37 -05007999
8000 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05008001 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05008002 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008003 elsiocb->context2 = bdeBuf2;
8004 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05008005 /* free mp if we are done with it */
8006 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05008007 lpfc_in_buf_free(phba, elsiocb->context2);
8008 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05008009 }
dea31012005-04-17 16:05:31 -05008010 }
dea31012005-04-17 16:05:31 -05008011}
James Smart92d7f7b2007-06-17 19:56:38 -05008012
Baoyou Xiebd4b3e52016-09-25 13:44:55 +08008013static void
James Smart4258e982015-12-16 18:11:58 -05008014lpfc_start_fdmi(struct lpfc_vport *vport)
8015{
8016 struct lpfc_hba *phba = vport->phba;
8017 struct lpfc_nodelist *ndlp;
8018
8019 /* If this is the first time, allocate an ndlp and initialize
8020 * it. Otherwise, make sure the node is enabled and then do the
8021 * login.
8022 */
8023 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8024 if (!ndlp) {
8025 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
8026 if (ndlp) {
8027 lpfc_nlp_init(vport, ndlp, FDMI_DID);
8028 ndlp->nlp_type |= NLP_FABRIC;
8029 } else {
8030 return;
8031 }
8032 }
8033 if (!NLP_CHK_NODE_ACT(ndlp))
8034 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8035
8036 if (ndlp) {
8037 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8038 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8039 }
8040}
8041
James Smarte59058c2008-08-24 21:49:00 -04008042/**
James Smart3621a712009-04-06 18:47:14 -04008043 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04008044 * @phba: pointer to lpfc hba data structure.
8045 * @vport: pointer to a virtual N_Port data structure.
8046 *
8047 * This routine issues a Port Login (PLOGI) to the Name Server with
8048 * State Change Request (SCR) for a @vport. This routine will create an
8049 * ndlp for the Name Server associated to the @vport if such node does
8050 * not already exist. The PLOGI to Name Server is issued by invoking the
8051 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8052 * (FDMI) is configured to the @vport, a FDMI node will be created and
8053 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8054 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008055void
8056lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8057{
James Smart4258e982015-12-16 18:11:58 -05008058 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05008059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8060
8061 /*
8062 * If lpfc_delay_discovery parameter is set and the clean address
8063 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8064 * discovery.
8065 */
8066 spin_lock_irq(shost->host_lock);
8067 if (vport->fc_flag & FC_DISC_DELAYED) {
8068 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04008069 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8070 "3334 Delay fc port discovery for %d seconds\n",
8071 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05008072 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04008073 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05008074 return;
8075 }
8076 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008077
8078 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8079 if (!ndlp) {
8080 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
8081 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008082 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05008083 lpfc_disc_start(vport);
8084 return;
8085 }
8086 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008087 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8088 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008089 return;
8090 }
8091 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05008092 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8093 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8094 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008095 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05008096 lpfc_disc_start(vport);
8097 return;
8098 }
8099 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8100 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8101 "0348 NameServer login: node freed\n");
8102 return;
8103 }
James Smart92d7f7b2007-06-17 19:56:38 -05008104 }
James Smart58da1ff2008-04-07 10:15:56 -04008105 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05008106
8107 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8108
8109 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8110 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008111 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8112 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008113 return;
8114 }
8115
James Smart8663cbb2016-03-31 14:12:33 -07008116 if ((phba->cfg_enable_SmartSAN ||
8117 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8118 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05008119 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008120}
8121
James Smarte59058c2008-08-24 21:49:00 -04008122/**
James Smart3621a712009-04-06 18:47:14 -04008123 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04008124 * @phba: pointer to lpfc hba data structure.
8125 * @pmb: pointer to the driver internal queue element for mailbox command.
8126 *
8127 * This routine is the completion callback function to register new vport
8128 * mailbox command. If the new vport mailbox command completes successfully,
8129 * the fabric registration login shall be performed on physical port (the
8130 * new vport created is actually a physical port, with VPI 0) or the port
8131 * login to Name Server for State Change Request (SCR) will be performed
8132 * on virtual port (real virtual port, with VPI greater than 0).
8133 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008134static void
8135lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8136{
8137 struct lpfc_vport *vport = pmb->vport;
8138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8139 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04008140 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05008141 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008142
James Smart09372822008-01-11 01:52:54 -05008143 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008144 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008145 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008146
8147 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04008148 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04008149 "0915 Register VPI failed : Status: x%x"
8150 " upd bit: x%x \n", mb->mbxStatus,
8151 mb->un.varRegVpi.upd);
8152 if (phba->sli_rev == LPFC_SLI_REV4 &&
8153 mb->un.varRegVpi.upd)
8154 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05008155
8156 switch (mb->mbxStatus) {
8157 case 0x11: /* unsupported feature */
8158 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05008159 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05008160 /* giving up on vport registration */
8161 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8162 spin_lock_irq(shost->host_lock);
8163 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8164 spin_unlock_irq(shost->host_lock);
8165 lpfc_can_disctmo(vport);
8166 break;
James Smart695a8142010-01-26 23:08:03 -05008167 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8168 case 0x20:
8169 spin_lock_irq(shost->host_lock);
8170 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8171 spin_unlock_irq(shost->host_lock);
8172 lpfc_init_vpi(phba, pmb, vport->vpi);
8173 pmb->vport = vport;
8174 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8175 rc = lpfc_sli_issue_mbox(phba, pmb,
8176 MBX_NOWAIT);
8177 if (rc == MBX_NOT_FINISHED) {
8178 lpfc_printf_vlog(vport,
8179 KERN_ERR, LOG_MBOX,
8180 "2732 Failed to issue INIT_VPI"
8181 " mailbox command\n");
8182 } else {
8183 lpfc_nlp_put(ndlp);
8184 return;
8185 }
8186
James Smart92d7f7b2007-06-17 19:56:38 -05008187 default:
8188 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04008189 if (phba->sli_rev == LPFC_SLI_REV4)
8190 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008191 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05008192 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008193 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008194 spin_unlock_irq(shost->host_lock);
James Smartd32c4de2017-03-04 09:30:25 -08008195 if (mb->mbxStatus == MBX_NOT_FINISHED)
8196 break;
8197 if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
8198 !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
8199 if (phba->sli_rev == LPFC_SLI_REV4)
8200 lpfc_issue_init_vfi(vport);
8201 else
8202 lpfc_initial_flogi(vport);
8203 } else {
James Smart7f5f3d02008-02-08 18:50:14 -05008204 lpfc_initial_fdisc(vport);
James Smartd32c4de2017-03-04 09:30:25 -08008205 }
James Smart92d7f7b2007-06-17 19:56:38 -05008206 break;
8207 }
James Smart92d7f7b2007-06-17 19:56:38 -05008208 } else {
James Smart695a8142010-01-26 23:08:03 -05008209 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05008210 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05008211 spin_unlock_irq(shost->host_lock);
8212 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04008213 if (phba->sli_rev < LPFC_SLI_REV4)
8214 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05008215 else {
James Smartfc2b9892010-02-26 14:15:29 -05008216 /*
8217 * If the physical port is instantiated using
8218 * FDISC, do not start vport discovery.
8219 */
8220 if (vport->port_state != LPFC_FDISC)
8221 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05008222 lpfc_do_scr_ns_plogi(phba, vport);
8223 }
8224 } else
James Smart92d7f7b2007-06-17 19:56:38 -05008225 lpfc_do_scr_ns_plogi(phba, vport);
8226 }
James Smart38b92ef2010-08-04 16:11:39 -04008227mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05008228 /* Now, we decrement the ndlp reference count held for this
8229 * callback function
8230 */
8231 lpfc_nlp_put(ndlp);
8232
James Smart92d7f7b2007-06-17 19:56:38 -05008233 mempool_free(pmb, phba->mbox_mem_pool);
8234 return;
8235}
8236
James Smarte59058c2008-08-24 21:49:00 -04008237/**
James Smart3621a712009-04-06 18:47:14 -04008238 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04008239 * @phba: pointer to lpfc hba data structure.
8240 * @vport: pointer to a host virtual N_Port data structure.
8241 * @ndlp: pointer to a node-list data structure.
8242 *
8243 * This routine registers the @vport as a new virtual port with a HBA.
8244 * It is done through a registering vpi mailbox command.
8245 **/
James Smart695a8142010-01-26 23:08:03 -05008246void
James Smart92d7f7b2007-06-17 19:56:38 -05008247lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8248 struct lpfc_nodelist *ndlp)
8249{
James Smart09372822008-01-11 01:52:54 -05008250 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008251 LPFC_MBOXQ_t *mbox;
8252
8253 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8254 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04008255 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05008256 mbox->vport = vport;
8257 mbox->context2 = lpfc_nlp_get(ndlp);
8258 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04008259 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05008260 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05008261 /* mailbox command not success, decrement ndlp
8262 * reference count for this command
8263 */
8264 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008265 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05008266
James Smarte8b62012007-08-02 11:10:09 -04008267 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8268 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05008269 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008270 }
8271 } else {
James Smarte8b62012007-08-02 11:10:09 -04008272 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8273 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05008274 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008275 }
James Smartfa4066b2008-01-11 01:53:27 -05008276 return;
8277
8278mbox_err_exit:
8279 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8280 spin_lock_irq(shost->host_lock);
8281 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8282 spin_unlock_irq(shost->host_lock);
8283 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008284}
8285
James Smarte59058c2008-08-24 21:49:00 -04008286/**
James Smart0c9ab6f2010-02-26 14:15:57 -05008287 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05008288 * @phba: pointer to lpfc hba data structure.
8289 *
James Smart0c9ab6f2010-02-26 14:15:57 -05008290 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05008291 **/
8292void
James Smart0c9ab6f2010-02-26 14:15:57 -05008293lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05008294{
8295 struct lpfc_vport **vports;
8296 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05008297 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05008298 int i;
James Smart695a8142010-01-26 23:08:03 -05008299
8300 /* Treat this failure as linkdown for all vports */
8301 link_state = phba->link_state;
8302 lpfc_linkdown(phba);
8303 phba->link_state = link_state;
8304
8305 vports = lpfc_create_vport_work_array(phba);
8306
8307 if (vports) {
8308 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8309 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8310 if (ndlp)
8311 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8312 lpfc_els_flush_cmd(vports[i]);
8313 }
8314 lpfc_destroy_vport_work_array(phba, vports);
8315 }
James Smart0c9ab6f2010-02-26 14:15:57 -05008316}
8317
8318/**
8319 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8320 * @phba: pointer to lpfc hba data structure.
8321 *
8322 * This routine abort all pending discovery commands and
8323 * start a timer to retry FLOGI for the physical port
8324 * discovery.
8325 **/
8326void
8327lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8328{
8329 struct lpfc_nodelist *ndlp;
8330 struct Scsi_Host *shost;
8331
8332 /* Cancel the all vports retry delay retry timers */
8333 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008334
8335 /* If fabric require FLOGI, then re-instantiate physical login */
8336 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8337 if (!ndlp)
8338 return;
8339
James Smart695a8142010-01-26 23:08:03 -05008340 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008341 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008342 spin_lock_irq(shost->host_lock);
8343 ndlp->nlp_flag |= NLP_DELAY_TMO;
8344 spin_unlock_irq(shost->host_lock);
8345 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8346 phba->pport->port_state = LPFC_FLOGI;
8347 return;
8348}
8349
8350/**
8351 * lpfc_fabric_login_reqd - Check if FLOGI required.
8352 * @phba: pointer to lpfc hba data structure.
8353 * @cmdiocb: pointer to FDISC command iocb.
8354 * @rspiocb: pointer to FDISC response iocb.
8355 *
8356 * This routine checks if a FLOGI is reguired for FDISC
8357 * to succeed.
8358 **/
8359static int
8360lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8361 struct lpfc_iocbq *cmdiocb,
8362 struct lpfc_iocbq *rspiocb)
8363{
8364
8365 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8366 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8367 return 0;
8368 else
8369 return 1;
8370}
8371
8372/**
James Smart3621a712009-04-06 18:47:14 -04008373 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008374 * @phba: pointer to lpfc hba data structure.
8375 * @cmdiocb: pointer to lpfc command iocb data structure.
8376 * @rspiocb: pointer to lpfc response iocb data structure.
8377 *
8378 * This routine is the completion callback function to a Fabric Discover
8379 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8380 * single threaded, each FDISC completion callback function will reset
8381 * the discovery timer for all vports such that the timers will not get
8382 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8383 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8384 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8385 * assigned to the vport has been changed with the completion of the FDISC
8386 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8387 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8388 * routine is invoked to register new vport with the HBA. Otherwise, the
8389 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8390 * Server for State Change Request (SCR).
8391 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008392static void
8393lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8394 struct lpfc_iocbq *rspiocb)
8395{
8396 struct lpfc_vport *vport = cmdiocb->vport;
8397 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8398 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8399 struct lpfc_nodelist *np;
8400 struct lpfc_nodelist *next_np;
8401 IOCB_t *irsp = &rspiocb->iocb;
8402 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008403 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8404 struct serv_parm *sp;
8405 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008406
James Smarte8b62012007-08-02 11:10:09 -04008407 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8408 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8409 irsp->ulpStatus, irsp->un.ulpWord[4],
8410 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008411 /* Since all FDISCs are being single threaded, we
8412 * must reset the discovery timer for ALL vports
8413 * waiting to send FDISC when one completes.
8414 */
8415 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8416 lpfc_set_disctmo(piocb->vport);
8417 }
8418
James Smart858c9f62007-06-17 19:56:39 -05008419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8420 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8421 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8422
James Smart92d7f7b2007-06-17 19:56:38 -05008423 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008424
8425 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8426 lpfc_retry_pport_discovery(phba);
8427 goto out;
8428 }
8429
James Smart92d7f7b2007-06-17 19:56:38 -05008430 /* Check for retry */
8431 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8432 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008433 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008434 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008435 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008436 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008437 goto fdisc_failed;
8438 }
James Smartd7c255b2008-08-24 21:50:00 -04008439 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008440 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008441 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008442 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008443 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008444 vport->fc_flag |= FC_PUBLIC_LOOP;
8445 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008446
James Smartd7c255b2008-08-24 21:50:00 -04008447 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8448 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008449 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008450 if (!prsp)
8451 goto out;
James Smart92494142011-02-16 12:39:44 -05008452 sp = prsp->virt + sizeof(uint32_t);
8453 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8454 memcpy(&vport->fabric_portname, &sp->portName,
8455 sizeof(struct lpfc_name));
8456 memcpy(&vport->fabric_nodename, &sp->nodeName,
8457 sizeof(struct lpfc_name));
8458 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008459 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8460 /* If our NportID changed, we need to ensure all
8461 * remaining NPORTs get unreg_login'ed so we can
8462 * issue unreg_vpi.
8463 */
8464 list_for_each_entry_safe(np, next_np,
8465 &vport->fc_nodes, nlp_listp) {
8466 if (!NLP_CHK_NODE_ACT(ndlp) ||
8467 (np->nlp_state != NLP_STE_NPR_NODE) ||
8468 !(np->nlp_flag & NLP_NPR_ADISC))
8469 continue;
James Smart09372822008-01-11 01:52:54 -05008470 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008471 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008472 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008473 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008474 }
James Smart78730cf2010-04-06 15:06:30 -04008475 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008476
8477 if (phba->sli_rev == LPFC_SLI_REV4)
8478 lpfc_sli4_unreg_all_rpis(vport);
8479
James Smartd7c255b2008-08-24 21:50:00 -04008480 lpfc_mbx_unreg_vpi(vport);
8481 spin_lock_irq(shost->host_lock);
8482 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008483 if (phba->sli_rev == LPFC_SLI_REV4)
8484 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008485 else
8486 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008487 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008488 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8489 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8490 /*
8491 * Driver needs to re-reg VPI in order for f/w
8492 * to update the MAC address.
8493 */
8494 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008495 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008496 }
8497
James Smartecfd03c2010-02-12 14:41:27 -05008498 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8499 lpfc_issue_init_vpi(vport);
8500 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008501 lpfc_register_new_vport(phba, vport, ndlp);
8502 else
8503 lpfc_do_scr_ns_plogi(phba, vport);
8504 goto out;
8505fdisc_failed:
James Smartc84163d2015-05-21 13:55:22 -04008506 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8507 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008508 /* Cancel discovery timer */
8509 lpfc_can_disctmo(vport);
8510 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008511out:
8512 lpfc_els_free_iocb(phba, cmdiocb);
8513}
8514
James Smarte59058c2008-08-24 21:49:00 -04008515/**
James Smart3621a712009-04-06 18:47:14 -04008516 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008517 * @vport: pointer to a virtual N_Port data structure.
8518 * @ndlp: pointer to a node-list data structure.
8519 * @retry: number of retries to the command IOCB.
8520 *
8521 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8522 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8523 * routine to issue the IOCB, which makes sure only one outstanding fabric
8524 * IOCB will be sent off HBA at any given time.
8525 *
8526 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8527 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8528 * will be stored into the context1 field of the IOCB for the completion
8529 * callback function to the FDISC ELS command.
8530 *
8531 * Return code
8532 * 0 - Successfully issued fdisc iocb command
8533 * 1 - Failed to issue fdisc iocb command
8534 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008535static int
James Smart92d7f7b2007-06-17 19:56:38 -05008536lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8537 uint8_t retry)
8538{
8539 struct lpfc_hba *phba = vport->phba;
8540 IOCB_t *icmd;
8541 struct lpfc_iocbq *elsiocb;
8542 struct serv_parm *sp;
8543 uint8_t *pcmd;
8544 uint16_t cmdsize;
8545 int did = ndlp->nlp_DID;
8546 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008547
James Smart5ffc2662009-11-18 15:39:44 -05008548 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008549 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008550 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8551 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8552 ELS_CMD_FDISC);
8553 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008554 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008555 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8556 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008557 return 1;
8558 }
8559
8560 icmd = &elsiocb->iocb;
8561 icmd->un.elsreq64.myID = 0;
8562 icmd->un.elsreq64.fl = 1;
8563
James Smart73d91e52011-10-10 21:32:10 -04008564 /*
8565 * SLI3 ports require a different context type value than SLI4.
8566 * Catch SLI3 ports here and override the prep.
8567 */
8568 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008569 icmd->ulpCt_h = 1;
8570 icmd->ulpCt_l = 0;
8571 }
James Smart92d7f7b2007-06-17 19:56:38 -05008572
8573 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8574 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8575 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8576 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8577 sp = (struct serv_parm *) pcmd;
8578 /* Setup CSPs accordingly for Fabric */
8579 sp->cmn.e_d_tov = 0;
8580 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008581 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008582 sp->cls1.classValid = 0;
8583 sp->cls2.seqDelivery = 1;
8584 sp->cls3.seqDelivery = 1;
8585
8586 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8587 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8588 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8589 pcmd += sizeof(uint32_t); /* Port Name */
8590 memcpy(pcmd, &vport->fc_portname, 8);
8591 pcmd += sizeof(uint32_t); /* Node Name */
8592 pcmd += sizeof(uint32_t); /* Node Name */
8593 memcpy(pcmd, &vport->fc_nodename, 8);
8594
8595 lpfc_set_disctmo(vport);
8596
8597 phba->fc_stat.elsXmitFDISC++;
8598 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8599
James Smart858c9f62007-06-17 19:56:39 -05008600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8601 "Issue FDISC: did:x%x",
8602 did, 0, 0);
8603
James Smart92d7f7b2007-06-17 19:56:38 -05008604 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8605 if (rc == IOCB_ERROR) {
8606 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008607 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008608 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8609 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008610 return 1;
8611 }
8612 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008613 return 0;
8614}
8615
James Smarte59058c2008-08-24 21:49:00 -04008616/**
James Smart3621a712009-04-06 18:47:14 -04008617 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008618 * @phba: pointer to lpfc hba data structure.
8619 * @cmdiocb: pointer to lpfc command iocb data structure.
8620 * @rspiocb: pointer to lpfc response iocb data structure.
8621 *
8622 * This routine is the completion callback function to the issuing of a LOGO
8623 * ELS command off a vport. It frees the command IOCB and then decrement the
8624 * reference count held on ndlp for this completion function, indicating that
8625 * the reference to the ndlp is no long needed. Note that the
8626 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8627 * callback function and an additional explicit ndlp reference decrementation
8628 * will trigger the actual release of the ndlp.
8629 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008630static void
8631lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8632 struct lpfc_iocbq *rspiocb)
8633{
8634 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008635 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008636 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008637 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008638
James Smart9589b0622011-04-16 11:03:17 -04008639 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008640 irsp = &rspiocb->iocb;
8641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8642 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8643 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008644
8645 lpfc_els_free_iocb(phba, cmdiocb);
8646 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008647
8648 /* Trigger the release of the ndlp after logo */
8649 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008650
8651 /* NPIV LOGO completes to NPort <nlp_DID> */
8652 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8653 "2928 NPIV LOGO completes to NPort x%x "
8654 "Data: x%x x%x x%x x%x\n",
8655 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8656 irsp->ulpTimeout, vport->num_disc_nodes);
8657
8658 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8659 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008660 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008661 vport->fc_flag &= ~FC_FABRIC;
8662 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008663 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008664 }
James Smart92d7f7b2007-06-17 19:56:38 -05008665}
8666
James Smarte59058c2008-08-24 21:49:00 -04008667/**
James Smart3621a712009-04-06 18:47:14 -04008668 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008669 * @vport: pointer to a virtual N_Port data structure.
8670 * @ndlp: pointer to a node-list data structure.
8671 *
8672 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8673 *
8674 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8675 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8676 * will be stored into the context1 field of the IOCB for the completion
8677 * callback function to the LOGO ELS command.
8678 *
8679 * Return codes
8680 * 0 - Successfully issued logo off the @vport
8681 * 1 - Failed to issue logo off the @vport
8682 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008683int
8684lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8685{
8686 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8687 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008688 struct lpfc_iocbq *elsiocb;
8689 uint8_t *pcmd;
8690 uint16_t cmdsize;
8691
8692 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8693 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8694 ELS_CMD_LOGO);
8695 if (!elsiocb)
8696 return 1;
8697
James Smart92d7f7b2007-06-17 19:56:38 -05008698 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8699 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8700 pcmd += sizeof(uint32_t);
8701
8702 /* Fill in LOGO payload */
8703 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8704 pcmd += sizeof(uint32_t);
8705 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8706
James Smart858c9f62007-06-17 19:56:39 -05008707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8708 "Issue LOGO npiv did:x%x flg:x%x",
8709 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8710
James Smart92d7f7b2007-06-17 19:56:38 -05008711 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8712 spin_lock_irq(shost->host_lock);
8713 ndlp->nlp_flag |= NLP_LOGO_SND;
8714 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008715 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8716 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05008717 spin_lock_irq(shost->host_lock);
8718 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8719 spin_unlock_irq(shost->host_lock);
8720 lpfc_els_free_iocb(phba, elsiocb);
8721 return 1;
8722 }
8723 return 0;
8724}
8725
James Smarte59058c2008-08-24 21:49:00 -04008726/**
James Smart3621a712009-04-06 18:47:14 -04008727 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04008728 * @ptr: holder for the timer function associated data.
8729 *
8730 * This routine is invoked by the fabric iocb block timer after
8731 * timeout. It posts the fabric iocb block timeout event by setting the
8732 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8733 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8734 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8735 * posted event WORKER_FABRIC_BLOCK_TMO.
8736 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008737void
8738lpfc_fabric_block_timeout(unsigned long ptr)
8739{
8740 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8741 unsigned long iflags;
8742 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04008743
James Smart92d7f7b2007-06-17 19:56:38 -05008744 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8745 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8746 if (!tmo_posted)
8747 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8748 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8749
James Smart5e9d9b82008-06-14 22:52:53 -04008750 if (!tmo_posted)
8751 lpfc_worker_wake_up(phba);
8752 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008753}
8754
James Smarte59058c2008-08-24 21:49:00 -04008755/**
James Smart3621a712009-04-06 18:47:14 -04008756 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04008757 * @phba: pointer to lpfc hba data structure.
8758 *
8759 * This routine issues one fabric iocb from the driver internal list to
8760 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8761 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8762 * remove one pending fabric iocb from the driver internal list and invokes
8763 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8764 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008765static void
8766lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8767{
8768 struct lpfc_iocbq *iocb;
8769 unsigned long iflags;
8770 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05008771 IOCB_t *cmd;
8772
8773repeat:
8774 iocb = NULL;
8775 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05008776 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05008777 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8778 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8779 list);
8780 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05008781 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05008782 atomic_inc(&phba->fabric_iocb_count);
8783 }
8784 spin_unlock_irqrestore(&phba->hbalock, iflags);
8785 if (iocb) {
8786 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8787 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8788 iocb->iocb_flag |= LPFC_IO_FABRIC;
8789
James Smart858c9f62007-06-17 19:56:39 -05008790 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8791 "Fabric sched1: ste:x%x",
8792 iocb->vport->port_state, 0, 0);
8793
James Smart3772a992009-05-22 14:50:54 -04008794 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008795
8796 if (ret == IOCB_ERROR) {
8797 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8798 iocb->fabric_iocb_cmpl = NULL;
8799 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8800 cmd = &iocb->iocb;
8801 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8802 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8803 iocb->iocb_cmpl(phba, iocb, iocb);
8804
8805 atomic_dec(&phba->fabric_iocb_count);
8806 goto repeat;
8807 }
8808 }
8809
8810 return;
8811}
8812
James Smarte59058c2008-08-24 21:49:00 -04008813/**
James Smart3621a712009-04-06 18:47:14 -04008814 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008815 * @phba: pointer to lpfc hba data structure.
8816 *
8817 * This routine unblocks the issuing fabric iocb command. The function
8818 * will clear the fabric iocb block bit and then invoke the routine
8819 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8820 * from the driver internal fabric iocb list.
8821 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008822void
8823lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8824{
8825 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8826
8827 lpfc_resume_fabric_iocbs(phba);
8828 return;
8829}
8830
James Smarte59058c2008-08-24 21:49:00 -04008831/**
James Smart3621a712009-04-06 18:47:14 -04008832 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008833 * @phba: pointer to lpfc hba data structure.
8834 *
8835 * This routine blocks the issuing fabric iocb for a specified amount of
8836 * time (currently 100 ms). This is done by set the fabric iocb block bit
8837 * and set up a timeout timer for 100ms. When the block bit is set, no more
8838 * fabric iocb will be issued out of the HBA.
8839 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008840static void
8841lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
8842{
8843 int blocked;
8844
8845 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05008846 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05008847 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04008848 mod_timer(&phba->fabric_block_timer,
8849 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05008850
8851 return;
8852}
8853
James Smarte59058c2008-08-24 21:49:00 -04008854/**
James Smart3621a712009-04-06 18:47:14 -04008855 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04008856 * @phba: pointer to lpfc hba data structure.
8857 * @cmdiocb: pointer to lpfc command iocb data structure.
8858 * @rspiocb: pointer to lpfc response iocb data structure.
8859 *
8860 * This routine is the callback function that is put to the fabric iocb's
8861 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8862 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8863 * function first restores and invokes the original iocb's callback function
8864 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8865 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8866 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008867static void
8868lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8869 struct lpfc_iocbq *rspiocb)
8870{
8871 struct ls_rjt stat;
8872
8873 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8874 BUG();
8875
8876 switch (rspiocb->iocb.ulpStatus) {
8877 case IOSTAT_NPORT_RJT:
8878 case IOSTAT_FABRIC_RJT:
8879 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
8880 lpfc_block_fabric_iocbs(phba);
8881 }
8882 break;
8883
8884 case IOSTAT_NPORT_BSY:
8885 case IOSTAT_FABRIC_BSY:
8886 lpfc_block_fabric_iocbs(phba);
8887 break;
8888
8889 case IOSTAT_LS_RJT:
8890 stat.un.lsRjtError =
8891 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
8892 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
8893 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
8894 lpfc_block_fabric_iocbs(phba);
8895 break;
8896 }
8897
8898 if (atomic_read(&phba->fabric_iocb_count) == 0)
8899 BUG();
8900
8901 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
8902 cmdiocb->fabric_iocb_cmpl = NULL;
8903 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
8904 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
8905
8906 atomic_dec(&phba->fabric_iocb_count);
8907 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05008908 /* Post any pending iocbs to HBA */
8909 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05008910 }
8911}
8912
James Smarte59058c2008-08-24 21:49:00 -04008913/**
James Smart3621a712009-04-06 18:47:14 -04008914 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008915 * @phba: pointer to lpfc hba data structure.
8916 * @iocb: pointer to lpfc command iocb data structure.
8917 *
8918 * This routine is used as the top-level API for issuing a fabric iocb command
8919 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8920 * function makes sure that only one fabric bound iocb will be outstanding at
8921 * any given time. As such, this function will first check to see whether there
8922 * is already an outstanding fabric iocb on the wire. If so, it will put the
8923 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8924 * issued later. Otherwise, it will issue the iocb on the wire and update the
8925 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8926 *
8927 * Note, this implementation has a potential sending out fabric IOCBs out of
8928 * order. The problem is caused by the construction of the "ready" boolen does
8929 * not include the condition that the internal fabric IOCB list is empty. As
8930 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8931 * ahead of the fabric IOCBs in the internal list.
8932 *
8933 * Return code
8934 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8935 * IOCB_ERROR - failed to issue fabric iocb
8936 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008937static int
James Smart92d7f7b2007-06-17 19:56:38 -05008938lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
8939{
8940 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05008941 int ready;
8942 int ret;
8943
8944 if (atomic_read(&phba->fabric_iocb_count) > 1)
8945 BUG();
8946
8947 spin_lock_irqsave(&phba->hbalock, iflags);
8948 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
8949 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8950
James Smart7f5f3d02008-02-08 18:50:14 -05008951 if (ready)
8952 /* Increment fabric iocb count to hold the position */
8953 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05008954 spin_unlock_irqrestore(&phba->hbalock, iflags);
8955 if (ready) {
8956 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8957 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8958 iocb->iocb_flag |= LPFC_IO_FABRIC;
8959
James Smart858c9f62007-06-17 19:56:39 -05008960 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8961 "Fabric sched2: ste:x%x",
8962 iocb->vport->port_state, 0, 0);
8963
James Smart3772a992009-05-22 14:50:54 -04008964 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008965
8966 if (ret == IOCB_ERROR) {
8967 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8968 iocb->fabric_iocb_cmpl = NULL;
8969 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8970 atomic_dec(&phba->fabric_iocb_count);
8971 }
8972 } else {
8973 spin_lock_irqsave(&phba->hbalock, iflags);
8974 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
8975 spin_unlock_irqrestore(&phba->hbalock, iflags);
8976 ret = IOCB_SUCCESS;
8977 }
8978 return ret;
8979}
8980
James Smarte59058c2008-08-24 21:49:00 -04008981/**
James Smart3621a712009-04-06 18:47:14 -04008982 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008983 * @vport: pointer to a virtual N_Port data structure.
8984 *
8985 * This routine aborts all the IOCBs associated with a @vport from the
8986 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8987 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8988 * list, removes each IOCB associated with the @vport off the list, set the
8989 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8990 * associated with the IOCB.
8991 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008992static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05008993{
8994 LIST_HEAD(completions);
8995 struct lpfc_hba *phba = vport->phba;
8996 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05008997
8998 spin_lock_irq(&phba->hbalock);
8999 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9000 list) {
9001
9002 if (piocb->vport != vport)
9003 continue;
9004
9005 list_move_tail(&piocb->list, &completions);
9006 }
9007 spin_unlock_irq(&phba->hbalock);
9008
James Smarta257bf92009-04-06 18:48:10 -04009009 /* Cancel all the IOCBs from the completions list */
9010 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9011 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009012}
9013
James Smarte59058c2008-08-24 21:49:00 -04009014/**
James Smart3621a712009-04-06 18:47:14 -04009015 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009016 * @ndlp: pointer to a node-list data structure.
9017 *
9018 * This routine aborts all the IOCBs associated with an @ndlp from the
9019 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9020 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9021 * list, removes each IOCB associated with the @ndlp off the list, set the
9022 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9023 * associated with the IOCB.
9024 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009025void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
9026{
9027 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04009028 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009029 struct lpfc_iocbq *tmp_iocb, *piocb;
9030 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05009031
9032 spin_lock_irq(&phba->hbalock);
9033 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9034 list) {
9035 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9036
9037 list_move_tail(&piocb->list, &completions);
9038 }
9039 }
9040 spin_unlock_irq(&phba->hbalock);
9041
James Smarta257bf92009-04-06 18:48:10 -04009042 /* Cancel all the IOCBs from the completions list */
9043 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9044 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009045}
9046
James Smarte59058c2008-08-24 21:49:00 -04009047/**
James Smart3621a712009-04-06 18:47:14 -04009048 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009049 * @phba: pointer to lpfc hba data structure.
9050 *
9051 * This routine aborts all the IOCBs currently on the driver internal
9052 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9053 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9054 * list, removes IOCBs off the list, set the status feild to
9055 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9056 * the IOCB.
9057 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009058void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9059{
9060 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009061
9062 spin_lock_irq(&phba->hbalock);
9063 list_splice_init(&phba->fabric_iocb_list, &completions);
9064 spin_unlock_irq(&phba->hbalock);
9065
James Smarta257bf92009-04-06 18:48:10 -04009066 /* Cancel all the IOCBs from the completions list */
9067 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9068 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009069}
James Smart6fb120a2009-05-22 14:52:59 -04009070
9071/**
James Smart1151e3e2011-02-16 12:39:35 -05009072 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9073 * @vport: pointer to lpfc vport data structure.
9074 *
9075 * This routine is invoked by the vport cleanup for deletions and the cleanup
9076 * for an ndlp on removal.
9077 **/
9078void
9079lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9080{
9081 struct lpfc_hba *phba = vport->phba;
9082 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9083 unsigned long iflag = 0;
9084
9085 spin_lock_irqsave(&phba->hbalock, iflag);
9086 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
9087 list_for_each_entry_safe(sglq_entry, sglq_next,
9088 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9089 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9090 sglq_entry->ndlp = NULL;
9091 }
9092 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
9093 spin_unlock_irqrestore(&phba->hbalock, iflag);
9094 return;
9095}
9096
9097/**
James Smart6fb120a2009-05-22 14:52:59 -04009098 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9099 * @phba: pointer to lpfc hba data structure.
9100 * @axri: pointer to the els xri abort wcqe structure.
9101 *
9102 * This routine is invoked by the worker thread to process a SLI4 slow-path
9103 * ELS aborted xri.
9104 **/
9105void
9106lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9107 struct sli4_wcqe_xri_aborted *axri)
9108{
9109 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05009110 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04009111 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05009112
James Smart6fb120a2009-05-22 14:52:59 -04009113 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9114 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05009115 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04009116 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04009117
James Smart0f65ff62010-02-26 14:14:23 -05009118 spin_lock_irqsave(&phba->hbalock, iflag);
9119 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009120 list_for_each_entry_safe(sglq_entry, sglq_next,
9121 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9122 if (sglq_entry->sli4_xritag == xri) {
9123 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05009124 ndlp = sglq_entry->ndlp;
9125 sglq_entry->ndlp = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -04009126 spin_lock(&pring->ring_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009127 list_add_tail(&sglq_entry->list,
9128 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05009129 sglq_entry->state = SGL_FREED;
James Smartdafe8ce2014-09-03 12:56:40 -04009130 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009131 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009132 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04009133 lpfc_set_rrq_active(phba, ndlp,
9134 sglq_entry->sli4_lxritag,
9135 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04009136
9137 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05009138 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04009139 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009140 return;
9141 }
9142 }
James Smart0f65ff62010-02-26 14:14:23 -05009143 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009144 lxri = lpfc_sli4_xri_inrange(phba, xri);
9145 if (lxri == NO_XRI) {
9146 spin_unlock_irqrestore(&phba->hbalock, iflag);
9147 return;
9148 }
James Smartdafe8ce2014-09-03 12:56:40 -04009149 spin_lock(&pring->ring_lock);
James Smart7851fe22011-07-22 18:36:52 -04009150 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05009151 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smartdafe8ce2014-09-03 12:56:40 -04009152 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009153 spin_unlock_irqrestore(&phba->hbalock, iflag);
9154 return;
9155 }
9156 sglq_entry->state = SGL_XRI_ABORTED;
James Smartdafe8ce2014-09-03 12:56:40 -04009157 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009158 spin_unlock_irqrestore(&phba->hbalock, iflag);
9159 return;
James Smart6fb120a2009-05-22 14:52:59 -04009160}
James Smart086a3452012-08-14 14:25:21 -04009161
9162/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9163 * @vport: pointer to virtual port object.
9164 * @ndlp: nodelist pointer for the impacted node.
9165 *
9166 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9167 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9168 * the driver is required to send a LOGO to the remote node before it
9169 * attempts to recover its login to the remote node.
9170 */
9171void
9172lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9173 struct lpfc_nodelist *ndlp)
9174{
9175 struct Scsi_Host *shost;
9176 struct lpfc_hba *phba;
9177 unsigned long flags = 0;
9178
9179 shost = lpfc_shost_from_vport(vport);
9180 phba = vport->phba;
9181 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9182 lpfc_printf_log(phba, KERN_INFO,
9183 LOG_SLI, "3093 No rport recovery needed. "
9184 "rport in state 0x%x\n", ndlp->nlp_state);
9185 return;
9186 }
9187 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9188 "3094 Start rport recovery on shost id 0x%x "
9189 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9190 "flags 0x%x\n",
9191 shost->host_no, ndlp->nlp_DID,
9192 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9193 ndlp->nlp_flag);
9194 /*
9195 * The rport is not responding. Remove the FCP-2 flag to prevent
9196 * an ADISC in the follow-up recovery code.
9197 */
9198 spin_lock_irqsave(shost->host_lock, flags);
9199 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9200 spin_unlock_irqrestore(shost->host_lock, flags);
9201 lpfc_issue_els_logo(vport, ndlp, 0);
9202 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
9203}
9204