1*4882a593Smuzhiyun /*******************************************************************
2*4882a593Smuzhiyun * This file is part of the Emulex Linux Device Driver for *
3*4882a593Smuzhiyun * Fibre Channel Host Bus Adapters. *
4*4882a593Smuzhiyun * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5*4882a593Smuzhiyun * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6*4882a593Smuzhiyun * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7*4882a593Smuzhiyun * EMULEX and SLI are trademarks of Emulex. *
8*4882a593Smuzhiyun * www.broadcom.com *
9*4882a593Smuzhiyun * Portions Copyright (C) 2004-2005 Christoph Hellwig *
10*4882a593Smuzhiyun * *
11*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or *
12*4882a593Smuzhiyun * modify it under the terms of version 2 of the GNU General *
13*4882a593Smuzhiyun * Public License as published by the Free Software Foundation. *
14*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful. *
15*4882a593Smuzhiyun * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16*4882a593Smuzhiyun * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18*4882a593Smuzhiyun * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19*4882a593Smuzhiyun * TO BE LEGALLY INVALID. See the GNU General Public License for *
20*4882a593Smuzhiyun * more details, a copy of which can be found in the file COPYING *
21*4882a593Smuzhiyun * included with this package. *
22*4882a593Smuzhiyun *******************************************************************/
23*4882a593Smuzhiyun /* See Fibre Channel protocol T11 FC-LS for details */
24*4882a593Smuzhiyun #include <linux/blkdev.h>
25*4882a593Smuzhiyun #include <linux/pci.h>
26*4882a593Smuzhiyun #include <linux/slab.h>
27*4882a593Smuzhiyun #include <linux/interrupt.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include <scsi/scsi.h>
30*4882a593Smuzhiyun #include <scsi/scsi_device.h>
31*4882a593Smuzhiyun #include <scsi/scsi_host.h>
32*4882a593Smuzhiyun #include <scsi/scsi_transport_fc.h>
33*4882a593Smuzhiyun #include <uapi/scsi/fc/fc_fs.h>
34*4882a593Smuzhiyun #include <uapi/scsi/fc/fc_els.h>
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun #include "lpfc_hw4.h"
37*4882a593Smuzhiyun #include "lpfc_hw.h"
38*4882a593Smuzhiyun #include "lpfc_sli.h"
39*4882a593Smuzhiyun #include "lpfc_sli4.h"
40*4882a593Smuzhiyun #include "lpfc_nl.h"
41*4882a593Smuzhiyun #include "lpfc_disc.h"
42*4882a593Smuzhiyun #include "lpfc_scsi.h"
43*4882a593Smuzhiyun #include "lpfc.h"
44*4882a593Smuzhiyun #include "lpfc_logmsg.h"
45*4882a593Smuzhiyun #include "lpfc_crtn.h"
46*4882a593Smuzhiyun #include "lpfc_vport.h"
47*4882a593Smuzhiyun #include "lpfc_debugfs.h"
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
50*4882a593Smuzhiyun struct lpfc_iocbq *);
51*4882a593Smuzhiyun static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
52*4882a593Smuzhiyun struct lpfc_iocbq *);
53*4882a593Smuzhiyun static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
54*4882a593Smuzhiyun static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
55*4882a593Smuzhiyun struct lpfc_nodelist *ndlp, uint8_t retry);
56*4882a593Smuzhiyun static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
57*4882a593Smuzhiyun struct lpfc_iocbq *iocb);
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun static int lpfc_max_els_tries = 3;
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /**
62*4882a593Smuzhiyun * lpfc_els_chk_latt - Check host link attention event for a vport
63*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
64*4882a593Smuzhiyun *
65*4882a593Smuzhiyun * This routine checks whether there is an outstanding host link
66*4882a593Smuzhiyun * attention event during the discovery process with the @vport. It is done
67*4882a593Smuzhiyun * by reading the HBA's Host Attention (HA) register. If there is any host
68*4882a593Smuzhiyun * link attention events during this @vport's discovery process, the @vport
69*4882a593Smuzhiyun * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
70*4882a593Smuzhiyun * be issued if the link state is not already in host link cleared state,
71*4882a593Smuzhiyun * and a return code shall indicate whether the host link attention event
72*4882a593Smuzhiyun * had happened.
73*4882a593Smuzhiyun *
74*4882a593Smuzhiyun * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
75*4882a593Smuzhiyun * state in LPFC_VPORT_READY, the request for checking host link attention
76*4882a593Smuzhiyun * event will be ignored and a return code shall indicate no host link
77*4882a593Smuzhiyun * attention event had happened.
78*4882a593Smuzhiyun *
79*4882a593Smuzhiyun * Return codes
80*4882a593Smuzhiyun * 0 - no host link attention event happened
81*4882a593Smuzhiyun * 1 - host link attention event happened
82*4882a593Smuzhiyun **/
83*4882a593Smuzhiyun int
lpfc_els_chk_latt(struct lpfc_vport * vport)84*4882a593Smuzhiyun lpfc_els_chk_latt(struct lpfc_vport *vport)
85*4882a593Smuzhiyun {
86*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
87*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
88*4882a593Smuzhiyun uint32_t ha_copy;
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun if (vport->port_state >= LPFC_VPORT_READY ||
91*4882a593Smuzhiyun phba->link_state == LPFC_LINK_DOWN ||
92*4882a593Smuzhiyun phba->sli_rev > LPFC_SLI_REV3)
93*4882a593Smuzhiyun return 0;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* Read the HBA Host Attention Register */
96*4882a593Smuzhiyun if (lpfc_readl(phba->HAregaddr, &ha_copy))
97*4882a593Smuzhiyun return 1;
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun if (!(ha_copy & HA_LATT))
100*4882a593Smuzhiyun return 0;
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Pending Link Event during Discovery */
103*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
104*4882a593Smuzhiyun "0237 Pending Link Event during "
105*4882a593Smuzhiyun "Discovery: State x%x\n",
106*4882a593Smuzhiyun phba->pport->port_state);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun /* CLEAR_LA should re-enable link attention events and
109*4882a593Smuzhiyun * we should then immediately take a LATT event. The
110*4882a593Smuzhiyun * LATT processing should call lpfc_linkdown() which
111*4882a593Smuzhiyun * will cleanup any left over in-progress discovery
112*4882a593Smuzhiyun * events.
113*4882a593Smuzhiyun */
114*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
115*4882a593Smuzhiyun vport->fc_flag |= FC_ABORT_DISCOVERY;
116*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun if (phba->link_state != LPFC_CLEAR_LA)
119*4882a593Smuzhiyun lpfc_issue_clear_la(phba, vport);
120*4882a593Smuzhiyun
121*4882a593Smuzhiyun return 1;
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun /**
125*4882a593Smuzhiyun * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
126*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
127*4882a593Smuzhiyun * @expectRsp: flag indicating whether response is expected.
128*4882a593Smuzhiyun * @cmdSize: size of the ELS command.
129*4882a593Smuzhiyun * @retry: number of retries to the command IOCB when it fails.
130*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
131*4882a593Smuzhiyun * @did: destination identifier.
132*4882a593Smuzhiyun * @elscmd: the ELS command code.
133*4882a593Smuzhiyun *
134*4882a593Smuzhiyun * This routine is used for allocating a lpfc-IOCB data structure from
135*4882a593Smuzhiyun * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
136*4882a593Smuzhiyun * passed into the routine for discovery state machine to issue an Extended
137*4882a593Smuzhiyun * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
138*4882a593Smuzhiyun * and preparation routine that is used by all the discovery state machine
139*4882a593Smuzhiyun * routines and the ELS command-specific fields will be later set up by
140*4882a593Smuzhiyun * the individual discovery machine routines after calling this routine
141*4882a593Smuzhiyun * allocating and preparing a generic IOCB data structure. It fills in the
142*4882a593Smuzhiyun * Buffer Descriptor Entries (BDEs), allocates buffers for both command
143*4882a593Smuzhiyun * payload and response payload (if expected). The reference count on the
144*4882a593Smuzhiyun * ndlp is incremented by 1 and the reference to the ndlp is put into
145*4882a593Smuzhiyun * context1 of the IOCB data structure for this IOCB to hold the ndlp
146*4882a593Smuzhiyun * reference for the command's callback function to access later.
147*4882a593Smuzhiyun *
148*4882a593Smuzhiyun * Return code
149*4882a593Smuzhiyun * Pointer to the newly allocated/prepared els iocb data structure
150*4882a593Smuzhiyun * NULL - when els iocb data structure allocation/preparation failed
151*4882a593Smuzhiyun **/
152*4882a593Smuzhiyun struct lpfc_iocbq *
lpfc_prep_els_iocb(struct lpfc_vport * vport,uint8_t expectRsp,uint16_t cmdSize,uint8_t retry,struct lpfc_nodelist * ndlp,uint32_t did,uint32_t elscmd)153*4882a593Smuzhiyun lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
154*4882a593Smuzhiyun uint16_t cmdSize, uint8_t retry,
155*4882a593Smuzhiyun struct lpfc_nodelist *ndlp, uint32_t did,
156*4882a593Smuzhiyun uint32_t elscmd)
157*4882a593Smuzhiyun {
158*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
159*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
160*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
161*4882a593Smuzhiyun struct ulp_bde64 *bpl;
162*4882a593Smuzhiyun IOCB_t *icmd;
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun if (!lpfc_is_link_up(phba))
166*4882a593Smuzhiyun return NULL;
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun /* Allocate buffer for command iocb */
169*4882a593Smuzhiyun elsiocb = lpfc_sli_get_iocbq(phba);
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun if (elsiocb == NULL)
172*4882a593Smuzhiyun return NULL;
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun /*
175*4882a593Smuzhiyun * If this command is for fabric controller and HBA running
176*4882a593Smuzhiyun * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
177*4882a593Smuzhiyun */
178*4882a593Smuzhiyun if ((did == Fabric_DID) &&
179*4882a593Smuzhiyun (phba->hba_flag & HBA_FIP_SUPPORT) &&
180*4882a593Smuzhiyun ((elscmd == ELS_CMD_FLOGI) ||
181*4882a593Smuzhiyun (elscmd == ELS_CMD_FDISC) ||
182*4882a593Smuzhiyun (elscmd == ELS_CMD_LOGO)))
183*4882a593Smuzhiyun switch (elscmd) {
184*4882a593Smuzhiyun case ELS_CMD_FLOGI:
185*4882a593Smuzhiyun elsiocb->iocb_flag |=
186*4882a593Smuzhiyun ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
187*4882a593Smuzhiyun & LPFC_FIP_ELS_ID_MASK);
188*4882a593Smuzhiyun break;
189*4882a593Smuzhiyun case ELS_CMD_FDISC:
190*4882a593Smuzhiyun elsiocb->iocb_flag |=
191*4882a593Smuzhiyun ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
192*4882a593Smuzhiyun & LPFC_FIP_ELS_ID_MASK);
193*4882a593Smuzhiyun break;
194*4882a593Smuzhiyun case ELS_CMD_LOGO:
195*4882a593Smuzhiyun elsiocb->iocb_flag |=
196*4882a593Smuzhiyun ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
197*4882a593Smuzhiyun & LPFC_FIP_ELS_ID_MASK);
198*4882a593Smuzhiyun break;
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun else
201*4882a593Smuzhiyun elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun icmd = &elsiocb->iocb;
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun /* fill in BDEs for command */
206*4882a593Smuzhiyun /* Allocate buffer for command payload */
207*4882a593Smuzhiyun pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
208*4882a593Smuzhiyun if (pcmd)
209*4882a593Smuzhiyun pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
210*4882a593Smuzhiyun if (!pcmd || !pcmd->virt)
211*4882a593Smuzhiyun goto els_iocb_free_pcmb_exit;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun INIT_LIST_HEAD(&pcmd->list);
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun /* Allocate buffer for response payload */
216*4882a593Smuzhiyun if (expectRsp) {
217*4882a593Smuzhiyun prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
218*4882a593Smuzhiyun if (prsp)
219*4882a593Smuzhiyun prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
220*4882a593Smuzhiyun &prsp->phys);
221*4882a593Smuzhiyun if (!prsp || !prsp->virt)
222*4882a593Smuzhiyun goto els_iocb_free_prsp_exit;
223*4882a593Smuzhiyun INIT_LIST_HEAD(&prsp->list);
224*4882a593Smuzhiyun } else
225*4882a593Smuzhiyun prsp = NULL;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun /* Allocate buffer for Buffer ptr list */
228*4882a593Smuzhiyun pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
229*4882a593Smuzhiyun if (pbuflist)
230*4882a593Smuzhiyun pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
231*4882a593Smuzhiyun &pbuflist->phys);
232*4882a593Smuzhiyun if (!pbuflist || !pbuflist->virt)
233*4882a593Smuzhiyun goto els_iocb_free_pbuf_exit;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun INIT_LIST_HEAD(&pbuflist->list);
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun if (expectRsp) {
238*4882a593Smuzhiyun icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
239*4882a593Smuzhiyun icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
240*4882a593Smuzhiyun icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
241*4882a593Smuzhiyun icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun icmd->un.elsreq64.remoteID = did; /* DID */
244*4882a593Smuzhiyun icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
245*4882a593Smuzhiyun if (elscmd == ELS_CMD_FLOGI)
246*4882a593Smuzhiyun icmd->ulpTimeout = FF_DEF_RATOV * 2;
247*4882a593Smuzhiyun else if (elscmd == ELS_CMD_LOGO)
248*4882a593Smuzhiyun icmd->ulpTimeout = phba->fc_ratov;
249*4882a593Smuzhiyun else
250*4882a593Smuzhiyun icmd->ulpTimeout = phba->fc_ratov * 2;
251*4882a593Smuzhiyun } else {
252*4882a593Smuzhiyun icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
253*4882a593Smuzhiyun icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
254*4882a593Smuzhiyun icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
255*4882a593Smuzhiyun icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
256*4882a593Smuzhiyun icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
257*4882a593Smuzhiyun icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun icmd->ulpBdeCount = 1;
260*4882a593Smuzhiyun icmd->ulpLe = 1;
261*4882a593Smuzhiyun icmd->ulpClass = CLASS3;
262*4882a593Smuzhiyun
263*4882a593Smuzhiyun /*
264*4882a593Smuzhiyun * If we have NPIV enabled, we want to send ELS traffic by VPI.
265*4882a593Smuzhiyun * For SLI4, since the driver controls VPIs we also want to include
266*4882a593Smuzhiyun * all ELS pt2pt protocol traffic as well.
267*4882a593Smuzhiyun */
268*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
269*4882a593Smuzhiyun ((phba->sli_rev == LPFC_SLI_REV4) &&
270*4882a593Smuzhiyun (vport->fc_flag & FC_PT2PT))) {
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun if (expectRsp) {
273*4882a593Smuzhiyun icmd->un.elsreq64.myID = vport->fc_myDID;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun /* For ELS_REQUEST64_CR, use the VPI by default */
276*4882a593Smuzhiyun icmd->ulpContext = phba->vpi_ids[vport->vpi];
277*4882a593Smuzhiyun }
278*4882a593Smuzhiyun
279*4882a593Smuzhiyun icmd->ulpCt_h = 0;
280*4882a593Smuzhiyun /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
281*4882a593Smuzhiyun if (elscmd == ELS_CMD_ECHO)
282*4882a593Smuzhiyun icmd->ulpCt_l = 0; /* context = invalid RPI */
283*4882a593Smuzhiyun else
284*4882a593Smuzhiyun icmd->ulpCt_l = 1; /* context = VPI */
285*4882a593Smuzhiyun }
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun bpl = (struct ulp_bde64 *) pbuflist->virt;
288*4882a593Smuzhiyun bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
289*4882a593Smuzhiyun bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
290*4882a593Smuzhiyun bpl->tus.f.bdeSize = cmdSize;
291*4882a593Smuzhiyun bpl->tus.f.bdeFlags = 0;
292*4882a593Smuzhiyun bpl->tus.w = le32_to_cpu(bpl->tus.w);
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun if (expectRsp) {
295*4882a593Smuzhiyun bpl++;
296*4882a593Smuzhiyun bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
297*4882a593Smuzhiyun bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
298*4882a593Smuzhiyun bpl->tus.f.bdeSize = FCELSSIZE;
299*4882a593Smuzhiyun bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
300*4882a593Smuzhiyun bpl->tus.w = le32_to_cpu(bpl->tus.w);
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun
303*4882a593Smuzhiyun /* prevent preparing iocb with NULL ndlp reference */
304*4882a593Smuzhiyun elsiocb->context1 = lpfc_nlp_get(ndlp);
305*4882a593Smuzhiyun if (!elsiocb->context1)
306*4882a593Smuzhiyun goto els_iocb_free_pbuf_exit;
307*4882a593Smuzhiyun elsiocb->context2 = pcmd;
308*4882a593Smuzhiyun elsiocb->context3 = pbuflist;
309*4882a593Smuzhiyun elsiocb->retry = retry;
310*4882a593Smuzhiyun elsiocb->vport = vport;
311*4882a593Smuzhiyun elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun if (prsp) {
314*4882a593Smuzhiyun list_add(&prsp->list, &pcmd->list);
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun if (expectRsp) {
317*4882a593Smuzhiyun /* Xmit ELS command <elsCmd> to remote NPORT <did> */
318*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
319*4882a593Smuzhiyun "0116 Xmit ELS command x%x to remote "
320*4882a593Smuzhiyun "NPORT x%x I/O tag: x%x, port state:x%x "
321*4882a593Smuzhiyun "rpi x%x fc_flag:x%x\n",
322*4882a593Smuzhiyun elscmd, did, elsiocb->iotag,
323*4882a593Smuzhiyun vport->port_state, ndlp->nlp_rpi,
324*4882a593Smuzhiyun vport->fc_flag);
325*4882a593Smuzhiyun } else {
326*4882a593Smuzhiyun /* Xmit ELS response <elsCmd> to remote NPORT <did> */
327*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
328*4882a593Smuzhiyun "0117 Xmit ELS response x%x to remote "
329*4882a593Smuzhiyun "NPORT x%x I/O tag: x%x, size: x%x "
330*4882a593Smuzhiyun "port_state x%x rpi x%x fc_flag x%x\n",
331*4882a593Smuzhiyun elscmd, ndlp->nlp_DID, elsiocb->iotag,
332*4882a593Smuzhiyun cmdSize, vport->port_state,
333*4882a593Smuzhiyun ndlp->nlp_rpi, vport->fc_flag);
334*4882a593Smuzhiyun }
335*4882a593Smuzhiyun return elsiocb;
336*4882a593Smuzhiyun
337*4882a593Smuzhiyun els_iocb_free_pbuf_exit:
338*4882a593Smuzhiyun if (expectRsp)
339*4882a593Smuzhiyun lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
340*4882a593Smuzhiyun kfree(pbuflist);
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun els_iocb_free_prsp_exit:
343*4882a593Smuzhiyun lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
344*4882a593Smuzhiyun kfree(prsp);
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun els_iocb_free_pcmb_exit:
347*4882a593Smuzhiyun kfree(pcmd);
348*4882a593Smuzhiyun lpfc_sli_release_iocbq(phba, elsiocb);
349*4882a593Smuzhiyun return NULL;
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun /**
353*4882a593Smuzhiyun * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
354*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
355*4882a593Smuzhiyun *
356*4882a593Smuzhiyun * This routine issues a fabric registration login for a @vport. An
357*4882a593Smuzhiyun * active ndlp node with Fabric_DID must already exist for this @vport.
358*4882a593Smuzhiyun * The routine invokes two mailbox commands to carry out fabric registration
359*4882a593Smuzhiyun * login through the HBA firmware: the first mailbox command requests the
360*4882a593Smuzhiyun * HBA to perform link configuration for the @vport; and the second mailbox
361*4882a593Smuzhiyun * command requests the HBA to perform the actual fabric registration login
362*4882a593Smuzhiyun * with the @vport.
363*4882a593Smuzhiyun *
364*4882a593Smuzhiyun * Return code
365*4882a593Smuzhiyun * 0 - successfully issued fabric registration login for @vport
366*4882a593Smuzhiyun * -ENXIO -- failed to issue fabric registration login for @vport
367*4882a593Smuzhiyun **/
368*4882a593Smuzhiyun int
lpfc_issue_fabric_reglogin(struct lpfc_vport * vport)369*4882a593Smuzhiyun lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
370*4882a593Smuzhiyun {
371*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
372*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
373*4882a593Smuzhiyun struct lpfc_dmabuf *mp;
374*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
375*4882a593Smuzhiyun struct serv_parm *sp;
376*4882a593Smuzhiyun int rc;
377*4882a593Smuzhiyun int err = 0;
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun sp = &phba->fc_fabparam;
380*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, Fabric_DID);
381*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
382*4882a593Smuzhiyun err = 1;
383*4882a593Smuzhiyun goto fail;
384*4882a593Smuzhiyun }
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
387*4882a593Smuzhiyun if (!mbox) {
388*4882a593Smuzhiyun err = 2;
389*4882a593Smuzhiyun goto fail;
390*4882a593Smuzhiyun }
391*4882a593Smuzhiyun
392*4882a593Smuzhiyun vport->port_state = LPFC_FABRIC_CFG_LINK;
393*4882a593Smuzhiyun lpfc_config_link(phba, mbox);
394*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
395*4882a593Smuzhiyun mbox->vport = vport;
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
398*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
399*4882a593Smuzhiyun err = 3;
400*4882a593Smuzhiyun goto fail_free_mbox;
401*4882a593Smuzhiyun }
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
404*4882a593Smuzhiyun if (!mbox) {
405*4882a593Smuzhiyun err = 4;
406*4882a593Smuzhiyun goto fail;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
409*4882a593Smuzhiyun ndlp->nlp_rpi);
410*4882a593Smuzhiyun if (rc) {
411*4882a593Smuzhiyun err = 5;
412*4882a593Smuzhiyun goto fail_free_mbox;
413*4882a593Smuzhiyun }
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
416*4882a593Smuzhiyun mbox->vport = vport;
417*4882a593Smuzhiyun /* increment the reference count on ndlp to hold reference
418*4882a593Smuzhiyun * for the callback routine.
419*4882a593Smuzhiyun */
420*4882a593Smuzhiyun mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
423*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
424*4882a593Smuzhiyun err = 6;
425*4882a593Smuzhiyun goto fail_issue_reg_login;
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun return 0;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun fail_issue_reg_login:
431*4882a593Smuzhiyun /* decrement the reference count on ndlp just incremented
432*4882a593Smuzhiyun * for the failed mbox command.
433*4882a593Smuzhiyun */
434*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
435*4882a593Smuzhiyun mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
436*4882a593Smuzhiyun lpfc_mbuf_free(phba, mp->virt, mp->phys);
437*4882a593Smuzhiyun kfree(mp);
438*4882a593Smuzhiyun fail_free_mbox:
439*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
440*4882a593Smuzhiyun
441*4882a593Smuzhiyun fail:
442*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
443*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
444*4882a593Smuzhiyun "0249 Cannot issue Register Fabric login: Err %d\n",
445*4882a593Smuzhiyun err);
446*4882a593Smuzhiyun return -ENXIO;
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun /**
450*4882a593Smuzhiyun * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
451*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
452*4882a593Smuzhiyun *
453*4882a593Smuzhiyun * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
454*4882a593Smuzhiyun * the @vport. This mailbox command is necessary for SLI4 port only.
455*4882a593Smuzhiyun *
456*4882a593Smuzhiyun * Return code
457*4882a593Smuzhiyun * 0 - successfully issued REG_VFI for @vport
458*4882a593Smuzhiyun * A failure code otherwise.
459*4882a593Smuzhiyun **/
460*4882a593Smuzhiyun int
lpfc_issue_reg_vfi(struct lpfc_vport * vport)461*4882a593Smuzhiyun lpfc_issue_reg_vfi(struct lpfc_vport *vport)
462*4882a593Smuzhiyun {
463*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
464*4882a593Smuzhiyun LPFC_MBOXQ_t *mboxq = NULL;
465*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
466*4882a593Smuzhiyun struct lpfc_dmabuf *dmabuf = NULL;
467*4882a593Smuzhiyun int rc = 0;
468*4882a593Smuzhiyun
469*4882a593Smuzhiyun /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
470*4882a593Smuzhiyun if ((phba->sli_rev == LPFC_SLI_REV4) &&
471*4882a593Smuzhiyun !(phba->link_flag & LS_LOOPBACK_MODE) &&
472*4882a593Smuzhiyun !(vport->fc_flag & FC_PT2PT)) {
473*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, Fabric_DID);
474*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
475*4882a593Smuzhiyun rc = -ENODEV;
476*4882a593Smuzhiyun goto fail;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
481*4882a593Smuzhiyun if (!mboxq) {
482*4882a593Smuzhiyun rc = -ENOMEM;
483*4882a593Smuzhiyun goto fail;
484*4882a593Smuzhiyun }
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
487*4882a593Smuzhiyun if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
488*4882a593Smuzhiyun dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
489*4882a593Smuzhiyun if (!dmabuf) {
490*4882a593Smuzhiyun rc = -ENOMEM;
491*4882a593Smuzhiyun goto fail;
492*4882a593Smuzhiyun }
493*4882a593Smuzhiyun dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
494*4882a593Smuzhiyun if (!dmabuf->virt) {
495*4882a593Smuzhiyun rc = -ENOMEM;
496*4882a593Smuzhiyun goto fail;
497*4882a593Smuzhiyun }
498*4882a593Smuzhiyun memcpy(dmabuf->virt, &phba->fc_fabparam,
499*4882a593Smuzhiyun sizeof(struct serv_parm));
500*4882a593Smuzhiyun }
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun vport->port_state = LPFC_FABRIC_CFG_LINK;
503*4882a593Smuzhiyun if (dmabuf)
504*4882a593Smuzhiyun lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
505*4882a593Smuzhiyun else
506*4882a593Smuzhiyun lpfc_reg_vfi(mboxq, vport, 0);
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
509*4882a593Smuzhiyun mboxq->vport = vport;
510*4882a593Smuzhiyun mboxq->ctx_buf = dmabuf;
511*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
512*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
513*4882a593Smuzhiyun rc = -ENXIO;
514*4882a593Smuzhiyun goto fail;
515*4882a593Smuzhiyun }
516*4882a593Smuzhiyun return 0;
517*4882a593Smuzhiyun
518*4882a593Smuzhiyun fail:
519*4882a593Smuzhiyun if (mboxq)
520*4882a593Smuzhiyun mempool_free(mboxq, phba->mbox_mem_pool);
521*4882a593Smuzhiyun if (dmabuf) {
522*4882a593Smuzhiyun if (dmabuf->virt)
523*4882a593Smuzhiyun lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
524*4882a593Smuzhiyun kfree(dmabuf);
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
528*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
529*4882a593Smuzhiyun "0289 Issue Register VFI failed: Err %d\n", rc);
530*4882a593Smuzhiyun return rc;
531*4882a593Smuzhiyun }
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun /**
534*4882a593Smuzhiyun * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
535*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
536*4882a593Smuzhiyun *
537*4882a593Smuzhiyun * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
538*4882a593Smuzhiyun * the @vport. This mailbox command is necessary for SLI4 port only.
539*4882a593Smuzhiyun *
540*4882a593Smuzhiyun * Return code
541*4882a593Smuzhiyun * 0 - successfully issued REG_VFI for @vport
542*4882a593Smuzhiyun * A failure code otherwise.
543*4882a593Smuzhiyun **/
544*4882a593Smuzhiyun int
lpfc_issue_unreg_vfi(struct lpfc_vport * vport)545*4882a593Smuzhiyun lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
546*4882a593Smuzhiyun {
547*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
548*4882a593Smuzhiyun struct Scsi_Host *shost;
549*4882a593Smuzhiyun LPFC_MBOXQ_t *mboxq;
550*4882a593Smuzhiyun int rc;
551*4882a593Smuzhiyun
552*4882a593Smuzhiyun mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
553*4882a593Smuzhiyun if (!mboxq) {
554*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
555*4882a593Smuzhiyun "2556 UNREG_VFI mbox allocation failed"
556*4882a593Smuzhiyun "HBA state x%x\n", phba->pport->port_state);
557*4882a593Smuzhiyun return -ENOMEM;
558*4882a593Smuzhiyun }
559*4882a593Smuzhiyun
560*4882a593Smuzhiyun lpfc_unreg_vfi(mboxq, vport);
561*4882a593Smuzhiyun mboxq->vport = vport;
562*4882a593Smuzhiyun mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
565*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
566*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
567*4882a593Smuzhiyun "2557 UNREG_VFI issue mbox failed rc x%x "
568*4882a593Smuzhiyun "HBA state x%x\n",
569*4882a593Smuzhiyun rc, phba->pport->port_state);
570*4882a593Smuzhiyun mempool_free(mboxq, phba->mbox_mem_pool);
571*4882a593Smuzhiyun return -EIO;
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun shost = lpfc_shost_from_vport(vport);
575*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
576*4882a593Smuzhiyun vport->fc_flag &= ~FC_VFI_REGISTERED;
577*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
578*4882a593Smuzhiyun return 0;
579*4882a593Smuzhiyun }
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun /**
582*4882a593Smuzhiyun * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
583*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
584*4882a593Smuzhiyun * @sp: pointer to service parameter data structure.
585*4882a593Smuzhiyun *
586*4882a593Smuzhiyun * This routine is called from FLOGI/FDISC completion handler functions.
587*4882a593Smuzhiyun * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
588*4882a593Smuzhiyun * node nodename is changed in the completion service parameter else return
589*4882a593Smuzhiyun * 0. This function also set flag in the vport data structure to delay
590*4882a593Smuzhiyun * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
591*4882a593Smuzhiyun * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
592*4882a593Smuzhiyun * node nodename is changed in the completion service parameter.
593*4882a593Smuzhiyun *
594*4882a593Smuzhiyun * Return code
595*4882a593Smuzhiyun * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
596*4882a593Smuzhiyun * 1 - FCID or Fabric Nodename or Fabric portname is changed.
597*4882a593Smuzhiyun *
598*4882a593Smuzhiyun **/
599*4882a593Smuzhiyun static uint8_t
lpfc_check_clean_addr_bit(struct lpfc_vport * vport,struct serv_parm * sp)600*4882a593Smuzhiyun lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
601*4882a593Smuzhiyun struct serv_parm *sp)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
604*4882a593Smuzhiyun uint8_t fabric_param_changed = 0;
605*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun if ((vport->fc_prevDID != vport->fc_myDID) ||
608*4882a593Smuzhiyun memcmp(&vport->fabric_portname, &sp->portName,
609*4882a593Smuzhiyun sizeof(struct lpfc_name)) ||
610*4882a593Smuzhiyun memcmp(&vport->fabric_nodename, &sp->nodeName,
611*4882a593Smuzhiyun sizeof(struct lpfc_name)) ||
612*4882a593Smuzhiyun (vport->vport_flag & FAWWPN_PARAM_CHG)) {
613*4882a593Smuzhiyun fabric_param_changed = 1;
614*4882a593Smuzhiyun vport->vport_flag &= ~FAWWPN_PARAM_CHG;
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun /*
617*4882a593Smuzhiyun * Word 1 Bit 31 in common service parameter is overloaded.
618*4882a593Smuzhiyun * Word 1 Bit 31 in FLOGI request is multiple NPort request
619*4882a593Smuzhiyun * Word 1 Bit 31 in FLOGI response is clean address bit
620*4882a593Smuzhiyun *
621*4882a593Smuzhiyun * If fabric parameter is changed and clean address bit is
622*4882a593Smuzhiyun * cleared delay nport discovery if
623*4882a593Smuzhiyun * - vport->fc_prevDID != 0 (not initial discovery) OR
624*4882a593Smuzhiyun * - lpfc_delay_discovery module parameter is set.
625*4882a593Smuzhiyun */
626*4882a593Smuzhiyun if (fabric_param_changed && !sp->cmn.clean_address_bit &&
627*4882a593Smuzhiyun (vport->fc_prevDID || phba->cfg_delay_discovery)) {
628*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
629*4882a593Smuzhiyun vport->fc_flag |= FC_DISC_DELAYED;
630*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
631*4882a593Smuzhiyun }
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun return fabric_param_changed;
634*4882a593Smuzhiyun }
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun
637*4882a593Smuzhiyun /**
638*4882a593Smuzhiyun * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
639*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
640*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
641*4882a593Smuzhiyun * @sp: pointer to service parameter data structure.
642*4882a593Smuzhiyun * @irsp: pointer to the IOCB within the lpfc response IOCB.
643*4882a593Smuzhiyun *
644*4882a593Smuzhiyun * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
645*4882a593Smuzhiyun * function to handle the completion of a Fabric Login (FLOGI) into a fabric
646*4882a593Smuzhiyun * port in a fabric topology. It properly sets up the parameters to the @ndlp
647*4882a593Smuzhiyun * from the IOCB response. It also check the newly assigned N_Port ID to the
648*4882a593Smuzhiyun * @vport against the previously assigned N_Port ID. If it is different from
649*4882a593Smuzhiyun * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
650*4882a593Smuzhiyun * is invoked on all the remaining nodes with the @vport to unregister the
651*4882a593Smuzhiyun * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
652*4882a593Smuzhiyun * is invoked to register login to the fabric.
653*4882a593Smuzhiyun *
654*4882a593Smuzhiyun * Return code
655*4882a593Smuzhiyun * 0 - Success (currently, always return 0)
656*4882a593Smuzhiyun **/
657*4882a593Smuzhiyun static int
lpfc_cmpl_els_flogi_fabric(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct serv_parm * sp,IOCB_t * irsp)658*4882a593Smuzhiyun lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
659*4882a593Smuzhiyun struct serv_parm *sp, IOCB_t *irsp)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
662*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
663*4882a593Smuzhiyun struct lpfc_nodelist *np;
664*4882a593Smuzhiyun struct lpfc_nodelist *next_np;
665*4882a593Smuzhiyun uint8_t fabric_param_changed;
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
668*4882a593Smuzhiyun vport->fc_flag |= FC_FABRIC;
669*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
672*4882a593Smuzhiyun if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
673*4882a593Smuzhiyun phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
674*4882a593Smuzhiyun
675*4882a593Smuzhiyun phba->fc_edtovResol = sp->cmn.edtovResolution;
676*4882a593Smuzhiyun phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
679*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
680*4882a593Smuzhiyun vport->fc_flag |= FC_PUBLIC_LOOP;
681*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
682*4882a593Smuzhiyun }
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
685*4882a593Smuzhiyun memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
686*4882a593Smuzhiyun memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
687*4882a593Smuzhiyun ndlp->nlp_class_sup = 0;
688*4882a593Smuzhiyun if (sp->cls1.classValid)
689*4882a593Smuzhiyun ndlp->nlp_class_sup |= FC_COS_CLASS1;
690*4882a593Smuzhiyun if (sp->cls2.classValid)
691*4882a593Smuzhiyun ndlp->nlp_class_sup |= FC_COS_CLASS2;
692*4882a593Smuzhiyun if (sp->cls3.classValid)
693*4882a593Smuzhiyun ndlp->nlp_class_sup |= FC_COS_CLASS3;
694*4882a593Smuzhiyun if (sp->cls4.classValid)
695*4882a593Smuzhiyun ndlp->nlp_class_sup |= FC_COS_CLASS4;
696*4882a593Smuzhiyun ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
697*4882a593Smuzhiyun sp->cmn.bbRcvSizeLsb;
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
700*4882a593Smuzhiyun if (fabric_param_changed) {
701*4882a593Smuzhiyun /* Reset FDMI attribute masks based on config parameter */
702*4882a593Smuzhiyun if (phba->cfg_enable_SmartSAN ||
703*4882a593Smuzhiyun (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
704*4882a593Smuzhiyun /* Setup appropriate attribute masks */
705*4882a593Smuzhiyun vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
706*4882a593Smuzhiyun if (phba->cfg_enable_SmartSAN)
707*4882a593Smuzhiyun vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
708*4882a593Smuzhiyun else
709*4882a593Smuzhiyun vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
710*4882a593Smuzhiyun } else {
711*4882a593Smuzhiyun vport->fdmi_hba_mask = 0;
712*4882a593Smuzhiyun vport->fdmi_port_mask = 0;
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun }
716*4882a593Smuzhiyun memcpy(&vport->fabric_portname, &sp->portName,
717*4882a593Smuzhiyun sizeof(struct lpfc_name));
718*4882a593Smuzhiyun memcpy(&vport->fabric_nodename, &sp->nodeName,
719*4882a593Smuzhiyun sizeof(struct lpfc_name));
720*4882a593Smuzhiyun memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
723*4882a593Smuzhiyun if (sp->cmn.response_multiple_NPort) {
724*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_WARNING,
725*4882a593Smuzhiyun LOG_ELS | LOG_VPORT,
726*4882a593Smuzhiyun "1816 FLOGI NPIV supported, "
727*4882a593Smuzhiyun "response data 0x%x\n",
728*4882a593Smuzhiyun sp->cmn.response_multiple_NPort);
729*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
730*4882a593Smuzhiyun phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
731*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
732*4882a593Smuzhiyun } else {
733*4882a593Smuzhiyun /* Because we asked f/w for NPIV it still expects us
734*4882a593Smuzhiyun to call reg_vnpid atleast for the physcial host */
735*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_WARNING,
736*4882a593Smuzhiyun LOG_ELS | LOG_VPORT,
737*4882a593Smuzhiyun "1817 Fabric does not support NPIV "
738*4882a593Smuzhiyun "- configuring single port mode.\n");
739*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
740*4882a593Smuzhiyun phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
741*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
742*4882a593Smuzhiyun }
743*4882a593Smuzhiyun }
744*4882a593Smuzhiyun
745*4882a593Smuzhiyun /*
746*4882a593Smuzhiyun * For FC we need to do some special processing because of the SLI
747*4882a593Smuzhiyun * Port's default settings of the Common Service Parameters.
748*4882a593Smuzhiyun */
749*4882a593Smuzhiyun if ((phba->sli_rev == LPFC_SLI_REV4) &&
750*4882a593Smuzhiyun (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
751*4882a593Smuzhiyun /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
752*4882a593Smuzhiyun if (fabric_param_changed)
753*4882a593Smuzhiyun lpfc_unregister_fcf_prep(phba);
754*4882a593Smuzhiyun
755*4882a593Smuzhiyun /* This should just update the VFI CSPs*/
756*4882a593Smuzhiyun if (vport->fc_flag & FC_VFI_REGISTERED)
757*4882a593Smuzhiyun lpfc_issue_reg_vfi(vport);
758*4882a593Smuzhiyun }
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun if (fabric_param_changed &&
761*4882a593Smuzhiyun !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun /* If our NportID changed, we need to ensure all
764*4882a593Smuzhiyun * remaining NPORTs get unreg_login'ed.
765*4882a593Smuzhiyun */
766*4882a593Smuzhiyun list_for_each_entry_safe(np, next_np,
767*4882a593Smuzhiyun &vport->fc_nodes, nlp_listp) {
768*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(np))
769*4882a593Smuzhiyun continue;
770*4882a593Smuzhiyun if ((np->nlp_state != NLP_STE_NPR_NODE) ||
771*4882a593Smuzhiyun !(np->nlp_flag & NLP_NPR_ADISC))
772*4882a593Smuzhiyun continue;
773*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
774*4882a593Smuzhiyun np->nlp_flag &= ~NLP_NPR_ADISC;
775*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
776*4882a593Smuzhiyun lpfc_unreg_rpi(vport, np);
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun lpfc_cleanup_pending_mbox(vport);
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4) {
781*4882a593Smuzhiyun lpfc_sli4_unreg_all_rpis(vport);
782*4882a593Smuzhiyun lpfc_mbx_unreg_vpi(vport);
783*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
784*4882a593Smuzhiyun vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
785*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun /*
789*4882a593Smuzhiyun * For SLI3 and SLI4, the VPI needs to be reregistered in
790*4882a593Smuzhiyun * response to this fabric parameter change event.
791*4882a593Smuzhiyun */
792*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
793*4882a593Smuzhiyun vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
794*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
795*4882a593Smuzhiyun } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
796*4882a593Smuzhiyun !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
797*4882a593Smuzhiyun /*
798*4882a593Smuzhiyun * Driver needs to re-reg VPI in order for f/w
799*4882a593Smuzhiyun * to update the MAC address.
800*4882a593Smuzhiyun */
801*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
802*4882a593Smuzhiyun lpfc_register_new_vport(phba, vport, ndlp);
803*4882a593Smuzhiyun return 0;
804*4882a593Smuzhiyun }
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4) {
807*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
808*4882a593Smuzhiyun if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
809*4882a593Smuzhiyun vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
810*4882a593Smuzhiyun lpfc_register_new_vport(phba, vport, ndlp);
811*4882a593Smuzhiyun else
812*4882a593Smuzhiyun lpfc_issue_fabric_reglogin(vport);
813*4882a593Smuzhiyun } else {
814*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
815*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
816*4882a593Smuzhiyun if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
817*4882a593Smuzhiyun (vport->vpi_state & LPFC_VPI_REGISTERED)) {
818*4882a593Smuzhiyun lpfc_start_fdiscs(phba);
819*4882a593Smuzhiyun lpfc_do_scr_ns_plogi(phba, vport);
820*4882a593Smuzhiyun } else if (vport->fc_flag & FC_VFI_REGISTERED)
821*4882a593Smuzhiyun lpfc_issue_init_vpi(vport);
822*4882a593Smuzhiyun else {
823*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
824*4882a593Smuzhiyun "3135 Need register VFI: (x%x/%x)\n",
825*4882a593Smuzhiyun vport->fc_prevDID, vport->fc_myDID);
826*4882a593Smuzhiyun lpfc_issue_reg_vfi(vport);
827*4882a593Smuzhiyun }
828*4882a593Smuzhiyun }
829*4882a593Smuzhiyun return 0;
830*4882a593Smuzhiyun }
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun /**
833*4882a593Smuzhiyun * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
834*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
835*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
836*4882a593Smuzhiyun * @sp: pointer to service parameter data structure.
837*4882a593Smuzhiyun *
838*4882a593Smuzhiyun * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
839*4882a593Smuzhiyun * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
840*4882a593Smuzhiyun * in a point-to-point topology. First, the @vport's N_Port Name is compared
841*4882a593Smuzhiyun * with the received N_Port Name: if the @vport's N_Port Name is greater than
842*4882a593Smuzhiyun * the received N_Port Name lexicographically, this node shall assign local
843*4882a593Smuzhiyun * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
844*4882a593Smuzhiyun * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
845*4882a593Smuzhiyun * this node shall just wait for the remote node to issue PLOGI and assign
846*4882a593Smuzhiyun * N_Port IDs.
847*4882a593Smuzhiyun *
848*4882a593Smuzhiyun * Return code
849*4882a593Smuzhiyun * 0 - Success
850*4882a593Smuzhiyun * -ENXIO - Fail
851*4882a593Smuzhiyun **/
852*4882a593Smuzhiyun static int
lpfc_cmpl_els_flogi_nport(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,struct serv_parm * sp)853*4882a593Smuzhiyun lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
854*4882a593Smuzhiyun struct serv_parm *sp)
855*4882a593Smuzhiyun {
856*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
857*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
858*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
859*4882a593Smuzhiyun int rc;
860*4882a593Smuzhiyun
861*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
862*4882a593Smuzhiyun vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
863*4882a593Smuzhiyun vport->fc_flag |= FC_PT2PT;
864*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
865*4882a593Smuzhiyun
866*4882a593Smuzhiyun /* If we are pt2pt with another NPort, force NPIV off! */
867*4882a593Smuzhiyun phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
868*4882a593Smuzhiyun
869*4882a593Smuzhiyun /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
870*4882a593Smuzhiyun if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
871*4882a593Smuzhiyun lpfc_unregister_fcf_prep(phba);
872*4882a593Smuzhiyun
873*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
874*4882a593Smuzhiyun vport->fc_flag &= ~FC_VFI_REGISTERED;
875*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
876*4882a593Smuzhiyun phba->fc_topology_changed = 0;
877*4882a593Smuzhiyun }
878*4882a593Smuzhiyun
879*4882a593Smuzhiyun rc = memcmp(&vport->fc_portname, &sp->portName,
880*4882a593Smuzhiyun sizeof(vport->fc_portname));
881*4882a593Smuzhiyun
882*4882a593Smuzhiyun if (rc >= 0) {
883*4882a593Smuzhiyun /* This side will initiate the PLOGI */
884*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
885*4882a593Smuzhiyun vport->fc_flag |= FC_PT2PT_PLOGI;
886*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
887*4882a593Smuzhiyun
888*4882a593Smuzhiyun /*
889*4882a593Smuzhiyun * N_Port ID cannot be 0, set our Id to LocalID
890*4882a593Smuzhiyun * the other side will be RemoteID.
891*4882a593Smuzhiyun */
892*4882a593Smuzhiyun
893*4882a593Smuzhiyun /* not equal */
894*4882a593Smuzhiyun if (rc)
895*4882a593Smuzhiyun vport->fc_myDID = PT2PT_LocalID;
896*4882a593Smuzhiyun
897*4882a593Smuzhiyun /* Decrement ndlp reference count indicating that ndlp can be
898*4882a593Smuzhiyun * safely released when other references to it are done.
899*4882a593Smuzhiyun */
900*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
903*4882a593Smuzhiyun if (!ndlp) {
904*4882a593Smuzhiyun /*
905*4882a593Smuzhiyun * Cannot find existing Fabric ndlp, so allocate a
906*4882a593Smuzhiyun * new one
907*4882a593Smuzhiyun */
908*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, PT2PT_RemoteID);
909*4882a593Smuzhiyun if (!ndlp)
910*4882a593Smuzhiyun goto fail;
911*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
912*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp,
913*4882a593Smuzhiyun NLP_STE_UNUSED_NODE);
914*4882a593Smuzhiyun if(!ndlp)
915*4882a593Smuzhiyun goto fail;
916*4882a593Smuzhiyun }
917*4882a593Smuzhiyun
918*4882a593Smuzhiyun memcpy(&ndlp->nlp_portname, &sp->portName,
919*4882a593Smuzhiyun sizeof(struct lpfc_name));
920*4882a593Smuzhiyun memcpy(&ndlp->nlp_nodename, &sp->nodeName,
921*4882a593Smuzhiyun sizeof(struct lpfc_name));
922*4882a593Smuzhiyun /* Set state will put ndlp onto node list if not already done */
923*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
924*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
925*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_NPR_2B_DISC;
926*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
929*4882a593Smuzhiyun if (!mbox)
930*4882a593Smuzhiyun goto fail;
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun lpfc_config_link(phba, mbox);
933*4882a593Smuzhiyun
934*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
935*4882a593Smuzhiyun mbox->vport = vport;
936*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
937*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
938*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
939*4882a593Smuzhiyun goto fail;
940*4882a593Smuzhiyun }
941*4882a593Smuzhiyun } else {
942*4882a593Smuzhiyun /* This side will wait for the PLOGI, decrement ndlp reference
943*4882a593Smuzhiyun * count indicating that ndlp can be released when other
944*4882a593Smuzhiyun * references to it are done.
945*4882a593Smuzhiyun */
946*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun /* Start discovery - this should just do CLEAR_LA */
949*4882a593Smuzhiyun lpfc_disc_start(vport);
950*4882a593Smuzhiyun }
951*4882a593Smuzhiyun
952*4882a593Smuzhiyun return 0;
953*4882a593Smuzhiyun fail:
954*4882a593Smuzhiyun return -ENXIO;
955*4882a593Smuzhiyun }
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun /**
958*4882a593Smuzhiyun * lpfc_cmpl_els_flogi - Completion callback function for flogi
959*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
960*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
961*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
962*4882a593Smuzhiyun *
963*4882a593Smuzhiyun * This routine is the top-level completion callback function for issuing
964*4882a593Smuzhiyun * a Fabric Login (FLOGI) command. If the response IOCB reported error,
965*4882a593Smuzhiyun * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
966*4882a593Smuzhiyun * retry has been made (either immediately or delayed with lpfc_els_retry()
967*4882a593Smuzhiyun * returning 1), the command IOCB will be released and function returned.
968*4882a593Smuzhiyun * If the retry attempt has been given up (possibly reach the maximum
969*4882a593Smuzhiyun * number of retries), one additional decrement of ndlp reference shall be
970*4882a593Smuzhiyun * invoked before going out after releasing the command IOCB. This will
971*4882a593Smuzhiyun * actually release the remote node (Note, lpfc_els_free_iocb() will also
972*4882a593Smuzhiyun * invoke one decrement of ndlp reference count). If no error reported in
973*4882a593Smuzhiyun * the IOCB status, the command Port ID field is used to determine whether
974*4882a593Smuzhiyun * this is a point-to-point topology or a fabric topology: if the Port ID
975*4882a593Smuzhiyun * field is assigned, it is a fabric topology; otherwise, it is a
976*4882a593Smuzhiyun * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
977*4882a593Smuzhiyun * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
978*4882a593Smuzhiyun * specific topology completion conditions.
979*4882a593Smuzhiyun **/
980*4882a593Smuzhiyun static void
lpfc_cmpl_els_flogi(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)981*4882a593Smuzhiyun lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
982*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
983*4882a593Smuzhiyun {
984*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
985*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
986*4882a593Smuzhiyun IOCB_t *irsp = &rspiocb->iocb;
987*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = cmdiocb->context1;
988*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
989*4882a593Smuzhiyun struct serv_parm *sp;
990*4882a593Smuzhiyun uint16_t fcf_index;
991*4882a593Smuzhiyun int rc;
992*4882a593Smuzhiyun
993*4882a593Smuzhiyun /* Check to see if link went down during discovery */
994*4882a593Smuzhiyun if (lpfc_els_chk_latt(vport)) {
995*4882a593Smuzhiyun /* One additional decrement on node reference count to
996*4882a593Smuzhiyun * trigger the release of the node
997*4882a593Smuzhiyun */
998*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
999*4882a593Smuzhiyun goto out;
1000*4882a593Smuzhiyun }
1001*4882a593Smuzhiyun
1002*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1003*4882a593Smuzhiyun "FLOGI cmpl: status:x%x/x%x state:x%x",
1004*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
1005*4882a593Smuzhiyun vport->port_state);
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun if (irsp->ulpStatus) {
1008*4882a593Smuzhiyun /*
1009*4882a593Smuzhiyun * In case of FIP mode, perform roundrobin FCF failover
1010*4882a593Smuzhiyun * due to new FCF discovery
1011*4882a593Smuzhiyun */
1012*4882a593Smuzhiyun if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
1013*4882a593Smuzhiyun (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1014*4882a593Smuzhiyun if (phba->link_state < LPFC_LINK_UP)
1015*4882a593Smuzhiyun goto stop_rr_fcf_flogi;
1016*4882a593Smuzhiyun if ((phba->fcoe_cvl_eventtag_attn ==
1017*4882a593Smuzhiyun phba->fcoe_cvl_eventtag) &&
1018*4882a593Smuzhiyun (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1019*4882a593Smuzhiyun ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1020*4882a593Smuzhiyun IOERR_SLI_ABORTED))
1021*4882a593Smuzhiyun goto stop_rr_fcf_flogi;
1022*4882a593Smuzhiyun else
1023*4882a593Smuzhiyun phba->fcoe_cvl_eventtag_attn =
1024*4882a593Smuzhiyun phba->fcoe_cvl_eventtag;
1025*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1026*4882a593Smuzhiyun "2611 FLOGI failed on FCF (x%x), "
1027*4882a593Smuzhiyun "status:x%x/x%x, tmo:x%x, perform "
1028*4882a593Smuzhiyun "roundrobin FCF failover\n",
1029*4882a593Smuzhiyun phba->fcf.current_rec.fcf_indx,
1030*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
1031*4882a593Smuzhiyun irsp->ulpTimeout);
1032*4882a593Smuzhiyun lpfc_sli4_set_fcf_flogi_fail(phba,
1033*4882a593Smuzhiyun phba->fcf.current_rec.fcf_indx);
1034*4882a593Smuzhiyun fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
1035*4882a593Smuzhiyun rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1036*4882a593Smuzhiyun if (rc)
1037*4882a593Smuzhiyun goto out;
1038*4882a593Smuzhiyun }
1039*4882a593Smuzhiyun
1040*4882a593Smuzhiyun stop_rr_fcf_flogi:
1041*4882a593Smuzhiyun /* FLOGI failure */
1042*4882a593Smuzhiyun if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1043*4882a593Smuzhiyun ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1044*4882a593Smuzhiyun IOERR_LOOP_OPEN_FAILURE)))
1045*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1046*4882a593Smuzhiyun "2858 FLOGI failure Status:x%x/x%x TMO"
1047*4882a593Smuzhiyun ":x%x Data x%x x%x\n",
1048*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
1049*4882a593Smuzhiyun irsp->ulpTimeout, phba->hba_flag,
1050*4882a593Smuzhiyun phba->fcf.fcf_flag);
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun /* Check for retry */
1053*4882a593Smuzhiyun if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1054*4882a593Smuzhiyun goto out;
1055*4882a593Smuzhiyun
1056*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_WARNING, LOG_TRACE_EVENT,
1057*4882a593Smuzhiyun "0150 FLOGI failure Status:x%x/x%x "
1058*4882a593Smuzhiyun "xri x%x TMO:x%x\n",
1059*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
1060*4882a593Smuzhiyun cmdiocb->sli4_xritag, irsp->ulpTimeout);
1061*4882a593Smuzhiyun
1062*4882a593Smuzhiyun /* If this is not a loop open failure, bail out */
1063*4882a593Smuzhiyun if (!(irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
1064*4882a593Smuzhiyun ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1065*4882a593Smuzhiyun IOERR_LOOP_OPEN_FAILURE)))
1066*4882a593Smuzhiyun goto flogifail;
1067*4882a593Smuzhiyun
1068*4882a593Smuzhiyun /* FLOGI failed, so there is no fabric */
1069*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
1070*4882a593Smuzhiyun vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP |
1071*4882a593Smuzhiyun FC_PT2PT_NO_NVME);
1072*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
1073*4882a593Smuzhiyun
1074*4882a593Smuzhiyun /* If private loop, then allow max outstanding els to be
1075*4882a593Smuzhiyun * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1076*4882a593Smuzhiyun * alpa map would take too long otherwise.
1077*4882a593Smuzhiyun */
1078*4882a593Smuzhiyun if (phba->alpa_map[0] == 0)
1079*4882a593Smuzhiyun vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
1080*4882a593Smuzhiyun if ((phba->sli_rev == LPFC_SLI_REV4) &&
1081*4882a593Smuzhiyun (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1082*4882a593Smuzhiyun (vport->fc_prevDID != vport->fc_myDID) ||
1083*4882a593Smuzhiyun phba->fc_topology_changed)) {
1084*4882a593Smuzhiyun if (vport->fc_flag & FC_VFI_REGISTERED) {
1085*4882a593Smuzhiyun if (phba->fc_topology_changed) {
1086*4882a593Smuzhiyun lpfc_unregister_fcf_prep(phba);
1087*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
1088*4882a593Smuzhiyun vport->fc_flag &= ~FC_VFI_REGISTERED;
1089*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
1090*4882a593Smuzhiyun phba->fc_topology_changed = 0;
1091*4882a593Smuzhiyun } else {
1092*4882a593Smuzhiyun lpfc_sli4_unreg_all_rpis(vport);
1093*4882a593Smuzhiyun }
1094*4882a593Smuzhiyun }
1095*4882a593Smuzhiyun
1096*4882a593Smuzhiyun /* Do not register VFI if the driver aborted FLOGI */
1097*4882a593Smuzhiyun if (!lpfc_error_lost_link(irsp))
1098*4882a593Smuzhiyun lpfc_issue_reg_vfi(vport);
1099*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1100*4882a593Smuzhiyun goto out;
1101*4882a593Smuzhiyun }
1102*4882a593Smuzhiyun goto flogifail;
1103*4882a593Smuzhiyun }
1104*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
1105*4882a593Smuzhiyun vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
1106*4882a593Smuzhiyun vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
1107*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
1108*4882a593Smuzhiyun
1109*4882a593Smuzhiyun /*
1110*4882a593Smuzhiyun * The FLogI succeeded. Sync the data for the CPU before
1111*4882a593Smuzhiyun * accessing it.
1112*4882a593Smuzhiyun */
1113*4882a593Smuzhiyun prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1114*4882a593Smuzhiyun if (!prsp)
1115*4882a593Smuzhiyun goto out;
1116*4882a593Smuzhiyun sp = prsp->virt + sizeof(uint32_t);
1117*4882a593Smuzhiyun
1118*4882a593Smuzhiyun /* FLOGI completes successfully */
1119*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1120*4882a593Smuzhiyun "0101 FLOGI completes successfully, I/O tag:x%x, "
1121*4882a593Smuzhiyun "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1122*4882a593Smuzhiyun cmdiocb->iotag, cmdiocb->sli4_xritag,
1123*4882a593Smuzhiyun irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1124*4882a593Smuzhiyun sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1125*4882a593Smuzhiyun vport->port_state, vport->fc_flag);
1126*4882a593Smuzhiyun
1127*4882a593Smuzhiyun if (vport->port_state == LPFC_FLOGI) {
1128*4882a593Smuzhiyun /*
1129*4882a593Smuzhiyun * If Common Service Parameters indicate Nport
1130*4882a593Smuzhiyun * we are point to point, if Fport we are Fabric.
1131*4882a593Smuzhiyun */
1132*4882a593Smuzhiyun if (sp->cmn.fPort)
1133*4882a593Smuzhiyun rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
1134*4882a593Smuzhiyun else if (!(phba->hba_flag & HBA_FCOE_MODE))
1135*4882a593Smuzhiyun rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
1136*4882a593Smuzhiyun else {
1137*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1138*4882a593Smuzhiyun "2831 FLOGI response with cleared Fabric "
1139*4882a593Smuzhiyun "bit fcf_index 0x%x "
1140*4882a593Smuzhiyun "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1141*4882a593Smuzhiyun "Fabric Name "
1142*4882a593Smuzhiyun "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1143*4882a593Smuzhiyun phba->fcf.current_rec.fcf_indx,
1144*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[0],
1145*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[1],
1146*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[2],
1147*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[3],
1148*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[4],
1149*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[5],
1150*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[6],
1151*4882a593Smuzhiyun phba->fcf.current_rec.switch_name[7],
1152*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[0],
1153*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[1],
1154*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[2],
1155*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[3],
1156*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[4],
1157*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[5],
1158*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[6],
1159*4882a593Smuzhiyun phba->fcf.current_rec.fabric_name[7]);
1160*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1161*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
1162*4882a593Smuzhiyun phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1163*4882a593Smuzhiyun phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1164*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
1165*4882a593Smuzhiyun phba->fcf.fcf_redisc_attempted = 0; /* reset */
1166*4882a593Smuzhiyun goto out;
1167*4882a593Smuzhiyun }
1168*4882a593Smuzhiyun if (!rc) {
1169*4882a593Smuzhiyun /* Mark the FCF discovery process done */
1170*4882a593Smuzhiyun if (phba->hba_flag & HBA_FIP_SUPPORT)
1171*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1172*4882a593Smuzhiyun LOG_ELS,
1173*4882a593Smuzhiyun "2769 FLOGI to FCF (x%x) "
1174*4882a593Smuzhiyun "completed successfully\n",
1175*4882a593Smuzhiyun phba->fcf.current_rec.fcf_indx);
1176*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
1177*4882a593Smuzhiyun phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1178*4882a593Smuzhiyun phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
1179*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
1180*4882a593Smuzhiyun phba->fcf.fcf_redisc_attempted = 0; /* reset */
1181*4882a593Smuzhiyun goto out;
1182*4882a593Smuzhiyun }
1183*4882a593Smuzhiyun } else if (vport->port_state > LPFC_FLOGI &&
1184*4882a593Smuzhiyun vport->fc_flag & FC_PT2PT) {
1185*4882a593Smuzhiyun /*
1186*4882a593Smuzhiyun * In a p2p topology, it is possible that discovery has
1187*4882a593Smuzhiyun * already progressed, and this completion can be ignored.
1188*4882a593Smuzhiyun * Recheck the indicated topology.
1189*4882a593Smuzhiyun */
1190*4882a593Smuzhiyun if (!sp->cmn.fPort)
1191*4882a593Smuzhiyun goto out;
1192*4882a593Smuzhiyun }
1193*4882a593Smuzhiyun
1194*4882a593Smuzhiyun flogifail:
1195*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
1196*4882a593Smuzhiyun phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1197*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
1198*4882a593Smuzhiyun
1199*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1200*4882a593Smuzhiyun
1201*4882a593Smuzhiyun if (!lpfc_error_lost_link(irsp)) {
1202*4882a593Smuzhiyun /* FLOGI failed, so just use loop map to make discovery list */
1203*4882a593Smuzhiyun lpfc_disc_list_loopmap(vport);
1204*4882a593Smuzhiyun
1205*4882a593Smuzhiyun /* Start discovery */
1206*4882a593Smuzhiyun lpfc_disc_start(vport);
1207*4882a593Smuzhiyun } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1208*4882a593Smuzhiyun (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1209*4882a593Smuzhiyun IOERR_SLI_ABORTED) &&
1210*4882a593Smuzhiyun ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1211*4882a593Smuzhiyun IOERR_SLI_DOWN))) &&
1212*4882a593Smuzhiyun (phba->link_state != LPFC_CLEAR_LA)) {
1213*4882a593Smuzhiyun /* If FLOGI failed enable link interrupt. */
1214*4882a593Smuzhiyun lpfc_issue_clear_la(phba, vport);
1215*4882a593Smuzhiyun }
1216*4882a593Smuzhiyun out:
1217*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
1218*4882a593Smuzhiyun }
1219*4882a593Smuzhiyun
1220*4882a593Smuzhiyun /**
1221*4882a593Smuzhiyun * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1222*4882a593Smuzhiyun * aborted during a link down
1223*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
1224*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
1225*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
1226*4882a593Smuzhiyun *
1227*4882a593Smuzhiyun */
1228*4882a593Smuzhiyun static void
lpfc_cmpl_els_link_down(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)1229*4882a593Smuzhiyun lpfc_cmpl_els_link_down(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1230*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
1231*4882a593Smuzhiyun {
1232*4882a593Smuzhiyun IOCB_t *irsp;
1233*4882a593Smuzhiyun uint32_t *pcmd;
1234*4882a593Smuzhiyun uint32_t cmd;
1235*4882a593Smuzhiyun
1236*4882a593Smuzhiyun pcmd = (uint32_t *)(((struct lpfc_dmabuf *)cmdiocb->context2)->virt);
1237*4882a593Smuzhiyun cmd = *pcmd;
1238*4882a593Smuzhiyun irsp = &rspiocb->iocb;
1239*4882a593Smuzhiyun
1240*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1241*4882a593Smuzhiyun "6445 ELS completes after LINK_DOWN: "
1242*4882a593Smuzhiyun " Status %x/%x cmd x%x flg x%x\n",
1243*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4], cmd,
1244*4882a593Smuzhiyun cmdiocb->iocb_flag);
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun if (cmdiocb->iocb_flag & LPFC_IO_FABRIC) {
1247*4882a593Smuzhiyun cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
1248*4882a593Smuzhiyun atomic_dec(&phba->fabric_iocb_count);
1249*4882a593Smuzhiyun }
1250*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
1251*4882a593Smuzhiyun }
1252*4882a593Smuzhiyun
1253*4882a593Smuzhiyun /**
1254*4882a593Smuzhiyun * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1255*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
1256*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
1257*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
1258*4882a593Smuzhiyun *
1259*4882a593Smuzhiyun * This routine issues a Fabric Login (FLOGI) Request ELS command
1260*4882a593Smuzhiyun * for a @vport. The initiator service parameters are put into the payload
1261*4882a593Smuzhiyun * of the FLOGI Request IOCB and the top-level callback function pointer
1262*4882a593Smuzhiyun * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1263*4882a593Smuzhiyun * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1264*4882a593Smuzhiyun * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1265*4882a593Smuzhiyun *
1266*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1267*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
1268*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
1269*4882a593Smuzhiyun * callback function to the FLOGI ELS command.
1270*4882a593Smuzhiyun *
1271*4882a593Smuzhiyun * Return code
1272*4882a593Smuzhiyun * 0 - successfully issued flogi iocb for @vport
1273*4882a593Smuzhiyun * 1 - failed to issue flogi iocb for @vport
1274*4882a593Smuzhiyun **/
1275*4882a593Smuzhiyun static int
lpfc_issue_els_flogi(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)1276*4882a593Smuzhiyun lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1277*4882a593Smuzhiyun uint8_t retry)
1278*4882a593Smuzhiyun {
1279*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
1280*4882a593Smuzhiyun struct serv_parm *sp;
1281*4882a593Smuzhiyun IOCB_t *icmd;
1282*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
1283*4882a593Smuzhiyun struct lpfc_iocbq defer_flogi_acc;
1284*4882a593Smuzhiyun uint8_t *pcmd;
1285*4882a593Smuzhiyun uint16_t cmdsize;
1286*4882a593Smuzhiyun uint32_t tmo, did;
1287*4882a593Smuzhiyun int rc;
1288*4882a593Smuzhiyun
1289*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1290*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1291*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_FLOGI);
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun if (!elsiocb)
1294*4882a593Smuzhiyun return 1;
1295*4882a593Smuzhiyun
1296*4882a593Smuzhiyun icmd = &elsiocb->iocb;
1297*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1298*4882a593Smuzhiyun
1299*4882a593Smuzhiyun /* For FLOGI request, remainder of payload is service parameters */
1300*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1301*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
1302*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1303*4882a593Smuzhiyun sp = (struct serv_parm *) pcmd;
1304*4882a593Smuzhiyun
1305*4882a593Smuzhiyun /* Setup CSPs accordingly for Fabric */
1306*4882a593Smuzhiyun sp->cmn.e_d_tov = 0;
1307*4882a593Smuzhiyun sp->cmn.w2.r_a_tov = 0;
1308*4882a593Smuzhiyun sp->cmn.virtual_fabric_support = 0;
1309*4882a593Smuzhiyun sp->cls1.classValid = 0;
1310*4882a593Smuzhiyun if (sp->cmn.fcphLow < FC_PH3)
1311*4882a593Smuzhiyun sp->cmn.fcphLow = FC_PH3;
1312*4882a593Smuzhiyun if (sp->cmn.fcphHigh < FC_PH3)
1313*4882a593Smuzhiyun sp->cmn.fcphHigh = FC_PH3;
1314*4882a593Smuzhiyun
1315*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4) {
1316*4882a593Smuzhiyun if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1317*4882a593Smuzhiyun LPFC_SLI_INTF_IF_TYPE_0) {
1318*4882a593Smuzhiyun elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1319*4882a593Smuzhiyun elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1320*4882a593Smuzhiyun /* FLOGI needs to be 3 for WQE FCFI */
1321*4882a593Smuzhiyun /* Set the fcfi to the fcfi we registered with */
1322*4882a593Smuzhiyun elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1323*4882a593Smuzhiyun }
1324*4882a593Smuzhiyun /* Can't do SLI4 class2 without support sequence coalescing */
1325*4882a593Smuzhiyun sp->cls2.classValid = 0;
1326*4882a593Smuzhiyun sp->cls2.seqDelivery = 0;
1327*4882a593Smuzhiyun } else {
1328*4882a593Smuzhiyun /* Historical, setting sequential-delivery bit for SLI3 */
1329*4882a593Smuzhiyun sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1330*4882a593Smuzhiyun sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
1331*4882a593Smuzhiyun if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1332*4882a593Smuzhiyun sp->cmn.request_multiple_Nport = 1;
1333*4882a593Smuzhiyun /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1334*4882a593Smuzhiyun icmd->ulpCt_h = 1;
1335*4882a593Smuzhiyun icmd->ulpCt_l = 0;
1336*4882a593Smuzhiyun } else
1337*4882a593Smuzhiyun sp->cmn.request_multiple_Nport = 0;
1338*4882a593Smuzhiyun }
1339*4882a593Smuzhiyun
1340*4882a593Smuzhiyun if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1341*4882a593Smuzhiyun icmd->un.elsreq64.myID = 0;
1342*4882a593Smuzhiyun icmd->un.elsreq64.fl = 1;
1343*4882a593Smuzhiyun }
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun tmo = phba->fc_ratov;
1346*4882a593Smuzhiyun phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1347*4882a593Smuzhiyun lpfc_set_disctmo(vport);
1348*4882a593Smuzhiyun phba->fc_ratov = tmo;
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun phba->fc_stat.elsXmitFLOGI++;
1351*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1352*4882a593Smuzhiyun
1353*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1354*4882a593Smuzhiyun "Issue FLOGI: opt:x%x",
1355*4882a593Smuzhiyun phba->sli3_options, 0, 0);
1356*4882a593Smuzhiyun
1357*4882a593Smuzhiyun rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1358*4882a593Smuzhiyun
1359*4882a593Smuzhiyun phba->hba_flag |= HBA_FLOGI_ISSUED;
1360*4882a593Smuzhiyun
1361*4882a593Smuzhiyun /* Check for a deferred FLOGI ACC condition */
1362*4882a593Smuzhiyun if (phba->defer_flogi_acc_flag) {
1363*4882a593Smuzhiyun did = vport->fc_myDID;
1364*4882a593Smuzhiyun vport->fc_myDID = Fabric_DID;
1365*4882a593Smuzhiyun
1366*4882a593Smuzhiyun memset(&defer_flogi_acc, 0, sizeof(struct lpfc_iocbq));
1367*4882a593Smuzhiyun
1368*4882a593Smuzhiyun defer_flogi_acc.iocb.ulpContext = phba->defer_flogi_acc_rx_id;
1369*4882a593Smuzhiyun defer_flogi_acc.iocb.unsli3.rcvsli3.ox_id =
1370*4882a593Smuzhiyun phba->defer_flogi_acc_ox_id;
1371*4882a593Smuzhiyun
1372*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1373*4882a593Smuzhiyun "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1374*4882a593Smuzhiyun " ox_id: x%x, hba_flag x%x\n",
1375*4882a593Smuzhiyun phba->defer_flogi_acc_rx_id,
1376*4882a593Smuzhiyun phba->defer_flogi_acc_ox_id, phba->hba_flag);
1377*4882a593Smuzhiyun
1378*4882a593Smuzhiyun /* Send deferred FLOGI ACC */
1379*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, &defer_flogi_acc,
1380*4882a593Smuzhiyun ndlp, NULL);
1381*4882a593Smuzhiyun
1382*4882a593Smuzhiyun phba->defer_flogi_acc_flag = false;
1383*4882a593Smuzhiyun
1384*4882a593Smuzhiyun vport->fc_myDID = did;
1385*4882a593Smuzhiyun }
1386*4882a593Smuzhiyun
1387*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
1388*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
1389*4882a593Smuzhiyun return 1;
1390*4882a593Smuzhiyun }
1391*4882a593Smuzhiyun return 0;
1392*4882a593Smuzhiyun }
1393*4882a593Smuzhiyun
1394*4882a593Smuzhiyun /**
1395*4882a593Smuzhiyun * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1396*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
1397*4882a593Smuzhiyun *
1398*4882a593Smuzhiyun * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1399*4882a593Smuzhiyun * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1400*4882a593Smuzhiyun * list and issues an abort IOCB commond on each outstanding IOCB that
1401*4882a593Smuzhiyun * contains a active Fabric_DID ndlp. Note that this function is to issue
1402*4882a593Smuzhiyun * the abort IOCB command on all the outstanding IOCBs, thus when this
1403*4882a593Smuzhiyun * function returns, it does not guarantee all the IOCBs are actually aborted.
1404*4882a593Smuzhiyun *
1405*4882a593Smuzhiyun * Return code
1406*4882a593Smuzhiyun * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1407*4882a593Smuzhiyun **/
1408*4882a593Smuzhiyun int
lpfc_els_abort_flogi(struct lpfc_hba * phba)1409*4882a593Smuzhiyun lpfc_els_abort_flogi(struct lpfc_hba *phba)
1410*4882a593Smuzhiyun {
1411*4882a593Smuzhiyun struct lpfc_sli_ring *pring;
1412*4882a593Smuzhiyun struct lpfc_iocbq *iocb, *next_iocb;
1413*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
1414*4882a593Smuzhiyun IOCB_t *icmd;
1415*4882a593Smuzhiyun
1416*4882a593Smuzhiyun /* Abort outstanding I/O on NPort <nlp_DID> */
1417*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1418*4882a593Smuzhiyun "0201 Abort outstanding I/O on NPort x%x\n",
1419*4882a593Smuzhiyun Fabric_DID);
1420*4882a593Smuzhiyun
1421*4882a593Smuzhiyun pring = lpfc_phba_elsring(phba);
1422*4882a593Smuzhiyun if (unlikely(!pring))
1423*4882a593Smuzhiyun return -EIO;
1424*4882a593Smuzhiyun
1425*4882a593Smuzhiyun /*
1426*4882a593Smuzhiyun * Check the txcmplq for an iocb that matches the nport the driver is
1427*4882a593Smuzhiyun * searching for.
1428*4882a593Smuzhiyun */
1429*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
1430*4882a593Smuzhiyun list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1431*4882a593Smuzhiyun icmd = &iocb->iocb;
1432*4882a593Smuzhiyun if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
1433*4882a593Smuzhiyun ndlp = (struct lpfc_nodelist *)(iocb->context1);
1434*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1435*4882a593Smuzhiyun (ndlp->nlp_DID == Fabric_DID))
1436*4882a593Smuzhiyun lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1437*4882a593Smuzhiyun }
1438*4882a593Smuzhiyun }
1439*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
1440*4882a593Smuzhiyun
1441*4882a593Smuzhiyun return 0;
1442*4882a593Smuzhiyun }
1443*4882a593Smuzhiyun
1444*4882a593Smuzhiyun /**
1445*4882a593Smuzhiyun * lpfc_initial_flogi - Issue an initial fabric login for a vport
1446*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
1447*4882a593Smuzhiyun *
1448*4882a593Smuzhiyun * This routine issues an initial Fabric Login (FLOGI) for the @vport
1449*4882a593Smuzhiyun * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1450*4882a593Smuzhiyun * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1451*4882a593Smuzhiyun * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1452*4882a593Smuzhiyun * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1453*4882a593Smuzhiyun * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1454*4882a593Smuzhiyun * @vport.
1455*4882a593Smuzhiyun *
1456*4882a593Smuzhiyun * Return code
1457*4882a593Smuzhiyun * 0 - failed to issue initial flogi for @vport
1458*4882a593Smuzhiyun * 1 - successfully issued initial flogi for @vport
1459*4882a593Smuzhiyun **/
1460*4882a593Smuzhiyun int
lpfc_initial_flogi(struct lpfc_vport * vport)1461*4882a593Smuzhiyun lpfc_initial_flogi(struct lpfc_vport *vport)
1462*4882a593Smuzhiyun {
1463*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
1464*4882a593Smuzhiyun
1465*4882a593Smuzhiyun vport->port_state = LPFC_FLOGI;
1466*4882a593Smuzhiyun lpfc_set_disctmo(vport);
1467*4882a593Smuzhiyun
1468*4882a593Smuzhiyun /* First look for the Fabric ndlp */
1469*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, Fabric_DID);
1470*4882a593Smuzhiyun if (!ndlp) {
1471*4882a593Smuzhiyun /* Cannot find existing Fabric ndlp, so allocate a new one */
1472*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, Fabric_DID);
1473*4882a593Smuzhiyun if (!ndlp)
1474*4882a593Smuzhiyun return 0;
1475*4882a593Smuzhiyun /* Set the node type */
1476*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
1477*4882a593Smuzhiyun /* Put ndlp onto node list */
1478*4882a593Smuzhiyun lpfc_enqueue_node(vport, ndlp);
1479*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1480*4882a593Smuzhiyun /* re-setup ndlp without removing from node list */
1481*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1482*4882a593Smuzhiyun if (!ndlp)
1483*4882a593Smuzhiyun return 0;
1484*4882a593Smuzhiyun }
1485*4882a593Smuzhiyun
1486*4882a593Smuzhiyun if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1487*4882a593Smuzhiyun /* This decrement of reference count to node shall kick off
1488*4882a593Smuzhiyun * the release of the node.
1489*4882a593Smuzhiyun */
1490*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1491*4882a593Smuzhiyun return 0;
1492*4882a593Smuzhiyun }
1493*4882a593Smuzhiyun return 1;
1494*4882a593Smuzhiyun }
1495*4882a593Smuzhiyun
1496*4882a593Smuzhiyun /**
1497*4882a593Smuzhiyun * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1498*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
1499*4882a593Smuzhiyun *
1500*4882a593Smuzhiyun * This routine issues an initial Fabric Discover (FDISC) for the @vport
1501*4882a593Smuzhiyun * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1502*4882a593Smuzhiyun * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1503*4882a593Smuzhiyun * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1504*4882a593Smuzhiyun * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1505*4882a593Smuzhiyun * is then invoked with the @vport and the ndlp to perform the FDISC for the
1506*4882a593Smuzhiyun * @vport.
1507*4882a593Smuzhiyun *
1508*4882a593Smuzhiyun * Return code
1509*4882a593Smuzhiyun * 0 - failed to issue initial fdisc for @vport
1510*4882a593Smuzhiyun * 1 - successfully issued initial fdisc for @vport
1511*4882a593Smuzhiyun **/
1512*4882a593Smuzhiyun int
lpfc_initial_fdisc(struct lpfc_vport * vport)1513*4882a593Smuzhiyun lpfc_initial_fdisc(struct lpfc_vport *vport)
1514*4882a593Smuzhiyun {
1515*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
1516*4882a593Smuzhiyun
1517*4882a593Smuzhiyun /* First look for the Fabric ndlp */
1518*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, Fabric_DID);
1519*4882a593Smuzhiyun if (!ndlp) {
1520*4882a593Smuzhiyun /* Cannot find existing Fabric ndlp, so allocate a new one */
1521*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, Fabric_DID);
1522*4882a593Smuzhiyun if (!ndlp)
1523*4882a593Smuzhiyun return 0;
1524*4882a593Smuzhiyun /* Put ndlp onto node list */
1525*4882a593Smuzhiyun lpfc_enqueue_node(vport, ndlp);
1526*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1527*4882a593Smuzhiyun /* re-setup ndlp without removing from node list */
1528*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1529*4882a593Smuzhiyun if (!ndlp)
1530*4882a593Smuzhiyun return 0;
1531*4882a593Smuzhiyun }
1532*4882a593Smuzhiyun
1533*4882a593Smuzhiyun if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1534*4882a593Smuzhiyun /* decrement node reference count to trigger the release of
1535*4882a593Smuzhiyun * the node.
1536*4882a593Smuzhiyun */
1537*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1538*4882a593Smuzhiyun return 0;
1539*4882a593Smuzhiyun }
1540*4882a593Smuzhiyun return 1;
1541*4882a593Smuzhiyun }
1542*4882a593Smuzhiyun
1543*4882a593Smuzhiyun /**
1544*4882a593Smuzhiyun * lpfc_more_plogi - Check and issue remaining plogis for a vport
1545*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
1546*4882a593Smuzhiyun *
1547*4882a593Smuzhiyun * This routine checks whether there are more remaining Port Logins
1548*4882a593Smuzhiyun * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1549*4882a593Smuzhiyun * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1550*4882a593Smuzhiyun * to issue ELS PLOGIs up to the configured discover threads with the
1551*4882a593Smuzhiyun * @vport (@vport->cfg_discovery_threads). The function also decrement
1552*4882a593Smuzhiyun * the @vport's num_disc_node by 1 if it is not already 0.
1553*4882a593Smuzhiyun **/
1554*4882a593Smuzhiyun void
lpfc_more_plogi(struct lpfc_vport * vport)1555*4882a593Smuzhiyun lpfc_more_plogi(struct lpfc_vport *vport)
1556*4882a593Smuzhiyun {
1557*4882a593Smuzhiyun if (vport->num_disc_nodes)
1558*4882a593Smuzhiyun vport->num_disc_nodes--;
1559*4882a593Smuzhiyun
1560*4882a593Smuzhiyun /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1561*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1562*4882a593Smuzhiyun "0232 Continue discovery with %d PLOGIs to go "
1563*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
1564*4882a593Smuzhiyun vport->num_disc_nodes, vport->fc_plogi_cnt,
1565*4882a593Smuzhiyun vport->fc_flag, vport->port_state);
1566*4882a593Smuzhiyun /* Check to see if there are more PLOGIs to be sent */
1567*4882a593Smuzhiyun if (vport->fc_flag & FC_NLP_MORE)
1568*4882a593Smuzhiyun /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1569*4882a593Smuzhiyun lpfc_els_disc_plogi(vport);
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun return;
1572*4882a593Smuzhiyun }
1573*4882a593Smuzhiyun
1574*4882a593Smuzhiyun /**
1575*4882a593Smuzhiyun * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1576*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
1577*4882a593Smuzhiyun * @prsp: pointer to response IOCB payload.
1578*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
1579*4882a593Smuzhiyun *
1580*4882a593Smuzhiyun * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1581*4882a593Smuzhiyun * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1582*4882a593Smuzhiyun * The following cases are considered N_Port confirmed:
1583*4882a593Smuzhiyun * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1584*4882a593Smuzhiyun * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1585*4882a593Smuzhiyun * it does not have WWPN assigned either. If the WWPN is confirmed, the
1586*4882a593Smuzhiyun * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1587*4882a593Smuzhiyun * 1) if there is a node on vport list other than the @ndlp with the same
1588*4882a593Smuzhiyun * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1589*4882a593Smuzhiyun * on that node to release the RPI associated with the node; 2) if there is
1590*4882a593Smuzhiyun * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1591*4882a593Smuzhiyun * into, a new node shall be allocated (or activated). In either case, the
1592*4882a593Smuzhiyun * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1593*4882a593Smuzhiyun * be released and the new_ndlp shall be put on to the vport node list and
1594*4882a593Smuzhiyun * its pointer returned as the confirmed node.
1595*4882a593Smuzhiyun *
1596*4882a593Smuzhiyun * Note that before the @ndlp got "released", the keepDID from not-matching
1597*4882a593Smuzhiyun * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1598*4882a593Smuzhiyun * of the @ndlp. This is because the release of @ndlp is actually to put it
1599*4882a593Smuzhiyun * into an inactive state on the vport node list and the vport node list
1600*4882a593Smuzhiyun * management algorithm does not allow two node with a same DID.
1601*4882a593Smuzhiyun *
1602*4882a593Smuzhiyun * Return code
1603*4882a593Smuzhiyun * pointer to the PLOGI N_Port @ndlp
1604*4882a593Smuzhiyun **/
1605*4882a593Smuzhiyun static struct lpfc_nodelist *
lpfc_plogi_confirm_nport(struct lpfc_hba * phba,uint32_t * prsp,struct lpfc_nodelist * ndlp)1606*4882a593Smuzhiyun lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1607*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
1608*4882a593Smuzhiyun {
1609*4882a593Smuzhiyun struct lpfc_vport *vport = ndlp->vport;
1610*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1611*4882a593Smuzhiyun struct lpfc_nodelist *new_ndlp;
1612*4882a593Smuzhiyun struct lpfc_rport_data *rdata;
1613*4882a593Smuzhiyun struct fc_rport *rport;
1614*4882a593Smuzhiyun struct serv_parm *sp;
1615*4882a593Smuzhiyun uint8_t name[sizeof(struct lpfc_name)];
1616*4882a593Smuzhiyun uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
1617*4882a593Smuzhiyun uint32_t keep_new_nlp_flag = 0;
1618*4882a593Smuzhiyun uint16_t keep_nlp_state;
1619*4882a593Smuzhiyun u32 keep_nlp_fc4_type = 0;
1620*4882a593Smuzhiyun struct lpfc_nvme_rport *keep_nrport = NULL;
1621*4882a593Smuzhiyun int put_node;
1622*4882a593Smuzhiyun int put_rport;
1623*4882a593Smuzhiyun unsigned long *active_rrqs_xri_bitmap = NULL;
1624*4882a593Smuzhiyun
1625*4882a593Smuzhiyun /* Fabric nodes can have the same WWPN so we don't bother searching
1626*4882a593Smuzhiyun * by WWPN. Just return the ndlp that was given to us.
1627*4882a593Smuzhiyun */
1628*4882a593Smuzhiyun if (ndlp->nlp_type & NLP_FABRIC)
1629*4882a593Smuzhiyun return ndlp;
1630*4882a593Smuzhiyun
1631*4882a593Smuzhiyun sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1632*4882a593Smuzhiyun memset(name, 0, sizeof(struct lpfc_name));
1633*4882a593Smuzhiyun
1634*4882a593Smuzhiyun /* Now we find out if the NPort we are logging into, matches the WWPN
1635*4882a593Smuzhiyun * we have for that ndlp. If not, we have some work to do.
1636*4882a593Smuzhiyun */
1637*4882a593Smuzhiyun new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1638*4882a593Smuzhiyun
1639*4882a593Smuzhiyun /* return immediately if the WWPN matches ndlp */
1640*4882a593Smuzhiyun if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1641*4882a593Smuzhiyun return ndlp;
1642*4882a593Smuzhiyun
1643*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4) {
1644*4882a593Smuzhiyun active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1645*4882a593Smuzhiyun GFP_KERNEL);
1646*4882a593Smuzhiyun if (active_rrqs_xri_bitmap)
1647*4882a593Smuzhiyun memset(active_rrqs_xri_bitmap, 0,
1648*4882a593Smuzhiyun phba->cfg_rrq_xri_bitmap_sz);
1649*4882a593Smuzhiyun }
1650*4882a593Smuzhiyun
1651*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1652*4882a593Smuzhiyun "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1653*4882a593Smuzhiyun "new_ndlp x%x x%x x%x\n",
1654*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_fc4_type,
1655*4882a593Smuzhiyun (new_ndlp ? new_ndlp->nlp_DID : 0),
1656*4882a593Smuzhiyun (new_ndlp ? new_ndlp->nlp_flag : 0),
1657*4882a593Smuzhiyun (new_ndlp ? new_ndlp->nlp_fc4_type : 0));
1658*4882a593Smuzhiyun
1659*4882a593Smuzhiyun if (!new_ndlp) {
1660*4882a593Smuzhiyun rc = memcmp(&ndlp->nlp_portname, name,
1661*4882a593Smuzhiyun sizeof(struct lpfc_name));
1662*4882a593Smuzhiyun if (!rc) {
1663*4882a593Smuzhiyun if (active_rrqs_xri_bitmap)
1664*4882a593Smuzhiyun mempool_free(active_rrqs_xri_bitmap,
1665*4882a593Smuzhiyun phba->active_rrq_pool);
1666*4882a593Smuzhiyun return ndlp;
1667*4882a593Smuzhiyun }
1668*4882a593Smuzhiyun new_ndlp = lpfc_nlp_init(vport, ndlp->nlp_DID);
1669*4882a593Smuzhiyun if (!new_ndlp) {
1670*4882a593Smuzhiyun if (active_rrqs_xri_bitmap)
1671*4882a593Smuzhiyun mempool_free(active_rrqs_xri_bitmap,
1672*4882a593Smuzhiyun phba->active_rrq_pool);
1673*4882a593Smuzhiyun return ndlp;
1674*4882a593Smuzhiyun }
1675*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1676*4882a593Smuzhiyun rc = memcmp(&ndlp->nlp_portname, name,
1677*4882a593Smuzhiyun sizeof(struct lpfc_name));
1678*4882a593Smuzhiyun if (!rc) {
1679*4882a593Smuzhiyun if (active_rrqs_xri_bitmap)
1680*4882a593Smuzhiyun mempool_free(active_rrqs_xri_bitmap,
1681*4882a593Smuzhiyun phba->active_rrq_pool);
1682*4882a593Smuzhiyun return ndlp;
1683*4882a593Smuzhiyun }
1684*4882a593Smuzhiyun new_ndlp = lpfc_enable_node(vport, new_ndlp,
1685*4882a593Smuzhiyun NLP_STE_UNUSED_NODE);
1686*4882a593Smuzhiyun if (!new_ndlp) {
1687*4882a593Smuzhiyun if (active_rrqs_xri_bitmap)
1688*4882a593Smuzhiyun mempool_free(active_rrqs_xri_bitmap,
1689*4882a593Smuzhiyun phba->active_rrq_pool);
1690*4882a593Smuzhiyun return ndlp;
1691*4882a593Smuzhiyun }
1692*4882a593Smuzhiyun keepDID = new_ndlp->nlp_DID;
1693*4882a593Smuzhiyun if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1694*4882a593Smuzhiyun memcpy(active_rrqs_xri_bitmap,
1695*4882a593Smuzhiyun new_ndlp->active_rrqs_xri_bitmap,
1696*4882a593Smuzhiyun phba->cfg_rrq_xri_bitmap_sz);
1697*4882a593Smuzhiyun } else {
1698*4882a593Smuzhiyun keepDID = new_ndlp->nlp_DID;
1699*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
1700*4882a593Smuzhiyun active_rrqs_xri_bitmap)
1701*4882a593Smuzhiyun memcpy(active_rrqs_xri_bitmap,
1702*4882a593Smuzhiyun new_ndlp->active_rrqs_xri_bitmap,
1703*4882a593Smuzhiyun phba->cfg_rrq_xri_bitmap_sz);
1704*4882a593Smuzhiyun }
1705*4882a593Smuzhiyun
1706*4882a593Smuzhiyun /* At this point in this routine, we know new_ndlp will be
1707*4882a593Smuzhiyun * returned. however, any previous GID_FTs that were done
1708*4882a593Smuzhiyun * would have updated nlp_fc4_type in ndlp, so we must ensure
1709*4882a593Smuzhiyun * new_ndlp has the right value.
1710*4882a593Smuzhiyun */
1711*4882a593Smuzhiyun if (vport->fc_flag & FC_FABRIC) {
1712*4882a593Smuzhiyun keep_nlp_fc4_type = new_ndlp->nlp_fc4_type;
1713*4882a593Smuzhiyun new_ndlp->nlp_fc4_type = ndlp->nlp_fc4_type;
1714*4882a593Smuzhiyun }
1715*4882a593Smuzhiyun
1716*4882a593Smuzhiyun lpfc_unreg_rpi(vport, new_ndlp);
1717*4882a593Smuzhiyun new_ndlp->nlp_DID = ndlp->nlp_DID;
1718*4882a593Smuzhiyun new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1719*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
1720*4882a593Smuzhiyun memcpy(new_ndlp->active_rrqs_xri_bitmap,
1721*4882a593Smuzhiyun ndlp->active_rrqs_xri_bitmap,
1722*4882a593Smuzhiyun phba->cfg_rrq_xri_bitmap_sz);
1723*4882a593Smuzhiyun
1724*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
1725*4882a593Smuzhiyun keep_new_nlp_flag = new_ndlp->nlp_flag;
1726*4882a593Smuzhiyun keep_nlp_flag = ndlp->nlp_flag;
1727*4882a593Smuzhiyun new_ndlp->nlp_flag = ndlp->nlp_flag;
1728*4882a593Smuzhiyun
1729*4882a593Smuzhiyun /* if new_ndlp had NLP_UNREG_INP set, keep it */
1730*4882a593Smuzhiyun if (keep_new_nlp_flag & NLP_UNREG_INP)
1731*4882a593Smuzhiyun new_ndlp->nlp_flag |= NLP_UNREG_INP;
1732*4882a593Smuzhiyun else
1733*4882a593Smuzhiyun new_ndlp->nlp_flag &= ~NLP_UNREG_INP;
1734*4882a593Smuzhiyun
1735*4882a593Smuzhiyun /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1736*4882a593Smuzhiyun if (keep_new_nlp_flag & NLP_RPI_REGISTERED)
1737*4882a593Smuzhiyun new_ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1738*4882a593Smuzhiyun else
1739*4882a593Smuzhiyun new_ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1740*4882a593Smuzhiyun
1741*4882a593Smuzhiyun ndlp->nlp_flag = keep_new_nlp_flag;
1742*4882a593Smuzhiyun
1743*4882a593Smuzhiyun /* if ndlp had NLP_UNREG_INP set, keep it */
1744*4882a593Smuzhiyun if (keep_nlp_flag & NLP_UNREG_INP)
1745*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_UNREG_INP;
1746*4882a593Smuzhiyun else
1747*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_UNREG_INP;
1748*4882a593Smuzhiyun
1749*4882a593Smuzhiyun /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1750*4882a593Smuzhiyun if (keep_nlp_flag & NLP_RPI_REGISTERED)
1751*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_RPI_REGISTERED;
1752*4882a593Smuzhiyun else
1753*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_RPI_REGISTERED;
1754*4882a593Smuzhiyun
1755*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
1756*4882a593Smuzhiyun
1757*4882a593Smuzhiyun /* Set nlp_states accordingly */
1758*4882a593Smuzhiyun keep_nlp_state = new_ndlp->nlp_state;
1759*4882a593Smuzhiyun lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1760*4882a593Smuzhiyun
1761*4882a593Smuzhiyun /* interchange the nvme remoteport structs */
1762*4882a593Smuzhiyun keep_nrport = new_ndlp->nrport;
1763*4882a593Smuzhiyun new_ndlp->nrport = ndlp->nrport;
1764*4882a593Smuzhiyun
1765*4882a593Smuzhiyun /* Move this back to NPR state */
1766*4882a593Smuzhiyun if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1767*4882a593Smuzhiyun /* The new_ndlp is replacing ndlp totally, so we need
1768*4882a593Smuzhiyun * to put ndlp on UNUSED list and try to free it.
1769*4882a593Smuzhiyun */
1770*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1771*4882a593Smuzhiyun "3179 PLOGI confirm NEW: %x %x\n",
1772*4882a593Smuzhiyun new_ndlp->nlp_DID, keepDID);
1773*4882a593Smuzhiyun
1774*4882a593Smuzhiyun /* Fix up the rport accordingly */
1775*4882a593Smuzhiyun rport = ndlp->rport;
1776*4882a593Smuzhiyun if (rport) {
1777*4882a593Smuzhiyun rdata = rport->dd_data;
1778*4882a593Smuzhiyun if (rdata->pnode == ndlp) {
1779*4882a593Smuzhiyun /* break the link before dropping the ref */
1780*4882a593Smuzhiyun ndlp->rport = NULL;
1781*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1782*4882a593Smuzhiyun rdata->pnode = lpfc_nlp_get(new_ndlp);
1783*4882a593Smuzhiyun new_ndlp->rport = rport;
1784*4882a593Smuzhiyun }
1785*4882a593Smuzhiyun new_ndlp->nlp_type = ndlp->nlp_type;
1786*4882a593Smuzhiyun }
1787*4882a593Smuzhiyun
1788*4882a593Smuzhiyun /* Fix up the nvme rport */
1789*4882a593Smuzhiyun if (ndlp->nrport) {
1790*4882a593Smuzhiyun ndlp->nrport = NULL;
1791*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1792*4882a593Smuzhiyun }
1793*4882a593Smuzhiyun
1794*4882a593Smuzhiyun /* We shall actually free the ndlp with both nlp_DID and
1795*4882a593Smuzhiyun * nlp_portname fields equals 0 to avoid any ndlp on the
1796*4882a593Smuzhiyun * nodelist never to be used.
1797*4882a593Smuzhiyun */
1798*4882a593Smuzhiyun if (ndlp->nlp_DID == 0) {
1799*4882a593Smuzhiyun spin_lock_irq(&phba->ndlp_lock);
1800*4882a593Smuzhiyun NLP_SET_FREE_REQ(ndlp);
1801*4882a593Smuzhiyun spin_unlock_irq(&phba->ndlp_lock);
1802*4882a593Smuzhiyun }
1803*4882a593Smuzhiyun
1804*4882a593Smuzhiyun /* Two ndlps cannot have the same did on the nodelist.
1805*4882a593Smuzhiyun * Note: for this case, ndlp has a NULL WWPN so setting
1806*4882a593Smuzhiyun * the nlp_fc4_type isn't required.
1807*4882a593Smuzhiyun */
1808*4882a593Smuzhiyun ndlp->nlp_DID = keepDID;
1809*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1810*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
1811*4882a593Smuzhiyun active_rrqs_xri_bitmap)
1812*4882a593Smuzhiyun memcpy(ndlp->active_rrqs_xri_bitmap,
1813*4882a593Smuzhiyun active_rrqs_xri_bitmap,
1814*4882a593Smuzhiyun phba->cfg_rrq_xri_bitmap_sz);
1815*4882a593Smuzhiyun
1816*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp))
1817*4882a593Smuzhiyun lpfc_drop_node(vport, ndlp);
1818*4882a593Smuzhiyun }
1819*4882a593Smuzhiyun else {
1820*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1821*4882a593Smuzhiyun "3180 PLOGI confirm SWAP: %x %x\n",
1822*4882a593Smuzhiyun new_ndlp->nlp_DID, keepDID);
1823*4882a593Smuzhiyun
1824*4882a593Smuzhiyun lpfc_unreg_rpi(vport, ndlp);
1825*4882a593Smuzhiyun
1826*4882a593Smuzhiyun /* Two ndlps cannot have the same did and the fc4
1827*4882a593Smuzhiyun * type must be transferred because the ndlp is in
1828*4882a593Smuzhiyun * flight.
1829*4882a593Smuzhiyun */
1830*4882a593Smuzhiyun ndlp->nlp_DID = keepDID;
1831*4882a593Smuzhiyun ndlp->nlp_fc4_type = keep_nlp_fc4_type;
1832*4882a593Smuzhiyun
1833*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
1834*4882a593Smuzhiyun active_rrqs_xri_bitmap)
1835*4882a593Smuzhiyun memcpy(ndlp->active_rrqs_xri_bitmap,
1836*4882a593Smuzhiyun active_rrqs_xri_bitmap,
1837*4882a593Smuzhiyun phba->cfg_rrq_xri_bitmap_sz);
1838*4882a593Smuzhiyun
1839*4882a593Smuzhiyun /* Since we are switching over to the new_ndlp,
1840*4882a593Smuzhiyun * reset the old ndlp state
1841*4882a593Smuzhiyun */
1842*4882a593Smuzhiyun if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1843*4882a593Smuzhiyun (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1844*4882a593Smuzhiyun keep_nlp_state = NLP_STE_NPR_NODE;
1845*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
1846*4882a593Smuzhiyun
1847*4882a593Smuzhiyun /* Previous ndlp no longer active with nvme host transport.
1848*4882a593Smuzhiyun * Remove reference from earlier registration unless the
1849*4882a593Smuzhiyun * nvme host took care of it.
1850*4882a593Smuzhiyun */
1851*4882a593Smuzhiyun if (ndlp->nrport)
1852*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1853*4882a593Smuzhiyun ndlp->nrport = keep_nrport;
1854*4882a593Smuzhiyun
1855*4882a593Smuzhiyun /* Fix up the rport accordingly */
1856*4882a593Smuzhiyun rport = ndlp->rport;
1857*4882a593Smuzhiyun if (rport) {
1858*4882a593Smuzhiyun rdata = rport->dd_data;
1859*4882a593Smuzhiyun put_node = rdata->pnode != NULL;
1860*4882a593Smuzhiyun put_rport = ndlp->rport != NULL;
1861*4882a593Smuzhiyun rdata->pnode = NULL;
1862*4882a593Smuzhiyun ndlp->rport = NULL;
1863*4882a593Smuzhiyun if (put_node)
1864*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
1865*4882a593Smuzhiyun if (put_rport)
1866*4882a593Smuzhiyun put_device(&rport->dev);
1867*4882a593Smuzhiyun }
1868*4882a593Smuzhiyun }
1869*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
1870*4882a593Smuzhiyun active_rrqs_xri_bitmap)
1871*4882a593Smuzhiyun mempool_free(active_rrqs_xri_bitmap,
1872*4882a593Smuzhiyun phba->active_rrq_pool);
1873*4882a593Smuzhiyun
1874*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS | LOG_NODE,
1875*4882a593Smuzhiyun "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1876*4882a593Smuzhiyun new_ndlp->nlp_DID, new_ndlp->nlp_flag,
1877*4882a593Smuzhiyun new_ndlp->nlp_fc4_type);
1878*4882a593Smuzhiyun
1879*4882a593Smuzhiyun return new_ndlp;
1880*4882a593Smuzhiyun }
1881*4882a593Smuzhiyun
1882*4882a593Smuzhiyun /**
1883*4882a593Smuzhiyun * lpfc_end_rscn - Check and handle more rscn for a vport
1884*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
1885*4882a593Smuzhiyun *
1886*4882a593Smuzhiyun * This routine checks whether more Registration State Change
1887*4882a593Smuzhiyun * Notifications (RSCNs) came in while the discovery state machine was in
1888*4882a593Smuzhiyun * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1889*4882a593Smuzhiyun * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1890*4882a593Smuzhiyun * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1891*4882a593Smuzhiyun * handling the RSCNs.
1892*4882a593Smuzhiyun **/
1893*4882a593Smuzhiyun void
lpfc_end_rscn(struct lpfc_vport * vport)1894*4882a593Smuzhiyun lpfc_end_rscn(struct lpfc_vport *vport)
1895*4882a593Smuzhiyun {
1896*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1897*4882a593Smuzhiyun
1898*4882a593Smuzhiyun if (vport->fc_flag & FC_RSCN_MODE) {
1899*4882a593Smuzhiyun /*
1900*4882a593Smuzhiyun * Check to see if more RSCNs came in while we were
1901*4882a593Smuzhiyun * processing this one.
1902*4882a593Smuzhiyun */
1903*4882a593Smuzhiyun if (vport->fc_rscn_id_cnt ||
1904*4882a593Smuzhiyun (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1905*4882a593Smuzhiyun lpfc_els_handle_rscn(vport);
1906*4882a593Smuzhiyun else {
1907*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
1908*4882a593Smuzhiyun vport->fc_flag &= ~FC_RSCN_MODE;
1909*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
1910*4882a593Smuzhiyun }
1911*4882a593Smuzhiyun }
1912*4882a593Smuzhiyun }
1913*4882a593Smuzhiyun
1914*4882a593Smuzhiyun /**
1915*4882a593Smuzhiyun * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1916*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
1917*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
1918*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
1919*4882a593Smuzhiyun *
1920*4882a593Smuzhiyun * This routine will call the clear rrq function to free the rrq and
1921*4882a593Smuzhiyun * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1922*4882a593Smuzhiyun * exist then the clear_rrq is still called because the rrq needs to
1923*4882a593Smuzhiyun * be freed.
1924*4882a593Smuzhiyun **/
1925*4882a593Smuzhiyun
1926*4882a593Smuzhiyun static void
lpfc_cmpl_els_rrq(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)1927*4882a593Smuzhiyun lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1928*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
1929*4882a593Smuzhiyun {
1930*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
1931*4882a593Smuzhiyun IOCB_t *irsp;
1932*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
1933*4882a593Smuzhiyun struct lpfc_node_rrq *rrq;
1934*4882a593Smuzhiyun
1935*4882a593Smuzhiyun /* we pass cmdiocb to state machine which needs rspiocb as well */
1936*4882a593Smuzhiyun rrq = cmdiocb->context_un.rrq;
1937*4882a593Smuzhiyun cmdiocb->context_un.rsp_iocb = rspiocb;
1938*4882a593Smuzhiyun
1939*4882a593Smuzhiyun irsp = &rspiocb->iocb;
1940*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1941*4882a593Smuzhiyun "RRQ cmpl: status:x%x/x%x did:x%x",
1942*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
1943*4882a593Smuzhiyun irsp->un.elsreq64.remoteID);
1944*4882a593Smuzhiyun
1945*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1946*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1947*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1948*4882a593Smuzhiyun "2882 RRQ completes to NPort x%x "
1949*4882a593Smuzhiyun "with no ndlp. Data: x%x x%x x%x\n",
1950*4882a593Smuzhiyun irsp->un.elsreq64.remoteID,
1951*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
1952*4882a593Smuzhiyun irsp->ulpIoTag);
1953*4882a593Smuzhiyun goto out;
1954*4882a593Smuzhiyun }
1955*4882a593Smuzhiyun
1956*4882a593Smuzhiyun /* rrq completes to NPort <nlp_DID> */
1957*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1958*4882a593Smuzhiyun "2880 RRQ completes to NPort x%x "
1959*4882a593Smuzhiyun "Data: x%x x%x x%x x%x x%x\n",
1960*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1961*4882a593Smuzhiyun irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1962*4882a593Smuzhiyun
1963*4882a593Smuzhiyun if (irsp->ulpStatus) {
1964*4882a593Smuzhiyun /* Check for retry */
1965*4882a593Smuzhiyun /* RRQ failed Don't print the vport to vport rjts */
1966*4882a593Smuzhiyun if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1967*4882a593Smuzhiyun (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1968*4882a593Smuzhiyun ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1969*4882a593Smuzhiyun (phba)->pport->cfg_log_verbose & LOG_ELS)
1970*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
1971*4882a593Smuzhiyun "2881 RRQ failure DID:%06X Status:"
1972*4882a593Smuzhiyun "x%x/x%x\n",
1973*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus,
1974*4882a593Smuzhiyun irsp->un.ulpWord[4]);
1975*4882a593Smuzhiyun }
1976*4882a593Smuzhiyun out:
1977*4882a593Smuzhiyun if (rrq)
1978*4882a593Smuzhiyun lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1979*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
1980*4882a593Smuzhiyun return;
1981*4882a593Smuzhiyun }
1982*4882a593Smuzhiyun /**
1983*4882a593Smuzhiyun * lpfc_cmpl_els_plogi - Completion callback function for plogi
1984*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
1985*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
1986*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
1987*4882a593Smuzhiyun *
1988*4882a593Smuzhiyun * This routine is the completion callback function for issuing the Port
1989*4882a593Smuzhiyun * Login (PLOGI) command. For PLOGI completion, there must be an active
1990*4882a593Smuzhiyun * ndlp on the vport node list that matches the remote node ID from the
1991*4882a593Smuzhiyun * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1992*4882a593Smuzhiyun * ignored and command IOCB released. The PLOGI response IOCB status is
1993*4882a593Smuzhiyun * checked for error conditons. If there is error status reported, PLOGI
1994*4882a593Smuzhiyun * retry shall be attempted by invoking the lpfc_els_retry() routine.
1995*4882a593Smuzhiyun * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1996*4882a593Smuzhiyun * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1997*4882a593Smuzhiyun * (DSM) is set for this PLOGI completion. Finally, it checks whether
1998*4882a593Smuzhiyun * there are additional N_Port nodes with the vport that need to perform
1999*4882a593Smuzhiyun * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
2000*4882a593Smuzhiyun * PLOGIs.
2001*4882a593Smuzhiyun **/
2002*4882a593Smuzhiyun static void
lpfc_cmpl_els_plogi(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2003*4882a593Smuzhiyun lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2004*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
2005*4882a593Smuzhiyun {
2006*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
2007*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2008*4882a593Smuzhiyun IOCB_t *irsp;
2009*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
2010*4882a593Smuzhiyun struct lpfc_dmabuf *prsp;
2011*4882a593Smuzhiyun int disc;
2012*4882a593Smuzhiyun
2013*4882a593Smuzhiyun /* we pass cmdiocb to state machine which needs rspiocb as well */
2014*4882a593Smuzhiyun cmdiocb->context_un.rsp_iocb = rspiocb;
2015*4882a593Smuzhiyun
2016*4882a593Smuzhiyun irsp = &rspiocb->iocb;
2017*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2018*4882a593Smuzhiyun "PLOGI cmpl: status:x%x/x%x did:x%x",
2019*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
2020*4882a593Smuzhiyun irsp->un.elsreq64.remoteID);
2021*4882a593Smuzhiyun
2022*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
2023*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
2024*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2025*4882a593Smuzhiyun "0136 PLOGI completes to NPort x%x "
2026*4882a593Smuzhiyun "with no ndlp. Data: x%x x%x x%x\n",
2027*4882a593Smuzhiyun irsp->un.elsreq64.remoteID,
2028*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
2029*4882a593Smuzhiyun irsp->ulpIoTag);
2030*4882a593Smuzhiyun goto out;
2031*4882a593Smuzhiyun }
2032*4882a593Smuzhiyun
2033*4882a593Smuzhiyun /* Since ndlp can be freed in the disc state machine, note if this node
2034*4882a593Smuzhiyun * is being used during discovery.
2035*4882a593Smuzhiyun */
2036*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2037*4882a593Smuzhiyun disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2038*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2039*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2040*4882a593Smuzhiyun
2041*4882a593Smuzhiyun /* PLOGI completes to NPort <nlp_DID> */
2042*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2043*4882a593Smuzhiyun "0102 PLOGI completes to NPort x%06x "
2044*4882a593Smuzhiyun "Data: x%x x%x x%x x%x x%x\n",
2045*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_fc4_type,
2046*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
2047*4882a593Smuzhiyun disc, vport->num_disc_nodes);
2048*4882a593Smuzhiyun
2049*4882a593Smuzhiyun /* Check to see if link went down during discovery */
2050*4882a593Smuzhiyun if (lpfc_els_chk_latt(vport)) {
2051*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2052*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2053*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2054*4882a593Smuzhiyun goto out;
2055*4882a593Smuzhiyun }
2056*4882a593Smuzhiyun
2057*4882a593Smuzhiyun if (irsp->ulpStatus) {
2058*4882a593Smuzhiyun /* Check for retry */
2059*4882a593Smuzhiyun if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2060*4882a593Smuzhiyun /* ELS command is being retried */
2061*4882a593Smuzhiyun if (disc) {
2062*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2063*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2064*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2065*4882a593Smuzhiyun }
2066*4882a593Smuzhiyun goto out;
2067*4882a593Smuzhiyun }
2068*4882a593Smuzhiyun /* PLOGI failed Don't print the vport to vport rjts */
2069*4882a593Smuzhiyun if (irsp->ulpStatus != IOSTAT_LS_RJT ||
2070*4882a593Smuzhiyun (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
2071*4882a593Smuzhiyun ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
2072*4882a593Smuzhiyun (phba)->pport->cfg_log_verbose & LOG_ELS)
2073*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2074*4882a593Smuzhiyun "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
2075*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus,
2076*4882a593Smuzhiyun irsp->un.ulpWord[4]);
2077*4882a593Smuzhiyun /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2078*4882a593Smuzhiyun if (!lpfc_error_lost_link(irsp))
2079*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2080*4882a593Smuzhiyun NLP_EVT_CMPL_PLOGI);
2081*4882a593Smuzhiyun } else {
2082*4882a593Smuzhiyun /* Good status, call state machine */
2083*4882a593Smuzhiyun prsp = list_entry(((struct lpfc_dmabuf *)
2084*4882a593Smuzhiyun cmdiocb->context2)->list.next,
2085*4882a593Smuzhiyun struct lpfc_dmabuf, list);
2086*4882a593Smuzhiyun ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
2087*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2088*4882a593Smuzhiyun NLP_EVT_CMPL_PLOGI);
2089*4882a593Smuzhiyun }
2090*4882a593Smuzhiyun
2091*4882a593Smuzhiyun if (disc && vport->num_disc_nodes) {
2092*4882a593Smuzhiyun /* Check to see if there are more PLOGIs to be sent */
2093*4882a593Smuzhiyun lpfc_more_plogi(vport);
2094*4882a593Smuzhiyun
2095*4882a593Smuzhiyun if (vport->num_disc_nodes == 0) {
2096*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2097*4882a593Smuzhiyun vport->fc_flag &= ~FC_NDISC_ACTIVE;
2098*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2099*4882a593Smuzhiyun
2100*4882a593Smuzhiyun lpfc_can_disctmo(vport);
2101*4882a593Smuzhiyun lpfc_end_rscn(vport);
2102*4882a593Smuzhiyun }
2103*4882a593Smuzhiyun }
2104*4882a593Smuzhiyun
2105*4882a593Smuzhiyun out:
2106*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
2107*4882a593Smuzhiyun return;
2108*4882a593Smuzhiyun }
2109*4882a593Smuzhiyun
2110*4882a593Smuzhiyun /**
2111*4882a593Smuzhiyun * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2112*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
2113*4882a593Smuzhiyun * @did: destination port identifier.
2114*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
2115*4882a593Smuzhiyun *
2116*4882a593Smuzhiyun * This routine issues a Port Login (PLOGI) command to a remote N_Port
2117*4882a593Smuzhiyun * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2118*4882a593Smuzhiyun * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2119*4882a593Smuzhiyun * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2120*4882a593Smuzhiyun * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2121*4882a593Smuzhiyun *
2122*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2123*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
2124*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
2125*4882a593Smuzhiyun * callback function to the PLOGI ELS command.
2126*4882a593Smuzhiyun *
2127*4882a593Smuzhiyun * Return code
2128*4882a593Smuzhiyun * 0 - Successfully issued a plogi for @vport
2129*4882a593Smuzhiyun * 1 - failed to issue a plogi for @vport
2130*4882a593Smuzhiyun **/
2131*4882a593Smuzhiyun int
lpfc_issue_els_plogi(struct lpfc_vport * vport,uint32_t did,uint8_t retry)2132*4882a593Smuzhiyun lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
2133*4882a593Smuzhiyun {
2134*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
2135*4882a593Smuzhiyun struct Scsi_Host *shost;
2136*4882a593Smuzhiyun struct serv_parm *sp;
2137*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
2138*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
2139*4882a593Smuzhiyun uint8_t *pcmd;
2140*4882a593Smuzhiyun uint16_t cmdsize;
2141*4882a593Smuzhiyun int ret;
2142*4882a593Smuzhiyun
2143*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, did);
2144*4882a593Smuzhiyun
2145*4882a593Smuzhiyun if (ndlp) {
2146*4882a593Smuzhiyun /* Defer the processing of the issue PLOGI until after the
2147*4882a593Smuzhiyun * outstanding UNREG_RPI mbox command completes, unless we
2148*4882a593Smuzhiyun * are going offline. This logic does not apply for Fabric DIDs
2149*4882a593Smuzhiyun */
2150*4882a593Smuzhiyun if ((ndlp->nlp_flag & NLP_UNREG_INP) &&
2151*4882a593Smuzhiyun ((ndlp->nlp_DID & Fabric_DID_MASK) != Fabric_DID_MASK) &&
2152*4882a593Smuzhiyun !(vport->fc_flag & FC_OFFLINE_MODE)) {
2153*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2154*4882a593Smuzhiyun "4110 Issue PLOGI x%x deferred "
2155*4882a593Smuzhiyun "on NPort x%x rpi x%x Data: x%px\n",
2156*4882a593Smuzhiyun ndlp->nlp_defer_did, ndlp->nlp_DID,
2157*4882a593Smuzhiyun ndlp->nlp_rpi, ndlp);
2158*4882a593Smuzhiyun
2159*4882a593Smuzhiyun /* We can only defer 1st PLOGI */
2160*4882a593Smuzhiyun if (ndlp->nlp_defer_did == NLP_EVT_NOTHING_PENDING)
2161*4882a593Smuzhiyun ndlp->nlp_defer_did = did;
2162*4882a593Smuzhiyun return 0;
2163*4882a593Smuzhiyun }
2164*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp))
2165*4882a593Smuzhiyun ndlp = NULL;
2166*4882a593Smuzhiyun }
2167*4882a593Smuzhiyun
2168*4882a593Smuzhiyun /* If ndlp is not NULL, we will bump the reference count on it */
2169*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
2170*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
2171*4882a593Smuzhiyun ELS_CMD_PLOGI);
2172*4882a593Smuzhiyun if (!elsiocb)
2173*4882a593Smuzhiyun return 1;
2174*4882a593Smuzhiyun
2175*4882a593Smuzhiyun shost = lpfc_shost_from_vport(vport);
2176*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2177*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_FCP_PRLI_RJT;
2178*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2179*4882a593Smuzhiyun
2180*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2181*4882a593Smuzhiyun
2182*4882a593Smuzhiyun /* For PLOGI request, remainder of payload is service parameters */
2183*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
2184*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
2185*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2186*4882a593Smuzhiyun sp = (struct serv_parm *) pcmd;
2187*4882a593Smuzhiyun
2188*4882a593Smuzhiyun /*
2189*4882a593Smuzhiyun * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2190*4882a593Smuzhiyun * to device on remote loops work.
2191*4882a593Smuzhiyun */
2192*4882a593Smuzhiyun if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
2193*4882a593Smuzhiyun sp->cmn.altBbCredit = 1;
2194*4882a593Smuzhiyun
2195*4882a593Smuzhiyun if (sp->cmn.fcphLow < FC_PH_4_3)
2196*4882a593Smuzhiyun sp->cmn.fcphLow = FC_PH_4_3;
2197*4882a593Smuzhiyun
2198*4882a593Smuzhiyun if (sp->cmn.fcphHigh < FC_PH3)
2199*4882a593Smuzhiyun sp->cmn.fcphHigh = FC_PH3;
2200*4882a593Smuzhiyun
2201*4882a593Smuzhiyun sp->cmn.valid_vendor_ver_level = 0;
2202*4882a593Smuzhiyun memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
2203*4882a593Smuzhiyun sp->cmn.bbRcvSizeMsb &= 0xF;
2204*4882a593Smuzhiyun
2205*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2206*4882a593Smuzhiyun "Issue PLOGI: did:x%x",
2207*4882a593Smuzhiyun did, 0, 0);
2208*4882a593Smuzhiyun
2209*4882a593Smuzhiyun /* If our firmware supports this feature, convey that
2210*4882a593Smuzhiyun * information to the target using the vendor specific field.
2211*4882a593Smuzhiyun */
2212*4882a593Smuzhiyun if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
2213*4882a593Smuzhiyun sp->cmn.valid_vendor_ver_level = 1;
2214*4882a593Smuzhiyun sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
2215*4882a593Smuzhiyun sp->un.vv.flags = cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
2216*4882a593Smuzhiyun }
2217*4882a593Smuzhiyun
2218*4882a593Smuzhiyun phba->fc_stat.elsXmitPLOGI++;
2219*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
2220*4882a593Smuzhiyun ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2221*4882a593Smuzhiyun
2222*4882a593Smuzhiyun if (ret == IOCB_ERROR) {
2223*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
2224*4882a593Smuzhiyun return 1;
2225*4882a593Smuzhiyun }
2226*4882a593Smuzhiyun return 0;
2227*4882a593Smuzhiyun }
2228*4882a593Smuzhiyun
2229*4882a593Smuzhiyun /**
2230*4882a593Smuzhiyun * lpfc_cmpl_els_prli - Completion callback function for prli
2231*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
2232*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
2233*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
2234*4882a593Smuzhiyun *
2235*4882a593Smuzhiyun * This routine is the completion callback function for a Process Login
2236*4882a593Smuzhiyun * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2237*4882a593Smuzhiyun * status. If there is error status reported, PRLI retry shall be attempted
2238*4882a593Smuzhiyun * by invoking the lpfc_els_retry() routine. Otherwise, the state
2239*4882a593Smuzhiyun * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2240*4882a593Smuzhiyun * ndlp to mark the PRLI completion.
2241*4882a593Smuzhiyun **/
2242*4882a593Smuzhiyun static void
lpfc_cmpl_els_prli(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2243*4882a593Smuzhiyun lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2244*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
2245*4882a593Smuzhiyun {
2246*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
2247*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2248*4882a593Smuzhiyun IOCB_t *irsp;
2249*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
2250*4882a593Smuzhiyun char *mode;
2251*4882a593Smuzhiyun u32 loglevel;
2252*4882a593Smuzhiyun
2253*4882a593Smuzhiyun /* we pass cmdiocb to state machine which needs rspiocb as well */
2254*4882a593Smuzhiyun cmdiocb->context_un.rsp_iocb = rspiocb;
2255*4882a593Smuzhiyun
2256*4882a593Smuzhiyun irsp = &(rspiocb->iocb);
2257*4882a593Smuzhiyun ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2258*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2259*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_PRLI_SND;
2260*4882a593Smuzhiyun
2261*4882a593Smuzhiyun /* Driver supports multiple FC4 types. Counters matter. */
2262*4882a593Smuzhiyun vport->fc_prli_sent--;
2263*4882a593Smuzhiyun ndlp->fc4_prli_sent--;
2264*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2265*4882a593Smuzhiyun
2266*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2267*4882a593Smuzhiyun "PRLI cmpl: status:x%x/x%x did:x%x",
2268*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
2269*4882a593Smuzhiyun ndlp->nlp_DID);
2270*4882a593Smuzhiyun
2271*4882a593Smuzhiyun /* PRLI completes to NPort <nlp_DID> */
2272*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2273*4882a593Smuzhiyun "0103 PRLI completes to NPort x%06x "
2274*4882a593Smuzhiyun "Data: x%x x%x x%x x%x\n",
2275*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2276*4882a593Smuzhiyun vport->num_disc_nodes, ndlp->fc4_prli_sent);
2277*4882a593Smuzhiyun
2278*4882a593Smuzhiyun /* Check to see if link went down during discovery */
2279*4882a593Smuzhiyun if (lpfc_els_chk_latt(vport))
2280*4882a593Smuzhiyun goto out;
2281*4882a593Smuzhiyun
2282*4882a593Smuzhiyun if (irsp->ulpStatus) {
2283*4882a593Smuzhiyun /* Check for retry */
2284*4882a593Smuzhiyun if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2285*4882a593Smuzhiyun /* ELS command is being retried */
2286*4882a593Smuzhiyun goto out;
2287*4882a593Smuzhiyun }
2288*4882a593Smuzhiyun
2289*4882a593Smuzhiyun /* If we don't send GFT_ID to Fabric, a PRLI error
2290*4882a593Smuzhiyun * could be expected.
2291*4882a593Smuzhiyun */
2292*4882a593Smuzhiyun if ((vport->fc_flag & FC_FABRIC) ||
2293*4882a593Smuzhiyun (vport->cfg_enable_fc4_type != LPFC_ENABLE_BOTH)) {
2294*4882a593Smuzhiyun mode = KERN_ERR;
2295*4882a593Smuzhiyun loglevel = LOG_TRACE_EVENT;
2296*4882a593Smuzhiyun } else {
2297*4882a593Smuzhiyun mode = KERN_INFO;
2298*4882a593Smuzhiyun loglevel = LOG_ELS;
2299*4882a593Smuzhiyun }
2300*4882a593Smuzhiyun
2301*4882a593Smuzhiyun /* PRLI failed */
2302*4882a593Smuzhiyun lpfc_printf_vlog(vport, mode, loglevel,
2303*4882a593Smuzhiyun "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2304*4882a593Smuzhiyun "data: x%x\n",
2305*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus,
2306*4882a593Smuzhiyun irsp->un.ulpWord[4], ndlp->fc4_prli_sent);
2307*4882a593Smuzhiyun
2308*4882a593Smuzhiyun /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2309*4882a593Smuzhiyun if (lpfc_error_lost_link(irsp))
2310*4882a593Smuzhiyun goto out;
2311*4882a593Smuzhiyun else
2312*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2313*4882a593Smuzhiyun NLP_EVT_CMPL_PRLI);
2314*4882a593Smuzhiyun } else {
2315*4882a593Smuzhiyun /* Good status, call state machine. However, if another
2316*4882a593Smuzhiyun * PRLI is outstanding, don't call the state machine
2317*4882a593Smuzhiyun * because final disposition to Mapped or Unmapped is
2318*4882a593Smuzhiyun * completed there.
2319*4882a593Smuzhiyun */
2320*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2321*4882a593Smuzhiyun NLP_EVT_CMPL_PRLI);
2322*4882a593Smuzhiyun }
2323*4882a593Smuzhiyun
2324*4882a593Smuzhiyun out:
2325*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
2326*4882a593Smuzhiyun return;
2327*4882a593Smuzhiyun }
2328*4882a593Smuzhiyun
2329*4882a593Smuzhiyun /**
2330*4882a593Smuzhiyun * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2331*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
2332*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
2333*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
2334*4882a593Smuzhiyun *
2335*4882a593Smuzhiyun * This routine issues a Process Login (PRLI) ELS command for the
2336*4882a593Smuzhiyun * @vport. The PRLI service parameters are set up in the payload of the
2337*4882a593Smuzhiyun * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2338*4882a593Smuzhiyun * is put to the IOCB completion callback func field before invoking the
2339*4882a593Smuzhiyun * routine lpfc_sli_issue_iocb() to send out PRLI command.
2340*4882a593Smuzhiyun *
2341*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2342*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
2343*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
2344*4882a593Smuzhiyun * callback function to the PRLI ELS command.
2345*4882a593Smuzhiyun *
2346*4882a593Smuzhiyun * Return code
2347*4882a593Smuzhiyun * 0 - successfully issued prli iocb command for @vport
2348*4882a593Smuzhiyun * 1 - failed to issue prli iocb command for @vport
2349*4882a593Smuzhiyun **/
2350*4882a593Smuzhiyun int
lpfc_issue_els_prli(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)2351*4882a593Smuzhiyun lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2352*4882a593Smuzhiyun uint8_t retry)
2353*4882a593Smuzhiyun {
2354*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2355*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
2356*4882a593Smuzhiyun PRLI *npr;
2357*4882a593Smuzhiyun struct lpfc_nvme_prli *npr_nvme;
2358*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
2359*4882a593Smuzhiyun uint8_t *pcmd;
2360*4882a593Smuzhiyun uint16_t cmdsize;
2361*4882a593Smuzhiyun u32 local_nlp_type, elscmd;
2362*4882a593Smuzhiyun
2363*4882a593Smuzhiyun /*
2364*4882a593Smuzhiyun * If we are in RSCN mode, the FC4 types supported from a
2365*4882a593Smuzhiyun * previous GFT_ID command may not be accurate. So, if we
2366*4882a593Smuzhiyun * are a NVME Initiator, always look for the possibility of
2367*4882a593Smuzhiyun * the remote NPort beng a NVME Target.
2368*4882a593Smuzhiyun */
2369*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
2370*4882a593Smuzhiyun vport->fc_flag & FC_RSCN_MODE &&
2371*4882a593Smuzhiyun vport->nvmei_support)
2372*4882a593Smuzhiyun ndlp->nlp_fc4_type |= NLP_FC4_NVME;
2373*4882a593Smuzhiyun local_nlp_type = ndlp->nlp_fc4_type;
2374*4882a593Smuzhiyun
2375*4882a593Smuzhiyun /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2376*4882a593Smuzhiyun * fields here before any of them can complete.
2377*4882a593Smuzhiyun */
2378*4882a593Smuzhiyun ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
2379*4882a593Smuzhiyun ndlp->nlp_type &= ~(NLP_NVME_TARGET | NLP_NVME_INITIATOR);
2380*4882a593Smuzhiyun ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
2381*4882a593Smuzhiyun ndlp->nlp_flag &= ~(NLP_FIRSTBURST | NLP_NPR_2B_DISC);
2382*4882a593Smuzhiyun ndlp->nvme_fb_size = 0;
2383*4882a593Smuzhiyun
2384*4882a593Smuzhiyun send_next_prli:
2385*4882a593Smuzhiyun if (local_nlp_type & NLP_FC4_FCP) {
2386*4882a593Smuzhiyun /* Payload is 4 + 16 = 20 x14 bytes. */
2387*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
2388*4882a593Smuzhiyun elscmd = ELS_CMD_PRLI;
2389*4882a593Smuzhiyun } else if (local_nlp_type & NLP_FC4_NVME) {
2390*4882a593Smuzhiyun /* Payload is 4 + 20 = 24 x18 bytes. */
2391*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli));
2392*4882a593Smuzhiyun elscmd = ELS_CMD_NVMEPRLI;
2393*4882a593Smuzhiyun } else {
2394*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2395*4882a593Smuzhiyun "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2396*4882a593Smuzhiyun ndlp->nlp_fc4_type, ndlp->nlp_DID);
2397*4882a593Smuzhiyun return 1;
2398*4882a593Smuzhiyun }
2399*4882a593Smuzhiyun
2400*4882a593Smuzhiyun /* SLI3 ports don't support NVME. If this rport is a strict NVME
2401*4882a593Smuzhiyun * FC4 type, implicitly LOGO.
2402*4882a593Smuzhiyun */
2403*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV3 &&
2404*4882a593Smuzhiyun ndlp->nlp_fc4_type == NLP_FC4_NVME) {
2405*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2406*4882a593Smuzhiyun "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2407*4882a593Smuzhiyun ndlp->nlp_type);
2408*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
2409*4882a593Smuzhiyun return 1;
2410*4882a593Smuzhiyun }
2411*4882a593Smuzhiyun
2412*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2413*4882a593Smuzhiyun ndlp->nlp_DID, elscmd);
2414*4882a593Smuzhiyun if (!elsiocb)
2415*4882a593Smuzhiyun return 1;
2416*4882a593Smuzhiyun
2417*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2418*4882a593Smuzhiyun
2419*4882a593Smuzhiyun /* For PRLI request, remainder of payload is service parameters */
2420*4882a593Smuzhiyun memset(pcmd, 0, cmdsize);
2421*4882a593Smuzhiyun
2422*4882a593Smuzhiyun if (local_nlp_type & NLP_FC4_FCP) {
2423*4882a593Smuzhiyun /* Remainder of payload is FCP PRLI parameter page.
2424*4882a593Smuzhiyun * Note: this data structure is defined as
2425*4882a593Smuzhiyun * BE/LE in the structure definition so no
2426*4882a593Smuzhiyun * byte swap call is made.
2427*4882a593Smuzhiyun */
2428*4882a593Smuzhiyun *((uint32_t *)(pcmd)) = ELS_CMD_PRLI;
2429*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
2430*4882a593Smuzhiyun npr = (PRLI *)pcmd;
2431*4882a593Smuzhiyun
2432*4882a593Smuzhiyun /*
2433*4882a593Smuzhiyun * If our firmware version is 3.20 or later,
2434*4882a593Smuzhiyun * set the following bits for FC-TAPE support.
2435*4882a593Smuzhiyun */
2436*4882a593Smuzhiyun if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2437*4882a593Smuzhiyun npr->ConfmComplAllowed = 1;
2438*4882a593Smuzhiyun npr->Retry = 1;
2439*4882a593Smuzhiyun npr->TaskRetryIdReq = 1;
2440*4882a593Smuzhiyun }
2441*4882a593Smuzhiyun npr->estabImagePair = 1;
2442*4882a593Smuzhiyun npr->readXferRdyDis = 1;
2443*4882a593Smuzhiyun if (vport->cfg_first_burst_size)
2444*4882a593Smuzhiyun npr->writeXferRdyDis = 1;
2445*4882a593Smuzhiyun
2446*4882a593Smuzhiyun /* For FCP support */
2447*4882a593Smuzhiyun npr->prliType = PRLI_FCP_TYPE;
2448*4882a593Smuzhiyun npr->initiatorFunc = 1;
2449*4882a593Smuzhiyun elsiocb->iocb_flag |= LPFC_PRLI_FCP_REQ;
2450*4882a593Smuzhiyun
2451*4882a593Smuzhiyun /* Remove FCP type - processed. */
2452*4882a593Smuzhiyun local_nlp_type &= ~NLP_FC4_FCP;
2453*4882a593Smuzhiyun } else if (local_nlp_type & NLP_FC4_NVME) {
2454*4882a593Smuzhiyun /* Remainder of payload is NVME PRLI parameter page.
2455*4882a593Smuzhiyun * This data structure is the newer definition that
2456*4882a593Smuzhiyun * uses bf macros so a byte swap is required.
2457*4882a593Smuzhiyun */
2458*4882a593Smuzhiyun *((uint32_t *)(pcmd)) = ELS_CMD_NVMEPRLI;
2459*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
2460*4882a593Smuzhiyun npr_nvme = (struct lpfc_nvme_prli *)pcmd;
2461*4882a593Smuzhiyun bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
2462*4882a593Smuzhiyun bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
2463*4882a593Smuzhiyun if (phba->nsler) {
2464*4882a593Smuzhiyun bf_set(prli_nsler, npr_nvme, 1);
2465*4882a593Smuzhiyun bf_set(prli_conf, npr_nvme, 1);
2466*4882a593Smuzhiyun }
2467*4882a593Smuzhiyun
2468*4882a593Smuzhiyun /* Only initiators request first burst. */
2469*4882a593Smuzhiyun if ((phba->cfg_nvme_enable_fb) &&
2470*4882a593Smuzhiyun !phba->nvmet_support)
2471*4882a593Smuzhiyun bf_set(prli_fba, npr_nvme, 1);
2472*4882a593Smuzhiyun
2473*4882a593Smuzhiyun if (phba->nvmet_support) {
2474*4882a593Smuzhiyun bf_set(prli_tgt, npr_nvme, 1);
2475*4882a593Smuzhiyun bf_set(prli_disc, npr_nvme, 1);
2476*4882a593Smuzhiyun } else {
2477*4882a593Smuzhiyun bf_set(prli_init, npr_nvme, 1);
2478*4882a593Smuzhiyun bf_set(prli_conf, npr_nvme, 1);
2479*4882a593Smuzhiyun }
2480*4882a593Smuzhiyun
2481*4882a593Smuzhiyun npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
2482*4882a593Smuzhiyun npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
2483*4882a593Smuzhiyun elsiocb->iocb_flag |= LPFC_PRLI_NVME_REQ;
2484*4882a593Smuzhiyun
2485*4882a593Smuzhiyun /* Remove NVME type - processed. */
2486*4882a593Smuzhiyun local_nlp_type &= ~NLP_FC4_NVME;
2487*4882a593Smuzhiyun }
2488*4882a593Smuzhiyun
2489*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2490*4882a593Smuzhiyun "Issue PRLI: did:x%x",
2491*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
2492*4882a593Smuzhiyun
2493*4882a593Smuzhiyun phba->fc_stat.elsXmitPRLI++;
2494*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
2495*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2496*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_PRLI_SND;
2497*4882a593Smuzhiyun
2498*4882a593Smuzhiyun /* The vport counters are used for lpfc_scan_finished, but
2499*4882a593Smuzhiyun * the ndlp is used to track outstanding PRLIs for different
2500*4882a593Smuzhiyun * FC4 types.
2501*4882a593Smuzhiyun */
2502*4882a593Smuzhiyun vport->fc_prli_sent++;
2503*4882a593Smuzhiyun ndlp->fc4_prli_sent++;
2504*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2505*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2506*4882a593Smuzhiyun IOCB_ERROR) {
2507*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2508*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_PRLI_SND;
2509*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2510*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
2511*4882a593Smuzhiyun return 1;
2512*4882a593Smuzhiyun }
2513*4882a593Smuzhiyun
2514*4882a593Smuzhiyun
2515*4882a593Smuzhiyun /* The driver supports 2 FC4 types. Make sure
2516*4882a593Smuzhiyun * a PRLI is issued for all types before exiting.
2517*4882a593Smuzhiyun */
2518*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
2519*4882a593Smuzhiyun local_nlp_type & (NLP_FC4_FCP | NLP_FC4_NVME))
2520*4882a593Smuzhiyun goto send_next_prli;
2521*4882a593Smuzhiyun
2522*4882a593Smuzhiyun return 0;
2523*4882a593Smuzhiyun }
2524*4882a593Smuzhiyun
2525*4882a593Smuzhiyun /**
2526*4882a593Smuzhiyun * lpfc_rscn_disc - Perform rscn discovery for a vport
2527*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
2528*4882a593Smuzhiyun *
2529*4882a593Smuzhiyun * This routine performs Registration State Change Notification (RSCN)
2530*4882a593Smuzhiyun * discovery for a @vport. If the @vport's node port recovery count is not
2531*4882a593Smuzhiyun * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2532*4882a593Smuzhiyun * the nodes that need recovery. If none of the PLOGI were needed through
2533*4882a593Smuzhiyun * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2534*4882a593Smuzhiyun * invoked to check and handle possible more RSCN came in during the period
2535*4882a593Smuzhiyun * of processing the current ones.
2536*4882a593Smuzhiyun **/
2537*4882a593Smuzhiyun static void
lpfc_rscn_disc(struct lpfc_vport * vport)2538*4882a593Smuzhiyun lpfc_rscn_disc(struct lpfc_vport *vport)
2539*4882a593Smuzhiyun {
2540*4882a593Smuzhiyun lpfc_can_disctmo(vport);
2541*4882a593Smuzhiyun
2542*4882a593Smuzhiyun /* RSCN discovery */
2543*4882a593Smuzhiyun /* go thru NPR nodes and issue ELS PLOGIs */
2544*4882a593Smuzhiyun if (vport->fc_npr_cnt)
2545*4882a593Smuzhiyun if (lpfc_els_disc_plogi(vport))
2546*4882a593Smuzhiyun return;
2547*4882a593Smuzhiyun
2548*4882a593Smuzhiyun lpfc_end_rscn(vport);
2549*4882a593Smuzhiyun }
2550*4882a593Smuzhiyun
2551*4882a593Smuzhiyun /**
2552*4882a593Smuzhiyun * lpfc_adisc_done - Complete the adisc phase of discovery
2553*4882a593Smuzhiyun * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2554*4882a593Smuzhiyun *
2555*4882a593Smuzhiyun * This function is called when the final ADISC is completed during discovery.
2556*4882a593Smuzhiyun * This function handles clearing link attention or issuing reg_vpi depending
2557*4882a593Smuzhiyun * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2558*4882a593Smuzhiyun * discovery.
2559*4882a593Smuzhiyun * This function is called with no locks held.
2560*4882a593Smuzhiyun **/
2561*4882a593Smuzhiyun static void
lpfc_adisc_done(struct lpfc_vport * vport)2562*4882a593Smuzhiyun lpfc_adisc_done(struct lpfc_vport *vport)
2563*4882a593Smuzhiyun {
2564*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2565*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
2566*4882a593Smuzhiyun
2567*4882a593Smuzhiyun /*
2568*4882a593Smuzhiyun * For NPIV, cmpl_reg_vpi will set port_state to READY,
2569*4882a593Smuzhiyun * and continue discovery.
2570*4882a593Smuzhiyun */
2571*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2572*4882a593Smuzhiyun !(vport->fc_flag & FC_RSCN_MODE) &&
2573*4882a593Smuzhiyun (phba->sli_rev < LPFC_SLI_REV4)) {
2574*4882a593Smuzhiyun /* The ADISCs are complete. Doesn't matter if they
2575*4882a593Smuzhiyun * succeeded or failed because the ADISC completion
2576*4882a593Smuzhiyun * routine guarantees to call the state machine and
2577*4882a593Smuzhiyun * the RPI is either unregistered (failed ADISC response)
2578*4882a593Smuzhiyun * or the RPI is still valid and the node is marked
2579*4882a593Smuzhiyun * mapped for a target. The exchanges should be in the
2580*4882a593Smuzhiyun * correct state. This code is specific to SLI3.
2581*4882a593Smuzhiyun */
2582*4882a593Smuzhiyun lpfc_issue_clear_la(phba, vport);
2583*4882a593Smuzhiyun lpfc_issue_reg_vpi(phba, vport);
2584*4882a593Smuzhiyun return;
2585*4882a593Smuzhiyun }
2586*4882a593Smuzhiyun /*
2587*4882a593Smuzhiyun * For SLI2, we need to set port_state to READY
2588*4882a593Smuzhiyun * and continue discovery.
2589*4882a593Smuzhiyun */
2590*4882a593Smuzhiyun if (vport->port_state < LPFC_VPORT_READY) {
2591*4882a593Smuzhiyun /* If we get here, there is nothing to ADISC */
2592*4882a593Smuzhiyun lpfc_issue_clear_la(phba, vport);
2593*4882a593Smuzhiyun if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2594*4882a593Smuzhiyun vport->num_disc_nodes = 0;
2595*4882a593Smuzhiyun /* go thru NPR list, issue ELS PLOGIs */
2596*4882a593Smuzhiyun if (vport->fc_npr_cnt)
2597*4882a593Smuzhiyun lpfc_els_disc_plogi(vport);
2598*4882a593Smuzhiyun if (!vport->num_disc_nodes) {
2599*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2600*4882a593Smuzhiyun vport->fc_flag &= ~FC_NDISC_ACTIVE;
2601*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2602*4882a593Smuzhiyun lpfc_can_disctmo(vport);
2603*4882a593Smuzhiyun lpfc_end_rscn(vport);
2604*4882a593Smuzhiyun }
2605*4882a593Smuzhiyun }
2606*4882a593Smuzhiyun vport->port_state = LPFC_VPORT_READY;
2607*4882a593Smuzhiyun } else
2608*4882a593Smuzhiyun lpfc_rscn_disc(vport);
2609*4882a593Smuzhiyun }
2610*4882a593Smuzhiyun
2611*4882a593Smuzhiyun /**
2612*4882a593Smuzhiyun * lpfc_more_adisc - Issue more adisc as needed
2613*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
2614*4882a593Smuzhiyun *
2615*4882a593Smuzhiyun * This routine determines whether there are more ndlps on a @vport
2616*4882a593Smuzhiyun * node list need to have Address Discover (ADISC) issued. If so, it will
2617*4882a593Smuzhiyun * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2618*4882a593Smuzhiyun * remaining nodes which need to have ADISC sent.
2619*4882a593Smuzhiyun **/
2620*4882a593Smuzhiyun void
lpfc_more_adisc(struct lpfc_vport * vport)2621*4882a593Smuzhiyun lpfc_more_adisc(struct lpfc_vport *vport)
2622*4882a593Smuzhiyun {
2623*4882a593Smuzhiyun if (vport->num_disc_nodes)
2624*4882a593Smuzhiyun vport->num_disc_nodes--;
2625*4882a593Smuzhiyun /* Continue discovery with <num_disc_nodes> ADISCs to go */
2626*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2627*4882a593Smuzhiyun "0210 Continue discovery with %d ADISCs to go "
2628*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
2629*4882a593Smuzhiyun vport->num_disc_nodes, vport->fc_adisc_cnt,
2630*4882a593Smuzhiyun vport->fc_flag, vport->port_state);
2631*4882a593Smuzhiyun /* Check to see if there are more ADISCs to be sent */
2632*4882a593Smuzhiyun if (vport->fc_flag & FC_NLP_MORE) {
2633*4882a593Smuzhiyun lpfc_set_disctmo(vport);
2634*4882a593Smuzhiyun /* go thru NPR nodes and issue any remaining ELS ADISCs */
2635*4882a593Smuzhiyun lpfc_els_disc_adisc(vport);
2636*4882a593Smuzhiyun }
2637*4882a593Smuzhiyun if (!vport->num_disc_nodes)
2638*4882a593Smuzhiyun lpfc_adisc_done(vport);
2639*4882a593Smuzhiyun return;
2640*4882a593Smuzhiyun }
2641*4882a593Smuzhiyun
2642*4882a593Smuzhiyun /**
2643*4882a593Smuzhiyun * lpfc_cmpl_els_adisc - Completion callback function for adisc
2644*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
2645*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
2646*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
2647*4882a593Smuzhiyun *
2648*4882a593Smuzhiyun * This routine is the completion function for issuing the Address Discover
2649*4882a593Smuzhiyun * (ADISC) command. It first checks to see whether link went down during
2650*4882a593Smuzhiyun * the discovery process. If so, the node will be marked as node port
2651*4882a593Smuzhiyun * recovery for issuing discover IOCB by the link attention handler and
2652*4882a593Smuzhiyun * exit. Otherwise, the response status is checked. If error was reported
2653*4882a593Smuzhiyun * in the response status, the ADISC command shall be retried by invoking
2654*4882a593Smuzhiyun * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2655*4882a593Smuzhiyun * the response status, the state machine is invoked to set transition
2656*4882a593Smuzhiyun * with respect to NLP_EVT_CMPL_ADISC event.
2657*4882a593Smuzhiyun **/
2658*4882a593Smuzhiyun static void
lpfc_cmpl_els_adisc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2659*4882a593Smuzhiyun lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2660*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
2661*4882a593Smuzhiyun {
2662*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
2663*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2664*4882a593Smuzhiyun IOCB_t *irsp;
2665*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
2666*4882a593Smuzhiyun int disc;
2667*4882a593Smuzhiyun
2668*4882a593Smuzhiyun /* we pass cmdiocb to state machine which needs rspiocb as well */
2669*4882a593Smuzhiyun cmdiocb->context_un.rsp_iocb = rspiocb;
2670*4882a593Smuzhiyun
2671*4882a593Smuzhiyun irsp = &(rspiocb->iocb);
2672*4882a593Smuzhiyun ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2673*4882a593Smuzhiyun
2674*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2675*4882a593Smuzhiyun "ADISC cmpl: status:x%x/x%x did:x%x",
2676*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
2677*4882a593Smuzhiyun ndlp->nlp_DID);
2678*4882a593Smuzhiyun
2679*4882a593Smuzhiyun /* Since ndlp can be freed in the disc state machine, note if this node
2680*4882a593Smuzhiyun * is being used during discovery.
2681*4882a593Smuzhiyun */
2682*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2683*4882a593Smuzhiyun disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2684*4882a593Smuzhiyun ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2685*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2686*4882a593Smuzhiyun /* ADISC completes to NPort <nlp_DID> */
2687*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2688*4882a593Smuzhiyun "0104 ADISC completes to NPort x%x "
2689*4882a593Smuzhiyun "Data: x%x x%x x%x x%x x%x\n",
2690*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2691*4882a593Smuzhiyun irsp->ulpTimeout, disc, vport->num_disc_nodes);
2692*4882a593Smuzhiyun /* Check to see if link went down during discovery */
2693*4882a593Smuzhiyun if (lpfc_els_chk_latt(vport)) {
2694*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2695*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2696*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2697*4882a593Smuzhiyun goto out;
2698*4882a593Smuzhiyun }
2699*4882a593Smuzhiyun
2700*4882a593Smuzhiyun if (irsp->ulpStatus) {
2701*4882a593Smuzhiyun /* Check for retry */
2702*4882a593Smuzhiyun if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2703*4882a593Smuzhiyun /* ELS command is being retried */
2704*4882a593Smuzhiyun if (disc) {
2705*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2706*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2707*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2708*4882a593Smuzhiyun lpfc_set_disctmo(vport);
2709*4882a593Smuzhiyun }
2710*4882a593Smuzhiyun goto out;
2711*4882a593Smuzhiyun }
2712*4882a593Smuzhiyun /* ADISC failed */
2713*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2714*4882a593Smuzhiyun "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2715*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus,
2716*4882a593Smuzhiyun irsp->un.ulpWord[4]);
2717*4882a593Smuzhiyun /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2718*4882a593Smuzhiyun if (!lpfc_error_lost_link(irsp))
2719*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2720*4882a593Smuzhiyun NLP_EVT_CMPL_ADISC);
2721*4882a593Smuzhiyun } else
2722*4882a593Smuzhiyun /* Good status, call state machine */
2723*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2724*4882a593Smuzhiyun NLP_EVT_CMPL_ADISC);
2725*4882a593Smuzhiyun
2726*4882a593Smuzhiyun /* Check to see if there are more ADISCs to be sent */
2727*4882a593Smuzhiyun if (disc && vport->num_disc_nodes)
2728*4882a593Smuzhiyun lpfc_more_adisc(vport);
2729*4882a593Smuzhiyun out:
2730*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
2731*4882a593Smuzhiyun return;
2732*4882a593Smuzhiyun }
2733*4882a593Smuzhiyun
2734*4882a593Smuzhiyun /**
2735*4882a593Smuzhiyun * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2736*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
2737*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
2738*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
2739*4882a593Smuzhiyun *
2740*4882a593Smuzhiyun * This routine issues an Address Discover (ADISC) for an @ndlp on a
2741*4882a593Smuzhiyun * @vport. It prepares the payload of the ADISC ELS command, updates the
2742*4882a593Smuzhiyun * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2743*4882a593Smuzhiyun * to issue the ADISC ELS command.
2744*4882a593Smuzhiyun *
2745*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2746*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
2747*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
2748*4882a593Smuzhiyun * callback function to the ADISC ELS command.
2749*4882a593Smuzhiyun *
2750*4882a593Smuzhiyun * Return code
2751*4882a593Smuzhiyun * 0 - successfully issued adisc
2752*4882a593Smuzhiyun * 1 - failed to issue adisc
2753*4882a593Smuzhiyun **/
2754*4882a593Smuzhiyun int
lpfc_issue_els_adisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)2755*4882a593Smuzhiyun lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2756*4882a593Smuzhiyun uint8_t retry)
2757*4882a593Smuzhiyun {
2758*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2759*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
2760*4882a593Smuzhiyun ADISC *ap;
2761*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
2762*4882a593Smuzhiyun uint8_t *pcmd;
2763*4882a593Smuzhiyun uint16_t cmdsize;
2764*4882a593Smuzhiyun
2765*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2766*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2767*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ADISC);
2768*4882a593Smuzhiyun if (!elsiocb)
2769*4882a593Smuzhiyun return 1;
2770*4882a593Smuzhiyun
2771*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2772*4882a593Smuzhiyun
2773*4882a593Smuzhiyun /* For ADISC request, remainder of payload is service parameters */
2774*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2775*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
2776*4882a593Smuzhiyun
2777*4882a593Smuzhiyun /* Fill in ADISC payload */
2778*4882a593Smuzhiyun ap = (ADISC *) pcmd;
2779*4882a593Smuzhiyun ap->hardAL_PA = phba->fc_pref_ALPA;
2780*4882a593Smuzhiyun memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2781*4882a593Smuzhiyun memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2782*4882a593Smuzhiyun ap->DID = be32_to_cpu(vport->fc_myDID);
2783*4882a593Smuzhiyun
2784*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2785*4882a593Smuzhiyun "Issue ADISC: did:x%x",
2786*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
2787*4882a593Smuzhiyun
2788*4882a593Smuzhiyun phba->fc_stat.elsXmitADISC++;
2789*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2790*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2791*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_ADISC_SND;
2792*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2793*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2794*4882a593Smuzhiyun IOCB_ERROR) {
2795*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2796*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_ADISC_SND;
2797*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2798*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
2799*4882a593Smuzhiyun return 1;
2800*4882a593Smuzhiyun }
2801*4882a593Smuzhiyun return 0;
2802*4882a593Smuzhiyun }
2803*4882a593Smuzhiyun
2804*4882a593Smuzhiyun /**
2805*4882a593Smuzhiyun * lpfc_cmpl_els_logo - Completion callback function for logo
2806*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
2807*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
2808*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
2809*4882a593Smuzhiyun *
2810*4882a593Smuzhiyun * This routine is the completion function for issuing the ELS Logout (LOGO)
2811*4882a593Smuzhiyun * command. If no error status was reported from the LOGO response, the
2812*4882a593Smuzhiyun * state machine of the associated ndlp shall be invoked for transition with
2813*4882a593Smuzhiyun * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2814*4882a593Smuzhiyun * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2815*4882a593Smuzhiyun **/
2816*4882a593Smuzhiyun static void
lpfc_cmpl_els_logo(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)2817*4882a593Smuzhiyun lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2818*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
2819*4882a593Smuzhiyun {
2820*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2821*4882a593Smuzhiyun struct lpfc_vport *vport = ndlp->vport;
2822*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2823*4882a593Smuzhiyun IOCB_t *irsp;
2824*4882a593Smuzhiyun struct lpfcMboxq *mbox;
2825*4882a593Smuzhiyun unsigned long flags;
2826*4882a593Smuzhiyun uint32_t skip_recovery = 0;
2827*4882a593Smuzhiyun
2828*4882a593Smuzhiyun /* we pass cmdiocb to state machine which needs rspiocb as well */
2829*4882a593Smuzhiyun cmdiocb->context_un.rsp_iocb = rspiocb;
2830*4882a593Smuzhiyun
2831*4882a593Smuzhiyun irsp = &(rspiocb->iocb);
2832*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2833*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_LOGO_SND;
2834*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2835*4882a593Smuzhiyun
2836*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2837*4882a593Smuzhiyun "LOGO cmpl: status:x%x/x%x did:x%x",
2838*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
2839*4882a593Smuzhiyun ndlp->nlp_DID);
2840*4882a593Smuzhiyun
2841*4882a593Smuzhiyun /* LOGO completes to NPort <nlp_DID> */
2842*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2843*4882a593Smuzhiyun "0105 LOGO completes to NPort x%x "
2844*4882a593Smuzhiyun "Data: x%x x%x x%x x%x\n",
2845*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2846*4882a593Smuzhiyun irsp->ulpTimeout, vport->num_disc_nodes);
2847*4882a593Smuzhiyun
2848*4882a593Smuzhiyun if (lpfc_els_chk_latt(vport)) {
2849*4882a593Smuzhiyun skip_recovery = 1;
2850*4882a593Smuzhiyun goto out;
2851*4882a593Smuzhiyun }
2852*4882a593Smuzhiyun
2853*4882a593Smuzhiyun /* Check to see if link went down during discovery */
2854*4882a593Smuzhiyun if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2855*4882a593Smuzhiyun /* NLP_EVT_DEVICE_RM should unregister the RPI
2856*4882a593Smuzhiyun * which should abort all outstanding IOs.
2857*4882a593Smuzhiyun */
2858*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2859*4882a593Smuzhiyun NLP_EVT_DEVICE_RM);
2860*4882a593Smuzhiyun skip_recovery = 1;
2861*4882a593Smuzhiyun goto out;
2862*4882a593Smuzhiyun }
2863*4882a593Smuzhiyun
2864*4882a593Smuzhiyun /* The LOGO will not be retried on failure. A LOGO was
2865*4882a593Smuzhiyun * issued to the remote rport and a ACC or RJT or no Answer are
2866*4882a593Smuzhiyun * all acceptable. Note the failure and move forward with
2867*4882a593Smuzhiyun * discovery. The PLOGI will retry.
2868*4882a593Smuzhiyun */
2869*4882a593Smuzhiyun if (irsp->ulpStatus) {
2870*4882a593Smuzhiyun /* LOGO failed */
2871*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
2872*4882a593Smuzhiyun "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2873*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus,
2874*4882a593Smuzhiyun irsp->un.ulpWord[4]);
2875*4882a593Smuzhiyun /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2876*4882a593Smuzhiyun if (lpfc_error_lost_link(irsp)) {
2877*4882a593Smuzhiyun skip_recovery = 1;
2878*4882a593Smuzhiyun goto out;
2879*4882a593Smuzhiyun }
2880*4882a593Smuzhiyun }
2881*4882a593Smuzhiyun
2882*4882a593Smuzhiyun /* Call state machine. This will unregister the rpi if needed. */
2883*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2884*4882a593Smuzhiyun
2885*4882a593Smuzhiyun out:
2886*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
2887*4882a593Smuzhiyun /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2888*4882a593Smuzhiyun if ((vport->fc_flag & FC_PT2PT) &&
2889*4882a593Smuzhiyun !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2890*4882a593Smuzhiyun phba->pport->fc_myDID = 0;
2891*4882a593Smuzhiyun
2892*4882a593Smuzhiyun if ((vport->cfg_enable_fc4_type == LPFC_ENABLE_BOTH) ||
2893*4882a593Smuzhiyun (vport->cfg_enable_fc4_type == LPFC_ENABLE_NVME)) {
2894*4882a593Smuzhiyun if (phba->nvmet_support)
2895*4882a593Smuzhiyun lpfc_nvmet_update_targetport(phba);
2896*4882a593Smuzhiyun else
2897*4882a593Smuzhiyun lpfc_nvme_update_localport(phba->pport);
2898*4882a593Smuzhiyun }
2899*4882a593Smuzhiyun
2900*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2901*4882a593Smuzhiyun if (mbox) {
2902*4882a593Smuzhiyun lpfc_config_link(phba, mbox);
2903*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2904*4882a593Smuzhiyun mbox->vport = vport;
2905*4882a593Smuzhiyun if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2906*4882a593Smuzhiyun MBX_NOT_FINISHED) {
2907*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
2908*4882a593Smuzhiyun skip_recovery = 1;
2909*4882a593Smuzhiyun }
2910*4882a593Smuzhiyun }
2911*4882a593Smuzhiyun }
2912*4882a593Smuzhiyun
2913*4882a593Smuzhiyun /*
2914*4882a593Smuzhiyun * If the node is a target, the handling attempts to recover the port.
2915*4882a593Smuzhiyun * For any other port type, the rpi is unregistered as an implicit
2916*4882a593Smuzhiyun * LOGO.
2917*4882a593Smuzhiyun */
2918*4882a593Smuzhiyun if (ndlp->nlp_type & (NLP_FCP_TARGET | NLP_NVME_TARGET) &&
2919*4882a593Smuzhiyun skip_recovery == 0) {
2920*4882a593Smuzhiyun lpfc_cancel_retry_delay_tmo(vport, ndlp);
2921*4882a593Smuzhiyun spin_lock_irqsave(shost->host_lock, flags);
2922*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2923*4882a593Smuzhiyun spin_unlock_irqrestore(shost->host_lock, flags);
2924*4882a593Smuzhiyun
2925*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2926*4882a593Smuzhiyun "3187 LOGO completes to NPort x%x: Start "
2927*4882a593Smuzhiyun "Recovery Data: x%x x%x x%x x%x\n",
2928*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus,
2929*4882a593Smuzhiyun irsp->un.ulpWord[4], irsp->ulpTimeout,
2930*4882a593Smuzhiyun vport->num_disc_nodes);
2931*4882a593Smuzhiyun lpfc_disc_start(vport);
2932*4882a593Smuzhiyun }
2933*4882a593Smuzhiyun return;
2934*4882a593Smuzhiyun }
2935*4882a593Smuzhiyun
2936*4882a593Smuzhiyun /**
2937*4882a593Smuzhiyun * lpfc_issue_els_logo - Issue a logo to an node on a vport
2938*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
2939*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
2940*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
2941*4882a593Smuzhiyun *
2942*4882a593Smuzhiyun * This routine constructs and issues an ELS Logout (LOGO) iocb command
2943*4882a593Smuzhiyun * to a remote node, referred by an @ndlp on a @vport. It constructs the
2944*4882a593Smuzhiyun * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2945*4882a593Smuzhiyun * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2946*4882a593Smuzhiyun *
2947*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2948*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
2949*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
2950*4882a593Smuzhiyun * callback function to the LOGO ELS command.
2951*4882a593Smuzhiyun *
2952*4882a593Smuzhiyun * Callers of this routine are expected to unregister the RPI first
2953*4882a593Smuzhiyun *
2954*4882a593Smuzhiyun * Return code
2955*4882a593Smuzhiyun * 0 - successfully issued logo
2956*4882a593Smuzhiyun * 1 - failed to issue logo
2957*4882a593Smuzhiyun **/
2958*4882a593Smuzhiyun int
lpfc_issue_els_logo(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)2959*4882a593Smuzhiyun lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2960*4882a593Smuzhiyun uint8_t retry)
2961*4882a593Smuzhiyun {
2962*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2963*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
2964*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
2965*4882a593Smuzhiyun uint8_t *pcmd;
2966*4882a593Smuzhiyun uint16_t cmdsize;
2967*4882a593Smuzhiyun int rc;
2968*4882a593Smuzhiyun
2969*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2970*4882a593Smuzhiyun if (ndlp->nlp_flag & NLP_LOGO_SND) {
2971*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2972*4882a593Smuzhiyun return 0;
2973*4882a593Smuzhiyun }
2974*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
2975*4882a593Smuzhiyun
2976*4882a593Smuzhiyun cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2977*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2978*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_LOGO);
2979*4882a593Smuzhiyun if (!elsiocb)
2980*4882a593Smuzhiyun return 1;
2981*4882a593Smuzhiyun
2982*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2983*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2984*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
2985*4882a593Smuzhiyun
2986*4882a593Smuzhiyun /* Fill in LOGO payload */
2987*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2988*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
2989*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2990*4882a593Smuzhiyun
2991*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2992*4882a593Smuzhiyun "Issue LOGO: did:x%x",
2993*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
2994*4882a593Smuzhiyun
2995*4882a593Smuzhiyun phba->fc_stat.elsXmitLOGO++;
2996*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2997*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
2998*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_LOGO_SND;
2999*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
3000*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3001*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3002*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
3003*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
3004*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_LOGO_SND;
3005*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3006*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
3007*4882a593Smuzhiyun return 1;
3008*4882a593Smuzhiyun }
3009*4882a593Smuzhiyun
3010*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
3011*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
3012*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3013*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3014*4882a593Smuzhiyun return 0;
3015*4882a593Smuzhiyun }
3016*4882a593Smuzhiyun
3017*4882a593Smuzhiyun /**
3018*4882a593Smuzhiyun * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3019*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
3020*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
3021*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
3022*4882a593Smuzhiyun *
3023*4882a593Smuzhiyun * This routine is a generic completion callback function for ELS commands.
3024*4882a593Smuzhiyun * Specifically, it is the callback function which does not need to perform
3025*4882a593Smuzhiyun * any command specific operations. It is currently used by the ELS command
3026*4882a593Smuzhiyun * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3027*4882a593Smuzhiyun * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3028*4882a593Smuzhiyun * Other than certain debug loggings, this callback function simply invokes the
3029*4882a593Smuzhiyun * lpfc_els_chk_latt() routine to check whether link went down during the
3030*4882a593Smuzhiyun * discovery process.
3031*4882a593Smuzhiyun **/
3032*4882a593Smuzhiyun static void
lpfc_cmpl_els_cmd(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)3033*4882a593Smuzhiyun lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3034*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
3035*4882a593Smuzhiyun {
3036*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
3037*4882a593Smuzhiyun IOCB_t *irsp;
3038*4882a593Smuzhiyun
3039*4882a593Smuzhiyun irsp = &rspiocb->iocb;
3040*4882a593Smuzhiyun
3041*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3042*4882a593Smuzhiyun "ELS cmd cmpl: status:x%x/x%x did:x%x",
3043*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
3044*4882a593Smuzhiyun irsp->un.elsreq64.remoteID);
3045*4882a593Smuzhiyun
3046*4882a593Smuzhiyun /* ELS cmd tag <ulpIoTag> completes */
3047*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3048*4882a593Smuzhiyun "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3049*4882a593Smuzhiyun irsp->ulpIoTag, irsp->ulpStatus,
3050*4882a593Smuzhiyun irsp->un.ulpWord[4], irsp->ulpTimeout);
3051*4882a593Smuzhiyun
3052*4882a593Smuzhiyun /* Check to see if link went down during discovery */
3053*4882a593Smuzhiyun lpfc_els_chk_latt(vport);
3054*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
3055*4882a593Smuzhiyun }
3056*4882a593Smuzhiyun
3057*4882a593Smuzhiyun /**
3058*4882a593Smuzhiyun * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3059*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
3060*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
3061*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
3062*4882a593Smuzhiyun *
3063*4882a593Smuzhiyun * This routine is a generic completion callback function for Discovery ELS cmd.
3064*4882a593Smuzhiyun * Currently used by the ELS command issuing routines for the ELS State Change
3065*4882a593Smuzhiyun * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3066*4882a593Smuzhiyun * These commands will be retried once only for ELS timeout errors.
3067*4882a593Smuzhiyun **/
3068*4882a593Smuzhiyun static void
lpfc_cmpl_els_disc_cmd(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)3069*4882a593Smuzhiyun lpfc_cmpl_els_disc_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3070*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
3071*4882a593Smuzhiyun {
3072*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
3073*4882a593Smuzhiyun IOCB_t *irsp;
3074*4882a593Smuzhiyun struct lpfc_els_rdf_rsp *prdf;
3075*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd, *prsp;
3076*4882a593Smuzhiyun u32 *pdata;
3077*4882a593Smuzhiyun u32 cmd;
3078*4882a593Smuzhiyun
3079*4882a593Smuzhiyun irsp = &rspiocb->iocb;
3080*4882a593Smuzhiyun
3081*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3082*4882a593Smuzhiyun "ELS cmd cmpl: status:x%x/x%x did:x%x",
3083*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
3084*4882a593Smuzhiyun irsp->un.elsreq64.remoteID);
3085*4882a593Smuzhiyun /* ELS cmd tag <ulpIoTag> completes */
3086*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3087*4882a593Smuzhiyun "0217 ELS cmd tag x%x completes Data: x%x x%x x%x "
3088*4882a593Smuzhiyun "x%x\n",
3089*4882a593Smuzhiyun irsp->ulpIoTag, irsp->ulpStatus,
3090*4882a593Smuzhiyun irsp->un.ulpWord[4], irsp->ulpTimeout,
3091*4882a593Smuzhiyun cmdiocb->retry);
3092*4882a593Smuzhiyun
3093*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3094*4882a593Smuzhiyun if (!pcmd)
3095*4882a593Smuzhiyun goto out;
3096*4882a593Smuzhiyun
3097*4882a593Smuzhiyun pdata = (u32 *)pcmd->virt;
3098*4882a593Smuzhiyun if (!pdata)
3099*4882a593Smuzhiyun goto out;
3100*4882a593Smuzhiyun cmd = *pdata;
3101*4882a593Smuzhiyun
3102*4882a593Smuzhiyun /* Only 1 retry for ELS Timeout only */
3103*4882a593Smuzhiyun if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT &&
3104*4882a593Smuzhiyun ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
3105*4882a593Smuzhiyun IOERR_SEQUENCE_TIMEOUT)) {
3106*4882a593Smuzhiyun cmdiocb->retry++;
3107*4882a593Smuzhiyun if (cmdiocb->retry <= 1) {
3108*4882a593Smuzhiyun switch (cmd) {
3109*4882a593Smuzhiyun case ELS_CMD_SCR:
3110*4882a593Smuzhiyun lpfc_issue_els_scr(vport, cmdiocb->retry);
3111*4882a593Smuzhiyun break;
3112*4882a593Smuzhiyun case ELS_CMD_RDF:
3113*4882a593Smuzhiyun cmdiocb->context1 = NULL; /* save ndlp refcnt */
3114*4882a593Smuzhiyun lpfc_issue_els_rdf(vport, cmdiocb->retry);
3115*4882a593Smuzhiyun break;
3116*4882a593Smuzhiyun }
3117*4882a593Smuzhiyun goto out;
3118*4882a593Smuzhiyun }
3119*4882a593Smuzhiyun phba->fc_stat.elsRetryExceeded++;
3120*4882a593Smuzhiyun }
3121*4882a593Smuzhiyun if (irsp->ulpStatus) {
3122*4882a593Smuzhiyun /* ELS discovery cmd completes with error */
3123*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3124*4882a593Smuzhiyun "4203 ELS cmd x%x error: x%x x%X\n", cmd,
3125*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4]);
3126*4882a593Smuzhiyun goto out;
3127*4882a593Smuzhiyun }
3128*4882a593Smuzhiyun
3129*4882a593Smuzhiyun /* The RDF response doesn't have any impact on the running driver
3130*4882a593Smuzhiyun * but the notification descriptors are dumped here for support.
3131*4882a593Smuzhiyun */
3132*4882a593Smuzhiyun if (cmd == ELS_CMD_RDF) {
3133*4882a593Smuzhiyun int i;
3134*4882a593Smuzhiyun
3135*4882a593Smuzhiyun prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
3136*4882a593Smuzhiyun if (!prsp)
3137*4882a593Smuzhiyun goto out;
3138*4882a593Smuzhiyun
3139*4882a593Smuzhiyun prdf = (struct lpfc_els_rdf_rsp *)prsp->virt;
3140*4882a593Smuzhiyun if (!prdf)
3141*4882a593Smuzhiyun goto out;
3142*4882a593Smuzhiyun
3143*4882a593Smuzhiyun for (i = 0; i < ELS_RDF_REG_TAG_CNT &&
3144*4882a593Smuzhiyun i < be32_to_cpu(prdf->reg_d1.reg_desc.count); i++)
3145*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3146*4882a593Smuzhiyun "4677 Fabric RDF Notification Grant Data: "
3147*4882a593Smuzhiyun "0x%08x\n",
3148*4882a593Smuzhiyun be32_to_cpu(
3149*4882a593Smuzhiyun prdf->reg_d1.desc_tags[i]));
3150*4882a593Smuzhiyun }
3151*4882a593Smuzhiyun
3152*4882a593Smuzhiyun out:
3153*4882a593Smuzhiyun /* Check to see if link went down during discovery */
3154*4882a593Smuzhiyun lpfc_els_chk_latt(vport);
3155*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
3156*4882a593Smuzhiyun return;
3157*4882a593Smuzhiyun }
3158*4882a593Smuzhiyun
3159*4882a593Smuzhiyun /**
3160*4882a593Smuzhiyun * lpfc_issue_els_scr - Issue a scr to an node on a vport
3161*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
3162*4882a593Smuzhiyun * @retry: retry counter for the command IOCB.
3163*4882a593Smuzhiyun *
3164*4882a593Smuzhiyun * This routine issues a State Change Request (SCR) to a fabric node
3165*4882a593Smuzhiyun * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3166*4882a593Smuzhiyun * first search the @vport node list to find the matching ndlp. If no such
3167*4882a593Smuzhiyun * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3168*4882a593Smuzhiyun * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3169*4882a593Smuzhiyun * routine is invoked to send the SCR IOCB.
3170*4882a593Smuzhiyun *
3171*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3172*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
3173*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
3174*4882a593Smuzhiyun * callback function to the SCR ELS command.
3175*4882a593Smuzhiyun *
3176*4882a593Smuzhiyun * Return code
3177*4882a593Smuzhiyun * 0 - Successfully issued scr command
3178*4882a593Smuzhiyun * 1 - Failed to issue scr command
3179*4882a593Smuzhiyun **/
3180*4882a593Smuzhiyun int
lpfc_issue_els_scr(struct lpfc_vport * vport,uint8_t retry)3181*4882a593Smuzhiyun lpfc_issue_els_scr(struct lpfc_vport *vport, uint8_t retry)
3182*4882a593Smuzhiyun {
3183*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
3184*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
3185*4882a593Smuzhiyun uint8_t *pcmd;
3186*4882a593Smuzhiyun uint16_t cmdsize;
3187*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
3188*4882a593Smuzhiyun
3189*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(SCR));
3190*4882a593Smuzhiyun
3191*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3192*4882a593Smuzhiyun if (!ndlp) {
3193*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3194*4882a593Smuzhiyun if (!ndlp)
3195*4882a593Smuzhiyun return 1;
3196*4882a593Smuzhiyun lpfc_enqueue_node(vport, ndlp);
3197*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3198*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3199*4882a593Smuzhiyun if (!ndlp)
3200*4882a593Smuzhiyun return 1;
3201*4882a593Smuzhiyun }
3202*4882a593Smuzhiyun
3203*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3204*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_SCR);
3205*4882a593Smuzhiyun
3206*4882a593Smuzhiyun if (!elsiocb) {
3207*4882a593Smuzhiyun /* This will trigger the release of the node just
3208*4882a593Smuzhiyun * allocated
3209*4882a593Smuzhiyun */
3210*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3211*4882a593Smuzhiyun return 1;
3212*4882a593Smuzhiyun }
3213*4882a593Smuzhiyun
3214*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3215*4882a593Smuzhiyun
3216*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
3217*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
3218*4882a593Smuzhiyun
3219*4882a593Smuzhiyun /* For SCR, remainder of payload is SCR parameter page */
3220*4882a593Smuzhiyun memset(pcmd, 0, sizeof(SCR));
3221*4882a593Smuzhiyun ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
3222*4882a593Smuzhiyun
3223*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3224*4882a593Smuzhiyun "Issue SCR: did:x%x",
3225*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
3226*4882a593Smuzhiyun
3227*4882a593Smuzhiyun phba->fc_stat.elsXmitSCR++;
3228*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3229*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3230*4882a593Smuzhiyun IOCB_ERROR) {
3231*4882a593Smuzhiyun /* The additional lpfc_nlp_put will cause the following
3232*4882a593Smuzhiyun * lpfc_els_free_iocb routine to trigger the rlease of
3233*4882a593Smuzhiyun * the node.
3234*4882a593Smuzhiyun */
3235*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3236*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
3237*4882a593Smuzhiyun return 1;
3238*4882a593Smuzhiyun }
3239*4882a593Smuzhiyun /* This will cause the callback-function lpfc_cmpl_els_cmd to
3240*4882a593Smuzhiyun * trigger the release of node.
3241*4882a593Smuzhiyun */
3242*4882a593Smuzhiyun if (!(vport->fc_flag & FC_PT2PT))
3243*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3244*4882a593Smuzhiyun return 0;
3245*4882a593Smuzhiyun }
3246*4882a593Smuzhiyun
3247*4882a593Smuzhiyun /**
3248*4882a593Smuzhiyun * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3249*4882a593Smuzhiyun * or the other nport (pt2pt).
3250*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
3251*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
3252*4882a593Smuzhiyun *
3253*4882a593Smuzhiyun * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3254*4882a593Smuzhiyun * when connected to a fabric, or to the remote port when connected
3255*4882a593Smuzhiyun * in point-to-point mode. When sent to the Fabric Controller, it will
3256*4882a593Smuzhiyun * replay the RSCN to registered recipients.
3257*4882a593Smuzhiyun *
3258*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3259*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
3260*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
3261*4882a593Smuzhiyun * callback function to the RSCN ELS command.
3262*4882a593Smuzhiyun *
3263*4882a593Smuzhiyun * Return code
3264*4882a593Smuzhiyun * 0 - Successfully issued RSCN command
3265*4882a593Smuzhiyun * 1 - Failed to issue RSCN command
3266*4882a593Smuzhiyun **/
3267*4882a593Smuzhiyun int
lpfc_issue_els_rscn(struct lpfc_vport * vport,uint8_t retry)3268*4882a593Smuzhiyun lpfc_issue_els_rscn(struct lpfc_vport *vport, uint8_t retry)
3269*4882a593Smuzhiyun {
3270*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
3271*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
3272*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
3273*4882a593Smuzhiyun struct {
3274*4882a593Smuzhiyun struct fc_els_rscn rscn;
3275*4882a593Smuzhiyun struct fc_els_rscn_page portid;
3276*4882a593Smuzhiyun } *event;
3277*4882a593Smuzhiyun uint32_t nportid;
3278*4882a593Smuzhiyun uint16_t cmdsize = sizeof(*event);
3279*4882a593Smuzhiyun
3280*4882a593Smuzhiyun /* Not supported for private loop */
3281*4882a593Smuzhiyun if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
3282*4882a593Smuzhiyun !(vport->fc_flag & FC_PUBLIC_LOOP))
3283*4882a593Smuzhiyun return 1;
3284*4882a593Smuzhiyun
3285*4882a593Smuzhiyun if (vport->fc_flag & FC_PT2PT) {
3286*4882a593Smuzhiyun /* find any mapped nport - that would be the other nport */
3287*4882a593Smuzhiyun ndlp = lpfc_findnode_mapped(vport);
3288*4882a593Smuzhiyun if (!ndlp)
3289*4882a593Smuzhiyun return 1;
3290*4882a593Smuzhiyun } else {
3291*4882a593Smuzhiyun nportid = FC_FID_FCTRL;
3292*4882a593Smuzhiyun /* find the fabric controller node */
3293*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, nportid);
3294*4882a593Smuzhiyun if (!ndlp) {
3295*4882a593Smuzhiyun /* if one didn't exist, make one */
3296*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, nportid);
3297*4882a593Smuzhiyun if (!ndlp)
3298*4882a593Smuzhiyun return 1;
3299*4882a593Smuzhiyun lpfc_enqueue_node(vport, ndlp);
3300*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3301*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp,
3302*4882a593Smuzhiyun NLP_STE_UNUSED_NODE);
3303*4882a593Smuzhiyun if (!ndlp)
3304*4882a593Smuzhiyun return 1;
3305*4882a593Smuzhiyun }
3306*4882a593Smuzhiyun }
3307*4882a593Smuzhiyun
3308*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3309*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_RSCN_XMT);
3310*4882a593Smuzhiyun
3311*4882a593Smuzhiyun if (!elsiocb) {
3312*4882a593Smuzhiyun /* This will trigger the release of the node just
3313*4882a593Smuzhiyun * allocated
3314*4882a593Smuzhiyun */
3315*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3316*4882a593Smuzhiyun return 1;
3317*4882a593Smuzhiyun }
3318*4882a593Smuzhiyun
3319*4882a593Smuzhiyun event = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3320*4882a593Smuzhiyun
3321*4882a593Smuzhiyun event->rscn.rscn_cmd = ELS_RSCN;
3322*4882a593Smuzhiyun event->rscn.rscn_page_len = sizeof(struct fc_els_rscn_page);
3323*4882a593Smuzhiyun event->rscn.rscn_plen = cpu_to_be16(cmdsize);
3324*4882a593Smuzhiyun
3325*4882a593Smuzhiyun nportid = vport->fc_myDID;
3326*4882a593Smuzhiyun /* appears that page flags must be 0 for fabric to broadcast RSCN */
3327*4882a593Smuzhiyun event->portid.rscn_page_flags = 0;
3328*4882a593Smuzhiyun event->portid.rscn_fid[0] = (nportid & 0x00FF0000) >> 16;
3329*4882a593Smuzhiyun event->portid.rscn_fid[1] = (nportid & 0x0000FF00) >> 8;
3330*4882a593Smuzhiyun event->portid.rscn_fid[2] = nportid & 0x000000FF;
3331*4882a593Smuzhiyun
3332*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3333*4882a593Smuzhiyun "Issue RSCN: did:x%x",
3334*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
3335*4882a593Smuzhiyun
3336*4882a593Smuzhiyun phba->fc_stat.elsXmitRSCN++;
3337*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3338*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3339*4882a593Smuzhiyun IOCB_ERROR) {
3340*4882a593Smuzhiyun /* The additional lpfc_nlp_put will cause the following
3341*4882a593Smuzhiyun * lpfc_els_free_iocb routine to trigger the rlease of
3342*4882a593Smuzhiyun * the node.
3343*4882a593Smuzhiyun */
3344*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3345*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
3346*4882a593Smuzhiyun return 1;
3347*4882a593Smuzhiyun }
3348*4882a593Smuzhiyun /* This will cause the callback-function lpfc_cmpl_els_cmd to
3349*4882a593Smuzhiyun * trigger the release of node.
3350*4882a593Smuzhiyun */
3351*4882a593Smuzhiyun if (!(vport->fc_flag & FC_PT2PT))
3352*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3353*4882a593Smuzhiyun
3354*4882a593Smuzhiyun return 0;
3355*4882a593Smuzhiyun }
3356*4882a593Smuzhiyun
3357*4882a593Smuzhiyun /**
3358*4882a593Smuzhiyun * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3359*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
3360*4882a593Smuzhiyun * @nportid: N_Port identifier to the remote node.
3361*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
3362*4882a593Smuzhiyun *
3363*4882a593Smuzhiyun * This routine issues a Fibre Channel Address Resolution Response
3364*4882a593Smuzhiyun * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3365*4882a593Smuzhiyun * is passed into the function. It first search the @vport node list to find
3366*4882a593Smuzhiyun * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3367*4882a593Smuzhiyun * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3368*4882a593Smuzhiyun * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3369*4882a593Smuzhiyun *
3370*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3371*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
3372*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
3373*4882a593Smuzhiyun * callback function to the PARPR ELS command.
3374*4882a593Smuzhiyun *
3375*4882a593Smuzhiyun * Return code
3376*4882a593Smuzhiyun * 0 - Successfully issued farpr command
3377*4882a593Smuzhiyun * 1 - Failed to issue farpr command
3378*4882a593Smuzhiyun **/
3379*4882a593Smuzhiyun static int
lpfc_issue_els_farpr(struct lpfc_vport * vport,uint32_t nportid,uint8_t retry)3380*4882a593Smuzhiyun lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
3381*4882a593Smuzhiyun {
3382*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
3383*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
3384*4882a593Smuzhiyun FARP *fp;
3385*4882a593Smuzhiyun uint8_t *pcmd;
3386*4882a593Smuzhiyun uint32_t *lp;
3387*4882a593Smuzhiyun uint16_t cmdsize;
3388*4882a593Smuzhiyun struct lpfc_nodelist *ondlp;
3389*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
3390*4882a593Smuzhiyun
3391*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(FARP));
3392*4882a593Smuzhiyun
3393*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, nportid);
3394*4882a593Smuzhiyun if (!ndlp) {
3395*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, nportid);
3396*4882a593Smuzhiyun if (!ndlp)
3397*4882a593Smuzhiyun return 1;
3398*4882a593Smuzhiyun lpfc_enqueue_node(vport, ndlp);
3399*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3400*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3401*4882a593Smuzhiyun if (!ndlp)
3402*4882a593Smuzhiyun return 1;
3403*4882a593Smuzhiyun }
3404*4882a593Smuzhiyun
3405*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3406*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_RNID);
3407*4882a593Smuzhiyun if (!elsiocb) {
3408*4882a593Smuzhiyun /* This will trigger the release of the node just
3409*4882a593Smuzhiyun * allocated
3410*4882a593Smuzhiyun */
3411*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3412*4882a593Smuzhiyun return 1;
3413*4882a593Smuzhiyun }
3414*4882a593Smuzhiyun
3415*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3416*4882a593Smuzhiyun
3417*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
3418*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
3419*4882a593Smuzhiyun
3420*4882a593Smuzhiyun /* Fill in FARPR payload */
3421*4882a593Smuzhiyun fp = (FARP *) (pcmd);
3422*4882a593Smuzhiyun memset(fp, 0, sizeof(FARP));
3423*4882a593Smuzhiyun lp = (uint32_t *) pcmd;
3424*4882a593Smuzhiyun *lp++ = be32_to_cpu(nportid);
3425*4882a593Smuzhiyun *lp++ = be32_to_cpu(vport->fc_myDID);
3426*4882a593Smuzhiyun fp->Rflags = 0;
3427*4882a593Smuzhiyun fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
3428*4882a593Smuzhiyun
3429*4882a593Smuzhiyun memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
3430*4882a593Smuzhiyun memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3431*4882a593Smuzhiyun ondlp = lpfc_findnode_did(vport, nportid);
3432*4882a593Smuzhiyun if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
3433*4882a593Smuzhiyun memcpy(&fp->OportName, &ondlp->nlp_portname,
3434*4882a593Smuzhiyun sizeof(struct lpfc_name));
3435*4882a593Smuzhiyun memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
3436*4882a593Smuzhiyun sizeof(struct lpfc_name));
3437*4882a593Smuzhiyun }
3438*4882a593Smuzhiyun
3439*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3440*4882a593Smuzhiyun "Issue FARPR: did:x%x",
3441*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
3442*4882a593Smuzhiyun
3443*4882a593Smuzhiyun phba->fc_stat.elsXmitFARPR++;
3444*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
3445*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3446*4882a593Smuzhiyun IOCB_ERROR) {
3447*4882a593Smuzhiyun /* The additional lpfc_nlp_put will cause the following
3448*4882a593Smuzhiyun * lpfc_els_free_iocb routine to trigger the release of
3449*4882a593Smuzhiyun * the node.
3450*4882a593Smuzhiyun */
3451*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3452*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
3453*4882a593Smuzhiyun return 1;
3454*4882a593Smuzhiyun }
3455*4882a593Smuzhiyun /* This will cause the callback-function lpfc_cmpl_els_cmd to
3456*4882a593Smuzhiyun * trigger the release of the node.
3457*4882a593Smuzhiyun */
3458*4882a593Smuzhiyun /* Don't release reference count as RDF is likely outstanding */
3459*4882a593Smuzhiyun return 0;
3460*4882a593Smuzhiyun }
3461*4882a593Smuzhiyun
3462*4882a593Smuzhiyun /**
3463*4882a593Smuzhiyun * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3464*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
3465*4882a593Smuzhiyun * @retry: retry counter for the command IOCB.
3466*4882a593Smuzhiyun *
3467*4882a593Smuzhiyun * This routine issues an ELS RDF to the Fabric Controller to register
3468*4882a593Smuzhiyun * for diagnostic functions.
3469*4882a593Smuzhiyun *
3470*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3471*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
3472*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
3473*4882a593Smuzhiyun * callback function to the RDF ELS command.
3474*4882a593Smuzhiyun *
3475*4882a593Smuzhiyun * Return code
3476*4882a593Smuzhiyun * 0 - Successfully issued rdf command
3477*4882a593Smuzhiyun * 1 - Failed to issue rdf command
3478*4882a593Smuzhiyun **/
3479*4882a593Smuzhiyun int
lpfc_issue_els_rdf(struct lpfc_vport * vport,uint8_t retry)3480*4882a593Smuzhiyun lpfc_issue_els_rdf(struct lpfc_vport *vport, uint8_t retry)
3481*4882a593Smuzhiyun {
3482*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
3483*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
3484*4882a593Smuzhiyun struct lpfc_els_rdf_req *prdf;
3485*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
3486*4882a593Smuzhiyun uint16_t cmdsize;
3487*4882a593Smuzhiyun
3488*4882a593Smuzhiyun cmdsize = sizeof(*prdf);
3489*4882a593Smuzhiyun
3490*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, Fabric_Cntl_DID);
3491*4882a593Smuzhiyun if (!ndlp) {
3492*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, Fabric_Cntl_DID);
3493*4882a593Smuzhiyun if (!ndlp)
3494*4882a593Smuzhiyun return -ENODEV;
3495*4882a593Smuzhiyun lpfc_enqueue_node(vport, ndlp);
3496*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
3497*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
3498*4882a593Smuzhiyun if (!ndlp)
3499*4882a593Smuzhiyun return -ENODEV;
3500*4882a593Smuzhiyun }
3501*4882a593Smuzhiyun
3502*4882a593Smuzhiyun /* RDF ELS is not required on an NPIV VN_Port. */
3503*4882a593Smuzhiyun if (vport->port_type == LPFC_NPIV_PORT) {
3504*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3505*4882a593Smuzhiyun return -EACCES;
3506*4882a593Smuzhiyun }
3507*4882a593Smuzhiyun
3508*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
3509*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_RDF);
3510*4882a593Smuzhiyun if (!elsiocb) {
3511*4882a593Smuzhiyun /* This will trigger the release of the node just
3512*4882a593Smuzhiyun * allocated
3513*4882a593Smuzhiyun */
3514*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3515*4882a593Smuzhiyun return -ENOMEM;
3516*4882a593Smuzhiyun }
3517*4882a593Smuzhiyun
3518*4882a593Smuzhiyun /* Configure the payload for the supported FPIN events. */
3519*4882a593Smuzhiyun prdf = (struct lpfc_els_rdf_req *)
3520*4882a593Smuzhiyun (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
3521*4882a593Smuzhiyun memset(prdf, 0, cmdsize);
3522*4882a593Smuzhiyun prdf->rdf.fpin_cmd = ELS_RDF;
3523*4882a593Smuzhiyun prdf->rdf.desc_len = cpu_to_be32(sizeof(struct lpfc_els_rdf_req) -
3524*4882a593Smuzhiyun sizeof(struct fc_els_rdf));
3525*4882a593Smuzhiyun prdf->reg_d1.reg_desc.desc_tag = cpu_to_be32(ELS_DTAG_FPIN_REGISTER);
3526*4882a593Smuzhiyun prdf->reg_d1.reg_desc.desc_len = cpu_to_be32(
3527*4882a593Smuzhiyun FC_TLV_DESC_LENGTH_FROM_SZ(prdf->reg_d1));
3528*4882a593Smuzhiyun prdf->reg_d1.reg_desc.count = cpu_to_be32(ELS_RDF_REG_TAG_CNT);
3529*4882a593Smuzhiyun prdf->reg_d1.desc_tags[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY);
3530*4882a593Smuzhiyun prdf->reg_d1.desc_tags[1] = cpu_to_be32(ELS_DTAG_DELIVERY);
3531*4882a593Smuzhiyun prdf->reg_d1.desc_tags[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST);
3532*4882a593Smuzhiyun prdf->reg_d1.desc_tags[3] = cpu_to_be32(ELS_DTAG_CONGESTION);
3533*4882a593Smuzhiyun
3534*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3535*4882a593Smuzhiyun "Issue RDF: did:x%x",
3536*4882a593Smuzhiyun ndlp->nlp_DID, 0, 0);
3537*4882a593Smuzhiyun
3538*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3539*4882a593Smuzhiyun "6444 Xmit RDF to remote NPORT x%x\n",
3540*4882a593Smuzhiyun ndlp->nlp_DID);
3541*4882a593Smuzhiyun
3542*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_disc_cmd;
3543*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
3544*4882a593Smuzhiyun IOCB_ERROR) {
3545*4882a593Smuzhiyun /* The additional lpfc_nlp_put will cause the following
3546*4882a593Smuzhiyun * lpfc_els_free_iocb routine to trigger the rlease of
3547*4882a593Smuzhiyun * the node.
3548*4882a593Smuzhiyun */
3549*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3550*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
3551*4882a593Smuzhiyun return -EIO;
3552*4882a593Smuzhiyun }
3553*4882a593Smuzhiyun
3554*4882a593Smuzhiyun /* An RDF was issued - this put ensures the ndlp is cleaned up
3555*4882a593Smuzhiyun * when the RDF completes.
3556*4882a593Smuzhiyun */
3557*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
3558*4882a593Smuzhiyun return 0;
3559*4882a593Smuzhiyun }
3560*4882a593Smuzhiyun
3561*4882a593Smuzhiyun /**
3562*4882a593Smuzhiyun * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3563*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
3564*4882a593Smuzhiyun * @nlp: pointer to a node-list data structure.
3565*4882a593Smuzhiyun *
3566*4882a593Smuzhiyun * This routine cancels the timer with a delayed IOCB-command retry for
3567*4882a593Smuzhiyun * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3568*4882a593Smuzhiyun * removes the ELS retry event if it presents. In addition, if the
3569*4882a593Smuzhiyun * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3570*4882a593Smuzhiyun * commands are sent for the @vport's nodes that require issuing discovery
3571*4882a593Smuzhiyun * ADISC.
3572*4882a593Smuzhiyun **/
3573*4882a593Smuzhiyun void
lpfc_cancel_retry_delay_tmo(struct lpfc_vport * vport,struct lpfc_nodelist * nlp)3574*4882a593Smuzhiyun lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
3575*4882a593Smuzhiyun {
3576*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3577*4882a593Smuzhiyun struct lpfc_work_evt *evtp;
3578*4882a593Smuzhiyun
3579*4882a593Smuzhiyun if (!(nlp->nlp_flag & NLP_DELAY_TMO))
3580*4882a593Smuzhiyun return;
3581*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
3582*4882a593Smuzhiyun nlp->nlp_flag &= ~NLP_DELAY_TMO;
3583*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3584*4882a593Smuzhiyun del_timer_sync(&nlp->nlp_delayfunc);
3585*4882a593Smuzhiyun nlp->nlp_last_elscmd = 0;
3586*4882a593Smuzhiyun if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
3587*4882a593Smuzhiyun list_del_init(&nlp->els_retry_evt.evt_listp);
3588*4882a593Smuzhiyun /* Decrement nlp reference count held for the delayed retry */
3589*4882a593Smuzhiyun evtp = &nlp->els_retry_evt;
3590*4882a593Smuzhiyun lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
3591*4882a593Smuzhiyun }
3592*4882a593Smuzhiyun if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
3593*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
3594*4882a593Smuzhiyun nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
3595*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3596*4882a593Smuzhiyun if (vport->num_disc_nodes) {
3597*4882a593Smuzhiyun if (vport->port_state < LPFC_VPORT_READY) {
3598*4882a593Smuzhiyun /* Check if there are more ADISCs to be sent */
3599*4882a593Smuzhiyun lpfc_more_adisc(vport);
3600*4882a593Smuzhiyun } else {
3601*4882a593Smuzhiyun /* Check if there are more PLOGIs to be sent */
3602*4882a593Smuzhiyun lpfc_more_plogi(vport);
3603*4882a593Smuzhiyun if (vport->num_disc_nodes == 0) {
3604*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
3605*4882a593Smuzhiyun vport->fc_flag &= ~FC_NDISC_ACTIVE;
3606*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3607*4882a593Smuzhiyun lpfc_can_disctmo(vport);
3608*4882a593Smuzhiyun lpfc_end_rscn(vport);
3609*4882a593Smuzhiyun }
3610*4882a593Smuzhiyun }
3611*4882a593Smuzhiyun }
3612*4882a593Smuzhiyun }
3613*4882a593Smuzhiyun return;
3614*4882a593Smuzhiyun }
3615*4882a593Smuzhiyun
3616*4882a593Smuzhiyun /**
3617*4882a593Smuzhiyun * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3618*4882a593Smuzhiyun * @t: pointer to the timer function associated data (ndlp).
3619*4882a593Smuzhiyun *
3620*4882a593Smuzhiyun * This routine is invoked by the ndlp delayed-function timer to check
3621*4882a593Smuzhiyun * whether there is any pending ELS retry event(s) with the node. If not, it
3622*4882a593Smuzhiyun * simply returns. Otherwise, if there is at least one ELS delayed event, it
3623*4882a593Smuzhiyun * adds the delayed events to the HBA work list and invokes the
3624*4882a593Smuzhiyun * lpfc_worker_wake_up() routine to wake up worker thread to process the
3625*4882a593Smuzhiyun * event. Note that lpfc_nlp_get() is called before posting the event to
3626*4882a593Smuzhiyun * the work list to hold reference count of ndlp so that it guarantees the
3627*4882a593Smuzhiyun * reference to ndlp will still be available when the worker thread gets
3628*4882a593Smuzhiyun * to the event associated with the ndlp.
3629*4882a593Smuzhiyun **/
3630*4882a593Smuzhiyun void
lpfc_els_retry_delay(struct timer_list * t)3631*4882a593Smuzhiyun lpfc_els_retry_delay(struct timer_list *t)
3632*4882a593Smuzhiyun {
3633*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = from_timer(ndlp, t, nlp_delayfunc);
3634*4882a593Smuzhiyun struct lpfc_vport *vport = ndlp->vport;
3635*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
3636*4882a593Smuzhiyun unsigned long flags;
3637*4882a593Smuzhiyun struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
3638*4882a593Smuzhiyun
3639*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, flags);
3640*4882a593Smuzhiyun if (!list_empty(&evtp->evt_listp)) {
3641*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, flags);
3642*4882a593Smuzhiyun return;
3643*4882a593Smuzhiyun }
3644*4882a593Smuzhiyun
3645*4882a593Smuzhiyun /* We need to hold the node by incrementing the reference
3646*4882a593Smuzhiyun * count until the queued work is done
3647*4882a593Smuzhiyun */
3648*4882a593Smuzhiyun evtp->evt_arg1 = lpfc_nlp_get(ndlp);
3649*4882a593Smuzhiyun if (evtp->evt_arg1) {
3650*4882a593Smuzhiyun evtp->evt = LPFC_EVT_ELS_RETRY;
3651*4882a593Smuzhiyun list_add_tail(&evtp->evt_listp, &phba->work_list);
3652*4882a593Smuzhiyun lpfc_worker_wake_up(phba);
3653*4882a593Smuzhiyun }
3654*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, flags);
3655*4882a593Smuzhiyun return;
3656*4882a593Smuzhiyun }
3657*4882a593Smuzhiyun
3658*4882a593Smuzhiyun /**
3659*4882a593Smuzhiyun * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3660*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
3661*4882a593Smuzhiyun *
3662*4882a593Smuzhiyun * This routine is the worker-thread handler for processing the @ndlp delayed
3663*4882a593Smuzhiyun * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3664*4882a593Smuzhiyun * the last ELS command from the associated ndlp and invokes the proper ELS
3665*4882a593Smuzhiyun * function according to the delayed ELS command to retry the command.
3666*4882a593Smuzhiyun **/
3667*4882a593Smuzhiyun void
lpfc_els_retry_delay_handler(struct lpfc_nodelist * ndlp)3668*4882a593Smuzhiyun lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3669*4882a593Smuzhiyun {
3670*4882a593Smuzhiyun struct lpfc_vport *vport = ndlp->vport;
3671*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3672*4882a593Smuzhiyun uint32_t cmd, retry;
3673*4882a593Smuzhiyun
3674*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
3675*4882a593Smuzhiyun cmd = ndlp->nlp_last_elscmd;
3676*4882a593Smuzhiyun ndlp->nlp_last_elscmd = 0;
3677*4882a593Smuzhiyun
3678*4882a593Smuzhiyun if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
3679*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3680*4882a593Smuzhiyun return;
3681*4882a593Smuzhiyun }
3682*4882a593Smuzhiyun
3683*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_DELAY_TMO;
3684*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
3685*4882a593Smuzhiyun /*
3686*4882a593Smuzhiyun * If a discovery event readded nlp_delayfunc after timer
3687*4882a593Smuzhiyun * firing and before processing the timer, cancel the
3688*4882a593Smuzhiyun * nlp_delayfunc.
3689*4882a593Smuzhiyun */
3690*4882a593Smuzhiyun del_timer_sync(&ndlp->nlp_delayfunc);
3691*4882a593Smuzhiyun retry = ndlp->nlp_retry;
3692*4882a593Smuzhiyun ndlp->nlp_retry = 0;
3693*4882a593Smuzhiyun
3694*4882a593Smuzhiyun switch (cmd) {
3695*4882a593Smuzhiyun case ELS_CMD_FLOGI:
3696*4882a593Smuzhiyun lpfc_issue_els_flogi(vport, ndlp, retry);
3697*4882a593Smuzhiyun break;
3698*4882a593Smuzhiyun case ELS_CMD_PLOGI:
3699*4882a593Smuzhiyun if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
3700*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
3701*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3702*4882a593Smuzhiyun }
3703*4882a593Smuzhiyun break;
3704*4882a593Smuzhiyun case ELS_CMD_ADISC:
3705*4882a593Smuzhiyun if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
3706*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
3707*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3708*4882a593Smuzhiyun }
3709*4882a593Smuzhiyun break;
3710*4882a593Smuzhiyun case ELS_CMD_PRLI:
3711*4882a593Smuzhiyun case ELS_CMD_NVMEPRLI:
3712*4882a593Smuzhiyun if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
3713*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
3714*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3715*4882a593Smuzhiyun }
3716*4882a593Smuzhiyun break;
3717*4882a593Smuzhiyun case ELS_CMD_LOGO:
3718*4882a593Smuzhiyun if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
3719*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
3720*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
3721*4882a593Smuzhiyun }
3722*4882a593Smuzhiyun break;
3723*4882a593Smuzhiyun case ELS_CMD_FDISC:
3724*4882a593Smuzhiyun if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3725*4882a593Smuzhiyun lpfc_issue_els_fdisc(vport, ndlp, retry);
3726*4882a593Smuzhiyun break;
3727*4882a593Smuzhiyun }
3728*4882a593Smuzhiyun return;
3729*4882a593Smuzhiyun }
3730*4882a593Smuzhiyun
3731*4882a593Smuzhiyun /**
3732*4882a593Smuzhiyun * lpfc_link_reset - Issue link reset
3733*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
3734*4882a593Smuzhiyun *
3735*4882a593Smuzhiyun * This routine performs link reset by sending INIT_LINK mailbox command.
3736*4882a593Smuzhiyun * For SLI-3 adapter, link attention interrupt is enabled before issuing
3737*4882a593Smuzhiyun * INIT_LINK mailbox command.
3738*4882a593Smuzhiyun *
3739*4882a593Smuzhiyun * Return code
3740*4882a593Smuzhiyun * 0 - Link reset initiated successfully
3741*4882a593Smuzhiyun * 1 - Failed to initiate link reset
3742*4882a593Smuzhiyun **/
3743*4882a593Smuzhiyun int
lpfc_link_reset(struct lpfc_vport * vport)3744*4882a593Smuzhiyun lpfc_link_reset(struct lpfc_vport *vport)
3745*4882a593Smuzhiyun {
3746*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
3747*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
3748*4882a593Smuzhiyun uint32_t control;
3749*4882a593Smuzhiyun int rc;
3750*4882a593Smuzhiyun
3751*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3752*4882a593Smuzhiyun "2851 Attempt link reset\n");
3753*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3754*4882a593Smuzhiyun if (!mbox) {
3755*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3756*4882a593Smuzhiyun "2852 Failed to allocate mbox memory");
3757*4882a593Smuzhiyun return 1;
3758*4882a593Smuzhiyun }
3759*4882a593Smuzhiyun
3760*4882a593Smuzhiyun /* Enable Link attention interrupts */
3761*4882a593Smuzhiyun if (phba->sli_rev <= LPFC_SLI_REV3) {
3762*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
3763*4882a593Smuzhiyun phba->sli.sli_flag |= LPFC_PROCESS_LA;
3764*4882a593Smuzhiyun control = readl(phba->HCregaddr);
3765*4882a593Smuzhiyun control |= HC_LAINT_ENA;
3766*4882a593Smuzhiyun writel(control, phba->HCregaddr);
3767*4882a593Smuzhiyun readl(phba->HCregaddr); /* flush */
3768*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
3769*4882a593Smuzhiyun }
3770*4882a593Smuzhiyun
3771*4882a593Smuzhiyun lpfc_init_link(phba, mbox, phba->cfg_topology,
3772*4882a593Smuzhiyun phba->cfg_link_speed);
3773*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3774*4882a593Smuzhiyun mbox->vport = vport;
3775*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3776*4882a593Smuzhiyun if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
3777*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
3778*4882a593Smuzhiyun "2853 Failed to issue INIT_LINK "
3779*4882a593Smuzhiyun "mbox command, rc:x%x\n", rc);
3780*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
3781*4882a593Smuzhiyun return 1;
3782*4882a593Smuzhiyun }
3783*4882a593Smuzhiyun
3784*4882a593Smuzhiyun return 0;
3785*4882a593Smuzhiyun }
3786*4882a593Smuzhiyun
3787*4882a593Smuzhiyun /**
3788*4882a593Smuzhiyun * lpfc_els_retry - Make retry decision on an els command iocb
3789*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
3790*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
3791*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
3792*4882a593Smuzhiyun *
3793*4882a593Smuzhiyun * This routine makes a retry decision on an ELS command IOCB, which has
3794*4882a593Smuzhiyun * failed. The following ELS IOCBs use this function for retrying the command
3795*4882a593Smuzhiyun * when previously issued command responsed with error status: FLOGI, PLOGI,
3796*4882a593Smuzhiyun * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3797*4882a593Smuzhiyun * returned error status, it makes the decision whether a retry shall be
3798*4882a593Smuzhiyun * issued for the command, and whether a retry shall be made immediately or
3799*4882a593Smuzhiyun * delayed. In the former case, the corresponding ELS command issuing-function
3800*4882a593Smuzhiyun * is called to retry the command. In the later case, the ELS command shall
3801*4882a593Smuzhiyun * be posted to the ndlp delayed event and delayed function timer set to the
3802*4882a593Smuzhiyun * ndlp for the delayed command issusing.
3803*4882a593Smuzhiyun *
3804*4882a593Smuzhiyun * Return code
3805*4882a593Smuzhiyun * 0 - No retry of els command is made
3806*4882a593Smuzhiyun * 1 - Immediate or delayed retry of els command is made
3807*4882a593Smuzhiyun **/
3808*4882a593Smuzhiyun static int
lpfc_els_retry(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)3809*4882a593Smuzhiyun lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3810*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
3811*4882a593Smuzhiyun {
3812*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
3813*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3814*4882a593Smuzhiyun IOCB_t *irsp = &rspiocb->iocb;
3815*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3816*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3817*4882a593Smuzhiyun uint32_t *elscmd;
3818*4882a593Smuzhiyun struct ls_rjt stat;
3819*4882a593Smuzhiyun int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
3820*4882a593Smuzhiyun int logerr = 0;
3821*4882a593Smuzhiyun uint32_t cmd = 0;
3822*4882a593Smuzhiyun uint32_t did;
3823*4882a593Smuzhiyun int link_reset = 0, rc;
3824*4882a593Smuzhiyun
3825*4882a593Smuzhiyun
3826*4882a593Smuzhiyun /* Note: context2 may be 0 for internal driver abort
3827*4882a593Smuzhiyun * of delays ELS command.
3828*4882a593Smuzhiyun */
3829*4882a593Smuzhiyun
3830*4882a593Smuzhiyun if (pcmd && pcmd->virt) {
3831*4882a593Smuzhiyun elscmd = (uint32_t *) (pcmd->virt);
3832*4882a593Smuzhiyun cmd = *elscmd++;
3833*4882a593Smuzhiyun }
3834*4882a593Smuzhiyun
3835*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp))
3836*4882a593Smuzhiyun did = ndlp->nlp_DID;
3837*4882a593Smuzhiyun else {
3838*4882a593Smuzhiyun /* We should only hit this case for retrying PLOGI */
3839*4882a593Smuzhiyun did = irsp->un.elsreq64.remoteID;
3840*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, did);
3841*4882a593Smuzhiyun if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3842*4882a593Smuzhiyun && (cmd != ELS_CMD_PLOGI))
3843*4882a593Smuzhiyun return 1;
3844*4882a593Smuzhiyun }
3845*4882a593Smuzhiyun
3846*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3847*4882a593Smuzhiyun "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3848*4882a593Smuzhiyun *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3849*4882a593Smuzhiyun
3850*4882a593Smuzhiyun switch (irsp->ulpStatus) {
3851*4882a593Smuzhiyun case IOSTAT_FCP_RSP_ERROR:
3852*4882a593Smuzhiyun break;
3853*4882a593Smuzhiyun case IOSTAT_REMOTE_STOP:
3854*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4) {
3855*4882a593Smuzhiyun /* This IO was aborted by the target, we don't
3856*4882a593Smuzhiyun * know the rxid and because we did not send the
3857*4882a593Smuzhiyun * ABTS we cannot generate and RRQ.
3858*4882a593Smuzhiyun */
3859*4882a593Smuzhiyun lpfc_set_rrq_active(phba, ndlp,
3860*4882a593Smuzhiyun cmdiocb->sli4_lxritag, 0, 0);
3861*4882a593Smuzhiyun }
3862*4882a593Smuzhiyun break;
3863*4882a593Smuzhiyun case IOSTAT_LOCAL_REJECT:
3864*4882a593Smuzhiyun switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
3865*4882a593Smuzhiyun case IOERR_LOOP_OPEN_FAILURE:
3866*4882a593Smuzhiyun if (cmd == ELS_CMD_FLOGI) {
3867*4882a593Smuzhiyun if (PCI_DEVICE_ID_HORNET ==
3868*4882a593Smuzhiyun phba->pcidev->device) {
3869*4882a593Smuzhiyun phba->fc_topology = LPFC_TOPOLOGY_LOOP;
3870*4882a593Smuzhiyun phba->pport->fc_myDID = 0;
3871*4882a593Smuzhiyun phba->alpa_map[0] = 0;
3872*4882a593Smuzhiyun phba->alpa_map[1] = 0;
3873*4882a593Smuzhiyun }
3874*4882a593Smuzhiyun }
3875*4882a593Smuzhiyun if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
3876*4882a593Smuzhiyun delay = 1000;
3877*4882a593Smuzhiyun retry = 1;
3878*4882a593Smuzhiyun break;
3879*4882a593Smuzhiyun
3880*4882a593Smuzhiyun case IOERR_ILLEGAL_COMMAND:
3881*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
3882*4882a593Smuzhiyun "0124 Retry illegal cmd x%x "
3883*4882a593Smuzhiyun "retry:x%x delay:x%x\n",
3884*4882a593Smuzhiyun cmd, cmdiocb->retry, delay);
3885*4882a593Smuzhiyun retry = 1;
3886*4882a593Smuzhiyun /* All command's retry policy */
3887*4882a593Smuzhiyun maxretry = 8;
3888*4882a593Smuzhiyun if (cmdiocb->retry > 2)
3889*4882a593Smuzhiyun delay = 1000;
3890*4882a593Smuzhiyun break;
3891*4882a593Smuzhiyun
3892*4882a593Smuzhiyun case IOERR_NO_RESOURCES:
3893*4882a593Smuzhiyun logerr = 1; /* HBA out of resources */
3894*4882a593Smuzhiyun retry = 1;
3895*4882a593Smuzhiyun if (cmdiocb->retry > 100)
3896*4882a593Smuzhiyun delay = 100;
3897*4882a593Smuzhiyun maxretry = 250;
3898*4882a593Smuzhiyun break;
3899*4882a593Smuzhiyun
3900*4882a593Smuzhiyun case IOERR_ILLEGAL_FRAME:
3901*4882a593Smuzhiyun delay = 100;
3902*4882a593Smuzhiyun retry = 1;
3903*4882a593Smuzhiyun break;
3904*4882a593Smuzhiyun
3905*4882a593Smuzhiyun case IOERR_INVALID_RPI:
3906*4882a593Smuzhiyun if (cmd == ELS_CMD_PLOGI &&
3907*4882a593Smuzhiyun did == NameServer_DID) {
3908*4882a593Smuzhiyun /* Continue forever if plogi to */
3909*4882a593Smuzhiyun /* the nameserver fails */
3910*4882a593Smuzhiyun maxretry = 0;
3911*4882a593Smuzhiyun delay = 100;
3912*4882a593Smuzhiyun }
3913*4882a593Smuzhiyun retry = 1;
3914*4882a593Smuzhiyun break;
3915*4882a593Smuzhiyun
3916*4882a593Smuzhiyun case IOERR_SEQUENCE_TIMEOUT:
3917*4882a593Smuzhiyun if (cmd == ELS_CMD_PLOGI &&
3918*4882a593Smuzhiyun did == NameServer_DID &&
3919*4882a593Smuzhiyun (cmdiocb->retry + 1) == maxretry) {
3920*4882a593Smuzhiyun /* Reset the Link */
3921*4882a593Smuzhiyun link_reset = 1;
3922*4882a593Smuzhiyun break;
3923*4882a593Smuzhiyun }
3924*4882a593Smuzhiyun retry = 1;
3925*4882a593Smuzhiyun delay = 100;
3926*4882a593Smuzhiyun break;
3927*4882a593Smuzhiyun }
3928*4882a593Smuzhiyun break;
3929*4882a593Smuzhiyun
3930*4882a593Smuzhiyun case IOSTAT_NPORT_RJT:
3931*4882a593Smuzhiyun case IOSTAT_FABRIC_RJT:
3932*4882a593Smuzhiyun if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3933*4882a593Smuzhiyun retry = 1;
3934*4882a593Smuzhiyun break;
3935*4882a593Smuzhiyun }
3936*4882a593Smuzhiyun break;
3937*4882a593Smuzhiyun
3938*4882a593Smuzhiyun case IOSTAT_NPORT_BSY:
3939*4882a593Smuzhiyun case IOSTAT_FABRIC_BSY:
3940*4882a593Smuzhiyun logerr = 1; /* Fabric / Remote NPort out of resources */
3941*4882a593Smuzhiyun retry = 1;
3942*4882a593Smuzhiyun break;
3943*4882a593Smuzhiyun
3944*4882a593Smuzhiyun case IOSTAT_LS_RJT:
3945*4882a593Smuzhiyun stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3946*4882a593Smuzhiyun /* Added for Vendor specifc support
3947*4882a593Smuzhiyun * Just keep retrying for these Rsn / Exp codes
3948*4882a593Smuzhiyun */
3949*4882a593Smuzhiyun if ((vport->fc_flag & FC_PT2PT) &&
3950*4882a593Smuzhiyun cmd == ELS_CMD_NVMEPRLI) {
3951*4882a593Smuzhiyun switch (stat.un.b.lsRjtRsnCode) {
3952*4882a593Smuzhiyun case LSRJT_UNABLE_TPC:
3953*4882a593Smuzhiyun case LSRJT_INVALID_CMD:
3954*4882a593Smuzhiyun case LSRJT_LOGICAL_ERR:
3955*4882a593Smuzhiyun case LSRJT_CMD_UNSUPPORTED:
3956*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_WARNING, LOG_ELS,
3957*4882a593Smuzhiyun "0168 NVME PRLI LS_RJT "
3958*4882a593Smuzhiyun "reason %x port doesn't "
3959*4882a593Smuzhiyun "support NVME, disabling NVME\n",
3960*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode);
3961*4882a593Smuzhiyun retry = 0;
3962*4882a593Smuzhiyun vport->fc_flag |= FC_PT2PT_NO_NVME;
3963*4882a593Smuzhiyun goto out_retry;
3964*4882a593Smuzhiyun }
3965*4882a593Smuzhiyun }
3966*4882a593Smuzhiyun switch (stat.un.b.lsRjtRsnCode) {
3967*4882a593Smuzhiyun case LSRJT_UNABLE_TPC:
3968*4882a593Smuzhiyun /* The driver has a VALID PLOGI but the rport has
3969*4882a593Smuzhiyun * rejected the PRLI - can't do it now. Delay
3970*4882a593Smuzhiyun * for 1 second and try again.
3971*4882a593Smuzhiyun *
3972*4882a593Smuzhiyun * However, if explanation is REQ_UNSUPPORTED there's
3973*4882a593Smuzhiyun * no point to retry PRLI.
3974*4882a593Smuzhiyun */
3975*4882a593Smuzhiyun if ((cmd == ELS_CMD_PRLI || cmd == ELS_CMD_NVMEPRLI) &&
3976*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp !=
3977*4882a593Smuzhiyun LSEXP_REQ_UNSUPPORTED) {
3978*4882a593Smuzhiyun delay = 1000;
3979*4882a593Smuzhiyun maxretry = lpfc_max_els_tries + 1;
3980*4882a593Smuzhiyun retry = 1;
3981*4882a593Smuzhiyun break;
3982*4882a593Smuzhiyun }
3983*4882a593Smuzhiyun
3984*4882a593Smuzhiyun /* Legacy bug fix code for targets with PLOGI delays. */
3985*4882a593Smuzhiyun if (stat.un.b.lsRjtRsnCodeExp ==
3986*4882a593Smuzhiyun LSEXP_CMD_IN_PROGRESS) {
3987*4882a593Smuzhiyun if (cmd == ELS_CMD_PLOGI) {
3988*4882a593Smuzhiyun delay = 1000;
3989*4882a593Smuzhiyun maxretry = 48;
3990*4882a593Smuzhiyun }
3991*4882a593Smuzhiyun retry = 1;
3992*4882a593Smuzhiyun break;
3993*4882a593Smuzhiyun }
3994*4882a593Smuzhiyun if (stat.un.b.lsRjtRsnCodeExp ==
3995*4882a593Smuzhiyun LSEXP_CANT_GIVE_DATA) {
3996*4882a593Smuzhiyun if (cmd == ELS_CMD_PLOGI) {
3997*4882a593Smuzhiyun delay = 1000;
3998*4882a593Smuzhiyun maxretry = 48;
3999*4882a593Smuzhiyun }
4000*4882a593Smuzhiyun retry = 1;
4001*4882a593Smuzhiyun break;
4002*4882a593Smuzhiyun }
4003*4882a593Smuzhiyun if (cmd == ELS_CMD_PLOGI) {
4004*4882a593Smuzhiyun delay = 1000;
4005*4882a593Smuzhiyun maxretry = lpfc_max_els_tries + 1;
4006*4882a593Smuzhiyun retry = 1;
4007*4882a593Smuzhiyun break;
4008*4882a593Smuzhiyun }
4009*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4010*4882a593Smuzhiyun (cmd == ELS_CMD_FDISC) &&
4011*4882a593Smuzhiyun (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
4012*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR,
4013*4882a593Smuzhiyun LOG_TRACE_EVENT,
4014*4882a593Smuzhiyun "0125 FDISC Failed (x%x). "
4015*4882a593Smuzhiyun "Fabric out of resources\n",
4016*4882a593Smuzhiyun stat.un.lsRjtError);
4017*4882a593Smuzhiyun lpfc_vport_set_state(vport,
4018*4882a593Smuzhiyun FC_VPORT_NO_FABRIC_RSCS);
4019*4882a593Smuzhiyun }
4020*4882a593Smuzhiyun break;
4021*4882a593Smuzhiyun
4022*4882a593Smuzhiyun case LSRJT_LOGICAL_BSY:
4023*4882a593Smuzhiyun if ((cmd == ELS_CMD_PLOGI) ||
4024*4882a593Smuzhiyun (cmd == ELS_CMD_PRLI) ||
4025*4882a593Smuzhiyun (cmd == ELS_CMD_NVMEPRLI)) {
4026*4882a593Smuzhiyun delay = 1000;
4027*4882a593Smuzhiyun maxretry = 48;
4028*4882a593Smuzhiyun } else if (cmd == ELS_CMD_FDISC) {
4029*4882a593Smuzhiyun /* FDISC retry policy */
4030*4882a593Smuzhiyun maxretry = 48;
4031*4882a593Smuzhiyun if (cmdiocb->retry >= 32)
4032*4882a593Smuzhiyun delay = 1000;
4033*4882a593Smuzhiyun }
4034*4882a593Smuzhiyun retry = 1;
4035*4882a593Smuzhiyun break;
4036*4882a593Smuzhiyun
4037*4882a593Smuzhiyun case LSRJT_LOGICAL_ERR:
4038*4882a593Smuzhiyun /* There are some cases where switches return this
4039*4882a593Smuzhiyun * error when they are not ready and should be returning
4040*4882a593Smuzhiyun * Logical Busy. We should delay every time.
4041*4882a593Smuzhiyun */
4042*4882a593Smuzhiyun if (cmd == ELS_CMD_FDISC &&
4043*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
4044*4882a593Smuzhiyun maxretry = 3;
4045*4882a593Smuzhiyun delay = 1000;
4046*4882a593Smuzhiyun retry = 1;
4047*4882a593Smuzhiyun } else if (cmd == ELS_CMD_FLOGI &&
4048*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp ==
4049*4882a593Smuzhiyun LSEXP_NOTHING_MORE) {
4050*4882a593Smuzhiyun vport->fc_sparam.cmn.bbRcvSizeMsb &= 0xf;
4051*4882a593Smuzhiyun retry = 1;
4052*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR,
4053*4882a593Smuzhiyun LOG_TRACE_EVENT,
4054*4882a593Smuzhiyun "0820 FLOGI Failed (x%x). "
4055*4882a593Smuzhiyun "BBCredit Not Supported\n",
4056*4882a593Smuzhiyun stat.un.lsRjtError);
4057*4882a593Smuzhiyun }
4058*4882a593Smuzhiyun break;
4059*4882a593Smuzhiyun
4060*4882a593Smuzhiyun case LSRJT_PROTOCOL_ERR:
4061*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4062*4882a593Smuzhiyun (cmd == ELS_CMD_FDISC) &&
4063*4882a593Smuzhiyun ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
4064*4882a593Smuzhiyun (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
4065*4882a593Smuzhiyun ) {
4066*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR,
4067*4882a593Smuzhiyun LOG_TRACE_EVENT,
4068*4882a593Smuzhiyun "0122 FDISC Failed (x%x). "
4069*4882a593Smuzhiyun "Fabric Detected Bad WWN\n",
4070*4882a593Smuzhiyun stat.un.lsRjtError);
4071*4882a593Smuzhiyun lpfc_vport_set_state(vport,
4072*4882a593Smuzhiyun FC_VPORT_FABRIC_REJ_WWN);
4073*4882a593Smuzhiyun }
4074*4882a593Smuzhiyun break;
4075*4882a593Smuzhiyun case LSRJT_VENDOR_UNIQUE:
4076*4882a593Smuzhiyun if ((stat.un.b.vendorUnique == 0x45) &&
4077*4882a593Smuzhiyun (cmd == ELS_CMD_FLOGI)) {
4078*4882a593Smuzhiyun goto out_retry;
4079*4882a593Smuzhiyun }
4080*4882a593Smuzhiyun break;
4081*4882a593Smuzhiyun case LSRJT_CMD_UNSUPPORTED:
4082*4882a593Smuzhiyun /* lpfc nvmet returns this type of LS_RJT when it
4083*4882a593Smuzhiyun * receives an FCP PRLI because lpfc nvmet only
4084*4882a593Smuzhiyun * support NVME. ELS request is terminated for FCP4
4085*4882a593Smuzhiyun * on this rport.
4086*4882a593Smuzhiyun */
4087*4882a593Smuzhiyun if (stat.un.b.lsRjtRsnCodeExp ==
4088*4882a593Smuzhiyun LSEXP_REQ_UNSUPPORTED && cmd == ELS_CMD_PRLI) {
4089*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
4090*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_FCP_PRLI_RJT;
4091*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
4092*4882a593Smuzhiyun retry = 0;
4093*4882a593Smuzhiyun goto out_retry;
4094*4882a593Smuzhiyun }
4095*4882a593Smuzhiyun break;
4096*4882a593Smuzhiyun }
4097*4882a593Smuzhiyun break;
4098*4882a593Smuzhiyun
4099*4882a593Smuzhiyun case IOSTAT_INTERMED_RSP:
4100*4882a593Smuzhiyun case IOSTAT_BA_RJT:
4101*4882a593Smuzhiyun break;
4102*4882a593Smuzhiyun
4103*4882a593Smuzhiyun default:
4104*4882a593Smuzhiyun break;
4105*4882a593Smuzhiyun }
4106*4882a593Smuzhiyun
4107*4882a593Smuzhiyun if (link_reset) {
4108*4882a593Smuzhiyun rc = lpfc_link_reset(vport);
4109*4882a593Smuzhiyun if (rc) {
4110*4882a593Smuzhiyun /* Do not give up. Retry PLOGI one more time and attempt
4111*4882a593Smuzhiyun * link reset if PLOGI fails again.
4112*4882a593Smuzhiyun */
4113*4882a593Smuzhiyun retry = 1;
4114*4882a593Smuzhiyun delay = 100;
4115*4882a593Smuzhiyun goto out_retry;
4116*4882a593Smuzhiyun }
4117*4882a593Smuzhiyun return 1;
4118*4882a593Smuzhiyun }
4119*4882a593Smuzhiyun
4120*4882a593Smuzhiyun if (did == FDMI_DID)
4121*4882a593Smuzhiyun retry = 1;
4122*4882a593Smuzhiyun
4123*4882a593Smuzhiyun if ((cmd == ELS_CMD_FLOGI) &&
4124*4882a593Smuzhiyun (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
4125*4882a593Smuzhiyun !lpfc_error_lost_link(irsp)) {
4126*4882a593Smuzhiyun /* FLOGI retry policy */
4127*4882a593Smuzhiyun retry = 1;
4128*4882a593Smuzhiyun /* retry FLOGI forever */
4129*4882a593Smuzhiyun if (phba->link_flag != LS_LOOPBACK_MODE)
4130*4882a593Smuzhiyun maxretry = 0;
4131*4882a593Smuzhiyun else
4132*4882a593Smuzhiyun maxretry = 2;
4133*4882a593Smuzhiyun
4134*4882a593Smuzhiyun if (cmdiocb->retry >= 100)
4135*4882a593Smuzhiyun delay = 5000;
4136*4882a593Smuzhiyun else if (cmdiocb->retry >= 32)
4137*4882a593Smuzhiyun delay = 1000;
4138*4882a593Smuzhiyun } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
4139*4882a593Smuzhiyun /* retry FDISCs every second up to devloss */
4140*4882a593Smuzhiyun retry = 1;
4141*4882a593Smuzhiyun maxretry = vport->cfg_devloss_tmo;
4142*4882a593Smuzhiyun delay = 1000;
4143*4882a593Smuzhiyun }
4144*4882a593Smuzhiyun
4145*4882a593Smuzhiyun cmdiocb->retry++;
4146*4882a593Smuzhiyun if (maxretry && (cmdiocb->retry >= maxretry)) {
4147*4882a593Smuzhiyun phba->fc_stat.elsRetryExceeded++;
4148*4882a593Smuzhiyun retry = 0;
4149*4882a593Smuzhiyun }
4150*4882a593Smuzhiyun
4151*4882a593Smuzhiyun if ((vport->load_flag & FC_UNLOADING) != 0)
4152*4882a593Smuzhiyun retry = 0;
4153*4882a593Smuzhiyun
4154*4882a593Smuzhiyun out_retry:
4155*4882a593Smuzhiyun if (retry) {
4156*4882a593Smuzhiyun if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
4157*4882a593Smuzhiyun /* Stop retrying PLOGI and FDISC if in FCF discovery */
4158*4882a593Smuzhiyun if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
4159*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4160*4882a593Smuzhiyun "2849 Stop retry ELS command "
4161*4882a593Smuzhiyun "x%x to remote NPORT x%x, "
4162*4882a593Smuzhiyun "Data: x%x x%x\n", cmd, did,
4163*4882a593Smuzhiyun cmdiocb->retry, delay);
4164*4882a593Smuzhiyun return 0;
4165*4882a593Smuzhiyun }
4166*4882a593Smuzhiyun }
4167*4882a593Smuzhiyun
4168*4882a593Smuzhiyun /* Retry ELS command <elsCmd> to remote NPORT <did> */
4169*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4170*4882a593Smuzhiyun "0107 Retry ELS command x%x to remote "
4171*4882a593Smuzhiyun "NPORT x%x Data: x%x x%x\n",
4172*4882a593Smuzhiyun cmd, did, cmdiocb->retry, delay);
4173*4882a593Smuzhiyun
4174*4882a593Smuzhiyun if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
4175*4882a593Smuzhiyun ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
4176*4882a593Smuzhiyun ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
4177*4882a593Smuzhiyun IOERR_NO_RESOURCES))) {
4178*4882a593Smuzhiyun /* Don't reset timer for no resources */
4179*4882a593Smuzhiyun
4180*4882a593Smuzhiyun /* If discovery / RSCN timer is running, reset it */
4181*4882a593Smuzhiyun if (timer_pending(&vport->fc_disctmo) ||
4182*4882a593Smuzhiyun (vport->fc_flag & FC_RSCN_MODE))
4183*4882a593Smuzhiyun lpfc_set_disctmo(vport);
4184*4882a593Smuzhiyun }
4185*4882a593Smuzhiyun
4186*4882a593Smuzhiyun phba->fc_stat.elsXmitRetry++;
4187*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
4188*4882a593Smuzhiyun phba->fc_stat.elsDelayRetry++;
4189*4882a593Smuzhiyun ndlp->nlp_retry = cmdiocb->retry;
4190*4882a593Smuzhiyun
4191*4882a593Smuzhiyun /* delay is specified in milliseconds */
4192*4882a593Smuzhiyun mod_timer(&ndlp->nlp_delayfunc,
4193*4882a593Smuzhiyun jiffies + msecs_to_jiffies(delay));
4194*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
4195*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_DELAY_TMO;
4196*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
4197*4882a593Smuzhiyun
4198*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
4199*4882a593Smuzhiyun if ((cmd == ELS_CMD_PRLI) ||
4200*4882a593Smuzhiyun (cmd == ELS_CMD_NVMEPRLI))
4201*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp,
4202*4882a593Smuzhiyun NLP_STE_PRLI_ISSUE);
4203*4882a593Smuzhiyun else
4204*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp,
4205*4882a593Smuzhiyun NLP_STE_NPR_NODE);
4206*4882a593Smuzhiyun ndlp->nlp_last_elscmd = cmd;
4207*4882a593Smuzhiyun
4208*4882a593Smuzhiyun return 1;
4209*4882a593Smuzhiyun }
4210*4882a593Smuzhiyun switch (cmd) {
4211*4882a593Smuzhiyun case ELS_CMD_FLOGI:
4212*4882a593Smuzhiyun lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
4213*4882a593Smuzhiyun return 1;
4214*4882a593Smuzhiyun case ELS_CMD_FDISC:
4215*4882a593Smuzhiyun lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
4216*4882a593Smuzhiyun return 1;
4217*4882a593Smuzhiyun case ELS_CMD_PLOGI:
4218*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
4219*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
4220*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp,
4221*4882a593Smuzhiyun NLP_STE_PLOGI_ISSUE);
4222*4882a593Smuzhiyun }
4223*4882a593Smuzhiyun lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
4224*4882a593Smuzhiyun return 1;
4225*4882a593Smuzhiyun case ELS_CMD_ADISC:
4226*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
4227*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4228*4882a593Smuzhiyun lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
4229*4882a593Smuzhiyun return 1;
4230*4882a593Smuzhiyun case ELS_CMD_PRLI:
4231*4882a593Smuzhiyun case ELS_CMD_NVMEPRLI:
4232*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
4233*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
4234*4882a593Smuzhiyun lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
4235*4882a593Smuzhiyun return 1;
4236*4882a593Smuzhiyun case ELS_CMD_LOGO:
4237*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
4238*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
4239*4882a593Smuzhiyun lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
4240*4882a593Smuzhiyun return 1;
4241*4882a593Smuzhiyun }
4242*4882a593Smuzhiyun }
4243*4882a593Smuzhiyun /* No retry ELS command <elsCmd> to remote NPORT <did> */
4244*4882a593Smuzhiyun if (logerr) {
4245*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4246*4882a593Smuzhiyun "0137 No retry ELS command x%x to remote "
4247*4882a593Smuzhiyun "NPORT x%x: Out of Resources: Error:x%x/%x\n",
4248*4882a593Smuzhiyun cmd, did, irsp->ulpStatus,
4249*4882a593Smuzhiyun irsp->un.ulpWord[4]);
4250*4882a593Smuzhiyun }
4251*4882a593Smuzhiyun else {
4252*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4253*4882a593Smuzhiyun "0108 No retry ELS command x%x to remote "
4254*4882a593Smuzhiyun "NPORT x%x Retried:%d Error:x%x/%x\n",
4255*4882a593Smuzhiyun cmd, did, cmdiocb->retry, irsp->ulpStatus,
4256*4882a593Smuzhiyun irsp->un.ulpWord[4]);
4257*4882a593Smuzhiyun }
4258*4882a593Smuzhiyun return 0;
4259*4882a593Smuzhiyun }
4260*4882a593Smuzhiyun
4261*4882a593Smuzhiyun /**
4262*4882a593Smuzhiyun * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
4263*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
4264*4882a593Smuzhiyun * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
4265*4882a593Smuzhiyun *
4266*4882a593Smuzhiyun * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
4267*4882a593Smuzhiyun * associated with a command IOCB back to the lpfc DMA buffer pool. It first
4268*4882a593Smuzhiyun * checks to see whether there is a lpfc DMA buffer associated with the
4269*4882a593Smuzhiyun * response of the command IOCB. If so, it will be released before releasing
4270*4882a593Smuzhiyun * the lpfc DMA buffer associated with the IOCB itself.
4271*4882a593Smuzhiyun *
4272*4882a593Smuzhiyun * Return code
4273*4882a593Smuzhiyun * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4274*4882a593Smuzhiyun **/
4275*4882a593Smuzhiyun static int
lpfc_els_free_data(struct lpfc_hba * phba,struct lpfc_dmabuf * buf_ptr1)4276*4882a593Smuzhiyun lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
4277*4882a593Smuzhiyun {
4278*4882a593Smuzhiyun struct lpfc_dmabuf *buf_ptr;
4279*4882a593Smuzhiyun
4280*4882a593Smuzhiyun /* Free the response before processing the command. */
4281*4882a593Smuzhiyun if (!list_empty(&buf_ptr1->list)) {
4282*4882a593Smuzhiyun list_remove_head(&buf_ptr1->list, buf_ptr,
4283*4882a593Smuzhiyun struct lpfc_dmabuf,
4284*4882a593Smuzhiyun list);
4285*4882a593Smuzhiyun lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4286*4882a593Smuzhiyun kfree(buf_ptr);
4287*4882a593Smuzhiyun }
4288*4882a593Smuzhiyun lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
4289*4882a593Smuzhiyun kfree(buf_ptr1);
4290*4882a593Smuzhiyun return 0;
4291*4882a593Smuzhiyun }
4292*4882a593Smuzhiyun
4293*4882a593Smuzhiyun /**
4294*4882a593Smuzhiyun * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
4295*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
4296*4882a593Smuzhiyun * @buf_ptr: pointer to the lpfc dma buffer data structure.
4297*4882a593Smuzhiyun *
4298*4882a593Smuzhiyun * This routine releases the lpfc Direct Memory Access (DMA) buffer
4299*4882a593Smuzhiyun * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
4300*4882a593Smuzhiyun * pool.
4301*4882a593Smuzhiyun *
4302*4882a593Smuzhiyun * Return code
4303*4882a593Smuzhiyun * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
4304*4882a593Smuzhiyun **/
4305*4882a593Smuzhiyun static int
lpfc_els_free_bpl(struct lpfc_hba * phba,struct lpfc_dmabuf * buf_ptr)4306*4882a593Smuzhiyun lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
4307*4882a593Smuzhiyun {
4308*4882a593Smuzhiyun lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
4309*4882a593Smuzhiyun kfree(buf_ptr);
4310*4882a593Smuzhiyun return 0;
4311*4882a593Smuzhiyun }
4312*4882a593Smuzhiyun
4313*4882a593Smuzhiyun /**
4314*4882a593Smuzhiyun * lpfc_els_free_iocb - Free a command iocb and its associated resources
4315*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
4316*4882a593Smuzhiyun * @elsiocb: pointer to lpfc els command iocb data structure.
4317*4882a593Smuzhiyun *
4318*4882a593Smuzhiyun * This routine frees a command IOCB and its associated resources. The
4319*4882a593Smuzhiyun * command IOCB data structure contains the reference to various associated
4320*4882a593Smuzhiyun * resources, these fields must be set to NULL if the associated reference
4321*4882a593Smuzhiyun * not present:
4322*4882a593Smuzhiyun * context1 - reference to ndlp
4323*4882a593Smuzhiyun * context2 - reference to cmd
4324*4882a593Smuzhiyun * context2->next - reference to rsp
4325*4882a593Smuzhiyun * context3 - reference to bpl
4326*4882a593Smuzhiyun *
4327*4882a593Smuzhiyun * It first properly decrements the reference count held on ndlp for the
4328*4882a593Smuzhiyun * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
4329*4882a593Smuzhiyun * set, it invokes the lpfc_els_free_data() routine to release the Direct
4330*4882a593Smuzhiyun * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
4331*4882a593Smuzhiyun * adds the DMA buffer the @phba data structure for the delayed release.
4332*4882a593Smuzhiyun * If reference to the Buffer Pointer List (BPL) is present, the
4333*4882a593Smuzhiyun * lpfc_els_free_bpl() routine is invoked to release the DMA memory
4334*4882a593Smuzhiyun * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
4335*4882a593Smuzhiyun * invoked to release the IOCB data structure back to @phba IOCBQ list.
4336*4882a593Smuzhiyun *
4337*4882a593Smuzhiyun * Return code
4338*4882a593Smuzhiyun * 0 - Success (currently, always return 0)
4339*4882a593Smuzhiyun **/
4340*4882a593Smuzhiyun int
lpfc_els_free_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * elsiocb)4341*4882a593Smuzhiyun lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
4342*4882a593Smuzhiyun {
4343*4882a593Smuzhiyun struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
4344*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
4345*4882a593Smuzhiyun
4346*4882a593Smuzhiyun ndlp = (struct lpfc_nodelist *)elsiocb->context1;
4347*4882a593Smuzhiyun if (ndlp) {
4348*4882a593Smuzhiyun if (ndlp->nlp_flag & NLP_DEFER_RM) {
4349*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
4350*4882a593Smuzhiyun
4351*4882a593Smuzhiyun /* If the ndlp is not being used by another discovery
4352*4882a593Smuzhiyun * thread, free it.
4353*4882a593Smuzhiyun */
4354*4882a593Smuzhiyun if (!lpfc_nlp_not_used(ndlp)) {
4355*4882a593Smuzhiyun /* If ndlp is being used by another discovery
4356*4882a593Smuzhiyun * thread, just clear NLP_DEFER_RM
4357*4882a593Smuzhiyun */
4358*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_DEFER_RM;
4359*4882a593Smuzhiyun }
4360*4882a593Smuzhiyun }
4361*4882a593Smuzhiyun else
4362*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
4363*4882a593Smuzhiyun elsiocb->context1 = NULL;
4364*4882a593Smuzhiyun }
4365*4882a593Smuzhiyun /* context2 = cmd, context2->next = rsp, context3 = bpl */
4366*4882a593Smuzhiyun if (elsiocb->context2) {
4367*4882a593Smuzhiyun if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
4368*4882a593Smuzhiyun /* Firmware could still be in progress of DMAing
4369*4882a593Smuzhiyun * payload, so don't free data buffer till after
4370*4882a593Smuzhiyun * a hbeat.
4371*4882a593Smuzhiyun */
4372*4882a593Smuzhiyun elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
4373*4882a593Smuzhiyun buf_ptr = elsiocb->context2;
4374*4882a593Smuzhiyun elsiocb->context2 = NULL;
4375*4882a593Smuzhiyun if (buf_ptr) {
4376*4882a593Smuzhiyun buf_ptr1 = NULL;
4377*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
4378*4882a593Smuzhiyun if (!list_empty(&buf_ptr->list)) {
4379*4882a593Smuzhiyun list_remove_head(&buf_ptr->list,
4380*4882a593Smuzhiyun buf_ptr1, struct lpfc_dmabuf,
4381*4882a593Smuzhiyun list);
4382*4882a593Smuzhiyun INIT_LIST_HEAD(&buf_ptr1->list);
4383*4882a593Smuzhiyun list_add_tail(&buf_ptr1->list,
4384*4882a593Smuzhiyun &phba->elsbuf);
4385*4882a593Smuzhiyun phba->elsbuf_cnt++;
4386*4882a593Smuzhiyun }
4387*4882a593Smuzhiyun INIT_LIST_HEAD(&buf_ptr->list);
4388*4882a593Smuzhiyun list_add_tail(&buf_ptr->list, &phba->elsbuf);
4389*4882a593Smuzhiyun phba->elsbuf_cnt++;
4390*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
4391*4882a593Smuzhiyun }
4392*4882a593Smuzhiyun } else {
4393*4882a593Smuzhiyun buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
4394*4882a593Smuzhiyun lpfc_els_free_data(phba, buf_ptr1);
4395*4882a593Smuzhiyun elsiocb->context2 = NULL;
4396*4882a593Smuzhiyun }
4397*4882a593Smuzhiyun }
4398*4882a593Smuzhiyun
4399*4882a593Smuzhiyun if (elsiocb->context3) {
4400*4882a593Smuzhiyun buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
4401*4882a593Smuzhiyun lpfc_els_free_bpl(phba, buf_ptr);
4402*4882a593Smuzhiyun elsiocb->context3 = NULL;
4403*4882a593Smuzhiyun }
4404*4882a593Smuzhiyun lpfc_sli_release_iocbq(phba, elsiocb);
4405*4882a593Smuzhiyun return 0;
4406*4882a593Smuzhiyun }
4407*4882a593Smuzhiyun
4408*4882a593Smuzhiyun /**
4409*4882a593Smuzhiyun * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
4410*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
4411*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
4412*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
4413*4882a593Smuzhiyun *
4414*4882a593Smuzhiyun * This routine is the completion callback function to the Logout (LOGO)
4415*4882a593Smuzhiyun * Accept (ACC) Response ELS command. This routine is invoked to indicate
4416*4882a593Smuzhiyun * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
4417*4882a593Smuzhiyun * release the ndlp if it has the last reference remaining (reference count
4418*4882a593Smuzhiyun * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
4419*4882a593Smuzhiyun * field to NULL to inform the following lpfc_els_free_iocb() routine no
4420*4882a593Smuzhiyun * ndlp reference count needs to be decremented. Otherwise, the ndlp
4421*4882a593Smuzhiyun * reference use-count shall be decremented by the lpfc_els_free_iocb()
4422*4882a593Smuzhiyun * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
4423*4882a593Smuzhiyun * IOCB data structure.
4424*4882a593Smuzhiyun **/
4425*4882a593Smuzhiyun static void
lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)4426*4882a593Smuzhiyun lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4427*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
4428*4882a593Smuzhiyun {
4429*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4430*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
4431*4882a593Smuzhiyun IOCB_t *irsp;
4432*4882a593Smuzhiyun
4433*4882a593Smuzhiyun irsp = &rspiocb->iocb;
4434*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4435*4882a593Smuzhiyun "ACC LOGO cmpl: status:x%x/x%x did:x%x",
4436*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
4437*4882a593Smuzhiyun /* ACC to LOGO completes to NPort <nlp_DID> */
4438*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4439*4882a593Smuzhiyun "0109 ACC to LOGO completes to NPort x%x "
4440*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
4441*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4442*4882a593Smuzhiyun ndlp->nlp_rpi);
4443*4882a593Smuzhiyun
4444*4882a593Smuzhiyun if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
4445*4882a593Smuzhiyun /* NPort Recovery mode or node is just allocated */
4446*4882a593Smuzhiyun if (!lpfc_nlp_not_used(ndlp)) {
4447*4882a593Smuzhiyun /* If the ndlp is being used by another discovery
4448*4882a593Smuzhiyun * thread, just unregister the RPI.
4449*4882a593Smuzhiyun */
4450*4882a593Smuzhiyun lpfc_unreg_rpi(vport, ndlp);
4451*4882a593Smuzhiyun } else {
4452*4882a593Smuzhiyun /* Indicate the node has already released, should
4453*4882a593Smuzhiyun * not reference to it from within lpfc_els_free_iocb.
4454*4882a593Smuzhiyun */
4455*4882a593Smuzhiyun cmdiocb->context1 = NULL;
4456*4882a593Smuzhiyun }
4457*4882a593Smuzhiyun }
4458*4882a593Smuzhiyun
4459*4882a593Smuzhiyun /*
4460*4882a593Smuzhiyun * The driver received a LOGO from the rport and has ACK'd it.
4461*4882a593Smuzhiyun * At this point, the driver is done so release the IOCB
4462*4882a593Smuzhiyun */
4463*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
4464*4882a593Smuzhiyun }
4465*4882a593Smuzhiyun
4466*4882a593Smuzhiyun /**
4467*4882a593Smuzhiyun * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
4468*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
4469*4882a593Smuzhiyun * @pmb: pointer to the driver internal queue element for mailbox command.
4470*4882a593Smuzhiyun *
4471*4882a593Smuzhiyun * This routine is the completion callback function for unregister default
4472*4882a593Smuzhiyun * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
4473*4882a593Smuzhiyun * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
4474*4882a593Smuzhiyun * decrements the ndlp reference count held for this completion callback
4475*4882a593Smuzhiyun * function. After that, it invokes the lpfc_nlp_not_used() to check
4476*4882a593Smuzhiyun * whether there is only one reference left on the ndlp. If so, it will
4477*4882a593Smuzhiyun * perform one more decrement and trigger the release of the ndlp.
4478*4882a593Smuzhiyun **/
4479*4882a593Smuzhiyun void
lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)4480*4882a593Smuzhiyun lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4481*4882a593Smuzhiyun {
4482*4882a593Smuzhiyun struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *)(pmb->ctx_buf);
4483*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
4484*4882a593Smuzhiyun
4485*4882a593Smuzhiyun pmb->ctx_buf = NULL;
4486*4882a593Smuzhiyun pmb->ctx_ndlp = NULL;
4487*4882a593Smuzhiyun
4488*4882a593Smuzhiyun lpfc_mbuf_free(phba, mp->virt, mp->phys);
4489*4882a593Smuzhiyun kfree(mp);
4490*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
4491*4882a593Smuzhiyun if (ndlp) {
4492*4882a593Smuzhiyun lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4493*4882a593Smuzhiyun "0006 rpi%x DID:%x flg:%x %d map:%x x%px\n",
4494*4882a593Smuzhiyun ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
4495*4882a593Smuzhiyun kref_read(&ndlp->kref),
4496*4882a593Smuzhiyun ndlp->nlp_usg_map, ndlp);
4497*4882a593Smuzhiyun if (NLP_CHK_NODE_ACT(ndlp)) {
4498*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
4499*4882a593Smuzhiyun /* This is the end of the default RPI cleanup logic for
4500*4882a593Smuzhiyun * this ndlp. If no other discovery threads are using
4501*4882a593Smuzhiyun * this ndlp, free all resources associated with it.
4502*4882a593Smuzhiyun */
4503*4882a593Smuzhiyun lpfc_nlp_not_used(ndlp);
4504*4882a593Smuzhiyun } else {
4505*4882a593Smuzhiyun lpfc_drop_node(ndlp->vport, ndlp);
4506*4882a593Smuzhiyun }
4507*4882a593Smuzhiyun }
4508*4882a593Smuzhiyun
4509*4882a593Smuzhiyun return;
4510*4882a593Smuzhiyun }
4511*4882a593Smuzhiyun
4512*4882a593Smuzhiyun /**
4513*4882a593Smuzhiyun * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
4514*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
4515*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
4516*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
4517*4882a593Smuzhiyun *
4518*4882a593Smuzhiyun * This routine is the completion callback function for ELS Response IOCB
4519*4882a593Smuzhiyun * command. In normal case, this callback function just properly sets the
4520*4882a593Smuzhiyun * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
4521*4882a593Smuzhiyun * field in the command IOCB is not NULL, the referred mailbox command will
4522*4882a593Smuzhiyun * be send out, and then invokes the lpfc_els_free_iocb() routine to release
4523*4882a593Smuzhiyun * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
4524*4882a593Smuzhiyun * link down event occurred during the discovery, the lpfc_nlp_not_used()
4525*4882a593Smuzhiyun * routine shall be invoked trying to release the ndlp if no other threads
4526*4882a593Smuzhiyun * are currently referring it.
4527*4882a593Smuzhiyun **/
4528*4882a593Smuzhiyun static void
lpfc_cmpl_els_rsp(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)4529*4882a593Smuzhiyun lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4530*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
4531*4882a593Smuzhiyun {
4532*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4533*4882a593Smuzhiyun struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
4534*4882a593Smuzhiyun struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
4535*4882a593Smuzhiyun IOCB_t *irsp;
4536*4882a593Smuzhiyun uint8_t *pcmd;
4537*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox = NULL;
4538*4882a593Smuzhiyun struct lpfc_dmabuf *mp = NULL;
4539*4882a593Smuzhiyun uint32_t ls_rjt = 0;
4540*4882a593Smuzhiyun
4541*4882a593Smuzhiyun irsp = &rspiocb->iocb;
4542*4882a593Smuzhiyun
4543*4882a593Smuzhiyun if (!vport) {
4544*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
4545*4882a593Smuzhiyun "3177 ELS response failed\n");
4546*4882a593Smuzhiyun goto out;
4547*4882a593Smuzhiyun }
4548*4882a593Smuzhiyun if (cmdiocb->context_un.mbox)
4549*4882a593Smuzhiyun mbox = cmdiocb->context_un.mbox;
4550*4882a593Smuzhiyun
4551*4882a593Smuzhiyun /* First determine if this is a LS_RJT cmpl. Note, this callback
4552*4882a593Smuzhiyun * function can have cmdiocb->contest1 (ndlp) field set to NULL.
4553*4882a593Smuzhiyun */
4554*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4555*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4556*4882a593Smuzhiyun (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
4557*4882a593Smuzhiyun /* A LS_RJT associated with Default RPI cleanup has its own
4558*4882a593Smuzhiyun * separate code path.
4559*4882a593Smuzhiyun */
4560*4882a593Smuzhiyun if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4561*4882a593Smuzhiyun ls_rjt = 1;
4562*4882a593Smuzhiyun }
4563*4882a593Smuzhiyun
4564*4882a593Smuzhiyun /* Check to see if link went down during discovery */
4565*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
4566*4882a593Smuzhiyun if (mbox) {
4567*4882a593Smuzhiyun mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4568*4882a593Smuzhiyun if (mp) {
4569*4882a593Smuzhiyun lpfc_mbuf_free(phba, mp->virt, mp->phys);
4570*4882a593Smuzhiyun kfree(mp);
4571*4882a593Smuzhiyun }
4572*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
4573*4882a593Smuzhiyun }
4574*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
4575*4882a593Smuzhiyun (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
4576*4882a593Smuzhiyun if (lpfc_nlp_not_used(ndlp)) {
4577*4882a593Smuzhiyun ndlp = NULL;
4578*4882a593Smuzhiyun /* Indicate the node has already released,
4579*4882a593Smuzhiyun * should not reference to it from within
4580*4882a593Smuzhiyun * the routine lpfc_els_free_iocb.
4581*4882a593Smuzhiyun */
4582*4882a593Smuzhiyun cmdiocb->context1 = NULL;
4583*4882a593Smuzhiyun }
4584*4882a593Smuzhiyun goto out;
4585*4882a593Smuzhiyun }
4586*4882a593Smuzhiyun
4587*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4588*4882a593Smuzhiyun "ELS rsp cmpl: status:x%x/x%x did:x%x",
4589*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
4590*4882a593Smuzhiyun cmdiocb->iocb.un.elsreq64.remoteID);
4591*4882a593Smuzhiyun /* ELS response tag <ulpIoTag> completes */
4592*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4593*4882a593Smuzhiyun "0110 ELS response tag x%x completes "
4594*4882a593Smuzhiyun "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4595*4882a593Smuzhiyun cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
4596*4882a593Smuzhiyun rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
4597*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4598*4882a593Smuzhiyun ndlp->nlp_rpi);
4599*4882a593Smuzhiyun if (mbox) {
4600*4882a593Smuzhiyun if ((rspiocb->iocb.ulpStatus == 0)
4601*4882a593Smuzhiyun && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
4602*4882a593Smuzhiyun if (!lpfc_unreg_rpi(vport, ndlp) &&
4603*4882a593Smuzhiyun (!(vport->fc_flag & FC_PT2PT)) &&
4604*4882a593Smuzhiyun (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4605*4882a593Smuzhiyun ndlp->nlp_state == NLP_STE_REG_LOGIN_ISSUE)) {
4606*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO,
4607*4882a593Smuzhiyun LOG_DISCOVERY,
4608*4882a593Smuzhiyun "0314 PLOGI recov DID x%x "
4609*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
4610*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_state,
4611*4882a593Smuzhiyun ndlp->nlp_rpi, ndlp->nlp_flag);
4612*4882a593Smuzhiyun mp = mbox->ctx_buf;
4613*4882a593Smuzhiyun if (mp) {
4614*4882a593Smuzhiyun lpfc_mbuf_free(phba, mp->virt,
4615*4882a593Smuzhiyun mp->phys);
4616*4882a593Smuzhiyun kfree(mp);
4617*4882a593Smuzhiyun }
4618*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
4619*4882a593Smuzhiyun goto out;
4620*4882a593Smuzhiyun }
4621*4882a593Smuzhiyun
4622*4882a593Smuzhiyun /* Increment reference count to ndlp to hold the
4623*4882a593Smuzhiyun * reference to ndlp for the callback function.
4624*4882a593Smuzhiyun */
4625*4882a593Smuzhiyun mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
4626*4882a593Smuzhiyun mbox->vport = vport;
4627*4882a593Smuzhiyun if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
4628*4882a593Smuzhiyun mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4629*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4630*4882a593Smuzhiyun }
4631*4882a593Smuzhiyun else {
4632*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
4633*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
4634*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp,
4635*4882a593Smuzhiyun NLP_STE_REG_LOGIN_ISSUE);
4636*4882a593Smuzhiyun }
4637*4882a593Smuzhiyun
4638*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
4639*4882a593Smuzhiyun if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4640*4882a593Smuzhiyun != MBX_NOT_FINISHED)
4641*4882a593Smuzhiyun goto out;
4642*4882a593Smuzhiyun
4643*4882a593Smuzhiyun /* Decrement the ndlp reference count we
4644*4882a593Smuzhiyun * set for this failed mailbox command.
4645*4882a593Smuzhiyun */
4646*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
4647*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
4648*4882a593Smuzhiyun
4649*4882a593Smuzhiyun /* ELS rsp: Cannot issue reg_login for <NPortid> */
4650*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
4651*4882a593Smuzhiyun "0138 ELS rsp: Cannot issue reg_login for x%x "
4652*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
4653*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4654*4882a593Smuzhiyun ndlp->nlp_rpi);
4655*4882a593Smuzhiyun
4656*4882a593Smuzhiyun if (lpfc_nlp_not_used(ndlp)) {
4657*4882a593Smuzhiyun ndlp = NULL;
4658*4882a593Smuzhiyun /* Indicate node has already been released,
4659*4882a593Smuzhiyun * should not reference to it from within
4660*4882a593Smuzhiyun * the routine lpfc_els_free_iocb.
4661*4882a593Smuzhiyun */
4662*4882a593Smuzhiyun cmdiocb->context1 = NULL;
4663*4882a593Smuzhiyun }
4664*4882a593Smuzhiyun } else {
4665*4882a593Smuzhiyun /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4666*4882a593Smuzhiyun if (!lpfc_error_lost_link(irsp) &&
4667*4882a593Smuzhiyun ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
4668*4882a593Smuzhiyun if (lpfc_nlp_not_used(ndlp)) {
4669*4882a593Smuzhiyun ndlp = NULL;
4670*4882a593Smuzhiyun /* Indicate node has already been
4671*4882a593Smuzhiyun * released, should not reference
4672*4882a593Smuzhiyun * to it from within the routine
4673*4882a593Smuzhiyun * lpfc_els_free_iocb.
4674*4882a593Smuzhiyun */
4675*4882a593Smuzhiyun cmdiocb->context1 = NULL;
4676*4882a593Smuzhiyun }
4677*4882a593Smuzhiyun }
4678*4882a593Smuzhiyun }
4679*4882a593Smuzhiyun mp = (struct lpfc_dmabuf *)mbox->ctx_buf;
4680*4882a593Smuzhiyun if (mp) {
4681*4882a593Smuzhiyun lpfc_mbuf_free(phba, mp->virt, mp->phys);
4682*4882a593Smuzhiyun kfree(mp);
4683*4882a593Smuzhiyun }
4684*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
4685*4882a593Smuzhiyun }
4686*4882a593Smuzhiyun out:
4687*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp) && shost) {
4688*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
4689*4882a593Smuzhiyun if (mbox)
4690*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
4691*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_RM_DFLT_RPI;
4692*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
4693*4882a593Smuzhiyun
4694*4882a593Smuzhiyun /* If the node is not being used by another discovery thread,
4695*4882a593Smuzhiyun * and we are sending a reject, we are done with it.
4696*4882a593Smuzhiyun * Release driver reference count here and free associated
4697*4882a593Smuzhiyun * resources.
4698*4882a593Smuzhiyun */
4699*4882a593Smuzhiyun if (ls_rjt)
4700*4882a593Smuzhiyun if (lpfc_nlp_not_used(ndlp))
4701*4882a593Smuzhiyun /* Indicate node has already been released,
4702*4882a593Smuzhiyun * should not reference to it from within
4703*4882a593Smuzhiyun * the routine lpfc_els_free_iocb.
4704*4882a593Smuzhiyun */
4705*4882a593Smuzhiyun cmdiocb->context1 = NULL;
4706*4882a593Smuzhiyun
4707*4882a593Smuzhiyun }
4708*4882a593Smuzhiyun
4709*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
4710*4882a593Smuzhiyun return;
4711*4882a593Smuzhiyun }
4712*4882a593Smuzhiyun
4713*4882a593Smuzhiyun /**
4714*4882a593Smuzhiyun * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4715*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
4716*4882a593Smuzhiyun * @flag: the els command code to be accepted.
4717*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
4718*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
4719*4882a593Smuzhiyun * @mbox: pointer to the driver internal queue element for mailbox command.
4720*4882a593Smuzhiyun *
4721*4882a593Smuzhiyun * This routine prepares and issues an Accept (ACC) response IOCB
4722*4882a593Smuzhiyun * command. It uses the @flag to properly set up the IOCB field for the
4723*4882a593Smuzhiyun * specific ACC response command to be issued and invokes the
4724*4882a593Smuzhiyun * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4725*4882a593Smuzhiyun * @mbox pointer is passed in, it will be put into the context_un.mbox
4726*4882a593Smuzhiyun * field of the IOCB for the completion callback function to issue the
4727*4882a593Smuzhiyun * mailbox command to the HBA later when callback is invoked.
4728*4882a593Smuzhiyun *
4729*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4730*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
4731*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
4732*4882a593Smuzhiyun * callback function to the corresponding response ELS IOCB command.
4733*4882a593Smuzhiyun *
4734*4882a593Smuzhiyun * Return code
4735*4882a593Smuzhiyun * 0 - Successfully issued acc response
4736*4882a593Smuzhiyun * 1 - Failed to issue acc response
4737*4882a593Smuzhiyun **/
4738*4882a593Smuzhiyun int
lpfc_els_rsp_acc(struct lpfc_vport * vport,uint32_t flag,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp,LPFC_MBOXQ_t * mbox)4739*4882a593Smuzhiyun lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
4740*4882a593Smuzhiyun struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4741*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox)
4742*4882a593Smuzhiyun {
4743*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4744*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
4745*4882a593Smuzhiyun IOCB_t *icmd;
4746*4882a593Smuzhiyun IOCB_t *oldcmd;
4747*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
4748*4882a593Smuzhiyun uint8_t *pcmd;
4749*4882a593Smuzhiyun struct serv_parm *sp;
4750*4882a593Smuzhiyun uint16_t cmdsize;
4751*4882a593Smuzhiyun int rc;
4752*4882a593Smuzhiyun ELS_PKT *els_pkt_ptr;
4753*4882a593Smuzhiyun
4754*4882a593Smuzhiyun oldcmd = &oldiocb->iocb;
4755*4882a593Smuzhiyun
4756*4882a593Smuzhiyun switch (flag) {
4757*4882a593Smuzhiyun case ELS_CMD_ACC:
4758*4882a593Smuzhiyun cmdsize = sizeof(uint32_t);
4759*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4760*4882a593Smuzhiyun ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4761*4882a593Smuzhiyun if (!elsiocb) {
4762*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
4763*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4764*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
4765*4882a593Smuzhiyun return 1;
4766*4882a593Smuzhiyun }
4767*4882a593Smuzhiyun
4768*4882a593Smuzhiyun icmd = &elsiocb->iocb;
4769*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4770*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4771*4882a593Smuzhiyun pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4772*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4773*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
4774*4882a593Smuzhiyun
4775*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4776*4882a593Smuzhiyun "Issue ACC: did:x%x flg:x%x",
4777*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
4778*4882a593Smuzhiyun break;
4779*4882a593Smuzhiyun case ELS_CMD_FLOGI:
4780*4882a593Smuzhiyun case ELS_CMD_PLOGI:
4781*4882a593Smuzhiyun cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
4782*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4783*4882a593Smuzhiyun ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
4784*4882a593Smuzhiyun if (!elsiocb)
4785*4882a593Smuzhiyun return 1;
4786*4882a593Smuzhiyun
4787*4882a593Smuzhiyun icmd = &elsiocb->iocb;
4788*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4789*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4790*4882a593Smuzhiyun pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4791*4882a593Smuzhiyun
4792*4882a593Smuzhiyun if (mbox)
4793*4882a593Smuzhiyun elsiocb->context_un.mbox = mbox;
4794*4882a593Smuzhiyun
4795*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4796*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
4797*4882a593Smuzhiyun sp = (struct serv_parm *)pcmd;
4798*4882a593Smuzhiyun
4799*4882a593Smuzhiyun if (flag == ELS_CMD_FLOGI) {
4800*4882a593Smuzhiyun /* Copy the received service parameters back */
4801*4882a593Smuzhiyun memcpy(sp, &phba->fc_fabparam,
4802*4882a593Smuzhiyun sizeof(struct serv_parm));
4803*4882a593Smuzhiyun
4804*4882a593Smuzhiyun /* Clear the F_Port bit */
4805*4882a593Smuzhiyun sp->cmn.fPort = 0;
4806*4882a593Smuzhiyun
4807*4882a593Smuzhiyun /* Mark all class service parameters as invalid */
4808*4882a593Smuzhiyun sp->cls1.classValid = 0;
4809*4882a593Smuzhiyun sp->cls2.classValid = 0;
4810*4882a593Smuzhiyun sp->cls3.classValid = 0;
4811*4882a593Smuzhiyun sp->cls4.classValid = 0;
4812*4882a593Smuzhiyun
4813*4882a593Smuzhiyun /* Copy our worldwide names */
4814*4882a593Smuzhiyun memcpy(&sp->portName, &vport->fc_sparam.portName,
4815*4882a593Smuzhiyun sizeof(struct lpfc_name));
4816*4882a593Smuzhiyun memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
4817*4882a593Smuzhiyun sizeof(struct lpfc_name));
4818*4882a593Smuzhiyun } else {
4819*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_sparam,
4820*4882a593Smuzhiyun sizeof(struct serv_parm));
4821*4882a593Smuzhiyun
4822*4882a593Smuzhiyun sp->cmn.valid_vendor_ver_level = 0;
4823*4882a593Smuzhiyun memset(sp->un.vendorVersion, 0,
4824*4882a593Smuzhiyun sizeof(sp->un.vendorVersion));
4825*4882a593Smuzhiyun sp->cmn.bbRcvSizeMsb &= 0xF;
4826*4882a593Smuzhiyun
4827*4882a593Smuzhiyun /* If our firmware supports this feature, convey that
4828*4882a593Smuzhiyun * info to the target using the vendor specific field.
4829*4882a593Smuzhiyun */
4830*4882a593Smuzhiyun if (phba->sli.sli_flag & LPFC_SLI_SUPPRESS_RSP) {
4831*4882a593Smuzhiyun sp->cmn.valid_vendor_ver_level = 1;
4832*4882a593Smuzhiyun sp->un.vv.vid = cpu_to_be32(LPFC_VV_EMLX_ID);
4833*4882a593Smuzhiyun sp->un.vv.flags =
4834*4882a593Smuzhiyun cpu_to_be32(LPFC_VV_SUPPRESS_RSP);
4835*4882a593Smuzhiyun }
4836*4882a593Smuzhiyun }
4837*4882a593Smuzhiyun
4838*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4839*4882a593Smuzhiyun "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4840*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
4841*4882a593Smuzhiyun break;
4842*4882a593Smuzhiyun case ELS_CMD_PRLO:
4843*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + sizeof(PRLO);
4844*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
4845*4882a593Smuzhiyun ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
4846*4882a593Smuzhiyun if (!elsiocb)
4847*4882a593Smuzhiyun return 1;
4848*4882a593Smuzhiyun
4849*4882a593Smuzhiyun icmd = &elsiocb->iocb;
4850*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4851*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4852*4882a593Smuzhiyun pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4853*4882a593Smuzhiyun
4854*4882a593Smuzhiyun memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
4855*4882a593Smuzhiyun sizeof(uint32_t) + sizeof(PRLO));
4856*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4857*4882a593Smuzhiyun els_pkt_ptr = (ELS_PKT *) pcmd;
4858*4882a593Smuzhiyun els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
4859*4882a593Smuzhiyun
4860*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4861*4882a593Smuzhiyun "Issue ACC PRLO: did:x%x flg:x%x",
4862*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
4863*4882a593Smuzhiyun break;
4864*4882a593Smuzhiyun default:
4865*4882a593Smuzhiyun return 1;
4866*4882a593Smuzhiyun }
4867*4882a593Smuzhiyun if (ndlp->nlp_flag & NLP_LOGO_ACC) {
4868*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
4869*4882a593Smuzhiyun if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4870*4882a593Smuzhiyun ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4871*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_LOGO_ACC;
4872*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
4873*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4874*4882a593Smuzhiyun } else {
4875*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4876*4882a593Smuzhiyun }
4877*4882a593Smuzhiyun
4878*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
4879*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4880*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
4881*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
4882*4882a593Smuzhiyun return 1;
4883*4882a593Smuzhiyun }
4884*4882a593Smuzhiyun return 0;
4885*4882a593Smuzhiyun }
4886*4882a593Smuzhiyun
4887*4882a593Smuzhiyun /**
4888*4882a593Smuzhiyun * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4889*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
4890*4882a593Smuzhiyun * @rejectError: reject response to issue
4891*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
4892*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
4893*4882a593Smuzhiyun * @mbox: pointer to the driver internal queue element for mailbox command.
4894*4882a593Smuzhiyun *
4895*4882a593Smuzhiyun * This routine prepares and issue an Reject (RJT) response IOCB
4896*4882a593Smuzhiyun * command. If a @mbox pointer is passed in, it will be put into the
4897*4882a593Smuzhiyun * context_un.mbox field of the IOCB for the completion callback function
4898*4882a593Smuzhiyun * to issue to the HBA later.
4899*4882a593Smuzhiyun *
4900*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4901*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
4902*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
4903*4882a593Smuzhiyun * callback function to the reject response ELS IOCB command.
4904*4882a593Smuzhiyun *
4905*4882a593Smuzhiyun * Return code
4906*4882a593Smuzhiyun * 0 - Successfully issued reject response
4907*4882a593Smuzhiyun * 1 - Failed to issue reject response
4908*4882a593Smuzhiyun **/
4909*4882a593Smuzhiyun int
lpfc_els_rsp_reject(struct lpfc_vport * vport,uint32_t rejectError,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp,LPFC_MBOXQ_t * mbox)4910*4882a593Smuzhiyun lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
4911*4882a593Smuzhiyun struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4912*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox)
4913*4882a593Smuzhiyun {
4914*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
4915*4882a593Smuzhiyun IOCB_t *icmd;
4916*4882a593Smuzhiyun IOCB_t *oldcmd;
4917*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
4918*4882a593Smuzhiyun uint8_t *pcmd;
4919*4882a593Smuzhiyun uint16_t cmdsize;
4920*4882a593Smuzhiyun int rc;
4921*4882a593Smuzhiyun
4922*4882a593Smuzhiyun cmdsize = 2 * sizeof(uint32_t);
4923*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4924*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_LS_RJT);
4925*4882a593Smuzhiyun if (!elsiocb)
4926*4882a593Smuzhiyun return 1;
4927*4882a593Smuzhiyun
4928*4882a593Smuzhiyun icmd = &elsiocb->iocb;
4929*4882a593Smuzhiyun oldcmd = &oldiocb->iocb;
4930*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4931*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4932*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4933*4882a593Smuzhiyun
4934*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4935*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
4936*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = rejectError;
4937*4882a593Smuzhiyun
4938*4882a593Smuzhiyun if (mbox)
4939*4882a593Smuzhiyun elsiocb->context_un.mbox = mbox;
4940*4882a593Smuzhiyun
4941*4882a593Smuzhiyun /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4942*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4943*4882a593Smuzhiyun "0129 Xmit ELS RJT x%x response tag x%x "
4944*4882a593Smuzhiyun "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4945*4882a593Smuzhiyun "rpi x%x\n",
4946*4882a593Smuzhiyun rejectError, elsiocb->iotag,
4947*4882a593Smuzhiyun elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4948*4882a593Smuzhiyun ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
4949*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4950*4882a593Smuzhiyun "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4951*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4952*4882a593Smuzhiyun
4953*4882a593Smuzhiyun phba->fc_stat.elsXmitLSRJT++;
4954*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4955*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4956*4882a593Smuzhiyun
4957*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
4958*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
4959*4882a593Smuzhiyun return 1;
4960*4882a593Smuzhiyun }
4961*4882a593Smuzhiyun return 0;
4962*4882a593Smuzhiyun }
4963*4882a593Smuzhiyun
4964*4882a593Smuzhiyun /**
4965*4882a593Smuzhiyun * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4966*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
4967*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
4968*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
4969*4882a593Smuzhiyun *
4970*4882a593Smuzhiyun * This routine prepares and issues an Accept (ACC) response to Address
4971*4882a593Smuzhiyun * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4972*4882a593Smuzhiyun * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4973*4882a593Smuzhiyun *
4974*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4975*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
4976*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
4977*4882a593Smuzhiyun * callback function to the ADISC Accept response ELS IOCB command.
4978*4882a593Smuzhiyun *
4979*4882a593Smuzhiyun * Return code
4980*4882a593Smuzhiyun * 0 - Successfully issued acc adisc response
4981*4882a593Smuzhiyun * 1 - Failed to issue adisc acc response
4982*4882a593Smuzhiyun **/
4983*4882a593Smuzhiyun int
lpfc_els_rsp_adisc_acc(struct lpfc_vport * vport,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)4984*4882a593Smuzhiyun lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4985*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
4986*4882a593Smuzhiyun {
4987*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
4988*4882a593Smuzhiyun ADISC *ap;
4989*4882a593Smuzhiyun IOCB_t *icmd, *oldcmd;
4990*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
4991*4882a593Smuzhiyun uint8_t *pcmd;
4992*4882a593Smuzhiyun uint16_t cmdsize;
4993*4882a593Smuzhiyun int rc;
4994*4882a593Smuzhiyun
4995*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + sizeof(ADISC);
4996*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4997*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
4998*4882a593Smuzhiyun if (!elsiocb)
4999*4882a593Smuzhiyun return 1;
5000*4882a593Smuzhiyun
5001*4882a593Smuzhiyun icmd = &elsiocb->iocb;
5002*4882a593Smuzhiyun oldcmd = &oldiocb->iocb;
5003*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5004*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5005*4882a593Smuzhiyun
5006*4882a593Smuzhiyun /* Xmit ADISC ACC response tag <ulpIoTag> */
5007*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5008*4882a593Smuzhiyun "0130 Xmit ADISC ACC response iotag x%x xri: "
5009*4882a593Smuzhiyun "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
5010*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext,
5011*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5012*4882a593Smuzhiyun ndlp->nlp_rpi);
5013*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5014*4882a593Smuzhiyun
5015*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5016*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
5017*4882a593Smuzhiyun
5018*4882a593Smuzhiyun ap = (ADISC *) (pcmd);
5019*4882a593Smuzhiyun ap->hardAL_PA = phba->fc_pref_ALPA;
5020*4882a593Smuzhiyun memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5021*4882a593Smuzhiyun memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5022*4882a593Smuzhiyun ap->DID = be32_to_cpu(vport->fc_myDID);
5023*4882a593Smuzhiyun
5024*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5025*4882a593Smuzhiyun "Issue ACC ADISC: did:x%x flg:x%x",
5026*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
5027*4882a593Smuzhiyun
5028*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
5029*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5030*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5031*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
5032*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
5033*4882a593Smuzhiyun return 1;
5034*4882a593Smuzhiyun }
5035*4882a593Smuzhiyun
5036*4882a593Smuzhiyun /* Xmit ELS ACC response tag <ulpIoTag> */
5037*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5038*4882a593Smuzhiyun "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5039*4882a593Smuzhiyun "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5040*4882a593Smuzhiyun "RPI: x%x, fc_flag x%x\n",
5041*4882a593Smuzhiyun rc, elsiocb->iotag, elsiocb->sli4_xritag,
5042*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5043*4882a593Smuzhiyun ndlp->nlp_rpi, vport->fc_flag);
5044*4882a593Smuzhiyun return 0;
5045*4882a593Smuzhiyun }
5046*4882a593Smuzhiyun
5047*4882a593Smuzhiyun /**
5048*4882a593Smuzhiyun * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
5049*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
5050*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
5051*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
5052*4882a593Smuzhiyun *
5053*4882a593Smuzhiyun * This routine prepares and issues an Accept (ACC) response to Process
5054*4882a593Smuzhiyun * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
5055*4882a593Smuzhiyun * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5056*4882a593Smuzhiyun *
5057*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5058*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
5059*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
5060*4882a593Smuzhiyun * callback function to the PRLI Accept response ELS IOCB command.
5061*4882a593Smuzhiyun *
5062*4882a593Smuzhiyun * Return code
5063*4882a593Smuzhiyun * 0 - Successfully issued acc prli response
5064*4882a593Smuzhiyun * 1 - Failed to issue acc prli response
5065*4882a593Smuzhiyun **/
5066*4882a593Smuzhiyun int
lpfc_els_rsp_prli_acc(struct lpfc_vport * vport,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)5067*4882a593Smuzhiyun lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
5068*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
5069*4882a593Smuzhiyun {
5070*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
5071*4882a593Smuzhiyun PRLI *npr;
5072*4882a593Smuzhiyun struct lpfc_nvme_prli *npr_nvme;
5073*4882a593Smuzhiyun lpfc_vpd_t *vpd;
5074*4882a593Smuzhiyun IOCB_t *icmd;
5075*4882a593Smuzhiyun IOCB_t *oldcmd;
5076*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
5077*4882a593Smuzhiyun uint8_t *pcmd;
5078*4882a593Smuzhiyun uint16_t cmdsize;
5079*4882a593Smuzhiyun uint32_t prli_fc4_req, *req_payload;
5080*4882a593Smuzhiyun struct lpfc_dmabuf *req_buf;
5081*4882a593Smuzhiyun int rc;
5082*4882a593Smuzhiyun u32 elsrspcmd;
5083*4882a593Smuzhiyun
5084*4882a593Smuzhiyun /* Need the incoming PRLI payload to determine if the ACC is for an
5085*4882a593Smuzhiyun * FC4 or NVME PRLI type. The PRLI type is at word 1.
5086*4882a593Smuzhiyun */
5087*4882a593Smuzhiyun req_buf = (struct lpfc_dmabuf *)oldiocb->context2;
5088*4882a593Smuzhiyun req_payload = (((uint32_t *)req_buf->virt) + 1);
5089*4882a593Smuzhiyun
5090*4882a593Smuzhiyun /* PRLI type payload is at byte 3 for FCP or NVME. */
5091*4882a593Smuzhiyun prli_fc4_req = be32_to_cpu(*req_payload);
5092*4882a593Smuzhiyun prli_fc4_req = (prli_fc4_req >> 24) & 0xff;
5093*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5094*4882a593Smuzhiyun "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
5095*4882a593Smuzhiyun prli_fc4_req, *((uint32_t *)req_payload));
5096*4882a593Smuzhiyun
5097*4882a593Smuzhiyun if (prli_fc4_req == PRLI_FCP_TYPE) {
5098*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + sizeof(PRLI);
5099*4882a593Smuzhiyun elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
5100*4882a593Smuzhiyun } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5101*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli);
5102*4882a593Smuzhiyun elsrspcmd = (ELS_CMD_ACC | (ELS_CMD_NVMEPRLI & ~ELS_RSP_MASK));
5103*4882a593Smuzhiyun } else {
5104*4882a593Smuzhiyun return 1;
5105*4882a593Smuzhiyun }
5106*4882a593Smuzhiyun
5107*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5108*4882a593Smuzhiyun ndlp->nlp_DID, elsrspcmd);
5109*4882a593Smuzhiyun if (!elsiocb)
5110*4882a593Smuzhiyun return 1;
5111*4882a593Smuzhiyun
5112*4882a593Smuzhiyun icmd = &elsiocb->iocb;
5113*4882a593Smuzhiyun oldcmd = &oldiocb->iocb;
5114*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5115*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5116*4882a593Smuzhiyun
5117*4882a593Smuzhiyun /* Xmit PRLI ACC response tag <ulpIoTag> */
5118*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5119*4882a593Smuzhiyun "0131 Xmit PRLI ACC response tag x%x xri x%x, "
5120*4882a593Smuzhiyun "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5121*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext,
5122*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5123*4882a593Smuzhiyun ndlp->nlp_rpi);
5124*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5125*4882a593Smuzhiyun memset(pcmd, 0, cmdsize);
5126*4882a593Smuzhiyun
5127*4882a593Smuzhiyun *((uint32_t *)(pcmd)) = elsrspcmd;
5128*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
5129*4882a593Smuzhiyun
5130*4882a593Smuzhiyun /* For PRLI, remainder of payload is PRLI parameter page */
5131*4882a593Smuzhiyun vpd = &phba->vpd;
5132*4882a593Smuzhiyun
5133*4882a593Smuzhiyun if (prli_fc4_req == PRLI_FCP_TYPE) {
5134*4882a593Smuzhiyun /*
5135*4882a593Smuzhiyun * If the remote port is a target and our firmware version
5136*4882a593Smuzhiyun * is 3.20 or later, set the following bits for FC-TAPE
5137*4882a593Smuzhiyun * support.
5138*4882a593Smuzhiyun */
5139*4882a593Smuzhiyun npr = (PRLI *) pcmd;
5140*4882a593Smuzhiyun if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
5141*4882a593Smuzhiyun (vpd->rev.feaLevelHigh >= 0x02)) {
5142*4882a593Smuzhiyun npr->ConfmComplAllowed = 1;
5143*4882a593Smuzhiyun npr->Retry = 1;
5144*4882a593Smuzhiyun npr->TaskRetryIdReq = 1;
5145*4882a593Smuzhiyun }
5146*4882a593Smuzhiyun npr->acceptRspCode = PRLI_REQ_EXECUTED;
5147*4882a593Smuzhiyun npr->estabImagePair = 1;
5148*4882a593Smuzhiyun npr->readXferRdyDis = 1;
5149*4882a593Smuzhiyun npr->ConfmComplAllowed = 1;
5150*4882a593Smuzhiyun npr->prliType = PRLI_FCP_TYPE;
5151*4882a593Smuzhiyun npr->initiatorFunc = 1;
5152*4882a593Smuzhiyun } else if (prli_fc4_req & PRLI_NVME_TYPE) {
5153*4882a593Smuzhiyun /* Respond with an NVME PRLI Type */
5154*4882a593Smuzhiyun npr_nvme = (struct lpfc_nvme_prli *) pcmd;
5155*4882a593Smuzhiyun bf_set(prli_type_code, npr_nvme, PRLI_NVME_TYPE);
5156*4882a593Smuzhiyun bf_set(prli_estabImagePair, npr_nvme, 0); /* Should be 0 */
5157*4882a593Smuzhiyun bf_set(prli_acc_rsp_code, npr_nvme, PRLI_REQ_EXECUTED);
5158*4882a593Smuzhiyun if (phba->nvmet_support) {
5159*4882a593Smuzhiyun bf_set(prli_tgt, npr_nvme, 1);
5160*4882a593Smuzhiyun bf_set(prli_disc, npr_nvme, 1);
5161*4882a593Smuzhiyun if (phba->cfg_nvme_enable_fb) {
5162*4882a593Smuzhiyun bf_set(prli_fba, npr_nvme, 1);
5163*4882a593Smuzhiyun
5164*4882a593Smuzhiyun /* TBD. Target mode needs to post buffers
5165*4882a593Smuzhiyun * that support the configured first burst
5166*4882a593Smuzhiyun * byte size.
5167*4882a593Smuzhiyun */
5168*4882a593Smuzhiyun bf_set(prli_fb_sz, npr_nvme,
5169*4882a593Smuzhiyun phba->cfg_nvmet_fb_size);
5170*4882a593Smuzhiyun }
5171*4882a593Smuzhiyun } else {
5172*4882a593Smuzhiyun bf_set(prli_init, npr_nvme, 1);
5173*4882a593Smuzhiyun }
5174*4882a593Smuzhiyun
5175*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_NVME_DISC,
5176*4882a593Smuzhiyun "6015 NVME issue PRLI ACC word1 x%08x "
5177*4882a593Smuzhiyun "word4 x%08x word5 x%08x flag x%x, "
5178*4882a593Smuzhiyun "fcp_info x%x nlp_type x%x\n",
5179*4882a593Smuzhiyun npr_nvme->word1, npr_nvme->word4,
5180*4882a593Smuzhiyun npr_nvme->word5, ndlp->nlp_flag,
5181*4882a593Smuzhiyun ndlp->nlp_fcp_info, ndlp->nlp_type);
5182*4882a593Smuzhiyun npr_nvme->word1 = cpu_to_be32(npr_nvme->word1);
5183*4882a593Smuzhiyun npr_nvme->word4 = cpu_to_be32(npr_nvme->word4);
5184*4882a593Smuzhiyun npr_nvme->word5 = cpu_to_be32(npr_nvme->word5);
5185*4882a593Smuzhiyun } else
5186*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5187*4882a593Smuzhiyun "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
5188*4882a593Smuzhiyun prli_fc4_req, ndlp->nlp_fc4_type,
5189*4882a593Smuzhiyun ndlp->nlp_DID);
5190*4882a593Smuzhiyun
5191*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5192*4882a593Smuzhiyun "Issue ACC PRLI: did:x%x flg:x%x",
5193*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
5194*4882a593Smuzhiyun
5195*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
5196*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5197*4882a593Smuzhiyun
5198*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5199*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
5200*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
5201*4882a593Smuzhiyun return 1;
5202*4882a593Smuzhiyun }
5203*4882a593Smuzhiyun return 0;
5204*4882a593Smuzhiyun }
5205*4882a593Smuzhiyun
5206*4882a593Smuzhiyun /**
5207*4882a593Smuzhiyun * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
5208*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
5209*4882a593Smuzhiyun * @format: rnid command format.
5210*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
5211*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
5212*4882a593Smuzhiyun *
5213*4882a593Smuzhiyun * This routine issues a Request Node Identification Data (RNID) Accept
5214*4882a593Smuzhiyun * (ACC) response. It constructs the RNID ACC response command according to
5215*4882a593Smuzhiyun * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
5216*4882a593Smuzhiyun * issue the response. Note that this command does not need to hold the ndlp
5217*4882a593Smuzhiyun * reference count for the callback. So, the ndlp reference count taken by
5218*4882a593Smuzhiyun * the lpfc_prep_els_iocb() routine is put back and the context1 field of
5219*4882a593Smuzhiyun * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
5220*4882a593Smuzhiyun * there is no ndlp reference available.
5221*4882a593Smuzhiyun *
5222*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5223*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
5224*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
5225*4882a593Smuzhiyun * callback function. However, for the RNID Accept Response ELS command,
5226*4882a593Smuzhiyun * this is undone later by this routine after the IOCB is allocated.
5227*4882a593Smuzhiyun *
5228*4882a593Smuzhiyun * Return code
5229*4882a593Smuzhiyun * 0 - Successfully issued acc rnid response
5230*4882a593Smuzhiyun * 1 - Failed to issue acc rnid response
5231*4882a593Smuzhiyun **/
5232*4882a593Smuzhiyun static int
lpfc_els_rsp_rnid_acc(struct lpfc_vport * vport,uint8_t format,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)5233*4882a593Smuzhiyun lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
5234*4882a593Smuzhiyun struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5235*4882a593Smuzhiyun {
5236*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
5237*4882a593Smuzhiyun RNID *rn;
5238*4882a593Smuzhiyun IOCB_t *icmd, *oldcmd;
5239*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
5240*4882a593Smuzhiyun uint8_t *pcmd;
5241*4882a593Smuzhiyun uint16_t cmdsize;
5242*4882a593Smuzhiyun int rc;
5243*4882a593Smuzhiyun
5244*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
5245*4882a593Smuzhiyun + (2 * sizeof(struct lpfc_name));
5246*4882a593Smuzhiyun if (format)
5247*4882a593Smuzhiyun cmdsize += sizeof(RNID_TOP_DISC);
5248*4882a593Smuzhiyun
5249*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5250*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
5251*4882a593Smuzhiyun if (!elsiocb)
5252*4882a593Smuzhiyun return 1;
5253*4882a593Smuzhiyun
5254*4882a593Smuzhiyun icmd = &elsiocb->iocb;
5255*4882a593Smuzhiyun oldcmd = &oldiocb->iocb;
5256*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5257*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
5258*4882a593Smuzhiyun
5259*4882a593Smuzhiyun /* Xmit RNID ACC response tag <ulpIoTag> */
5260*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5261*4882a593Smuzhiyun "0132 Xmit RNID ACC response tag x%x xri x%x\n",
5262*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext);
5263*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5264*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5265*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
5266*4882a593Smuzhiyun
5267*4882a593Smuzhiyun memset(pcmd, 0, sizeof(RNID));
5268*4882a593Smuzhiyun rn = (RNID *) (pcmd);
5269*4882a593Smuzhiyun rn->Format = format;
5270*4882a593Smuzhiyun rn->CommonLen = (2 * sizeof(struct lpfc_name));
5271*4882a593Smuzhiyun memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
5272*4882a593Smuzhiyun memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
5273*4882a593Smuzhiyun switch (format) {
5274*4882a593Smuzhiyun case 0:
5275*4882a593Smuzhiyun rn->SpecificLen = 0;
5276*4882a593Smuzhiyun break;
5277*4882a593Smuzhiyun case RNID_TOPOLOGY_DISC:
5278*4882a593Smuzhiyun rn->SpecificLen = sizeof(RNID_TOP_DISC);
5279*4882a593Smuzhiyun memcpy(&rn->un.topologyDisc.portName,
5280*4882a593Smuzhiyun &vport->fc_portname, sizeof(struct lpfc_name));
5281*4882a593Smuzhiyun rn->un.topologyDisc.unitType = RNID_HBA;
5282*4882a593Smuzhiyun rn->un.topologyDisc.physPort = 0;
5283*4882a593Smuzhiyun rn->un.topologyDisc.attachedNodes = 0;
5284*4882a593Smuzhiyun break;
5285*4882a593Smuzhiyun default:
5286*4882a593Smuzhiyun rn->CommonLen = 0;
5287*4882a593Smuzhiyun rn->SpecificLen = 0;
5288*4882a593Smuzhiyun break;
5289*4882a593Smuzhiyun }
5290*4882a593Smuzhiyun
5291*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5292*4882a593Smuzhiyun "Issue ACC RNID: did:x%x flg:x%x",
5293*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
5294*4882a593Smuzhiyun
5295*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
5296*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5297*4882a593Smuzhiyun
5298*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5299*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
5300*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
5301*4882a593Smuzhiyun return 1;
5302*4882a593Smuzhiyun }
5303*4882a593Smuzhiyun return 0;
5304*4882a593Smuzhiyun }
5305*4882a593Smuzhiyun
5306*4882a593Smuzhiyun /**
5307*4882a593Smuzhiyun * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
5308*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
5309*4882a593Smuzhiyun * @iocb: pointer to the lpfc command iocb data structure.
5310*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
5311*4882a593Smuzhiyun *
5312*4882a593Smuzhiyun * Return
5313*4882a593Smuzhiyun **/
5314*4882a593Smuzhiyun static void
lpfc_els_clear_rrq(struct lpfc_vport * vport,struct lpfc_iocbq * iocb,struct lpfc_nodelist * ndlp)5315*4882a593Smuzhiyun lpfc_els_clear_rrq(struct lpfc_vport *vport,
5316*4882a593Smuzhiyun struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
5317*4882a593Smuzhiyun {
5318*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
5319*4882a593Smuzhiyun uint8_t *pcmd;
5320*4882a593Smuzhiyun struct RRQ *rrq;
5321*4882a593Smuzhiyun uint16_t rxid;
5322*4882a593Smuzhiyun uint16_t xri;
5323*4882a593Smuzhiyun struct lpfc_node_rrq *prrq;
5324*4882a593Smuzhiyun
5325*4882a593Smuzhiyun
5326*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
5327*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
5328*4882a593Smuzhiyun rrq = (struct RRQ *)pcmd;
5329*4882a593Smuzhiyun rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
5330*4882a593Smuzhiyun rxid = bf_get(rrq_rxid, rrq);
5331*4882a593Smuzhiyun
5332*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5333*4882a593Smuzhiyun "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
5334*4882a593Smuzhiyun " x%x x%x\n",
5335*4882a593Smuzhiyun be32_to_cpu(bf_get(rrq_did, rrq)),
5336*4882a593Smuzhiyun bf_get(rrq_oxid, rrq),
5337*4882a593Smuzhiyun rxid,
5338*4882a593Smuzhiyun iocb->iotag, iocb->iocb.ulpContext);
5339*4882a593Smuzhiyun
5340*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5341*4882a593Smuzhiyun "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
5342*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
5343*4882a593Smuzhiyun if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
5344*4882a593Smuzhiyun xri = bf_get(rrq_oxid, rrq);
5345*4882a593Smuzhiyun else
5346*4882a593Smuzhiyun xri = rxid;
5347*4882a593Smuzhiyun prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
5348*4882a593Smuzhiyun if (prrq)
5349*4882a593Smuzhiyun lpfc_clr_rrq_active(phba, xri, prrq);
5350*4882a593Smuzhiyun return;
5351*4882a593Smuzhiyun }
5352*4882a593Smuzhiyun
5353*4882a593Smuzhiyun /**
5354*4882a593Smuzhiyun * lpfc_els_rsp_echo_acc - Issue echo acc response
5355*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
5356*4882a593Smuzhiyun * @data: pointer to echo data to return in the accept.
5357*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
5358*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
5359*4882a593Smuzhiyun *
5360*4882a593Smuzhiyun * Return code
5361*4882a593Smuzhiyun * 0 - Successfully issued acc echo response
5362*4882a593Smuzhiyun * 1 - Failed to issue acc echo response
5363*4882a593Smuzhiyun **/
5364*4882a593Smuzhiyun static int
lpfc_els_rsp_echo_acc(struct lpfc_vport * vport,uint8_t * data,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)5365*4882a593Smuzhiyun lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
5366*4882a593Smuzhiyun struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5367*4882a593Smuzhiyun {
5368*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
5369*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
5370*4882a593Smuzhiyun uint8_t *pcmd;
5371*4882a593Smuzhiyun uint16_t cmdsize;
5372*4882a593Smuzhiyun int rc;
5373*4882a593Smuzhiyun
5374*4882a593Smuzhiyun cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
5375*4882a593Smuzhiyun
5376*4882a593Smuzhiyun /* The accumulated length can exceed the BPL_SIZE. For
5377*4882a593Smuzhiyun * now, use this as the limit
5378*4882a593Smuzhiyun */
5379*4882a593Smuzhiyun if (cmdsize > LPFC_BPL_SIZE)
5380*4882a593Smuzhiyun cmdsize = LPFC_BPL_SIZE;
5381*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5382*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
5383*4882a593Smuzhiyun if (!elsiocb)
5384*4882a593Smuzhiyun return 1;
5385*4882a593Smuzhiyun
5386*4882a593Smuzhiyun elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
5387*4882a593Smuzhiyun elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
5388*4882a593Smuzhiyun
5389*4882a593Smuzhiyun /* Xmit ECHO ACC response tag <ulpIoTag> */
5390*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5391*4882a593Smuzhiyun "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
5392*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext);
5393*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5394*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5395*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
5396*4882a593Smuzhiyun memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
5397*4882a593Smuzhiyun
5398*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
5399*4882a593Smuzhiyun "Issue ACC ECHO: did:x%x flg:x%x",
5400*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
5401*4882a593Smuzhiyun
5402*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
5403*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5404*4882a593Smuzhiyun
5405*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5406*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
5407*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
5408*4882a593Smuzhiyun return 1;
5409*4882a593Smuzhiyun }
5410*4882a593Smuzhiyun return 0;
5411*4882a593Smuzhiyun }
5412*4882a593Smuzhiyun
5413*4882a593Smuzhiyun /**
5414*4882a593Smuzhiyun * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
5415*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
5416*4882a593Smuzhiyun *
5417*4882a593Smuzhiyun * This routine issues Address Discover (ADISC) ELS commands to those
5418*4882a593Smuzhiyun * N_Ports which are in node port recovery state and ADISC has not been issued
5419*4882a593Smuzhiyun * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
5420*4882a593Smuzhiyun * lpfc_issue_els_adisc() routine, the per @vport number of discover count
5421*4882a593Smuzhiyun * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
5422*4882a593Smuzhiyun * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
5423*4882a593Smuzhiyun * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
5424*4882a593Smuzhiyun * IOCBs quit for later pick up. On the other hand, after walking through
5425*4882a593Smuzhiyun * all the ndlps with the @vport and there is none ADISC IOCB issued, the
5426*4882a593Smuzhiyun * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
5427*4882a593Smuzhiyun * no more ADISC need to be sent.
5428*4882a593Smuzhiyun *
5429*4882a593Smuzhiyun * Return code
5430*4882a593Smuzhiyun * The number of N_Ports with adisc issued.
5431*4882a593Smuzhiyun **/
5432*4882a593Smuzhiyun int
lpfc_els_disc_adisc(struct lpfc_vport * vport)5433*4882a593Smuzhiyun lpfc_els_disc_adisc(struct lpfc_vport *vport)
5434*4882a593Smuzhiyun {
5435*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5436*4882a593Smuzhiyun struct lpfc_nodelist *ndlp, *next_ndlp;
5437*4882a593Smuzhiyun int sentadisc = 0;
5438*4882a593Smuzhiyun
5439*4882a593Smuzhiyun /* go thru NPR nodes and issue any remaining ELS ADISCs */
5440*4882a593Smuzhiyun list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5441*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp))
5442*4882a593Smuzhiyun continue;
5443*4882a593Smuzhiyun if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5444*4882a593Smuzhiyun (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5445*4882a593Smuzhiyun (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
5446*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
5447*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_NPR_ADISC;
5448*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
5449*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
5450*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
5451*4882a593Smuzhiyun lpfc_issue_els_adisc(vport, ndlp, 0);
5452*4882a593Smuzhiyun sentadisc++;
5453*4882a593Smuzhiyun vport->num_disc_nodes++;
5454*4882a593Smuzhiyun if (vport->num_disc_nodes >=
5455*4882a593Smuzhiyun vport->cfg_discovery_threads) {
5456*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
5457*4882a593Smuzhiyun vport->fc_flag |= FC_NLP_MORE;
5458*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
5459*4882a593Smuzhiyun break;
5460*4882a593Smuzhiyun }
5461*4882a593Smuzhiyun }
5462*4882a593Smuzhiyun }
5463*4882a593Smuzhiyun if (sentadisc == 0) {
5464*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
5465*4882a593Smuzhiyun vport->fc_flag &= ~FC_NLP_MORE;
5466*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
5467*4882a593Smuzhiyun }
5468*4882a593Smuzhiyun return sentadisc;
5469*4882a593Smuzhiyun }
5470*4882a593Smuzhiyun
5471*4882a593Smuzhiyun /**
5472*4882a593Smuzhiyun * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
5473*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
5474*4882a593Smuzhiyun *
5475*4882a593Smuzhiyun * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
5476*4882a593Smuzhiyun * which are in node port recovery state, with a @vport. Each time an ELS
5477*4882a593Smuzhiyun * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
5478*4882a593Smuzhiyun * the per @vport number of discover count (num_disc_nodes) shall be
5479*4882a593Smuzhiyun * incremented. If the num_disc_nodes reaches a pre-configured threshold
5480*4882a593Smuzhiyun * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
5481*4882a593Smuzhiyun * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
5482*4882a593Smuzhiyun * later pick up. On the other hand, after walking through all the ndlps with
5483*4882a593Smuzhiyun * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
5484*4882a593Smuzhiyun * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
5485*4882a593Smuzhiyun * PLOGI need to be sent.
5486*4882a593Smuzhiyun *
5487*4882a593Smuzhiyun * Return code
5488*4882a593Smuzhiyun * The number of N_Ports with plogi issued.
5489*4882a593Smuzhiyun **/
5490*4882a593Smuzhiyun int
lpfc_els_disc_plogi(struct lpfc_vport * vport)5491*4882a593Smuzhiyun lpfc_els_disc_plogi(struct lpfc_vport *vport)
5492*4882a593Smuzhiyun {
5493*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5494*4882a593Smuzhiyun struct lpfc_nodelist *ndlp, *next_ndlp;
5495*4882a593Smuzhiyun int sentplogi = 0;
5496*4882a593Smuzhiyun
5497*4882a593Smuzhiyun /* go thru NPR nodes and issue any remaining ELS PLOGIs */
5498*4882a593Smuzhiyun list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
5499*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp))
5500*4882a593Smuzhiyun continue;
5501*4882a593Smuzhiyun if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
5502*4882a593Smuzhiyun (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
5503*4882a593Smuzhiyun (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
5504*4882a593Smuzhiyun (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
5505*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
5506*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5507*4882a593Smuzhiyun lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5508*4882a593Smuzhiyun sentplogi++;
5509*4882a593Smuzhiyun vport->num_disc_nodes++;
5510*4882a593Smuzhiyun if (vport->num_disc_nodes >=
5511*4882a593Smuzhiyun vport->cfg_discovery_threads) {
5512*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
5513*4882a593Smuzhiyun vport->fc_flag |= FC_NLP_MORE;
5514*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
5515*4882a593Smuzhiyun break;
5516*4882a593Smuzhiyun }
5517*4882a593Smuzhiyun }
5518*4882a593Smuzhiyun }
5519*4882a593Smuzhiyun
5520*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5521*4882a593Smuzhiyun "6452 Discover PLOGI %d flag x%x\n",
5522*4882a593Smuzhiyun sentplogi, vport->fc_flag);
5523*4882a593Smuzhiyun
5524*4882a593Smuzhiyun if (sentplogi) {
5525*4882a593Smuzhiyun lpfc_set_disctmo(vport);
5526*4882a593Smuzhiyun }
5527*4882a593Smuzhiyun else {
5528*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
5529*4882a593Smuzhiyun vport->fc_flag &= ~FC_NLP_MORE;
5530*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
5531*4882a593Smuzhiyun }
5532*4882a593Smuzhiyun return sentplogi;
5533*4882a593Smuzhiyun }
5534*4882a593Smuzhiyun
5535*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc * desc,uint32_t word0)5536*4882a593Smuzhiyun lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
5537*4882a593Smuzhiyun uint32_t word0)
5538*4882a593Smuzhiyun {
5539*4882a593Smuzhiyun
5540*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
5541*4882a593Smuzhiyun desc->payload.els_req = word0;
5542*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->payload));
5543*4882a593Smuzhiyun
5544*4882a593Smuzhiyun return sizeof(struct fc_rdp_link_service_desc);
5545*4882a593Smuzhiyun }
5546*4882a593Smuzhiyun
5547*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc * desc,uint8_t * page_a0,uint8_t * page_a2)5548*4882a593Smuzhiyun lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
5549*4882a593Smuzhiyun uint8_t *page_a0, uint8_t *page_a2)
5550*4882a593Smuzhiyun {
5551*4882a593Smuzhiyun uint16_t wavelength;
5552*4882a593Smuzhiyun uint16_t temperature;
5553*4882a593Smuzhiyun uint16_t rx_power;
5554*4882a593Smuzhiyun uint16_t tx_bias;
5555*4882a593Smuzhiyun uint16_t tx_power;
5556*4882a593Smuzhiyun uint16_t vcc;
5557*4882a593Smuzhiyun uint16_t flag = 0;
5558*4882a593Smuzhiyun struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
5559*4882a593Smuzhiyun struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
5560*4882a593Smuzhiyun
5561*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
5562*4882a593Smuzhiyun
5563*4882a593Smuzhiyun trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
5564*4882a593Smuzhiyun &page_a0[SSF_TRANSCEIVER_CODE_B4];
5565*4882a593Smuzhiyun trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
5566*4882a593Smuzhiyun &page_a0[SSF_TRANSCEIVER_CODE_B5];
5567*4882a593Smuzhiyun
5568*4882a593Smuzhiyun if ((trasn_code_byte4->fc_sw_laser) ||
5569*4882a593Smuzhiyun (trasn_code_byte5->fc_sw_laser_sl) ||
5570*4882a593Smuzhiyun (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
5571*4882a593Smuzhiyun flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
5572*4882a593Smuzhiyun } else if (trasn_code_byte4->fc_lw_laser) {
5573*4882a593Smuzhiyun wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
5574*4882a593Smuzhiyun page_a0[SSF_WAVELENGTH_B0];
5575*4882a593Smuzhiyun if (wavelength == SFP_WAVELENGTH_LC1310)
5576*4882a593Smuzhiyun flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
5577*4882a593Smuzhiyun if (wavelength == SFP_WAVELENGTH_LL1550)
5578*4882a593Smuzhiyun flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
5579*4882a593Smuzhiyun }
5580*4882a593Smuzhiyun /* check if its SFP+ */
5581*4882a593Smuzhiyun flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
5582*4882a593Smuzhiyun SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
5583*4882a593Smuzhiyun << SFP_FLAG_CT_SHIFT;
5584*4882a593Smuzhiyun
5585*4882a593Smuzhiyun /* check if its OPTICAL */
5586*4882a593Smuzhiyun flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
5587*4882a593Smuzhiyun SFP_FLAG_IS_OPTICAL_PORT : 0)
5588*4882a593Smuzhiyun << SFP_FLAG_IS_OPTICAL_SHIFT;
5589*4882a593Smuzhiyun
5590*4882a593Smuzhiyun temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
5591*4882a593Smuzhiyun page_a2[SFF_TEMPERATURE_B0]);
5592*4882a593Smuzhiyun vcc = (page_a2[SFF_VCC_B1] << 8 |
5593*4882a593Smuzhiyun page_a2[SFF_VCC_B0]);
5594*4882a593Smuzhiyun tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
5595*4882a593Smuzhiyun page_a2[SFF_TXPOWER_B0]);
5596*4882a593Smuzhiyun tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
5597*4882a593Smuzhiyun page_a2[SFF_TX_BIAS_CURRENT_B0]);
5598*4882a593Smuzhiyun rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
5599*4882a593Smuzhiyun page_a2[SFF_RXPOWER_B0]);
5600*4882a593Smuzhiyun desc->sfp_info.temperature = cpu_to_be16(temperature);
5601*4882a593Smuzhiyun desc->sfp_info.rx_power = cpu_to_be16(rx_power);
5602*4882a593Smuzhiyun desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
5603*4882a593Smuzhiyun desc->sfp_info.tx_power = cpu_to_be16(tx_power);
5604*4882a593Smuzhiyun desc->sfp_info.vcc = cpu_to_be16(vcc);
5605*4882a593Smuzhiyun
5606*4882a593Smuzhiyun desc->sfp_info.flags = cpu_to_be16(flag);
5607*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->sfp_info));
5608*4882a593Smuzhiyun
5609*4882a593Smuzhiyun return sizeof(struct fc_rdp_sfp_desc);
5610*4882a593Smuzhiyun }
5611*4882a593Smuzhiyun
5612*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc * desc,READ_LNK_VAR * stat)5613*4882a593Smuzhiyun lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
5614*4882a593Smuzhiyun READ_LNK_VAR *stat)
5615*4882a593Smuzhiyun {
5616*4882a593Smuzhiyun uint32_t type;
5617*4882a593Smuzhiyun
5618*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
5619*4882a593Smuzhiyun
5620*4882a593Smuzhiyun type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
5621*4882a593Smuzhiyun
5622*4882a593Smuzhiyun desc->info.port_type = cpu_to_be32(type);
5623*4882a593Smuzhiyun
5624*4882a593Smuzhiyun desc->info.link_status.link_failure_cnt =
5625*4882a593Smuzhiyun cpu_to_be32(stat->linkFailureCnt);
5626*4882a593Smuzhiyun desc->info.link_status.loss_of_synch_cnt =
5627*4882a593Smuzhiyun cpu_to_be32(stat->lossSyncCnt);
5628*4882a593Smuzhiyun desc->info.link_status.loss_of_signal_cnt =
5629*4882a593Smuzhiyun cpu_to_be32(stat->lossSignalCnt);
5630*4882a593Smuzhiyun desc->info.link_status.primitive_seq_proto_err =
5631*4882a593Smuzhiyun cpu_to_be32(stat->primSeqErrCnt);
5632*4882a593Smuzhiyun desc->info.link_status.invalid_trans_word =
5633*4882a593Smuzhiyun cpu_to_be32(stat->invalidXmitWord);
5634*4882a593Smuzhiyun desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
5635*4882a593Smuzhiyun
5636*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->info));
5637*4882a593Smuzhiyun
5638*4882a593Smuzhiyun return sizeof(struct fc_rdp_link_error_status_desc);
5639*4882a593Smuzhiyun }
5640*4882a593Smuzhiyun
5641*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc * desc,READ_LNK_VAR * stat,struct lpfc_vport * vport)5642*4882a593Smuzhiyun lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
5643*4882a593Smuzhiyun struct lpfc_vport *vport)
5644*4882a593Smuzhiyun {
5645*4882a593Smuzhiyun uint32_t bbCredit;
5646*4882a593Smuzhiyun
5647*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
5648*4882a593Smuzhiyun
5649*4882a593Smuzhiyun bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
5650*4882a593Smuzhiyun (vport->fc_sparam.cmn.bbCreditMsb << 8);
5651*4882a593Smuzhiyun desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
5652*4882a593Smuzhiyun if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
5653*4882a593Smuzhiyun bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
5654*4882a593Smuzhiyun (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
5655*4882a593Smuzhiyun desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
5656*4882a593Smuzhiyun } else {
5657*4882a593Smuzhiyun desc->bbc_info.attached_port_bbc = 0;
5658*4882a593Smuzhiyun }
5659*4882a593Smuzhiyun
5660*4882a593Smuzhiyun desc->bbc_info.rtt = 0;
5661*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->bbc_info));
5662*4882a593Smuzhiyun
5663*4882a593Smuzhiyun return sizeof(struct fc_rdp_bbc_desc);
5664*4882a593Smuzhiyun }
5665*4882a593Smuzhiyun
5666*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_oed_temp_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)5667*4882a593Smuzhiyun lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
5668*4882a593Smuzhiyun struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
5669*4882a593Smuzhiyun {
5670*4882a593Smuzhiyun uint32_t flags = 0;
5671*4882a593Smuzhiyun
5672*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5673*4882a593Smuzhiyun
5674*4882a593Smuzhiyun desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
5675*4882a593Smuzhiyun desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
5676*4882a593Smuzhiyun desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
5677*4882a593Smuzhiyun desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
5678*4882a593Smuzhiyun
5679*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5680*4882a593Smuzhiyun flags |= RDP_OET_HIGH_ALARM;
5681*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5682*4882a593Smuzhiyun flags |= RDP_OET_LOW_ALARM;
5683*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
5684*4882a593Smuzhiyun flags |= RDP_OET_HIGH_WARNING;
5685*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
5686*4882a593Smuzhiyun flags |= RDP_OET_LOW_WARNING;
5687*4882a593Smuzhiyun
5688*4882a593Smuzhiyun flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
5689*4882a593Smuzhiyun desc->oed_info.function_flags = cpu_to_be32(flags);
5690*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->oed_info));
5691*4882a593Smuzhiyun return sizeof(struct fc_rdp_oed_sfp_desc);
5692*4882a593Smuzhiyun }
5693*4882a593Smuzhiyun
5694*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)5695*4882a593Smuzhiyun lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
5696*4882a593Smuzhiyun struct fc_rdp_oed_sfp_desc *desc,
5697*4882a593Smuzhiyun uint8_t *page_a2)
5698*4882a593Smuzhiyun {
5699*4882a593Smuzhiyun uint32_t flags = 0;
5700*4882a593Smuzhiyun
5701*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5702*4882a593Smuzhiyun
5703*4882a593Smuzhiyun desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
5704*4882a593Smuzhiyun desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
5705*4882a593Smuzhiyun desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
5706*4882a593Smuzhiyun desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
5707*4882a593Smuzhiyun
5708*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5709*4882a593Smuzhiyun flags |= RDP_OET_HIGH_ALARM;
5710*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5711*4882a593Smuzhiyun flags |= RDP_OET_LOW_ALARM;
5712*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
5713*4882a593Smuzhiyun flags |= RDP_OET_HIGH_WARNING;
5714*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
5715*4882a593Smuzhiyun flags |= RDP_OET_LOW_WARNING;
5716*4882a593Smuzhiyun
5717*4882a593Smuzhiyun flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
5718*4882a593Smuzhiyun desc->oed_info.function_flags = cpu_to_be32(flags);
5719*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->oed_info));
5720*4882a593Smuzhiyun return sizeof(struct fc_rdp_oed_sfp_desc);
5721*4882a593Smuzhiyun }
5722*4882a593Smuzhiyun
5723*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)5724*4882a593Smuzhiyun lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
5725*4882a593Smuzhiyun struct fc_rdp_oed_sfp_desc *desc,
5726*4882a593Smuzhiyun uint8_t *page_a2)
5727*4882a593Smuzhiyun {
5728*4882a593Smuzhiyun uint32_t flags = 0;
5729*4882a593Smuzhiyun
5730*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5731*4882a593Smuzhiyun
5732*4882a593Smuzhiyun desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
5733*4882a593Smuzhiyun desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
5734*4882a593Smuzhiyun desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
5735*4882a593Smuzhiyun desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
5736*4882a593Smuzhiyun
5737*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5738*4882a593Smuzhiyun flags |= RDP_OET_HIGH_ALARM;
5739*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
5740*4882a593Smuzhiyun flags |= RDP_OET_LOW_ALARM;
5741*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
5742*4882a593Smuzhiyun flags |= RDP_OET_HIGH_WARNING;
5743*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
5744*4882a593Smuzhiyun flags |= RDP_OET_LOW_WARNING;
5745*4882a593Smuzhiyun
5746*4882a593Smuzhiyun flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
5747*4882a593Smuzhiyun desc->oed_info.function_flags = cpu_to_be32(flags);
5748*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->oed_info));
5749*4882a593Smuzhiyun return sizeof(struct fc_rdp_oed_sfp_desc);
5750*4882a593Smuzhiyun }
5751*4882a593Smuzhiyun
5752*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)5753*4882a593Smuzhiyun lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
5754*4882a593Smuzhiyun struct fc_rdp_oed_sfp_desc *desc,
5755*4882a593Smuzhiyun uint8_t *page_a2)
5756*4882a593Smuzhiyun {
5757*4882a593Smuzhiyun uint32_t flags = 0;
5758*4882a593Smuzhiyun
5759*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5760*4882a593Smuzhiyun
5761*4882a593Smuzhiyun desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
5762*4882a593Smuzhiyun desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
5763*4882a593Smuzhiyun desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
5764*4882a593Smuzhiyun desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
5765*4882a593Smuzhiyun
5766*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5767*4882a593Smuzhiyun flags |= RDP_OET_HIGH_ALARM;
5768*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
5769*4882a593Smuzhiyun flags |= RDP_OET_LOW_ALARM;
5770*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
5771*4882a593Smuzhiyun flags |= RDP_OET_HIGH_WARNING;
5772*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
5773*4882a593Smuzhiyun flags |= RDP_OET_LOW_WARNING;
5774*4882a593Smuzhiyun
5775*4882a593Smuzhiyun flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
5776*4882a593Smuzhiyun desc->oed_info.function_flags = cpu_to_be32(flags);
5777*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->oed_info));
5778*4882a593Smuzhiyun return sizeof(struct fc_rdp_oed_sfp_desc);
5779*4882a593Smuzhiyun }
5780*4882a593Smuzhiyun
5781*4882a593Smuzhiyun
5782*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba * phba,struct fc_rdp_oed_sfp_desc * desc,uint8_t * page_a2)5783*4882a593Smuzhiyun lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
5784*4882a593Smuzhiyun struct fc_rdp_oed_sfp_desc *desc,
5785*4882a593Smuzhiyun uint8_t *page_a2)
5786*4882a593Smuzhiyun {
5787*4882a593Smuzhiyun uint32_t flags = 0;
5788*4882a593Smuzhiyun
5789*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
5790*4882a593Smuzhiyun
5791*4882a593Smuzhiyun desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
5792*4882a593Smuzhiyun desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
5793*4882a593Smuzhiyun desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
5794*4882a593Smuzhiyun desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
5795*4882a593Smuzhiyun
5796*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5797*4882a593Smuzhiyun flags |= RDP_OET_HIGH_ALARM;
5798*4882a593Smuzhiyun if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
5799*4882a593Smuzhiyun flags |= RDP_OET_LOW_ALARM;
5800*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
5801*4882a593Smuzhiyun flags |= RDP_OET_HIGH_WARNING;
5802*4882a593Smuzhiyun if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
5803*4882a593Smuzhiyun flags |= RDP_OET_LOW_WARNING;
5804*4882a593Smuzhiyun
5805*4882a593Smuzhiyun flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
5806*4882a593Smuzhiyun desc->oed_info.function_flags = cpu_to_be32(flags);
5807*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->oed_info));
5808*4882a593Smuzhiyun return sizeof(struct fc_rdp_oed_sfp_desc);
5809*4882a593Smuzhiyun }
5810*4882a593Smuzhiyun
5811*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc * desc,uint8_t * page_a0,struct lpfc_vport * vport)5812*4882a593Smuzhiyun lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
5813*4882a593Smuzhiyun uint8_t *page_a0, struct lpfc_vport *vport)
5814*4882a593Smuzhiyun {
5815*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
5816*4882a593Smuzhiyun memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
5817*4882a593Smuzhiyun memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
5818*4882a593Smuzhiyun memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
5819*4882a593Smuzhiyun memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 4);
5820*4882a593Smuzhiyun memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
5821*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->opd_info));
5822*4882a593Smuzhiyun return sizeof(struct fc_rdp_opd_sfp_desc);
5823*4882a593Smuzhiyun }
5824*4882a593Smuzhiyun
5825*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc * desc,READ_LNK_VAR * stat)5826*4882a593Smuzhiyun lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
5827*4882a593Smuzhiyun {
5828*4882a593Smuzhiyun if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
5829*4882a593Smuzhiyun return 0;
5830*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
5831*4882a593Smuzhiyun
5832*4882a593Smuzhiyun desc->info.CorrectedBlocks =
5833*4882a593Smuzhiyun cpu_to_be32(stat->fecCorrBlkCount);
5834*4882a593Smuzhiyun desc->info.UncorrectableBlocks =
5835*4882a593Smuzhiyun cpu_to_be32(stat->fecUncorrBlkCount);
5836*4882a593Smuzhiyun
5837*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->info));
5838*4882a593Smuzhiyun
5839*4882a593Smuzhiyun return sizeof(struct fc_fec_rdp_desc);
5840*4882a593Smuzhiyun }
5841*4882a593Smuzhiyun
5842*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc * desc,struct lpfc_hba * phba)5843*4882a593Smuzhiyun lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
5844*4882a593Smuzhiyun {
5845*4882a593Smuzhiyun uint16_t rdp_cap = 0;
5846*4882a593Smuzhiyun uint16_t rdp_speed;
5847*4882a593Smuzhiyun
5848*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
5849*4882a593Smuzhiyun
5850*4882a593Smuzhiyun switch (phba->fc_linkspeed) {
5851*4882a593Smuzhiyun case LPFC_LINK_SPEED_1GHZ:
5852*4882a593Smuzhiyun rdp_speed = RDP_PS_1GB;
5853*4882a593Smuzhiyun break;
5854*4882a593Smuzhiyun case LPFC_LINK_SPEED_2GHZ:
5855*4882a593Smuzhiyun rdp_speed = RDP_PS_2GB;
5856*4882a593Smuzhiyun break;
5857*4882a593Smuzhiyun case LPFC_LINK_SPEED_4GHZ:
5858*4882a593Smuzhiyun rdp_speed = RDP_PS_4GB;
5859*4882a593Smuzhiyun break;
5860*4882a593Smuzhiyun case LPFC_LINK_SPEED_8GHZ:
5861*4882a593Smuzhiyun rdp_speed = RDP_PS_8GB;
5862*4882a593Smuzhiyun break;
5863*4882a593Smuzhiyun case LPFC_LINK_SPEED_10GHZ:
5864*4882a593Smuzhiyun rdp_speed = RDP_PS_10GB;
5865*4882a593Smuzhiyun break;
5866*4882a593Smuzhiyun case LPFC_LINK_SPEED_16GHZ:
5867*4882a593Smuzhiyun rdp_speed = RDP_PS_16GB;
5868*4882a593Smuzhiyun break;
5869*4882a593Smuzhiyun case LPFC_LINK_SPEED_32GHZ:
5870*4882a593Smuzhiyun rdp_speed = RDP_PS_32GB;
5871*4882a593Smuzhiyun break;
5872*4882a593Smuzhiyun case LPFC_LINK_SPEED_64GHZ:
5873*4882a593Smuzhiyun rdp_speed = RDP_PS_64GB;
5874*4882a593Smuzhiyun break;
5875*4882a593Smuzhiyun default:
5876*4882a593Smuzhiyun rdp_speed = RDP_PS_UNKNOWN;
5877*4882a593Smuzhiyun break;
5878*4882a593Smuzhiyun }
5879*4882a593Smuzhiyun
5880*4882a593Smuzhiyun desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
5881*4882a593Smuzhiyun
5882*4882a593Smuzhiyun if (phba->lmt & LMT_128Gb)
5883*4882a593Smuzhiyun rdp_cap |= RDP_PS_128GB;
5884*4882a593Smuzhiyun if (phba->lmt & LMT_64Gb)
5885*4882a593Smuzhiyun rdp_cap |= RDP_PS_64GB;
5886*4882a593Smuzhiyun if (phba->lmt & LMT_32Gb)
5887*4882a593Smuzhiyun rdp_cap |= RDP_PS_32GB;
5888*4882a593Smuzhiyun if (phba->lmt & LMT_16Gb)
5889*4882a593Smuzhiyun rdp_cap |= RDP_PS_16GB;
5890*4882a593Smuzhiyun if (phba->lmt & LMT_10Gb)
5891*4882a593Smuzhiyun rdp_cap |= RDP_PS_10GB;
5892*4882a593Smuzhiyun if (phba->lmt & LMT_8Gb)
5893*4882a593Smuzhiyun rdp_cap |= RDP_PS_8GB;
5894*4882a593Smuzhiyun if (phba->lmt & LMT_4Gb)
5895*4882a593Smuzhiyun rdp_cap |= RDP_PS_4GB;
5896*4882a593Smuzhiyun if (phba->lmt & LMT_2Gb)
5897*4882a593Smuzhiyun rdp_cap |= RDP_PS_2GB;
5898*4882a593Smuzhiyun if (phba->lmt & LMT_1Gb)
5899*4882a593Smuzhiyun rdp_cap |= RDP_PS_1GB;
5900*4882a593Smuzhiyun
5901*4882a593Smuzhiyun if (rdp_cap == 0)
5902*4882a593Smuzhiyun rdp_cap = RDP_CAP_UNKNOWN;
5903*4882a593Smuzhiyun if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
5904*4882a593Smuzhiyun rdp_cap |= RDP_CAP_USER_CONFIGURED;
5905*4882a593Smuzhiyun
5906*4882a593Smuzhiyun desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
5907*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->info));
5908*4882a593Smuzhiyun return sizeof(struct fc_rdp_port_speed_desc);
5909*4882a593Smuzhiyun }
5910*4882a593Smuzhiyun
5911*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc * desc,struct lpfc_vport * vport)5912*4882a593Smuzhiyun lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
5913*4882a593Smuzhiyun struct lpfc_vport *vport)
5914*4882a593Smuzhiyun {
5915*4882a593Smuzhiyun
5916*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5917*4882a593Smuzhiyun
5918*4882a593Smuzhiyun memcpy(desc->port_names.wwnn, &vport->fc_nodename,
5919*4882a593Smuzhiyun sizeof(desc->port_names.wwnn));
5920*4882a593Smuzhiyun
5921*4882a593Smuzhiyun memcpy(desc->port_names.wwpn, &vport->fc_portname,
5922*4882a593Smuzhiyun sizeof(desc->port_names.wwpn));
5923*4882a593Smuzhiyun
5924*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->port_names));
5925*4882a593Smuzhiyun return sizeof(struct fc_rdp_port_name_desc);
5926*4882a593Smuzhiyun }
5927*4882a593Smuzhiyun
5928*4882a593Smuzhiyun static uint32_t
lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc * desc,struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)5929*4882a593Smuzhiyun lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5930*4882a593Smuzhiyun struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5931*4882a593Smuzhiyun {
5932*4882a593Smuzhiyun
5933*4882a593Smuzhiyun desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5934*4882a593Smuzhiyun if (vport->fc_flag & FC_FABRIC) {
5935*4882a593Smuzhiyun memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5936*4882a593Smuzhiyun sizeof(desc->port_names.wwnn));
5937*4882a593Smuzhiyun
5938*4882a593Smuzhiyun memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5939*4882a593Smuzhiyun sizeof(desc->port_names.wwpn));
5940*4882a593Smuzhiyun } else { /* Point to Point */
5941*4882a593Smuzhiyun memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5942*4882a593Smuzhiyun sizeof(desc->port_names.wwnn));
5943*4882a593Smuzhiyun
5944*4882a593Smuzhiyun memcpy(desc->port_names.wwpn, &ndlp->nlp_portname,
5945*4882a593Smuzhiyun sizeof(desc->port_names.wwpn));
5946*4882a593Smuzhiyun }
5947*4882a593Smuzhiyun
5948*4882a593Smuzhiyun desc->length = cpu_to_be32(sizeof(desc->port_names));
5949*4882a593Smuzhiyun return sizeof(struct fc_rdp_port_name_desc);
5950*4882a593Smuzhiyun }
5951*4882a593Smuzhiyun
5952*4882a593Smuzhiyun static void
lpfc_els_rdp_cmpl(struct lpfc_hba * phba,struct lpfc_rdp_context * rdp_context,int status)5953*4882a593Smuzhiyun lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5954*4882a593Smuzhiyun int status)
5955*4882a593Smuzhiyun {
5956*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5957*4882a593Smuzhiyun struct lpfc_vport *vport = ndlp->vport;
5958*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
5959*4882a593Smuzhiyun struct ulp_bde64 *bpl;
5960*4882a593Smuzhiyun IOCB_t *icmd;
5961*4882a593Smuzhiyun uint8_t *pcmd;
5962*4882a593Smuzhiyun struct ls_rjt *stat;
5963*4882a593Smuzhiyun struct fc_rdp_res_frame *rdp_res;
5964*4882a593Smuzhiyun uint32_t cmdsize, len;
5965*4882a593Smuzhiyun uint16_t *flag_ptr;
5966*4882a593Smuzhiyun int rc;
5967*4882a593Smuzhiyun
5968*4882a593Smuzhiyun if (status != SUCCESS)
5969*4882a593Smuzhiyun goto error;
5970*4882a593Smuzhiyun
5971*4882a593Smuzhiyun /* This will change once we know the true size of the RDP payload */
5972*4882a593Smuzhiyun cmdsize = sizeof(struct fc_rdp_res_frame);
5973*4882a593Smuzhiyun
5974*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5975*4882a593Smuzhiyun lpfc_max_els_tries, rdp_context->ndlp,
5976*4882a593Smuzhiyun rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5977*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
5978*4882a593Smuzhiyun if (!elsiocb)
5979*4882a593Smuzhiyun goto free_rdp_context;
5980*4882a593Smuzhiyun
5981*4882a593Smuzhiyun icmd = &elsiocb->iocb;
5982*4882a593Smuzhiyun icmd->ulpContext = rdp_context->rx_id;
5983*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5984*4882a593Smuzhiyun
5985*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5986*4882a593Smuzhiyun "2171 Xmit RDP response tag x%x xri x%x, "
5987*4882a593Smuzhiyun "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5988*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext,
5989*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5990*4882a593Smuzhiyun ndlp->nlp_rpi);
5991*4882a593Smuzhiyun rdp_res = (struct fc_rdp_res_frame *)
5992*4882a593Smuzhiyun (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5993*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5994*4882a593Smuzhiyun memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5995*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5996*4882a593Smuzhiyun
5997*4882a593Smuzhiyun /* Update Alarm and Warning */
5998*4882a593Smuzhiyun flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5999*4882a593Smuzhiyun phba->sfp_alarm |= *flag_ptr;
6000*4882a593Smuzhiyun flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
6001*4882a593Smuzhiyun phba->sfp_warning |= *flag_ptr;
6002*4882a593Smuzhiyun
6003*4882a593Smuzhiyun /* For RDP payload */
6004*4882a593Smuzhiyun len = 8;
6005*4882a593Smuzhiyun len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
6006*4882a593Smuzhiyun (len + pcmd), ELS_CMD_RDP);
6007*4882a593Smuzhiyun
6008*4882a593Smuzhiyun len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
6009*4882a593Smuzhiyun rdp_context->page_a0, rdp_context->page_a2);
6010*4882a593Smuzhiyun len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
6011*4882a593Smuzhiyun phba);
6012*4882a593Smuzhiyun len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
6013*4882a593Smuzhiyun (len + pcmd), &rdp_context->link_stat);
6014*4882a593Smuzhiyun len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
6015*4882a593Smuzhiyun (len + pcmd), vport);
6016*4882a593Smuzhiyun len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
6017*4882a593Smuzhiyun (len + pcmd), vport, ndlp);
6018*4882a593Smuzhiyun len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
6019*4882a593Smuzhiyun &rdp_context->link_stat);
6020*4882a593Smuzhiyun len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
6021*4882a593Smuzhiyun &rdp_context->link_stat, vport);
6022*4882a593Smuzhiyun len += lpfc_rdp_res_oed_temp_desc(phba,
6023*4882a593Smuzhiyun (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6024*4882a593Smuzhiyun rdp_context->page_a2);
6025*4882a593Smuzhiyun len += lpfc_rdp_res_oed_voltage_desc(phba,
6026*4882a593Smuzhiyun (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6027*4882a593Smuzhiyun rdp_context->page_a2);
6028*4882a593Smuzhiyun len += lpfc_rdp_res_oed_txbias_desc(phba,
6029*4882a593Smuzhiyun (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6030*4882a593Smuzhiyun rdp_context->page_a2);
6031*4882a593Smuzhiyun len += lpfc_rdp_res_oed_txpower_desc(phba,
6032*4882a593Smuzhiyun (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6033*4882a593Smuzhiyun rdp_context->page_a2);
6034*4882a593Smuzhiyun len += lpfc_rdp_res_oed_rxpower_desc(phba,
6035*4882a593Smuzhiyun (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
6036*4882a593Smuzhiyun rdp_context->page_a2);
6037*4882a593Smuzhiyun len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
6038*4882a593Smuzhiyun rdp_context->page_a0, vport);
6039*4882a593Smuzhiyun
6040*4882a593Smuzhiyun rdp_res->length = cpu_to_be32(len - 8);
6041*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6042*4882a593Smuzhiyun
6043*4882a593Smuzhiyun /* Now that we know the true size of the payload, update the BPL */
6044*4882a593Smuzhiyun bpl = (struct ulp_bde64 *)
6045*4882a593Smuzhiyun (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
6046*4882a593Smuzhiyun bpl->tus.f.bdeSize = len;
6047*4882a593Smuzhiyun bpl->tus.f.bdeFlags = 0;
6048*4882a593Smuzhiyun bpl->tus.w = le32_to_cpu(bpl->tus.w);
6049*4882a593Smuzhiyun
6050*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
6051*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6052*4882a593Smuzhiyun if (rc == IOCB_ERROR)
6053*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
6054*4882a593Smuzhiyun
6055*4882a593Smuzhiyun kfree(rdp_context);
6056*4882a593Smuzhiyun
6057*4882a593Smuzhiyun return;
6058*4882a593Smuzhiyun error:
6059*4882a593Smuzhiyun cmdsize = 2 * sizeof(uint32_t);
6060*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
6061*4882a593Smuzhiyun ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
6062*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
6063*4882a593Smuzhiyun if (!elsiocb)
6064*4882a593Smuzhiyun goto free_rdp_context;
6065*4882a593Smuzhiyun
6066*4882a593Smuzhiyun icmd = &elsiocb->iocb;
6067*4882a593Smuzhiyun icmd->ulpContext = rdp_context->rx_id;
6068*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
6069*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6070*4882a593Smuzhiyun
6071*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
6072*4882a593Smuzhiyun stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6073*4882a593Smuzhiyun stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6074*4882a593Smuzhiyun
6075*4882a593Smuzhiyun phba->fc_stat.elsXmitLSRJT++;
6076*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6077*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6078*4882a593Smuzhiyun
6079*4882a593Smuzhiyun if (rc == IOCB_ERROR)
6080*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
6081*4882a593Smuzhiyun free_rdp_context:
6082*4882a593Smuzhiyun kfree(rdp_context);
6083*4882a593Smuzhiyun }
6084*4882a593Smuzhiyun
6085*4882a593Smuzhiyun static int
lpfc_get_rdp_info(struct lpfc_hba * phba,struct lpfc_rdp_context * rdp_context)6086*4882a593Smuzhiyun lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
6087*4882a593Smuzhiyun {
6088*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox = NULL;
6089*4882a593Smuzhiyun int rc;
6090*4882a593Smuzhiyun
6091*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6092*4882a593Smuzhiyun if (!mbox) {
6093*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
6094*4882a593Smuzhiyun "7105 failed to allocate mailbox memory");
6095*4882a593Smuzhiyun return 1;
6096*4882a593Smuzhiyun }
6097*4882a593Smuzhiyun
6098*4882a593Smuzhiyun if (lpfc_sli4_dump_page_a0(phba, mbox))
6099*4882a593Smuzhiyun goto prep_mbox_fail;
6100*4882a593Smuzhiyun mbox->vport = rdp_context->ndlp->vport;
6101*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
6102*4882a593Smuzhiyun mbox->ctx_ndlp = (struct lpfc_rdp_context *)rdp_context;
6103*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6104*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED)
6105*4882a593Smuzhiyun goto issue_mbox_fail;
6106*4882a593Smuzhiyun
6107*4882a593Smuzhiyun return 0;
6108*4882a593Smuzhiyun
6109*4882a593Smuzhiyun prep_mbox_fail:
6110*4882a593Smuzhiyun issue_mbox_fail:
6111*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
6112*4882a593Smuzhiyun return 1;
6113*4882a593Smuzhiyun }
6114*4882a593Smuzhiyun
6115*4882a593Smuzhiyun /*
6116*4882a593Smuzhiyun * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
6117*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6118*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
6119*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
6120*4882a593Smuzhiyun *
6121*4882a593Smuzhiyun * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
6122*4882a593Smuzhiyun * IOCB. First, the payload of the unsolicited RDP is checked.
6123*4882a593Smuzhiyun * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
6124*4882a593Smuzhiyun * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
6125*4882a593Smuzhiyun * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
6126*4882a593Smuzhiyun * gather all data and send RDP response.
6127*4882a593Smuzhiyun *
6128*4882a593Smuzhiyun * Return code
6129*4882a593Smuzhiyun * 0 - Sent the acc response
6130*4882a593Smuzhiyun * 1 - Sent the reject response.
6131*4882a593Smuzhiyun */
6132*4882a593Smuzhiyun static int
lpfc_els_rcv_rdp(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)6133*4882a593Smuzhiyun lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6134*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
6135*4882a593Smuzhiyun {
6136*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
6137*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
6138*4882a593Smuzhiyun uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
6139*4882a593Smuzhiyun struct fc_rdp_req_frame *rdp_req;
6140*4882a593Smuzhiyun struct lpfc_rdp_context *rdp_context;
6141*4882a593Smuzhiyun IOCB_t *cmd = NULL;
6142*4882a593Smuzhiyun struct ls_rjt stat;
6143*4882a593Smuzhiyun
6144*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4 ||
6145*4882a593Smuzhiyun bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6146*4882a593Smuzhiyun LPFC_SLI_INTF_IF_TYPE_2) {
6147*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
6148*4882a593Smuzhiyun rjt_expl = LSEXP_REQ_UNSUPPORTED;
6149*4882a593Smuzhiyun goto error;
6150*4882a593Smuzhiyun }
6151*4882a593Smuzhiyun
6152*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
6153*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
6154*4882a593Smuzhiyun rjt_expl = LSEXP_REQ_UNSUPPORTED;
6155*4882a593Smuzhiyun goto error;
6156*4882a593Smuzhiyun }
6157*4882a593Smuzhiyun
6158*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6159*4882a593Smuzhiyun rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
6160*4882a593Smuzhiyun
6161*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6162*4882a593Smuzhiyun "2422 ELS RDP Request "
6163*4882a593Smuzhiyun "dec len %d tag x%x port_id %d len %d\n",
6164*4882a593Smuzhiyun be32_to_cpu(rdp_req->rdp_des_length),
6165*4882a593Smuzhiyun be32_to_cpu(rdp_req->nport_id_desc.tag),
6166*4882a593Smuzhiyun be32_to_cpu(rdp_req->nport_id_desc.nport_id),
6167*4882a593Smuzhiyun be32_to_cpu(rdp_req->nport_id_desc.length));
6168*4882a593Smuzhiyun
6169*4882a593Smuzhiyun if (sizeof(struct fc_rdp_nport_desc) !=
6170*4882a593Smuzhiyun be32_to_cpu(rdp_req->rdp_des_length))
6171*4882a593Smuzhiyun goto rjt_logerr;
6172*4882a593Smuzhiyun if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
6173*4882a593Smuzhiyun goto rjt_logerr;
6174*4882a593Smuzhiyun if (RDP_NPORT_ID_SIZE !=
6175*4882a593Smuzhiyun be32_to_cpu(rdp_req->nport_id_desc.length))
6176*4882a593Smuzhiyun goto rjt_logerr;
6177*4882a593Smuzhiyun rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
6178*4882a593Smuzhiyun if (!rdp_context) {
6179*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
6180*4882a593Smuzhiyun goto error;
6181*4882a593Smuzhiyun }
6182*4882a593Smuzhiyun
6183*4882a593Smuzhiyun cmd = &cmdiocb->iocb;
6184*4882a593Smuzhiyun rdp_context->ndlp = lpfc_nlp_get(ndlp);
6185*4882a593Smuzhiyun rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
6186*4882a593Smuzhiyun rdp_context->rx_id = cmd->ulpContext;
6187*4882a593Smuzhiyun rdp_context->cmpl = lpfc_els_rdp_cmpl;
6188*4882a593Smuzhiyun if (lpfc_get_rdp_info(phba, rdp_context)) {
6189*4882a593Smuzhiyun lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
6190*4882a593Smuzhiyun "2423 Unable to send mailbox");
6191*4882a593Smuzhiyun kfree(rdp_context);
6192*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
6193*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
6194*4882a593Smuzhiyun goto error;
6195*4882a593Smuzhiyun }
6196*4882a593Smuzhiyun
6197*4882a593Smuzhiyun return 0;
6198*4882a593Smuzhiyun
6199*4882a593Smuzhiyun rjt_logerr:
6200*4882a593Smuzhiyun rjt_err = LSRJT_LOGICAL_ERR;
6201*4882a593Smuzhiyun
6202*4882a593Smuzhiyun error:
6203*4882a593Smuzhiyun memset(&stat, 0, sizeof(stat));
6204*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = rjt_err;
6205*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = rjt_expl;
6206*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6207*4882a593Smuzhiyun return 1;
6208*4882a593Smuzhiyun }
6209*4882a593Smuzhiyun
6210*4882a593Smuzhiyun
6211*4882a593Smuzhiyun static void
lpfc_els_lcb_rsp(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)6212*4882a593Smuzhiyun lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6213*4882a593Smuzhiyun {
6214*4882a593Smuzhiyun MAILBOX_t *mb;
6215*4882a593Smuzhiyun IOCB_t *icmd;
6216*4882a593Smuzhiyun uint8_t *pcmd;
6217*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
6218*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
6219*4882a593Smuzhiyun struct ls_rjt *stat;
6220*4882a593Smuzhiyun union lpfc_sli4_cfg_shdr *shdr;
6221*4882a593Smuzhiyun struct lpfc_lcb_context *lcb_context;
6222*4882a593Smuzhiyun struct fc_lcb_res_frame *lcb_res;
6223*4882a593Smuzhiyun uint32_t cmdsize, shdr_status, shdr_add_status;
6224*4882a593Smuzhiyun int rc;
6225*4882a593Smuzhiyun
6226*4882a593Smuzhiyun mb = &pmb->u.mb;
6227*4882a593Smuzhiyun lcb_context = (struct lpfc_lcb_context *)pmb->ctx_ndlp;
6228*4882a593Smuzhiyun ndlp = lcb_context->ndlp;
6229*4882a593Smuzhiyun pmb->ctx_ndlp = NULL;
6230*4882a593Smuzhiyun pmb->ctx_buf = NULL;
6231*4882a593Smuzhiyun
6232*4882a593Smuzhiyun shdr = (union lpfc_sli4_cfg_shdr *)
6233*4882a593Smuzhiyun &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
6234*4882a593Smuzhiyun shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
6235*4882a593Smuzhiyun shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
6236*4882a593Smuzhiyun
6237*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
6238*4882a593Smuzhiyun "0194 SET_BEACON_CONFIG mailbox "
6239*4882a593Smuzhiyun "completed with status x%x add_status x%x,"
6240*4882a593Smuzhiyun " mbx status x%x\n",
6241*4882a593Smuzhiyun shdr_status, shdr_add_status, mb->mbxStatus);
6242*4882a593Smuzhiyun
6243*4882a593Smuzhiyun if ((mb->mbxStatus != MBX_SUCCESS) || shdr_status ||
6244*4882a593Smuzhiyun (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE) ||
6245*4882a593Smuzhiyun (shdr_add_status == ADD_STATUS_INVALID_REQUEST)) {
6246*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
6247*4882a593Smuzhiyun goto error;
6248*4882a593Smuzhiyun }
6249*4882a593Smuzhiyun
6250*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
6251*4882a593Smuzhiyun cmdsize = sizeof(struct fc_lcb_res_frame);
6252*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6253*4882a593Smuzhiyun lpfc_max_els_tries, ndlp,
6254*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
6255*4882a593Smuzhiyun
6256*4882a593Smuzhiyun /* Decrement the ndlp reference count from previous mbox command */
6257*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
6258*4882a593Smuzhiyun
6259*4882a593Smuzhiyun if (!elsiocb)
6260*4882a593Smuzhiyun goto free_lcb_context;
6261*4882a593Smuzhiyun
6262*4882a593Smuzhiyun lcb_res = (struct fc_lcb_res_frame *)
6263*4882a593Smuzhiyun (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6264*4882a593Smuzhiyun
6265*4882a593Smuzhiyun memset(lcb_res, 0, sizeof(struct fc_lcb_res_frame));
6266*4882a593Smuzhiyun icmd = &elsiocb->iocb;
6267*4882a593Smuzhiyun icmd->ulpContext = lcb_context->rx_id;
6268*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6269*4882a593Smuzhiyun
6270*4882a593Smuzhiyun pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6271*4882a593Smuzhiyun *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
6272*4882a593Smuzhiyun lcb_res->lcb_sub_command = lcb_context->sub_command;
6273*4882a593Smuzhiyun lcb_res->lcb_type = lcb_context->type;
6274*4882a593Smuzhiyun lcb_res->capability = lcb_context->capability;
6275*4882a593Smuzhiyun lcb_res->lcb_frequency = lcb_context->frequency;
6276*4882a593Smuzhiyun lcb_res->lcb_duration = lcb_context->duration;
6277*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6278*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
6279*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6280*4882a593Smuzhiyun if (rc == IOCB_ERROR)
6281*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
6282*4882a593Smuzhiyun
6283*4882a593Smuzhiyun kfree(lcb_context);
6284*4882a593Smuzhiyun return;
6285*4882a593Smuzhiyun
6286*4882a593Smuzhiyun error:
6287*4882a593Smuzhiyun cmdsize = sizeof(struct fc_lcb_res_frame);
6288*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6289*4882a593Smuzhiyun lpfc_max_els_tries, ndlp,
6290*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_LS_RJT);
6291*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
6292*4882a593Smuzhiyun if (!elsiocb)
6293*4882a593Smuzhiyun goto free_lcb_context;
6294*4882a593Smuzhiyun
6295*4882a593Smuzhiyun icmd = &elsiocb->iocb;
6296*4882a593Smuzhiyun icmd->ulpContext = lcb_context->rx_id;
6297*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
6298*4882a593Smuzhiyun pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
6299*4882a593Smuzhiyun
6300*4882a593Smuzhiyun *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
6301*4882a593Smuzhiyun stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
6302*4882a593Smuzhiyun stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6303*4882a593Smuzhiyun
6304*4882a593Smuzhiyun if (shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)
6305*4882a593Smuzhiyun stat->un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
6306*4882a593Smuzhiyun
6307*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6308*4882a593Smuzhiyun phba->fc_stat.elsXmitLSRJT++;
6309*4882a593Smuzhiyun rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6310*4882a593Smuzhiyun if (rc == IOCB_ERROR)
6311*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
6312*4882a593Smuzhiyun free_lcb_context:
6313*4882a593Smuzhiyun kfree(lcb_context);
6314*4882a593Smuzhiyun }
6315*4882a593Smuzhiyun
6316*4882a593Smuzhiyun static int
lpfc_sli4_set_beacon(struct lpfc_vport * vport,struct lpfc_lcb_context * lcb_context,uint32_t beacon_state)6317*4882a593Smuzhiyun lpfc_sli4_set_beacon(struct lpfc_vport *vport,
6318*4882a593Smuzhiyun struct lpfc_lcb_context *lcb_context,
6319*4882a593Smuzhiyun uint32_t beacon_state)
6320*4882a593Smuzhiyun {
6321*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
6322*4882a593Smuzhiyun union lpfc_sli4_cfg_shdr *cfg_shdr;
6323*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox = NULL;
6324*4882a593Smuzhiyun uint32_t len;
6325*4882a593Smuzhiyun int rc;
6326*4882a593Smuzhiyun
6327*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6328*4882a593Smuzhiyun if (!mbox)
6329*4882a593Smuzhiyun return 1;
6330*4882a593Smuzhiyun
6331*4882a593Smuzhiyun cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
6332*4882a593Smuzhiyun len = sizeof(struct lpfc_mbx_set_beacon_config) -
6333*4882a593Smuzhiyun sizeof(struct lpfc_sli4_cfg_mhdr);
6334*4882a593Smuzhiyun lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
6335*4882a593Smuzhiyun LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
6336*4882a593Smuzhiyun LPFC_SLI4_MBX_EMBED);
6337*4882a593Smuzhiyun mbox->ctx_ndlp = (void *)lcb_context;
6338*4882a593Smuzhiyun mbox->vport = phba->pport;
6339*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_els_lcb_rsp;
6340*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
6341*4882a593Smuzhiyun phba->sli4_hba.physical_port);
6342*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
6343*4882a593Smuzhiyun beacon_state);
6344*4882a593Smuzhiyun mbox->u.mqe.un.beacon_config.word5 = 0; /* Reserved */
6345*4882a593Smuzhiyun
6346*4882a593Smuzhiyun /*
6347*4882a593Smuzhiyun * Check bv1s bit before issuing the mailbox
6348*4882a593Smuzhiyun * if bv1s == 1, LCB V1 supported
6349*4882a593Smuzhiyun * else, LCB V0 supported
6350*4882a593Smuzhiyun */
6351*4882a593Smuzhiyun
6352*4882a593Smuzhiyun if (phba->sli4_hba.pc_sli4_params.bv1s) {
6353*4882a593Smuzhiyun /* COMMON_SET_BEACON_CONFIG_V1 */
6354*4882a593Smuzhiyun cfg_shdr->request.word9 = BEACON_VERSION_V1;
6355*4882a593Smuzhiyun lcb_context->capability |= LCB_CAPABILITY_DURATION;
6356*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_port_type,
6357*4882a593Smuzhiyun &mbox->u.mqe.un.beacon_config, 0);
6358*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_duration_v1,
6359*4882a593Smuzhiyun &mbox->u.mqe.un.beacon_config,
6360*4882a593Smuzhiyun be16_to_cpu(lcb_context->duration));
6361*4882a593Smuzhiyun } else {
6362*4882a593Smuzhiyun /* COMMON_SET_BEACON_CONFIG_V0 */
6363*4882a593Smuzhiyun if (be16_to_cpu(lcb_context->duration) != 0) {
6364*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
6365*4882a593Smuzhiyun return 1;
6366*4882a593Smuzhiyun }
6367*4882a593Smuzhiyun cfg_shdr->request.word9 = BEACON_VERSION_V0;
6368*4882a593Smuzhiyun lcb_context->capability &= ~(LCB_CAPABILITY_DURATION);
6369*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_state,
6370*4882a593Smuzhiyun &mbox->u.mqe.un.beacon_config, beacon_state);
6371*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_port_type,
6372*4882a593Smuzhiyun &mbox->u.mqe.un.beacon_config, 1);
6373*4882a593Smuzhiyun bf_set(lpfc_mbx_set_beacon_duration,
6374*4882a593Smuzhiyun &mbox->u.mqe.un.beacon_config,
6375*4882a593Smuzhiyun be16_to_cpu(lcb_context->duration));
6376*4882a593Smuzhiyun }
6377*4882a593Smuzhiyun
6378*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
6379*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
6380*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
6381*4882a593Smuzhiyun return 1;
6382*4882a593Smuzhiyun }
6383*4882a593Smuzhiyun
6384*4882a593Smuzhiyun return 0;
6385*4882a593Smuzhiyun }
6386*4882a593Smuzhiyun
6387*4882a593Smuzhiyun
6388*4882a593Smuzhiyun /**
6389*4882a593Smuzhiyun * lpfc_els_rcv_lcb - Process an unsolicited LCB
6390*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6391*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
6392*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
6393*4882a593Smuzhiyun *
6394*4882a593Smuzhiyun * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
6395*4882a593Smuzhiyun * First, the payload of the unsolicited LCB is checked.
6396*4882a593Smuzhiyun * Then based on Subcommand beacon will either turn on or off.
6397*4882a593Smuzhiyun *
6398*4882a593Smuzhiyun * Return code
6399*4882a593Smuzhiyun * 0 - Sent the acc response
6400*4882a593Smuzhiyun * 1 - Sent the reject response.
6401*4882a593Smuzhiyun **/
6402*4882a593Smuzhiyun static int
lpfc_els_rcv_lcb(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)6403*4882a593Smuzhiyun lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6404*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
6405*4882a593Smuzhiyun {
6406*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
6407*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
6408*4882a593Smuzhiyun uint8_t *lp;
6409*4882a593Smuzhiyun struct fc_lcb_request_frame *beacon;
6410*4882a593Smuzhiyun struct lpfc_lcb_context *lcb_context;
6411*4882a593Smuzhiyun uint8_t state, rjt_err;
6412*4882a593Smuzhiyun struct ls_rjt stat;
6413*4882a593Smuzhiyun
6414*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
6415*4882a593Smuzhiyun lp = (uint8_t *)pcmd->virt;
6416*4882a593Smuzhiyun beacon = (struct fc_lcb_request_frame *)pcmd->virt;
6417*4882a593Smuzhiyun
6418*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6419*4882a593Smuzhiyun "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
6420*4882a593Smuzhiyun "type x%x frequency %x duration x%x\n",
6421*4882a593Smuzhiyun lp[0], lp[1], lp[2],
6422*4882a593Smuzhiyun beacon->lcb_command,
6423*4882a593Smuzhiyun beacon->lcb_sub_command,
6424*4882a593Smuzhiyun beacon->lcb_type,
6425*4882a593Smuzhiyun beacon->lcb_frequency,
6426*4882a593Smuzhiyun be16_to_cpu(beacon->lcb_duration));
6427*4882a593Smuzhiyun
6428*4882a593Smuzhiyun if (beacon->lcb_sub_command != LPFC_LCB_ON &&
6429*4882a593Smuzhiyun beacon->lcb_sub_command != LPFC_LCB_OFF) {
6430*4882a593Smuzhiyun rjt_err = LSRJT_CMD_UNSUPPORTED;
6431*4882a593Smuzhiyun goto rjt;
6432*4882a593Smuzhiyun }
6433*4882a593Smuzhiyun
6434*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4 ||
6435*4882a593Smuzhiyun phba->hba_flag & HBA_FCOE_MODE ||
6436*4882a593Smuzhiyun (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) <
6437*4882a593Smuzhiyun LPFC_SLI_INTF_IF_TYPE_2)) {
6438*4882a593Smuzhiyun rjt_err = LSRJT_CMD_UNSUPPORTED;
6439*4882a593Smuzhiyun goto rjt;
6440*4882a593Smuzhiyun }
6441*4882a593Smuzhiyun
6442*4882a593Smuzhiyun lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
6443*4882a593Smuzhiyun if (!lcb_context) {
6444*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
6445*4882a593Smuzhiyun goto rjt;
6446*4882a593Smuzhiyun }
6447*4882a593Smuzhiyun
6448*4882a593Smuzhiyun state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
6449*4882a593Smuzhiyun lcb_context->sub_command = beacon->lcb_sub_command;
6450*4882a593Smuzhiyun lcb_context->capability = 0;
6451*4882a593Smuzhiyun lcb_context->type = beacon->lcb_type;
6452*4882a593Smuzhiyun lcb_context->frequency = beacon->lcb_frequency;
6453*4882a593Smuzhiyun lcb_context->duration = beacon->lcb_duration;
6454*4882a593Smuzhiyun lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
6455*4882a593Smuzhiyun lcb_context->rx_id = cmdiocb->iocb.ulpContext;
6456*4882a593Smuzhiyun lcb_context->ndlp = lpfc_nlp_get(ndlp);
6457*4882a593Smuzhiyun if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
6458*4882a593Smuzhiyun lpfc_printf_vlog(ndlp->vport, KERN_ERR, LOG_TRACE_EVENT,
6459*4882a593Smuzhiyun "0193 failed to send mail box");
6460*4882a593Smuzhiyun kfree(lcb_context);
6461*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
6462*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
6463*4882a593Smuzhiyun goto rjt;
6464*4882a593Smuzhiyun }
6465*4882a593Smuzhiyun return 0;
6466*4882a593Smuzhiyun rjt:
6467*4882a593Smuzhiyun memset(&stat, 0, sizeof(stat));
6468*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = rjt_err;
6469*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6470*4882a593Smuzhiyun return 1;
6471*4882a593Smuzhiyun }
6472*4882a593Smuzhiyun
6473*4882a593Smuzhiyun
6474*4882a593Smuzhiyun /**
6475*4882a593Smuzhiyun * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
6476*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6477*4882a593Smuzhiyun *
6478*4882a593Smuzhiyun * This routine cleans up any Registration State Change Notification
6479*4882a593Smuzhiyun * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
6480*4882a593Smuzhiyun * @vport together with the host_lock is used to prevent multiple thread
6481*4882a593Smuzhiyun * trying to access the RSCN array on a same @vport at the same time.
6482*4882a593Smuzhiyun **/
6483*4882a593Smuzhiyun void
lpfc_els_flush_rscn(struct lpfc_vport * vport)6484*4882a593Smuzhiyun lpfc_els_flush_rscn(struct lpfc_vport *vport)
6485*4882a593Smuzhiyun {
6486*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6487*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
6488*4882a593Smuzhiyun int i;
6489*4882a593Smuzhiyun
6490*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
6491*4882a593Smuzhiyun if (vport->fc_rscn_flush) {
6492*4882a593Smuzhiyun /* Another thread is walking fc_rscn_id_list on this vport */
6493*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6494*4882a593Smuzhiyun return;
6495*4882a593Smuzhiyun }
6496*4882a593Smuzhiyun /* Indicate we are walking lpfc_els_flush_rscn on this vport */
6497*4882a593Smuzhiyun vport->fc_rscn_flush = 1;
6498*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6499*4882a593Smuzhiyun
6500*4882a593Smuzhiyun for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6501*4882a593Smuzhiyun lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
6502*4882a593Smuzhiyun vport->fc_rscn_id_list[i] = NULL;
6503*4882a593Smuzhiyun }
6504*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
6505*4882a593Smuzhiyun vport->fc_rscn_id_cnt = 0;
6506*4882a593Smuzhiyun vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
6507*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6508*4882a593Smuzhiyun lpfc_can_disctmo(vport);
6509*4882a593Smuzhiyun /* Indicate we are done walking this fc_rscn_id_list */
6510*4882a593Smuzhiyun vport->fc_rscn_flush = 0;
6511*4882a593Smuzhiyun }
6512*4882a593Smuzhiyun
6513*4882a593Smuzhiyun /**
6514*4882a593Smuzhiyun * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
6515*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6516*4882a593Smuzhiyun * @did: remote destination port identifier.
6517*4882a593Smuzhiyun *
6518*4882a593Smuzhiyun * This routine checks whether there is any pending Registration State
6519*4882a593Smuzhiyun * Configuration Notification (RSCN) to a @did on @vport.
6520*4882a593Smuzhiyun *
6521*4882a593Smuzhiyun * Return code
6522*4882a593Smuzhiyun * None zero - The @did matched with a pending rscn
6523*4882a593Smuzhiyun * 0 - not able to match @did with a pending rscn
6524*4882a593Smuzhiyun **/
6525*4882a593Smuzhiyun int
lpfc_rscn_payload_check(struct lpfc_vport * vport,uint32_t did)6526*4882a593Smuzhiyun lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
6527*4882a593Smuzhiyun {
6528*4882a593Smuzhiyun D_ID ns_did;
6529*4882a593Smuzhiyun D_ID rscn_did;
6530*4882a593Smuzhiyun uint32_t *lp;
6531*4882a593Smuzhiyun uint32_t payload_len, i;
6532*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6533*4882a593Smuzhiyun
6534*4882a593Smuzhiyun ns_did.un.word = did;
6535*4882a593Smuzhiyun
6536*4882a593Smuzhiyun /* Never match fabric nodes for RSCNs */
6537*4882a593Smuzhiyun if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6538*4882a593Smuzhiyun return 0;
6539*4882a593Smuzhiyun
6540*4882a593Smuzhiyun /* If we are doing a FULL RSCN rediscovery, match everything */
6541*4882a593Smuzhiyun if (vport->fc_flag & FC_RSCN_DISCOVERY)
6542*4882a593Smuzhiyun return did;
6543*4882a593Smuzhiyun
6544*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
6545*4882a593Smuzhiyun if (vport->fc_rscn_flush) {
6546*4882a593Smuzhiyun /* Another thread is walking fc_rscn_id_list on this vport */
6547*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6548*4882a593Smuzhiyun return 0;
6549*4882a593Smuzhiyun }
6550*4882a593Smuzhiyun /* Indicate we are walking fc_rscn_id_list on this vport */
6551*4882a593Smuzhiyun vport->fc_rscn_flush = 1;
6552*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6553*4882a593Smuzhiyun for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
6554*4882a593Smuzhiyun lp = vport->fc_rscn_id_list[i]->virt;
6555*4882a593Smuzhiyun payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6556*4882a593Smuzhiyun payload_len -= sizeof(uint32_t); /* take off word 0 */
6557*4882a593Smuzhiyun while (payload_len) {
6558*4882a593Smuzhiyun rscn_did.un.word = be32_to_cpu(*lp++);
6559*4882a593Smuzhiyun payload_len -= sizeof(uint32_t);
6560*4882a593Smuzhiyun switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
6561*4882a593Smuzhiyun case RSCN_ADDRESS_FORMAT_PORT:
6562*4882a593Smuzhiyun if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6563*4882a593Smuzhiyun && (ns_did.un.b.area == rscn_did.un.b.area)
6564*4882a593Smuzhiyun && (ns_did.un.b.id == rscn_did.un.b.id))
6565*4882a593Smuzhiyun goto return_did_out;
6566*4882a593Smuzhiyun break;
6567*4882a593Smuzhiyun case RSCN_ADDRESS_FORMAT_AREA:
6568*4882a593Smuzhiyun if ((ns_did.un.b.domain == rscn_did.un.b.domain)
6569*4882a593Smuzhiyun && (ns_did.un.b.area == rscn_did.un.b.area))
6570*4882a593Smuzhiyun goto return_did_out;
6571*4882a593Smuzhiyun break;
6572*4882a593Smuzhiyun case RSCN_ADDRESS_FORMAT_DOMAIN:
6573*4882a593Smuzhiyun if (ns_did.un.b.domain == rscn_did.un.b.domain)
6574*4882a593Smuzhiyun goto return_did_out;
6575*4882a593Smuzhiyun break;
6576*4882a593Smuzhiyun case RSCN_ADDRESS_FORMAT_FABRIC:
6577*4882a593Smuzhiyun goto return_did_out;
6578*4882a593Smuzhiyun }
6579*4882a593Smuzhiyun }
6580*4882a593Smuzhiyun }
6581*4882a593Smuzhiyun /* Indicate we are done with walking fc_rscn_id_list on this vport */
6582*4882a593Smuzhiyun vport->fc_rscn_flush = 0;
6583*4882a593Smuzhiyun return 0;
6584*4882a593Smuzhiyun return_did_out:
6585*4882a593Smuzhiyun /* Indicate we are done with walking fc_rscn_id_list on this vport */
6586*4882a593Smuzhiyun vport->fc_rscn_flush = 0;
6587*4882a593Smuzhiyun return did;
6588*4882a593Smuzhiyun }
6589*4882a593Smuzhiyun
6590*4882a593Smuzhiyun /**
6591*4882a593Smuzhiyun * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
6592*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6593*4882a593Smuzhiyun *
6594*4882a593Smuzhiyun * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
6595*4882a593Smuzhiyun * state machine for a @vport's nodes that are with pending RSCN (Registration
6596*4882a593Smuzhiyun * State Change Notification).
6597*4882a593Smuzhiyun *
6598*4882a593Smuzhiyun * Return code
6599*4882a593Smuzhiyun * 0 - Successful (currently alway return 0)
6600*4882a593Smuzhiyun **/
6601*4882a593Smuzhiyun static int
lpfc_rscn_recovery_check(struct lpfc_vport * vport)6602*4882a593Smuzhiyun lpfc_rscn_recovery_check(struct lpfc_vport *vport)
6603*4882a593Smuzhiyun {
6604*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = NULL;
6605*4882a593Smuzhiyun
6606*4882a593Smuzhiyun /* Move all affected nodes by pending RSCNs to NPR state. */
6607*4882a593Smuzhiyun list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
6608*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp) ||
6609*4882a593Smuzhiyun (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
6610*4882a593Smuzhiyun !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
6611*4882a593Smuzhiyun continue;
6612*4882a593Smuzhiyun
6613*4882a593Smuzhiyun /* NVME Target mode does not do RSCN Recovery. */
6614*4882a593Smuzhiyun if (vport->phba->nvmet_support)
6615*4882a593Smuzhiyun continue;
6616*4882a593Smuzhiyun
6617*4882a593Smuzhiyun /* If we are in the process of doing discovery on this
6618*4882a593Smuzhiyun * NPort, let it continue on its own.
6619*4882a593Smuzhiyun */
6620*4882a593Smuzhiyun switch (ndlp->nlp_state) {
6621*4882a593Smuzhiyun case NLP_STE_PLOGI_ISSUE:
6622*4882a593Smuzhiyun case NLP_STE_ADISC_ISSUE:
6623*4882a593Smuzhiyun case NLP_STE_REG_LOGIN_ISSUE:
6624*4882a593Smuzhiyun case NLP_STE_PRLI_ISSUE:
6625*4882a593Smuzhiyun case NLP_STE_LOGO_ISSUE:
6626*4882a593Smuzhiyun continue;
6627*4882a593Smuzhiyun }
6628*4882a593Smuzhiyun
6629*4882a593Smuzhiyun /* Check to see if we need to NVME rescan this target
6630*4882a593Smuzhiyun * remoteport.
6631*4882a593Smuzhiyun */
6632*4882a593Smuzhiyun if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6633*4882a593Smuzhiyun ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6634*4882a593Smuzhiyun lpfc_nvme_rescan_port(vport, ndlp);
6635*4882a593Smuzhiyun
6636*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, NULL,
6637*4882a593Smuzhiyun NLP_EVT_DEVICE_RECOVERY);
6638*4882a593Smuzhiyun lpfc_cancel_retry_delay_tmo(vport, ndlp);
6639*4882a593Smuzhiyun }
6640*4882a593Smuzhiyun return 0;
6641*4882a593Smuzhiyun }
6642*4882a593Smuzhiyun
6643*4882a593Smuzhiyun /**
6644*4882a593Smuzhiyun * lpfc_send_rscn_event - Send an RSCN event to management application
6645*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6646*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
6647*4882a593Smuzhiyun *
6648*4882a593Smuzhiyun * lpfc_send_rscn_event sends an RSCN netlink event to management
6649*4882a593Smuzhiyun * applications.
6650*4882a593Smuzhiyun */
6651*4882a593Smuzhiyun static void
lpfc_send_rscn_event(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb)6652*4882a593Smuzhiyun lpfc_send_rscn_event(struct lpfc_vport *vport,
6653*4882a593Smuzhiyun struct lpfc_iocbq *cmdiocb)
6654*4882a593Smuzhiyun {
6655*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
6656*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6657*4882a593Smuzhiyun uint32_t *payload_ptr;
6658*4882a593Smuzhiyun uint32_t payload_len;
6659*4882a593Smuzhiyun struct lpfc_rscn_event_header *rscn_event_data;
6660*4882a593Smuzhiyun
6661*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6662*4882a593Smuzhiyun payload_ptr = (uint32_t *) pcmd->virt;
6663*4882a593Smuzhiyun payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
6664*4882a593Smuzhiyun
6665*4882a593Smuzhiyun rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
6666*4882a593Smuzhiyun payload_len, GFP_KERNEL);
6667*4882a593Smuzhiyun if (!rscn_event_data) {
6668*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
6669*4882a593Smuzhiyun "0147 Failed to allocate memory for RSCN event\n");
6670*4882a593Smuzhiyun return;
6671*4882a593Smuzhiyun }
6672*4882a593Smuzhiyun rscn_event_data->event_type = FC_REG_RSCN_EVENT;
6673*4882a593Smuzhiyun rscn_event_data->payload_length = payload_len;
6674*4882a593Smuzhiyun memcpy(rscn_event_data->rscn_payload, payload_ptr,
6675*4882a593Smuzhiyun payload_len);
6676*4882a593Smuzhiyun
6677*4882a593Smuzhiyun fc_host_post_vendor_event(shost,
6678*4882a593Smuzhiyun fc_get_event_number(),
6679*4882a593Smuzhiyun sizeof(struct lpfc_rscn_event_header) + payload_len,
6680*4882a593Smuzhiyun (char *)rscn_event_data,
6681*4882a593Smuzhiyun LPFC_NL_VENDOR_ID);
6682*4882a593Smuzhiyun
6683*4882a593Smuzhiyun kfree(rscn_event_data);
6684*4882a593Smuzhiyun }
6685*4882a593Smuzhiyun
6686*4882a593Smuzhiyun /**
6687*4882a593Smuzhiyun * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6688*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6689*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
6690*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
6691*4882a593Smuzhiyun *
6692*4882a593Smuzhiyun * This routine processes an unsolicited RSCN (Registration State Change
6693*4882a593Smuzhiyun * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6694*4882a593Smuzhiyun * to invoke fc_host_post_event() routine to the FC transport layer. If the
6695*4882a593Smuzhiyun * discover state machine is about to begin discovery, it just accepts the
6696*4882a593Smuzhiyun * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6697*4882a593Smuzhiyun * contains N_Port IDs for other vports on this HBA, it just accepts the
6698*4882a593Smuzhiyun * RSCN and ignore processing it. If the state machine is in the recovery
6699*4882a593Smuzhiyun * state, the fc_rscn_id_list of this @vport is walked and the
6700*4882a593Smuzhiyun * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6701*4882a593Smuzhiyun * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6702*4882a593Smuzhiyun * routine is invoked to handle the RSCN event.
6703*4882a593Smuzhiyun *
6704*4882a593Smuzhiyun * Return code
6705*4882a593Smuzhiyun * 0 - Just sent the acc response
6706*4882a593Smuzhiyun * 1 - Sent the acc response and waited for name server completion
6707*4882a593Smuzhiyun **/
6708*4882a593Smuzhiyun static int
lpfc_els_rcv_rscn(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)6709*4882a593Smuzhiyun lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6710*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
6711*4882a593Smuzhiyun {
6712*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6713*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
6714*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
6715*4882a593Smuzhiyun uint32_t *lp, *datap;
6716*4882a593Smuzhiyun uint32_t payload_len, length, nportid, *cmd;
6717*4882a593Smuzhiyun int rscn_cnt;
6718*4882a593Smuzhiyun int rscn_id = 0, hba_id = 0;
6719*4882a593Smuzhiyun int i, tmo;
6720*4882a593Smuzhiyun
6721*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6722*4882a593Smuzhiyun lp = (uint32_t *) pcmd->virt;
6723*4882a593Smuzhiyun
6724*4882a593Smuzhiyun payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
6725*4882a593Smuzhiyun payload_len -= sizeof(uint32_t); /* take off word 0 */
6726*4882a593Smuzhiyun /* RSCN received */
6727*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6728*4882a593Smuzhiyun "0214 RSCN received Data: x%x x%x x%x x%x\n",
6729*4882a593Smuzhiyun vport->fc_flag, payload_len, *lp,
6730*4882a593Smuzhiyun vport->fc_rscn_id_cnt);
6731*4882a593Smuzhiyun
6732*4882a593Smuzhiyun /* Send an RSCN event to the management application */
6733*4882a593Smuzhiyun lpfc_send_rscn_event(vport, cmdiocb);
6734*4882a593Smuzhiyun
6735*4882a593Smuzhiyun for (i = 0; i < payload_len/sizeof(uint32_t); i++)
6736*4882a593Smuzhiyun fc_host_post_event(shost, fc_get_event_number(),
6737*4882a593Smuzhiyun FCH_EVT_RSCN, lp[i]);
6738*4882a593Smuzhiyun
6739*4882a593Smuzhiyun /* Check if RSCN is coming from a direct-connected remote NPort */
6740*4882a593Smuzhiyun if (vport->fc_flag & FC_PT2PT) {
6741*4882a593Smuzhiyun /* If so, just ACC it, no other action needed for now */
6742*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6743*4882a593Smuzhiyun "2024 pt2pt RSCN %08x Data: x%x x%x\n",
6744*4882a593Smuzhiyun *lp, vport->fc_flag, payload_len);
6745*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6746*4882a593Smuzhiyun
6747*4882a593Smuzhiyun /* Check to see if we need to NVME rescan this target
6748*4882a593Smuzhiyun * remoteport.
6749*4882a593Smuzhiyun */
6750*4882a593Smuzhiyun if (ndlp->nlp_fc4_type & NLP_FC4_NVME &&
6751*4882a593Smuzhiyun ndlp->nlp_type & (NLP_NVME_TARGET | NLP_NVME_DISCOVERY))
6752*4882a593Smuzhiyun lpfc_nvme_rescan_port(vport, ndlp);
6753*4882a593Smuzhiyun return 0;
6754*4882a593Smuzhiyun }
6755*4882a593Smuzhiyun
6756*4882a593Smuzhiyun /* If we are about to begin discovery, just ACC the RSCN.
6757*4882a593Smuzhiyun * Discovery processing will satisfy it.
6758*4882a593Smuzhiyun */
6759*4882a593Smuzhiyun if (vport->port_state <= LPFC_NS_QRY) {
6760*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6761*4882a593Smuzhiyun "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6762*4882a593Smuzhiyun ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6763*4882a593Smuzhiyun
6764*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6765*4882a593Smuzhiyun return 0;
6766*4882a593Smuzhiyun }
6767*4882a593Smuzhiyun
6768*4882a593Smuzhiyun /* If this RSCN just contains NPortIDs for other vports on this HBA,
6769*4882a593Smuzhiyun * just ACC and ignore it.
6770*4882a593Smuzhiyun */
6771*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6772*4882a593Smuzhiyun !(vport->cfg_peer_port_login)) {
6773*4882a593Smuzhiyun i = payload_len;
6774*4882a593Smuzhiyun datap = lp;
6775*4882a593Smuzhiyun while (i > 0) {
6776*4882a593Smuzhiyun nportid = *datap++;
6777*4882a593Smuzhiyun nportid = ((be32_to_cpu(nportid)) & Mask_DID);
6778*4882a593Smuzhiyun i -= sizeof(uint32_t);
6779*4882a593Smuzhiyun rscn_id++;
6780*4882a593Smuzhiyun if (lpfc_find_vport_by_did(phba, nportid))
6781*4882a593Smuzhiyun hba_id++;
6782*4882a593Smuzhiyun }
6783*4882a593Smuzhiyun if (rscn_id == hba_id) {
6784*4882a593Smuzhiyun /* ALL NPortIDs in RSCN are on HBA */
6785*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6786*4882a593Smuzhiyun "0219 Ignore RSCN "
6787*4882a593Smuzhiyun "Data: x%x x%x x%x x%x\n",
6788*4882a593Smuzhiyun vport->fc_flag, payload_len,
6789*4882a593Smuzhiyun *lp, vport->fc_rscn_id_cnt);
6790*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6791*4882a593Smuzhiyun "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6792*4882a593Smuzhiyun ndlp->nlp_DID, vport->port_state,
6793*4882a593Smuzhiyun ndlp->nlp_flag);
6794*4882a593Smuzhiyun
6795*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
6796*4882a593Smuzhiyun ndlp, NULL);
6797*4882a593Smuzhiyun return 0;
6798*4882a593Smuzhiyun }
6799*4882a593Smuzhiyun }
6800*4882a593Smuzhiyun
6801*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
6802*4882a593Smuzhiyun if (vport->fc_rscn_flush) {
6803*4882a593Smuzhiyun /* Another thread is walking fc_rscn_id_list on this vport */
6804*4882a593Smuzhiyun vport->fc_flag |= FC_RSCN_DISCOVERY;
6805*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6806*4882a593Smuzhiyun /* Send back ACC */
6807*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6808*4882a593Smuzhiyun return 0;
6809*4882a593Smuzhiyun }
6810*4882a593Smuzhiyun /* Indicate we are walking fc_rscn_id_list on this vport */
6811*4882a593Smuzhiyun vport->fc_rscn_flush = 1;
6812*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6813*4882a593Smuzhiyun /* Get the array count after successfully have the token */
6814*4882a593Smuzhiyun rscn_cnt = vport->fc_rscn_id_cnt;
6815*4882a593Smuzhiyun /* If we are already processing an RSCN, save the received
6816*4882a593Smuzhiyun * RSCN payload buffer, cmdiocb->context2 to process later.
6817*4882a593Smuzhiyun */
6818*4882a593Smuzhiyun if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
6819*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6820*4882a593Smuzhiyun "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6821*4882a593Smuzhiyun ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6822*4882a593Smuzhiyun
6823*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
6824*4882a593Smuzhiyun vport->fc_flag |= FC_RSCN_DEFERRED;
6825*4882a593Smuzhiyun
6826*4882a593Smuzhiyun /* Restart disctmo if its already running */
6827*4882a593Smuzhiyun if (vport->fc_flag & FC_DISC_TMO) {
6828*4882a593Smuzhiyun tmo = ((phba->fc_ratov * 3) + 3);
6829*4882a593Smuzhiyun mod_timer(&vport->fc_disctmo,
6830*4882a593Smuzhiyun jiffies + msecs_to_jiffies(1000 * tmo));
6831*4882a593Smuzhiyun }
6832*4882a593Smuzhiyun if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
6833*4882a593Smuzhiyun !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
6834*4882a593Smuzhiyun vport->fc_flag |= FC_RSCN_MODE;
6835*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6836*4882a593Smuzhiyun if (rscn_cnt) {
6837*4882a593Smuzhiyun cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
6838*4882a593Smuzhiyun length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
6839*4882a593Smuzhiyun }
6840*4882a593Smuzhiyun if ((rscn_cnt) &&
6841*4882a593Smuzhiyun (payload_len + length <= LPFC_BPL_SIZE)) {
6842*4882a593Smuzhiyun *cmd &= ELS_CMD_MASK;
6843*4882a593Smuzhiyun *cmd |= cpu_to_be32(payload_len + length);
6844*4882a593Smuzhiyun memcpy(((uint8_t *)cmd) + length, lp,
6845*4882a593Smuzhiyun payload_len);
6846*4882a593Smuzhiyun } else {
6847*4882a593Smuzhiyun vport->fc_rscn_id_list[rscn_cnt] = pcmd;
6848*4882a593Smuzhiyun vport->fc_rscn_id_cnt++;
6849*4882a593Smuzhiyun /* If we zero, cmdiocb->context2, the calling
6850*4882a593Smuzhiyun * routine will not try to free it.
6851*4882a593Smuzhiyun */
6852*4882a593Smuzhiyun cmdiocb->context2 = NULL;
6853*4882a593Smuzhiyun }
6854*4882a593Smuzhiyun /* Deferred RSCN */
6855*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6856*4882a593Smuzhiyun "0235 Deferred RSCN "
6857*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
6858*4882a593Smuzhiyun vport->fc_rscn_id_cnt, vport->fc_flag,
6859*4882a593Smuzhiyun vport->port_state);
6860*4882a593Smuzhiyun } else {
6861*4882a593Smuzhiyun vport->fc_flag |= FC_RSCN_DISCOVERY;
6862*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6863*4882a593Smuzhiyun /* ReDiscovery RSCN */
6864*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6865*4882a593Smuzhiyun "0234 ReDiscovery RSCN "
6866*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
6867*4882a593Smuzhiyun vport->fc_rscn_id_cnt, vport->fc_flag,
6868*4882a593Smuzhiyun vport->port_state);
6869*4882a593Smuzhiyun }
6870*4882a593Smuzhiyun /* Indicate we are done walking fc_rscn_id_list on this vport */
6871*4882a593Smuzhiyun vport->fc_rscn_flush = 0;
6872*4882a593Smuzhiyun /* Send back ACC */
6873*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6874*4882a593Smuzhiyun /* send RECOVERY event for ALL nodes that match RSCN payload */
6875*4882a593Smuzhiyun lpfc_rscn_recovery_check(vport);
6876*4882a593Smuzhiyun return 0;
6877*4882a593Smuzhiyun }
6878*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6879*4882a593Smuzhiyun "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6880*4882a593Smuzhiyun ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
6881*4882a593Smuzhiyun
6882*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
6883*4882a593Smuzhiyun vport->fc_flag |= FC_RSCN_MODE;
6884*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
6885*4882a593Smuzhiyun vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
6886*4882a593Smuzhiyun /* Indicate we are done walking fc_rscn_id_list on this vport */
6887*4882a593Smuzhiyun vport->fc_rscn_flush = 0;
6888*4882a593Smuzhiyun /*
6889*4882a593Smuzhiyun * If we zero, cmdiocb->context2, the calling routine will
6890*4882a593Smuzhiyun * not try to free it.
6891*4882a593Smuzhiyun */
6892*4882a593Smuzhiyun cmdiocb->context2 = NULL;
6893*4882a593Smuzhiyun lpfc_set_disctmo(vport);
6894*4882a593Smuzhiyun /* Send back ACC */
6895*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
6896*4882a593Smuzhiyun /* send RECOVERY event for ALL nodes that match RSCN payload */
6897*4882a593Smuzhiyun lpfc_rscn_recovery_check(vport);
6898*4882a593Smuzhiyun return lpfc_els_handle_rscn(vport);
6899*4882a593Smuzhiyun }
6900*4882a593Smuzhiyun
6901*4882a593Smuzhiyun /**
6902*4882a593Smuzhiyun * lpfc_els_handle_rscn - Handle rscn for a vport
6903*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6904*4882a593Smuzhiyun *
6905*4882a593Smuzhiyun * This routine handles the Registration State Configuration Notification
6906*4882a593Smuzhiyun * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6907*4882a593Smuzhiyun * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6908*4882a593Smuzhiyun * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6909*4882a593Smuzhiyun * NameServer shall be issued. If CT command to the NameServer fails to be
6910*4882a593Smuzhiyun * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6911*4882a593Smuzhiyun * RSCN activities with the @vport.
6912*4882a593Smuzhiyun *
6913*4882a593Smuzhiyun * Return code
6914*4882a593Smuzhiyun * 0 - Cleaned up rscn on the @vport
6915*4882a593Smuzhiyun * 1 - Wait for plogi to name server before proceed
6916*4882a593Smuzhiyun **/
6917*4882a593Smuzhiyun int
lpfc_els_handle_rscn(struct lpfc_vport * vport)6918*4882a593Smuzhiyun lpfc_els_handle_rscn(struct lpfc_vport *vport)
6919*4882a593Smuzhiyun {
6920*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
6921*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
6922*4882a593Smuzhiyun
6923*4882a593Smuzhiyun /* Ignore RSCN if the port is being torn down. */
6924*4882a593Smuzhiyun if (vport->load_flag & FC_UNLOADING) {
6925*4882a593Smuzhiyun lpfc_els_flush_rscn(vport);
6926*4882a593Smuzhiyun return 0;
6927*4882a593Smuzhiyun }
6928*4882a593Smuzhiyun
6929*4882a593Smuzhiyun /* Start timer for RSCN processing */
6930*4882a593Smuzhiyun lpfc_set_disctmo(vport);
6931*4882a593Smuzhiyun
6932*4882a593Smuzhiyun /* RSCN processed */
6933*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
6934*4882a593Smuzhiyun "0215 RSCN processed Data: x%x x%x x%x x%x x%x x%x\n",
6935*4882a593Smuzhiyun vport->fc_flag, 0, vport->fc_rscn_id_cnt,
6936*4882a593Smuzhiyun vport->port_state, vport->num_disc_nodes,
6937*4882a593Smuzhiyun vport->gidft_inp);
6938*4882a593Smuzhiyun
6939*4882a593Smuzhiyun /* To process RSCN, first compare RSCN data with NameServer */
6940*4882a593Smuzhiyun vport->fc_ns_retry = 0;
6941*4882a593Smuzhiyun vport->num_disc_nodes = 0;
6942*4882a593Smuzhiyun
6943*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, NameServer_DID);
6944*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp)
6945*4882a593Smuzhiyun && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
6946*4882a593Smuzhiyun /* Good ndlp, issue CT Request to NameServer. Need to
6947*4882a593Smuzhiyun * know how many gidfts were issued. If none, then just
6948*4882a593Smuzhiyun * flush the RSCN. Otherwise, the outstanding requests
6949*4882a593Smuzhiyun * need to complete.
6950*4882a593Smuzhiyun */
6951*4882a593Smuzhiyun if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_FT) {
6952*4882a593Smuzhiyun if (lpfc_issue_gidft(vport) > 0)
6953*4882a593Smuzhiyun return 1;
6954*4882a593Smuzhiyun } else if (phba->cfg_ns_query == LPFC_NS_QUERY_GID_PT) {
6955*4882a593Smuzhiyun if (lpfc_issue_gidpt(vport) > 0)
6956*4882a593Smuzhiyun return 1;
6957*4882a593Smuzhiyun } else {
6958*4882a593Smuzhiyun return 1;
6959*4882a593Smuzhiyun }
6960*4882a593Smuzhiyun } else {
6961*4882a593Smuzhiyun /* Nameserver login in question. Revalidate. */
6962*4882a593Smuzhiyun if (ndlp) {
6963*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp,
6964*4882a593Smuzhiyun NLP_STE_PLOGI_ISSUE);
6965*4882a593Smuzhiyun if (!ndlp) {
6966*4882a593Smuzhiyun lpfc_els_flush_rscn(vport);
6967*4882a593Smuzhiyun return 0;
6968*4882a593Smuzhiyun }
6969*4882a593Smuzhiyun ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
6970*4882a593Smuzhiyun } else {
6971*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, NameServer_DID);
6972*4882a593Smuzhiyun if (!ndlp) {
6973*4882a593Smuzhiyun lpfc_els_flush_rscn(vport);
6974*4882a593Smuzhiyun return 0;
6975*4882a593Smuzhiyun }
6976*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
6977*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6978*4882a593Smuzhiyun }
6979*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
6980*4882a593Smuzhiyun lpfc_issue_els_plogi(vport, NameServer_DID, 0);
6981*4882a593Smuzhiyun /* Wait for NameServer login cmpl before we can
6982*4882a593Smuzhiyun * continue
6983*4882a593Smuzhiyun */
6984*4882a593Smuzhiyun return 1;
6985*4882a593Smuzhiyun }
6986*4882a593Smuzhiyun
6987*4882a593Smuzhiyun lpfc_els_flush_rscn(vport);
6988*4882a593Smuzhiyun return 0;
6989*4882a593Smuzhiyun }
6990*4882a593Smuzhiyun
6991*4882a593Smuzhiyun /**
6992*4882a593Smuzhiyun * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6993*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
6994*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
6995*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
6996*4882a593Smuzhiyun *
6997*4882a593Smuzhiyun * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6998*4882a593Smuzhiyun * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6999*4882a593Smuzhiyun * point topology. As an unsolicited FLOGI should not be received in a loop
7000*4882a593Smuzhiyun * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
7001*4882a593Smuzhiyun * lpfc_check_sparm() routine is invoked to check the parameters in the
7002*4882a593Smuzhiyun * unsolicited FLOGI. If parameters validation failed, the routine
7003*4882a593Smuzhiyun * lpfc_els_rsp_reject() shall be called with reject reason code set to
7004*4882a593Smuzhiyun * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
7005*4882a593Smuzhiyun * FLOGI shall be compared with the Port WWN of the @vport to determine who
7006*4882a593Smuzhiyun * will initiate PLOGI. The higher lexicographical value party shall has
7007*4882a593Smuzhiyun * higher priority (as the winning port) and will initiate PLOGI and
7008*4882a593Smuzhiyun * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
7009*4882a593Smuzhiyun * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
7010*4882a593Smuzhiyun * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
7011*4882a593Smuzhiyun *
7012*4882a593Smuzhiyun * Return code
7013*4882a593Smuzhiyun * 0 - Successfully processed the unsolicited flogi
7014*4882a593Smuzhiyun * 1 - Failed to process the unsolicited flogi
7015*4882a593Smuzhiyun **/
7016*4882a593Smuzhiyun static int
lpfc_els_rcv_flogi(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7017*4882a593Smuzhiyun lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7018*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7019*4882a593Smuzhiyun {
7020*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7021*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7022*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7023*4882a593Smuzhiyun uint32_t *lp = (uint32_t *) pcmd->virt;
7024*4882a593Smuzhiyun IOCB_t *icmd = &cmdiocb->iocb;
7025*4882a593Smuzhiyun struct serv_parm *sp;
7026*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
7027*4882a593Smuzhiyun uint32_t cmd, did;
7028*4882a593Smuzhiyun int rc;
7029*4882a593Smuzhiyun uint32_t fc_flag = 0;
7030*4882a593Smuzhiyun uint32_t port_state = 0;
7031*4882a593Smuzhiyun
7032*4882a593Smuzhiyun cmd = *lp++;
7033*4882a593Smuzhiyun sp = (struct serv_parm *) lp;
7034*4882a593Smuzhiyun
7035*4882a593Smuzhiyun /* FLOGI received */
7036*4882a593Smuzhiyun
7037*4882a593Smuzhiyun lpfc_set_disctmo(vport);
7038*4882a593Smuzhiyun
7039*4882a593Smuzhiyun if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
7040*4882a593Smuzhiyun /* We should never receive a FLOGI in loop mode, ignore it */
7041*4882a593Smuzhiyun did = icmd->un.elsreq64.remoteID;
7042*4882a593Smuzhiyun
7043*4882a593Smuzhiyun /* An FLOGI ELS command <elsCmd> was received from DID <did> in
7044*4882a593Smuzhiyun Loop Mode */
7045*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
7046*4882a593Smuzhiyun "0113 An FLOGI ELS command x%x was "
7047*4882a593Smuzhiyun "received from DID x%x in Loop Mode\n",
7048*4882a593Smuzhiyun cmd, did);
7049*4882a593Smuzhiyun return 1;
7050*4882a593Smuzhiyun }
7051*4882a593Smuzhiyun
7052*4882a593Smuzhiyun (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
7053*4882a593Smuzhiyun
7054*4882a593Smuzhiyun /*
7055*4882a593Smuzhiyun * If our portname is greater than the remote portname,
7056*4882a593Smuzhiyun * then we initiate Nport login.
7057*4882a593Smuzhiyun */
7058*4882a593Smuzhiyun
7059*4882a593Smuzhiyun rc = memcmp(&vport->fc_portname, &sp->portName,
7060*4882a593Smuzhiyun sizeof(struct lpfc_name));
7061*4882a593Smuzhiyun
7062*4882a593Smuzhiyun if (!rc) {
7063*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4) {
7064*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool,
7065*4882a593Smuzhiyun GFP_KERNEL);
7066*4882a593Smuzhiyun if (!mbox)
7067*4882a593Smuzhiyun return 1;
7068*4882a593Smuzhiyun lpfc_linkdown(phba);
7069*4882a593Smuzhiyun lpfc_init_link(phba, mbox,
7070*4882a593Smuzhiyun phba->cfg_topology,
7071*4882a593Smuzhiyun phba->cfg_link_speed);
7072*4882a593Smuzhiyun mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
7073*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
7074*4882a593Smuzhiyun mbox->vport = vport;
7075*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, mbox,
7076*4882a593Smuzhiyun MBX_NOWAIT);
7077*4882a593Smuzhiyun lpfc_set_loopback_flag(phba);
7078*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED)
7079*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
7080*4882a593Smuzhiyun return 1;
7081*4882a593Smuzhiyun }
7082*4882a593Smuzhiyun
7083*4882a593Smuzhiyun /* abort the flogi coming back to ourselves
7084*4882a593Smuzhiyun * due to external loopback on the port.
7085*4882a593Smuzhiyun */
7086*4882a593Smuzhiyun lpfc_els_abort_flogi(phba);
7087*4882a593Smuzhiyun return 0;
7088*4882a593Smuzhiyun
7089*4882a593Smuzhiyun } else if (rc > 0) { /* greater than */
7090*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
7091*4882a593Smuzhiyun vport->fc_flag |= FC_PT2PT_PLOGI;
7092*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
7093*4882a593Smuzhiyun
7094*4882a593Smuzhiyun /* If we have the high WWPN we can assign our own
7095*4882a593Smuzhiyun * myDID; otherwise, we have to WAIT for a PLOGI
7096*4882a593Smuzhiyun * from the remote NPort to find out what it
7097*4882a593Smuzhiyun * will be.
7098*4882a593Smuzhiyun */
7099*4882a593Smuzhiyun vport->fc_myDID = PT2PT_LocalID;
7100*4882a593Smuzhiyun } else {
7101*4882a593Smuzhiyun vport->fc_myDID = PT2PT_RemoteID;
7102*4882a593Smuzhiyun }
7103*4882a593Smuzhiyun
7104*4882a593Smuzhiyun /*
7105*4882a593Smuzhiyun * The vport state should go to LPFC_FLOGI only
7106*4882a593Smuzhiyun * AFTER we issue a FLOGI, not receive one.
7107*4882a593Smuzhiyun */
7108*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
7109*4882a593Smuzhiyun fc_flag = vport->fc_flag;
7110*4882a593Smuzhiyun port_state = vport->port_state;
7111*4882a593Smuzhiyun vport->fc_flag |= FC_PT2PT;
7112*4882a593Smuzhiyun vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7113*4882a593Smuzhiyun
7114*4882a593Smuzhiyun /* Acking an unsol FLOGI. Count 1 for link bounce
7115*4882a593Smuzhiyun * work-around.
7116*4882a593Smuzhiyun */
7117*4882a593Smuzhiyun vport->rcv_flogi_cnt++;
7118*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
7119*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7120*4882a593Smuzhiyun "3311 Rcv Flogi PS x%x new PS x%x "
7121*4882a593Smuzhiyun "fc_flag x%x new fc_flag x%x\n",
7122*4882a593Smuzhiyun port_state, vport->port_state,
7123*4882a593Smuzhiyun fc_flag, vport->fc_flag);
7124*4882a593Smuzhiyun
7125*4882a593Smuzhiyun /*
7126*4882a593Smuzhiyun * We temporarily set fc_myDID to make it look like we are
7127*4882a593Smuzhiyun * a Fabric. This is done just so we end up with the right
7128*4882a593Smuzhiyun * did / sid on the FLOGI ACC rsp.
7129*4882a593Smuzhiyun */
7130*4882a593Smuzhiyun did = vport->fc_myDID;
7131*4882a593Smuzhiyun vport->fc_myDID = Fabric_DID;
7132*4882a593Smuzhiyun
7133*4882a593Smuzhiyun memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
7134*4882a593Smuzhiyun
7135*4882a593Smuzhiyun /* Defer ACC response until AFTER we issue a FLOGI */
7136*4882a593Smuzhiyun if (!(phba->hba_flag & HBA_FLOGI_ISSUED)) {
7137*4882a593Smuzhiyun phba->defer_flogi_acc_rx_id = cmdiocb->iocb.ulpContext;
7138*4882a593Smuzhiyun phba->defer_flogi_acc_ox_id =
7139*4882a593Smuzhiyun cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7140*4882a593Smuzhiyun
7141*4882a593Smuzhiyun vport->fc_myDID = did;
7142*4882a593Smuzhiyun
7143*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7144*4882a593Smuzhiyun "3344 Deferring FLOGI ACC: rx_id: x%x,"
7145*4882a593Smuzhiyun " ox_id: x%x, hba_flag x%x\n",
7146*4882a593Smuzhiyun phba->defer_flogi_acc_rx_id,
7147*4882a593Smuzhiyun phba->defer_flogi_acc_ox_id, phba->hba_flag);
7148*4882a593Smuzhiyun
7149*4882a593Smuzhiyun phba->defer_flogi_acc_flag = true;
7150*4882a593Smuzhiyun
7151*4882a593Smuzhiyun return 0;
7152*4882a593Smuzhiyun }
7153*4882a593Smuzhiyun
7154*4882a593Smuzhiyun /* Send back ACC */
7155*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
7156*4882a593Smuzhiyun
7157*4882a593Smuzhiyun /* Now lets put fc_myDID back to what its supposed to be */
7158*4882a593Smuzhiyun vport->fc_myDID = did;
7159*4882a593Smuzhiyun
7160*4882a593Smuzhiyun return 0;
7161*4882a593Smuzhiyun }
7162*4882a593Smuzhiyun
7163*4882a593Smuzhiyun /**
7164*4882a593Smuzhiyun * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
7165*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7166*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7167*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7168*4882a593Smuzhiyun *
7169*4882a593Smuzhiyun * This routine processes Request Node Identification Data (RNID) IOCB
7170*4882a593Smuzhiyun * received as an ELS unsolicited event. Only when the RNID specified format
7171*4882a593Smuzhiyun * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
7172*4882a593Smuzhiyun * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
7173*4882a593Smuzhiyun * Accept (ACC) the RNID ELS command. All the other RNID formats are
7174*4882a593Smuzhiyun * rejected by invoking the lpfc_els_rsp_reject() routine.
7175*4882a593Smuzhiyun *
7176*4882a593Smuzhiyun * Return code
7177*4882a593Smuzhiyun * 0 - Successfully processed rnid iocb (currently always return 0)
7178*4882a593Smuzhiyun **/
7179*4882a593Smuzhiyun static int
lpfc_els_rcv_rnid(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7180*4882a593Smuzhiyun lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7181*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7182*4882a593Smuzhiyun {
7183*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
7184*4882a593Smuzhiyun uint32_t *lp;
7185*4882a593Smuzhiyun RNID *rn;
7186*4882a593Smuzhiyun struct ls_rjt stat;
7187*4882a593Smuzhiyun
7188*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7189*4882a593Smuzhiyun lp = (uint32_t *) pcmd->virt;
7190*4882a593Smuzhiyun
7191*4882a593Smuzhiyun lp++;
7192*4882a593Smuzhiyun rn = (RNID *) lp;
7193*4882a593Smuzhiyun
7194*4882a593Smuzhiyun /* RNID received */
7195*4882a593Smuzhiyun
7196*4882a593Smuzhiyun switch (rn->Format) {
7197*4882a593Smuzhiyun case 0:
7198*4882a593Smuzhiyun case RNID_TOPOLOGY_DISC:
7199*4882a593Smuzhiyun /* Send back ACC */
7200*4882a593Smuzhiyun lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
7201*4882a593Smuzhiyun break;
7202*4882a593Smuzhiyun default:
7203*4882a593Smuzhiyun /* Reject this request because format not supported */
7204*4882a593Smuzhiyun stat.un.b.lsRjtRsvd0 = 0;
7205*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7206*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7207*4882a593Smuzhiyun stat.un.b.vendorUnique = 0;
7208*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7209*4882a593Smuzhiyun NULL);
7210*4882a593Smuzhiyun }
7211*4882a593Smuzhiyun return 0;
7212*4882a593Smuzhiyun }
7213*4882a593Smuzhiyun
7214*4882a593Smuzhiyun /**
7215*4882a593Smuzhiyun * lpfc_els_rcv_echo - Process an unsolicited echo iocb
7216*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7217*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7218*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7219*4882a593Smuzhiyun *
7220*4882a593Smuzhiyun * Return code
7221*4882a593Smuzhiyun * 0 - Successfully processed echo iocb (currently always return 0)
7222*4882a593Smuzhiyun **/
7223*4882a593Smuzhiyun static int
lpfc_els_rcv_echo(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7224*4882a593Smuzhiyun lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7225*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7226*4882a593Smuzhiyun {
7227*4882a593Smuzhiyun uint8_t *pcmd;
7228*4882a593Smuzhiyun
7229*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
7230*4882a593Smuzhiyun
7231*4882a593Smuzhiyun /* skip over first word of echo command to find echo data */
7232*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
7233*4882a593Smuzhiyun
7234*4882a593Smuzhiyun lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
7235*4882a593Smuzhiyun return 0;
7236*4882a593Smuzhiyun }
7237*4882a593Smuzhiyun
7238*4882a593Smuzhiyun /**
7239*4882a593Smuzhiyun * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
7240*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7241*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7242*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7243*4882a593Smuzhiyun *
7244*4882a593Smuzhiyun * This routine processes a Link Incident Report Registration(LIRR) IOCB
7245*4882a593Smuzhiyun * received as an ELS unsolicited event. Currently, this function just invokes
7246*4882a593Smuzhiyun * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
7247*4882a593Smuzhiyun *
7248*4882a593Smuzhiyun * Return code
7249*4882a593Smuzhiyun * 0 - Successfully processed lirr iocb (currently always return 0)
7250*4882a593Smuzhiyun **/
7251*4882a593Smuzhiyun static int
lpfc_els_rcv_lirr(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7252*4882a593Smuzhiyun lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7253*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7254*4882a593Smuzhiyun {
7255*4882a593Smuzhiyun struct ls_rjt stat;
7256*4882a593Smuzhiyun
7257*4882a593Smuzhiyun /* For now, unconditionally reject this command */
7258*4882a593Smuzhiyun stat.un.b.lsRjtRsvd0 = 0;
7259*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7260*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7261*4882a593Smuzhiyun stat.un.b.vendorUnique = 0;
7262*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7263*4882a593Smuzhiyun return 0;
7264*4882a593Smuzhiyun }
7265*4882a593Smuzhiyun
7266*4882a593Smuzhiyun /**
7267*4882a593Smuzhiyun * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
7268*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7269*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7270*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7271*4882a593Smuzhiyun *
7272*4882a593Smuzhiyun * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
7273*4882a593Smuzhiyun * received as an ELS unsolicited event. A request to RRQ shall only
7274*4882a593Smuzhiyun * be accepted if the Originator Nx_Port N_Port_ID or the Responder
7275*4882a593Smuzhiyun * Nx_Port N_Port_ID of the target Exchange is the same as the
7276*4882a593Smuzhiyun * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
7277*4882a593Smuzhiyun * not accepted, an LS_RJT with reason code "Unable to perform
7278*4882a593Smuzhiyun * command request" and reason code explanation "Invalid Originator
7279*4882a593Smuzhiyun * S_ID" shall be returned. For now, we just unconditionally accept
7280*4882a593Smuzhiyun * RRQ from the target.
7281*4882a593Smuzhiyun **/
7282*4882a593Smuzhiyun static void
lpfc_els_rcv_rrq(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7283*4882a593Smuzhiyun lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7284*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7285*4882a593Smuzhiyun {
7286*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7287*4882a593Smuzhiyun if (vport->phba->sli_rev == LPFC_SLI_REV4)
7288*4882a593Smuzhiyun lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
7289*4882a593Smuzhiyun }
7290*4882a593Smuzhiyun
7291*4882a593Smuzhiyun /**
7292*4882a593Smuzhiyun * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
7293*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
7294*4882a593Smuzhiyun * @pmb: pointer to the driver internal queue element for mailbox command.
7295*4882a593Smuzhiyun *
7296*4882a593Smuzhiyun * This routine is the completion callback function for the MBX_READ_LNK_STAT
7297*4882a593Smuzhiyun * mailbox command. This callback function is to actually send the Accept
7298*4882a593Smuzhiyun * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
7299*4882a593Smuzhiyun * collects the link statistics from the completion of the MBX_READ_LNK_STAT
7300*4882a593Smuzhiyun * mailbox command, constructs the RPS response with the link statistics
7301*4882a593Smuzhiyun * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
7302*4882a593Smuzhiyun * response to the RPS.
7303*4882a593Smuzhiyun *
7304*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7305*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
7306*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
7307*4882a593Smuzhiyun * callback function to the RPS Accept Response ELS IOCB command.
7308*4882a593Smuzhiyun *
7309*4882a593Smuzhiyun **/
7310*4882a593Smuzhiyun static void
lpfc_els_rsp_rls_acc(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)7311*4882a593Smuzhiyun lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7312*4882a593Smuzhiyun {
7313*4882a593Smuzhiyun MAILBOX_t *mb;
7314*4882a593Smuzhiyun IOCB_t *icmd;
7315*4882a593Smuzhiyun struct RLS_RSP *rls_rsp;
7316*4882a593Smuzhiyun uint8_t *pcmd;
7317*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
7318*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
7319*4882a593Smuzhiyun uint16_t oxid;
7320*4882a593Smuzhiyun uint16_t rxid;
7321*4882a593Smuzhiyun uint32_t cmdsize;
7322*4882a593Smuzhiyun
7323*4882a593Smuzhiyun mb = &pmb->u.mb;
7324*4882a593Smuzhiyun
7325*4882a593Smuzhiyun ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
7326*4882a593Smuzhiyun rxid = (uint16_t)((unsigned long)(pmb->ctx_buf) & 0xffff);
7327*4882a593Smuzhiyun oxid = (uint16_t)(((unsigned long)(pmb->ctx_buf) >> 16) & 0xffff);
7328*4882a593Smuzhiyun pmb->ctx_buf = NULL;
7329*4882a593Smuzhiyun pmb->ctx_ndlp = NULL;
7330*4882a593Smuzhiyun
7331*4882a593Smuzhiyun if (mb->mbxStatus) {
7332*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
7333*4882a593Smuzhiyun return;
7334*4882a593Smuzhiyun }
7335*4882a593Smuzhiyun
7336*4882a593Smuzhiyun cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
7337*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7338*4882a593Smuzhiyun lpfc_max_els_tries, ndlp,
7339*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
7340*4882a593Smuzhiyun
7341*4882a593Smuzhiyun /* Decrement the ndlp reference count from previous mbox command */
7342*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
7343*4882a593Smuzhiyun
7344*4882a593Smuzhiyun if (!elsiocb) {
7345*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
7346*4882a593Smuzhiyun return;
7347*4882a593Smuzhiyun }
7348*4882a593Smuzhiyun
7349*4882a593Smuzhiyun icmd = &elsiocb->iocb;
7350*4882a593Smuzhiyun icmd->ulpContext = rxid;
7351*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oxid;
7352*4882a593Smuzhiyun
7353*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7354*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7355*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* Skip past command */
7356*4882a593Smuzhiyun rls_rsp = (struct RLS_RSP *)pcmd;
7357*4882a593Smuzhiyun
7358*4882a593Smuzhiyun rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
7359*4882a593Smuzhiyun rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
7360*4882a593Smuzhiyun rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
7361*4882a593Smuzhiyun rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
7362*4882a593Smuzhiyun rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
7363*4882a593Smuzhiyun rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
7364*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
7365*4882a593Smuzhiyun /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7366*4882a593Smuzhiyun lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7367*4882a593Smuzhiyun "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
7368*4882a593Smuzhiyun "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
7369*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext,
7370*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7371*4882a593Smuzhiyun ndlp->nlp_rpi);
7372*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7373*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
7374*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7375*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
7376*4882a593Smuzhiyun }
7377*4882a593Smuzhiyun
7378*4882a593Smuzhiyun /**
7379*4882a593Smuzhiyun * lpfc_els_rcv_rls - Process an unsolicited rls iocb
7380*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7381*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7382*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7383*4882a593Smuzhiyun *
7384*4882a593Smuzhiyun * This routine processes Read Link Status (RLS) IOCB received as an
7385*4882a593Smuzhiyun * ELS unsolicited event. It first checks the remote port state. If the
7386*4882a593Smuzhiyun * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7387*4882a593Smuzhiyun * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7388*4882a593Smuzhiyun * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
7389*4882a593Smuzhiyun * for reading the HBA link statistics. It is for the callback function,
7390*4882a593Smuzhiyun * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
7391*4882a593Smuzhiyun * to actually sending out RPL Accept (ACC) response.
7392*4882a593Smuzhiyun *
7393*4882a593Smuzhiyun * Return codes
7394*4882a593Smuzhiyun * 0 - Successfully processed rls iocb (currently always return 0)
7395*4882a593Smuzhiyun **/
7396*4882a593Smuzhiyun static int
lpfc_els_rcv_rls(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7397*4882a593Smuzhiyun lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7398*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7399*4882a593Smuzhiyun {
7400*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7401*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
7402*4882a593Smuzhiyun struct ls_rjt stat;
7403*4882a593Smuzhiyun
7404*4882a593Smuzhiyun if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7405*4882a593Smuzhiyun (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7406*4882a593Smuzhiyun /* reject the unsolicited RLS request and done with it */
7407*4882a593Smuzhiyun goto reject_out;
7408*4882a593Smuzhiyun
7409*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
7410*4882a593Smuzhiyun if (mbox) {
7411*4882a593Smuzhiyun lpfc_read_lnk_stat(phba, mbox);
7412*4882a593Smuzhiyun mbox->ctx_buf = (void *)((unsigned long)
7413*4882a593Smuzhiyun ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
7414*4882a593Smuzhiyun cmdiocb->iocb.ulpContext)); /* rx_id */
7415*4882a593Smuzhiyun mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
7416*4882a593Smuzhiyun mbox->vport = vport;
7417*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
7418*4882a593Smuzhiyun if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
7419*4882a593Smuzhiyun != MBX_NOT_FINISHED)
7420*4882a593Smuzhiyun /* Mbox completion will send ELS Response */
7421*4882a593Smuzhiyun return 0;
7422*4882a593Smuzhiyun /* Decrement reference count used for the failed mbox
7423*4882a593Smuzhiyun * command.
7424*4882a593Smuzhiyun */
7425*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
7426*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
7427*4882a593Smuzhiyun }
7428*4882a593Smuzhiyun reject_out:
7429*4882a593Smuzhiyun /* issue rejection response */
7430*4882a593Smuzhiyun stat.un.b.lsRjtRsvd0 = 0;
7431*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7432*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7433*4882a593Smuzhiyun stat.un.b.vendorUnique = 0;
7434*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7435*4882a593Smuzhiyun return 0;
7436*4882a593Smuzhiyun }
7437*4882a593Smuzhiyun
7438*4882a593Smuzhiyun /**
7439*4882a593Smuzhiyun * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
7440*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7441*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7442*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7443*4882a593Smuzhiyun *
7444*4882a593Smuzhiyun * This routine processes Read Timout Value (RTV) IOCB received as an
7445*4882a593Smuzhiyun * ELS unsolicited event. It first checks the remote port state. If the
7446*4882a593Smuzhiyun * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
7447*4882a593Smuzhiyun * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
7448*4882a593Smuzhiyun * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
7449*4882a593Smuzhiyun * Value (RTV) unsolicited IOCB event.
7450*4882a593Smuzhiyun *
7451*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7452*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
7453*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
7454*4882a593Smuzhiyun * callback function to the RTV Accept Response ELS IOCB command.
7455*4882a593Smuzhiyun *
7456*4882a593Smuzhiyun * Return codes
7457*4882a593Smuzhiyun * 0 - Successfully processed rtv iocb (currently always return 0)
7458*4882a593Smuzhiyun **/
7459*4882a593Smuzhiyun static int
lpfc_els_rcv_rtv(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7460*4882a593Smuzhiyun lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7461*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7462*4882a593Smuzhiyun {
7463*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7464*4882a593Smuzhiyun struct ls_rjt stat;
7465*4882a593Smuzhiyun struct RTV_RSP *rtv_rsp;
7466*4882a593Smuzhiyun uint8_t *pcmd;
7467*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
7468*4882a593Smuzhiyun uint32_t cmdsize;
7469*4882a593Smuzhiyun
7470*4882a593Smuzhiyun
7471*4882a593Smuzhiyun if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7472*4882a593Smuzhiyun (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
7473*4882a593Smuzhiyun /* reject the unsolicited RTV request and done with it */
7474*4882a593Smuzhiyun goto reject_out;
7475*4882a593Smuzhiyun
7476*4882a593Smuzhiyun cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
7477*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
7478*4882a593Smuzhiyun lpfc_max_els_tries, ndlp,
7479*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
7480*4882a593Smuzhiyun
7481*4882a593Smuzhiyun if (!elsiocb)
7482*4882a593Smuzhiyun return 1;
7483*4882a593Smuzhiyun
7484*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7485*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7486*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* Skip past command */
7487*4882a593Smuzhiyun
7488*4882a593Smuzhiyun /* use the command's xri in the response */
7489*4882a593Smuzhiyun elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
7490*4882a593Smuzhiyun elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
7491*4882a593Smuzhiyun
7492*4882a593Smuzhiyun rtv_rsp = (struct RTV_RSP *)pcmd;
7493*4882a593Smuzhiyun
7494*4882a593Smuzhiyun /* populate RTV payload */
7495*4882a593Smuzhiyun rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
7496*4882a593Smuzhiyun rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
7497*4882a593Smuzhiyun bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
7498*4882a593Smuzhiyun bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
7499*4882a593Smuzhiyun rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
7500*4882a593Smuzhiyun
7501*4882a593Smuzhiyun /* Xmit ELS RLS ACC response tag <ulpIoTag> */
7502*4882a593Smuzhiyun lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
7503*4882a593Smuzhiyun "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
7504*4882a593Smuzhiyun "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
7505*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
7506*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext,
7507*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7508*4882a593Smuzhiyun ndlp->nlp_rpi,
7509*4882a593Smuzhiyun rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
7510*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7511*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
7512*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
7513*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
7514*4882a593Smuzhiyun return 0;
7515*4882a593Smuzhiyun
7516*4882a593Smuzhiyun reject_out:
7517*4882a593Smuzhiyun /* issue rejection response */
7518*4882a593Smuzhiyun stat.un.b.lsRjtRsvd0 = 0;
7519*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7520*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7521*4882a593Smuzhiyun stat.un.b.vendorUnique = 0;
7522*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
7523*4882a593Smuzhiyun return 0;
7524*4882a593Smuzhiyun }
7525*4882a593Smuzhiyun
7526*4882a593Smuzhiyun /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
7527*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7528*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7529*4882a593Smuzhiyun * @did: DID of the target.
7530*4882a593Smuzhiyun * @rrq: Pointer to the rrq struct.
7531*4882a593Smuzhiyun *
7532*4882a593Smuzhiyun * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7533*4882a593Smuzhiyun * Successful the the completion handler will clear the RRQ.
7534*4882a593Smuzhiyun *
7535*4882a593Smuzhiyun * Return codes
7536*4882a593Smuzhiyun * 0 - Successfully sent rrq els iocb.
7537*4882a593Smuzhiyun * 1 - Failed to send rrq els iocb.
7538*4882a593Smuzhiyun **/
7539*4882a593Smuzhiyun static int
lpfc_issue_els_rrq(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint32_t did,struct lpfc_node_rrq * rrq)7540*4882a593Smuzhiyun lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7541*4882a593Smuzhiyun uint32_t did, struct lpfc_node_rrq *rrq)
7542*4882a593Smuzhiyun {
7543*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7544*4882a593Smuzhiyun struct RRQ *els_rrq;
7545*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
7546*4882a593Smuzhiyun uint8_t *pcmd;
7547*4882a593Smuzhiyun uint16_t cmdsize;
7548*4882a593Smuzhiyun int ret;
7549*4882a593Smuzhiyun
7550*4882a593Smuzhiyun
7551*4882a593Smuzhiyun if (ndlp != rrq->ndlp)
7552*4882a593Smuzhiyun ndlp = rrq->ndlp;
7553*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7554*4882a593Smuzhiyun return 1;
7555*4882a593Smuzhiyun
7556*4882a593Smuzhiyun /* If ndlp is not NULL, we will bump the reference count on it */
7557*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
7558*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
7559*4882a593Smuzhiyun ELS_CMD_RRQ);
7560*4882a593Smuzhiyun if (!elsiocb)
7561*4882a593Smuzhiyun return 1;
7562*4882a593Smuzhiyun
7563*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7564*4882a593Smuzhiyun
7565*4882a593Smuzhiyun /* For RRQ request, remainder of payload is Exchange IDs */
7566*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
7567*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
7568*4882a593Smuzhiyun els_rrq = (struct RRQ *) pcmd;
7569*4882a593Smuzhiyun
7570*4882a593Smuzhiyun bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
7571*4882a593Smuzhiyun bf_set(rrq_rxid, els_rrq, rrq->rxid);
7572*4882a593Smuzhiyun bf_set(rrq_did, els_rrq, vport->fc_myDID);
7573*4882a593Smuzhiyun els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
7574*4882a593Smuzhiyun els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
7575*4882a593Smuzhiyun
7576*4882a593Smuzhiyun
7577*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7578*4882a593Smuzhiyun "Issue RRQ: did:x%x",
7579*4882a593Smuzhiyun did, rrq->xritag, rrq->rxid);
7580*4882a593Smuzhiyun elsiocb->context_un.rrq = rrq;
7581*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
7582*4882a593Smuzhiyun ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
7583*4882a593Smuzhiyun
7584*4882a593Smuzhiyun if (ret == IOCB_ERROR) {
7585*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
7586*4882a593Smuzhiyun return 1;
7587*4882a593Smuzhiyun }
7588*4882a593Smuzhiyun return 0;
7589*4882a593Smuzhiyun }
7590*4882a593Smuzhiyun
7591*4882a593Smuzhiyun /**
7592*4882a593Smuzhiyun * lpfc_send_rrq - Sends ELS RRQ if needed.
7593*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
7594*4882a593Smuzhiyun * @rrq: pointer to the active rrq.
7595*4882a593Smuzhiyun *
7596*4882a593Smuzhiyun * This routine will call the lpfc_issue_els_rrq if the rrq is
7597*4882a593Smuzhiyun * still active for the xri. If this function returns a failure then
7598*4882a593Smuzhiyun * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7599*4882a593Smuzhiyun *
7600*4882a593Smuzhiyun * Returns 0 Success.
7601*4882a593Smuzhiyun * 1 Failure.
7602*4882a593Smuzhiyun **/
7603*4882a593Smuzhiyun int
lpfc_send_rrq(struct lpfc_hba * phba,struct lpfc_node_rrq * rrq)7604*4882a593Smuzhiyun lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
7605*4882a593Smuzhiyun {
7606*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
7607*4882a593Smuzhiyun rrq->nlp_DID);
7608*4882a593Smuzhiyun if (!ndlp)
7609*4882a593Smuzhiyun return 1;
7610*4882a593Smuzhiyun
7611*4882a593Smuzhiyun if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
7612*4882a593Smuzhiyun return lpfc_issue_els_rrq(rrq->vport, ndlp,
7613*4882a593Smuzhiyun rrq->nlp_DID, rrq);
7614*4882a593Smuzhiyun else
7615*4882a593Smuzhiyun return 1;
7616*4882a593Smuzhiyun }
7617*4882a593Smuzhiyun
7618*4882a593Smuzhiyun /**
7619*4882a593Smuzhiyun * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7620*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7621*4882a593Smuzhiyun * @cmdsize: size of the ELS command.
7622*4882a593Smuzhiyun * @oldiocb: pointer to the original lpfc command iocb data structure.
7623*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7624*4882a593Smuzhiyun *
7625*4882a593Smuzhiyun * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7626*4882a593Smuzhiyun * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7627*4882a593Smuzhiyun *
7628*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7629*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
7630*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
7631*4882a593Smuzhiyun * callback function to the RPL Accept Response ELS command.
7632*4882a593Smuzhiyun *
7633*4882a593Smuzhiyun * Return code
7634*4882a593Smuzhiyun * 0 - Successfully issued ACC RPL ELS command
7635*4882a593Smuzhiyun * 1 - Failed to issue ACC RPL ELS command
7636*4882a593Smuzhiyun **/
7637*4882a593Smuzhiyun static int
lpfc_els_rsp_rpl_acc(struct lpfc_vport * vport,uint16_t cmdsize,struct lpfc_iocbq * oldiocb,struct lpfc_nodelist * ndlp)7638*4882a593Smuzhiyun lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
7639*4882a593Smuzhiyun struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
7640*4882a593Smuzhiyun {
7641*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7642*4882a593Smuzhiyun IOCB_t *icmd, *oldcmd;
7643*4882a593Smuzhiyun RPL_RSP rpl_rsp;
7644*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
7645*4882a593Smuzhiyun uint8_t *pcmd;
7646*4882a593Smuzhiyun
7647*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
7648*4882a593Smuzhiyun ndlp->nlp_DID, ELS_CMD_ACC);
7649*4882a593Smuzhiyun
7650*4882a593Smuzhiyun if (!elsiocb)
7651*4882a593Smuzhiyun return 1;
7652*4882a593Smuzhiyun
7653*4882a593Smuzhiyun icmd = &elsiocb->iocb;
7654*4882a593Smuzhiyun oldcmd = &oldiocb->iocb;
7655*4882a593Smuzhiyun icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
7656*4882a593Smuzhiyun icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
7657*4882a593Smuzhiyun
7658*4882a593Smuzhiyun pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7659*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
7660*4882a593Smuzhiyun pcmd += sizeof(uint16_t);
7661*4882a593Smuzhiyun *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
7662*4882a593Smuzhiyun pcmd += sizeof(uint16_t);
7663*4882a593Smuzhiyun
7664*4882a593Smuzhiyun /* Setup the RPL ACC payload */
7665*4882a593Smuzhiyun rpl_rsp.listLen = be32_to_cpu(1);
7666*4882a593Smuzhiyun rpl_rsp.index = 0;
7667*4882a593Smuzhiyun rpl_rsp.port_num_blk.portNum = 0;
7668*4882a593Smuzhiyun rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
7669*4882a593Smuzhiyun memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
7670*4882a593Smuzhiyun sizeof(struct lpfc_name));
7671*4882a593Smuzhiyun memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
7672*4882a593Smuzhiyun /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7673*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7674*4882a593Smuzhiyun "0120 Xmit ELS RPL ACC response tag x%x "
7675*4882a593Smuzhiyun "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7676*4882a593Smuzhiyun "rpi x%x\n",
7677*4882a593Smuzhiyun elsiocb->iotag, elsiocb->iocb.ulpContext,
7678*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
7679*4882a593Smuzhiyun ndlp->nlp_rpi);
7680*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
7681*4882a593Smuzhiyun phba->fc_stat.elsXmitACC++;
7682*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7683*4882a593Smuzhiyun IOCB_ERROR) {
7684*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
7685*4882a593Smuzhiyun return 1;
7686*4882a593Smuzhiyun }
7687*4882a593Smuzhiyun return 0;
7688*4882a593Smuzhiyun }
7689*4882a593Smuzhiyun
7690*4882a593Smuzhiyun /**
7691*4882a593Smuzhiyun * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7692*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7693*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7694*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7695*4882a593Smuzhiyun *
7696*4882a593Smuzhiyun * This routine processes Read Port List (RPL) IOCB received as an ELS
7697*4882a593Smuzhiyun * unsolicited event. It first checks the remote port state. If the remote
7698*4882a593Smuzhiyun * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7699*4882a593Smuzhiyun * invokes the lpfc_els_rsp_reject() routine to send reject response.
7700*4882a593Smuzhiyun * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7701*4882a593Smuzhiyun * to accept the RPL.
7702*4882a593Smuzhiyun *
7703*4882a593Smuzhiyun * Return code
7704*4882a593Smuzhiyun * 0 - Successfully processed rpl iocb (currently always return 0)
7705*4882a593Smuzhiyun **/
7706*4882a593Smuzhiyun static int
lpfc_els_rcv_rpl(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7707*4882a593Smuzhiyun lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7708*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7709*4882a593Smuzhiyun {
7710*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
7711*4882a593Smuzhiyun uint32_t *lp;
7712*4882a593Smuzhiyun uint32_t maxsize;
7713*4882a593Smuzhiyun uint16_t cmdsize;
7714*4882a593Smuzhiyun RPL *rpl;
7715*4882a593Smuzhiyun struct ls_rjt stat;
7716*4882a593Smuzhiyun
7717*4882a593Smuzhiyun if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
7718*4882a593Smuzhiyun (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
7719*4882a593Smuzhiyun /* issue rejection response */
7720*4882a593Smuzhiyun stat.un.b.lsRjtRsvd0 = 0;
7721*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
7722*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
7723*4882a593Smuzhiyun stat.un.b.vendorUnique = 0;
7724*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
7725*4882a593Smuzhiyun NULL);
7726*4882a593Smuzhiyun /* rejected the unsolicited RPL request and done with it */
7727*4882a593Smuzhiyun return 0;
7728*4882a593Smuzhiyun }
7729*4882a593Smuzhiyun
7730*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7731*4882a593Smuzhiyun lp = (uint32_t *) pcmd->virt;
7732*4882a593Smuzhiyun rpl = (RPL *) (lp + 1);
7733*4882a593Smuzhiyun maxsize = be32_to_cpu(rpl->maxsize);
7734*4882a593Smuzhiyun
7735*4882a593Smuzhiyun /* We support only one port */
7736*4882a593Smuzhiyun if ((rpl->index == 0) &&
7737*4882a593Smuzhiyun ((maxsize == 0) ||
7738*4882a593Smuzhiyun ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
7739*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
7740*4882a593Smuzhiyun } else {
7741*4882a593Smuzhiyun cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
7742*4882a593Smuzhiyun }
7743*4882a593Smuzhiyun lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
7744*4882a593Smuzhiyun
7745*4882a593Smuzhiyun return 0;
7746*4882a593Smuzhiyun }
7747*4882a593Smuzhiyun
7748*4882a593Smuzhiyun /**
7749*4882a593Smuzhiyun * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7750*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
7751*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7752*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7753*4882a593Smuzhiyun *
7754*4882a593Smuzhiyun * This routine processes Fibre Channel Address Resolution Protocol
7755*4882a593Smuzhiyun * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7756*4882a593Smuzhiyun * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7757*4882a593Smuzhiyun * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7758*4882a593Smuzhiyun * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7759*4882a593Smuzhiyun * remote PortName is compared against the FC PortName stored in the @vport
7760*4882a593Smuzhiyun * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7761*4882a593Smuzhiyun * compared against the FC NodeName stored in the @vport data structure.
7762*4882a593Smuzhiyun * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7763*4882a593Smuzhiyun * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7764*4882a593Smuzhiyun * invoked to send out FARP Response to the remote node. Before sending the
7765*4882a593Smuzhiyun * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7766*4882a593Smuzhiyun * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7767*4882a593Smuzhiyun * routine is invoked to log into the remote port first.
7768*4882a593Smuzhiyun *
7769*4882a593Smuzhiyun * Return code
7770*4882a593Smuzhiyun * 0 - Either the FARP Match Mode not supported or successfully processed
7771*4882a593Smuzhiyun **/
7772*4882a593Smuzhiyun static int
lpfc_els_rcv_farp(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7773*4882a593Smuzhiyun lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7774*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7775*4882a593Smuzhiyun {
7776*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
7777*4882a593Smuzhiyun uint32_t *lp;
7778*4882a593Smuzhiyun IOCB_t *icmd;
7779*4882a593Smuzhiyun FARP *fp;
7780*4882a593Smuzhiyun uint32_t cnt, did;
7781*4882a593Smuzhiyun
7782*4882a593Smuzhiyun icmd = &cmdiocb->iocb;
7783*4882a593Smuzhiyun did = icmd->un.elsreq64.remoteID;
7784*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7785*4882a593Smuzhiyun lp = (uint32_t *) pcmd->virt;
7786*4882a593Smuzhiyun
7787*4882a593Smuzhiyun lp++;
7788*4882a593Smuzhiyun fp = (FARP *) lp;
7789*4882a593Smuzhiyun /* FARP-REQ received from DID <did> */
7790*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7791*4882a593Smuzhiyun "0601 FARP-REQ received from DID x%x\n", did);
7792*4882a593Smuzhiyun /* We will only support match on WWPN or WWNN */
7793*4882a593Smuzhiyun if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
7794*4882a593Smuzhiyun return 0;
7795*4882a593Smuzhiyun }
7796*4882a593Smuzhiyun
7797*4882a593Smuzhiyun cnt = 0;
7798*4882a593Smuzhiyun /* If this FARP command is searching for my portname */
7799*4882a593Smuzhiyun if (fp->Mflags & FARP_MATCH_PORT) {
7800*4882a593Smuzhiyun if (memcmp(&fp->RportName, &vport->fc_portname,
7801*4882a593Smuzhiyun sizeof(struct lpfc_name)) == 0)
7802*4882a593Smuzhiyun cnt = 1;
7803*4882a593Smuzhiyun }
7804*4882a593Smuzhiyun
7805*4882a593Smuzhiyun /* If this FARP command is searching for my nodename */
7806*4882a593Smuzhiyun if (fp->Mflags & FARP_MATCH_NODE) {
7807*4882a593Smuzhiyun if (memcmp(&fp->RnodeName, &vport->fc_nodename,
7808*4882a593Smuzhiyun sizeof(struct lpfc_name)) == 0)
7809*4882a593Smuzhiyun cnt = 1;
7810*4882a593Smuzhiyun }
7811*4882a593Smuzhiyun
7812*4882a593Smuzhiyun if (cnt) {
7813*4882a593Smuzhiyun if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
7814*4882a593Smuzhiyun (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
7815*4882a593Smuzhiyun /* Log back into the node before sending the FARP. */
7816*4882a593Smuzhiyun if (fp->Rflags & FARP_REQUEST_PLOGI) {
7817*4882a593Smuzhiyun ndlp->nlp_prev_state = ndlp->nlp_state;
7818*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp,
7819*4882a593Smuzhiyun NLP_STE_PLOGI_ISSUE);
7820*4882a593Smuzhiyun lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
7821*4882a593Smuzhiyun }
7822*4882a593Smuzhiyun
7823*4882a593Smuzhiyun /* Send a FARP response to that node */
7824*4882a593Smuzhiyun if (fp->Rflags & FARP_REQUEST_FARPR)
7825*4882a593Smuzhiyun lpfc_issue_els_farpr(vport, did, 0);
7826*4882a593Smuzhiyun }
7827*4882a593Smuzhiyun }
7828*4882a593Smuzhiyun return 0;
7829*4882a593Smuzhiyun }
7830*4882a593Smuzhiyun
7831*4882a593Smuzhiyun /**
7832*4882a593Smuzhiyun * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7833*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7834*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7835*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
7836*4882a593Smuzhiyun *
7837*4882a593Smuzhiyun * This routine processes Fibre Channel Address Resolution Protocol
7838*4882a593Smuzhiyun * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7839*4882a593Smuzhiyun * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7840*4882a593Smuzhiyun * the FARP response request.
7841*4882a593Smuzhiyun *
7842*4882a593Smuzhiyun * Return code
7843*4882a593Smuzhiyun * 0 - Successfully processed FARPR IOCB (currently always return 0)
7844*4882a593Smuzhiyun **/
7845*4882a593Smuzhiyun static int
lpfc_els_rcv_farpr(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * ndlp)7846*4882a593Smuzhiyun lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7847*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
7848*4882a593Smuzhiyun {
7849*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
7850*4882a593Smuzhiyun uint32_t *lp;
7851*4882a593Smuzhiyun IOCB_t *icmd;
7852*4882a593Smuzhiyun uint32_t did;
7853*4882a593Smuzhiyun
7854*4882a593Smuzhiyun icmd = &cmdiocb->iocb;
7855*4882a593Smuzhiyun did = icmd->un.elsreq64.remoteID;
7856*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7857*4882a593Smuzhiyun lp = (uint32_t *) pcmd->virt;
7858*4882a593Smuzhiyun
7859*4882a593Smuzhiyun lp++;
7860*4882a593Smuzhiyun /* FARP-RSP received from DID <did> */
7861*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7862*4882a593Smuzhiyun "0600 FARP-RSP received from DID x%x\n", did);
7863*4882a593Smuzhiyun /* ACCEPT the Farp resp request */
7864*4882a593Smuzhiyun lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
7865*4882a593Smuzhiyun
7866*4882a593Smuzhiyun return 0;
7867*4882a593Smuzhiyun }
7868*4882a593Smuzhiyun
7869*4882a593Smuzhiyun /**
7870*4882a593Smuzhiyun * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7871*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
7872*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
7873*4882a593Smuzhiyun * @fan_ndlp: pointer to a node-list data structure.
7874*4882a593Smuzhiyun *
7875*4882a593Smuzhiyun * This routine processes a Fabric Address Notification (FAN) IOCB
7876*4882a593Smuzhiyun * command received as an ELS unsolicited event. The FAN ELS command will
7877*4882a593Smuzhiyun * only be processed on a physical port (i.e., the @vport represents the
7878*4882a593Smuzhiyun * physical port). The fabric NodeName and PortName from the FAN IOCB are
7879*4882a593Smuzhiyun * compared against those in the phba data structure. If any of those is
7880*4882a593Smuzhiyun * different, the lpfc_initial_flogi() routine is invoked to initialize
7881*4882a593Smuzhiyun * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7882*4882a593Smuzhiyun * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7883*4882a593Smuzhiyun * is invoked to register login to the fabric.
7884*4882a593Smuzhiyun *
7885*4882a593Smuzhiyun * Return code
7886*4882a593Smuzhiyun * 0 - Successfully processed fan iocb (currently always return 0).
7887*4882a593Smuzhiyun **/
7888*4882a593Smuzhiyun static int
lpfc_els_rcv_fan(struct lpfc_vport * vport,struct lpfc_iocbq * cmdiocb,struct lpfc_nodelist * fan_ndlp)7889*4882a593Smuzhiyun lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7890*4882a593Smuzhiyun struct lpfc_nodelist *fan_ndlp)
7891*4882a593Smuzhiyun {
7892*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7893*4882a593Smuzhiyun uint32_t *lp;
7894*4882a593Smuzhiyun FAN *fp;
7895*4882a593Smuzhiyun
7896*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7897*4882a593Smuzhiyun lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7898*4882a593Smuzhiyun fp = (FAN *) ++lp;
7899*4882a593Smuzhiyun /* FAN received; Fan does not have a reply sequence */
7900*4882a593Smuzhiyun if ((vport == phba->pport) &&
7901*4882a593Smuzhiyun (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
7902*4882a593Smuzhiyun if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
7903*4882a593Smuzhiyun sizeof(struct lpfc_name))) ||
7904*4882a593Smuzhiyun (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
7905*4882a593Smuzhiyun sizeof(struct lpfc_name)))) {
7906*4882a593Smuzhiyun /* This port has switched fabrics. FLOGI is required */
7907*4882a593Smuzhiyun lpfc_issue_init_vfi(vport);
7908*4882a593Smuzhiyun } else {
7909*4882a593Smuzhiyun /* FAN verified - skip FLOGI */
7910*4882a593Smuzhiyun vport->fc_myDID = vport->fc_prevDID;
7911*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4)
7912*4882a593Smuzhiyun lpfc_issue_fabric_reglogin(vport);
7913*4882a593Smuzhiyun else {
7914*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7915*4882a593Smuzhiyun "3138 Need register VFI: (x%x/%x)\n",
7916*4882a593Smuzhiyun vport->fc_prevDID, vport->fc_myDID);
7917*4882a593Smuzhiyun lpfc_issue_reg_vfi(vport);
7918*4882a593Smuzhiyun }
7919*4882a593Smuzhiyun }
7920*4882a593Smuzhiyun }
7921*4882a593Smuzhiyun return 0;
7922*4882a593Smuzhiyun }
7923*4882a593Smuzhiyun
7924*4882a593Smuzhiyun /**
7925*4882a593Smuzhiyun * lpfc_els_timeout - Handler funciton to the els timer
7926*4882a593Smuzhiyun * @t: timer context used to obtain the vport.
7927*4882a593Smuzhiyun *
7928*4882a593Smuzhiyun * This routine is invoked by the ELS timer after timeout. It posts the ELS
7929*4882a593Smuzhiyun * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7930*4882a593Smuzhiyun * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7931*4882a593Smuzhiyun * up the worker thread. It is for the worker thread to invoke the routine
7932*4882a593Smuzhiyun * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7933*4882a593Smuzhiyun **/
7934*4882a593Smuzhiyun void
lpfc_els_timeout(struct timer_list * t)7935*4882a593Smuzhiyun lpfc_els_timeout(struct timer_list *t)
7936*4882a593Smuzhiyun {
7937*4882a593Smuzhiyun struct lpfc_vport *vport = from_timer(vport, t, els_tmofunc);
7938*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7939*4882a593Smuzhiyun uint32_t tmo_posted;
7940*4882a593Smuzhiyun unsigned long iflag;
7941*4882a593Smuzhiyun
7942*4882a593Smuzhiyun spin_lock_irqsave(&vport->work_port_lock, iflag);
7943*4882a593Smuzhiyun tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
7944*4882a593Smuzhiyun if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7945*4882a593Smuzhiyun vport->work_port_events |= WORKER_ELS_TMO;
7946*4882a593Smuzhiyun spin_unlock_irqrestore(&vport->work_port_lock, iflag);
7947*4882a593Smuzhiyun
7948*4882a593Smuzhiyun if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
7949*4882a593Smuzhiyun lpfc_worker_wake_up(phba);
7950*4882a593Smuzhiyun return;
7951*4882a593Smuzhiyun }
7952*4882a593Smuzhiyun
7953*4882a593Smuzhiyun
7954*4882a593Smuzhiyun /**
7955*4882a593Smuzhiyun * lpfc_els_timeout_handler - Process an els timeout event
7956*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
7957*4882a593Smuzhiyun *
7958*4882a593Smuzhiyun * This routine is the actual handler function that processes an ELS timeout
7959*4882a593Smuzhiyun * event. It walks the ELS ring to get and abort all the IOCBs (except the
7960*4882a593Smuzhiyun * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7961*4882a593Smuzhiyun * invoking the lpfc_sli_issue_abort_iotag() routine.
7962*4882a593Smuzhiyun **/
7963*4882a593Smuzhiyun void
lpfc_els_timeout_handler(struct lpfc_vport * vport)7964*4882a593Smuzhiyun lpfc_els_timeout_handler(struct lpfc_vport *vport)
7965*4882a593Smuzhiyun {
7966*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
7967*4882a593Smuzhiyun struct lpfc_sli_ring *pring;
7968*4882a593Smuzhiyun struct lpfc_iocbq *tmp_iocb, *piocb;
7969*4882a593Smuzhiyun IOCB_t *cmd = NULL;
7970*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd;
7971*4882a593Smuzhiyun uint32_t els_command = 0;
7972*4882a593Smuzhiyun uint32_t timeout;
7973*4882a593Smuzhiyun uint32_t remote_ID = 0xffffffff;
7974*4882a593Smuzhiyun LIST_HEAD(abort_list);
7975*4882a593Smuzhiyun
7976*4882a593Smuzhiyun
7977*4882a593Smuzhiyun timeout = (uint32_t)(phba->fc_ratov << 1);
7978*4882a593Smuzhiyun
7979*4882a593Smuzhiyun pring = lpfc_phba_elsring(phba);
7980*4882a593Smuzhiyun if (unlikely(!pring))
7981*4882a593Smuzhiyun return;
7982*4882a593Smuzhiyun
7983*4882a593Smuzhiyun if (phba->pport->load_flag & FC_UNLOADING)
7984*4882a593Smuzhiyun return;
7985*4882a593Smuzhiyun
7986*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
7987*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
7988*4882a593Smuzhiyun spin_lock(&pring->ring_lock);
7989*4882a593Smuzhiyun
7990*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7991*4882a593Smuzhiyun cmd = &piocb->iocb;
7992*4882a593Smuzhiyun
7993*4882a593Smuzhiyun if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7994*4882a593Smuzhiyun piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7995*4882a593Smuzhiyun piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
7996*4882a593Smuzhiyun continue;
7997*4882a593Smuzhiyun
7998*4882a593Smuzhiyun if (piocb->vport != vport)
7999*4882a593Smuzhiyun continue;
8000*4882a593Smuzhiyun
8001*4882a593Smuzhiyun pcmd = (struct lpfc_dmabuf *) piocb->context2;
8002*4882a593Smuzhiyun if (pcmd)
8003*4882a593Smuzhiyun els_command = *(uint32_t *) (pcmd->virt);
8004*4882a593Smuzhiyun
8005*4882a593Smuzhiyun if (els_command == ELS_CMD_FARP ||
8006*4882a593Smuzhiyun els_command == ELS_CMD_FARPR ||
8007*4882a593Smuzhiyun els_command == ELS_CMD_FDISC)
8008*4882a593Smuzhiyun continue;
8009*4882a593Smuzhiyun
8010*4882a593Smuzhiyun if (piocb->drvrTimeout > 0) {
8011*4882a593Smuzhiyun if (piocb->drvrTimeout >= timeout)
8012*4882a593Smuzhiyun piocb->drvrTimeout -= timeout;
8013*4882a593Smuzhiyun else
8014*4882a593Smuzhiyun piocb->drvrTimeout = 0;
8015*4882a593Smuzhiyun continue;
8016*4882a593Smuzhiyun }
8017*4882a593Smuzhiyun
8018*4882a593Smuzhiyun remote_ID = 0xffffffff;
8019*4882a593Smuzhiyun if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
8020*4882a593Smuzhiyun remote_ID = cmd->un.elsreq64.remoteID;
8021*4882a593Smuzhiyun else {
8022*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
8023*4882a593Smuzhiyun ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
8024*4882a593Smuzhiyun if (ndlp && NLP_CHK_NODE_ACT(ndlp))
8025*4882a593Smuzhiyun remote_ID = ndlp->nlp_DID;
8026*4882a593Smuzhiyun }
8027*4882a593Smuzhiyun list_add_tail(&piocb->dlist, &abort_list);
8028*4882a593Smuzhiyun }
8029*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
8030*4882a593Smuzhiyun spin_unlock(&pring->ring_lock);
8031*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
8032*4882a593Smuzhiyun
8033*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8034*4882a593Smuzhiyun cmd = &piocb->iocb;
8035*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8036*4882a593Smuzhiyun "0127 ELS timeout Data: x%x x%x x%x "
8037*4882a593Smuzhiyun "x%x\n", els_command,
8038*4882a593Smuzhiyun remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
8039*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
8040*4882a593Smuzhiyun list_del_init(&piocb->dlist);
8041*4882a593Smuzhiyun lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8042*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
8043*4882a593Smuzhiyun }
8044*4882a593Smuzhiyun
8045*4882a593Smuzhiyun if (!list_empty(&pring->txcmplq))
8046*4882a593Smuzhiyun if (!(phba->pport->load_flag & FC_UNLOADING))
8047*4882a593Smuzhiyun mod_timer(&vport->els_tmofunc,
8048*4882a593Smuzhiyun jiffies + msecs_to_jiffies(1000 * timeout));
8049*4882a593Smuzhiyun }
8050*4882a593Smuzhiyun
8051*4882a593Smuzhiyun /**
8052*4882a593Smuzhiyun * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
8053*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
8054*4882a593Smuzhiyun *
8055*4882a593Smuzhiyun * This routine is used to clean up all the outstanding ELS commands on a
8056*4882a593Smuzhiyun * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
8057*4882a593Smuzhiyun * routine. After that, it walks the ELS transmit queue to remove all the
8058*4882a593Smuzhiyun * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
8059*4882a593Smuzhiyun * the IOCBs with a non-NULL completion callback function, the callback
8060*4882a593Smuzhiyun * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8061*4882a593Smuzhiyun * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
8062*4882a593Smuzhiyun * callback function, the IOCB will simply be released. Finally, it walks
8063*4882a593Smuzhiyun * the ELS transmit completion queue to issue an abort IOCB to any transmit
8064*4882a593Smuzhiyun * completion queue IOCB that is associated with the @vport and is not
8065*4882a593Smuzhiyun * an IOCB from libdfc (i.e., the management plane IOCBs that are not
8066*4882a593Smuzhiyun * part of the discovery state machine) out to HBA by invoking the
8067*4882a593Smuzhiyun * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
8068*4882a593Smuzhiyun * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
8069*4882a593Smuzhiyun * the IOCBs are aborted when this function returns.
8070*4882a593Smuzhiyun **/
8071*4882a593Smuzhiyun void
lpfc_els_flush_cmd(struct lpfc_vport * vport)8072*4882a593Smuzhiyun lpfc_els_flush_cmd(struct lpfc_vport *vport)
8073*4882a593Smuzhiyun {
8074*4882a593Smuzhiyun LIST_HEAD(abort_list);
8075*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
8076*4882a593Smuzhiyun struct lpfc_sli_ring *pring;
8077*4882a593Smuzhiyun struct lpfc_iocbq *tmp_iocb, *piocb;
8078*4882a593Smuzhiyun IOCB_t *cmd = NULL;
8079*4882a593Smuzhiyun unsigned long iflags = 0;
8080*4882a593Smuzhiyun
8081*4882a593Smuzhiyun lpfc_fabric_abort_vport(vport);
8082*4882a593Smuzhiyun
8083*4882a593Smuzhiyun /*
8084*4882a593Smuzhiyun * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
8085*4882a593Smuzhiyun * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
8086*4882a593Smuzhiyun * ultimately grabs the ring_lock, the driver must splice the list into
8087*4882a593Smuzhiyun * a working list and release the locks before calling the abort.
8088*4882a593Smuzhiyun */
8089*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflags);
8090*4882a593Smuzhiyun pring = lpfc_phba_elsring(phba);
8091*4882a593Smuzhiyun
8092*4882a593Smuzhiyun /* Bail out if we've no ELS wq, like in PCI error recovery case. */
8093*4882a593Smuzhiyun if (unlikely(!pring)) {
8094*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
8095*4882a593Smuzhiyun return;
8096*4882a593Smuzhiyun }
8097*4882a593Smuzhiyun
8098*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
8099*4882a593Smuzhiyun spin_lock(&pring->ring_lock);
8100*4882a593Smuzhiyun
8101*4882a593Smuzhiyun /* First we need to issue aborts to outstanding cmds on txcmpl */
8102*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
8103*4882a593Smuzhiyun if (piocb->iocb_flag & LPFC_IO_LIBDFC)
8104*4882a593Smuzhiyun continue;
8105*4882a593Smuzhiyun
8106*4882a593Smuzhiyun if (piocb->vport != vport)
8107*4882a593Smuzhiyun continue;
8108*4882a593Smuzhiyun
8109*4882a593Smuzhiyun if (piocb->iocb_flag & LPFC_DRIVER_ABORTED)
8110*4882a593Smuzhiyun continue;
8111*4882a593Smuzhiyun
8112*4882a593Smuzhiyun /* On the ELS ring we can have ELS_REQUESTs or
8113*4882a593Smuzhiyun * GEN_REQUESTs waiting for a response.
8114*4882a593Smuzhiyun */
8115*4882a593Smuzhiyun cmd = &piocb->iocb;
8116*4882a593Smuzhiyun if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
8117*4882a593Smuzhiyun list_add_tail(&piocb->dlist, &abort_list);
8118*4882a593Smuzhiyun
8119*4882a593Smuzhiyun /* If the link is down when flushing ELS commands
8120*4882a593Smuzhiyun * the firmware will not complete them till after
8121*4882a593Smuzhiyun * the link comes back up. This may confuse
8122*4882a593Smuzhiyun * discovery for the new link up, so we need to
8123*4882a593Smuzhiyun * change the compl routine to just clean up the iocb
8124*4882a593Smuzhiyun * and avoid any retry logic.
8125*4882a593Smuzhiyun */
8126*4882a593Smuzhiyun if (phba->link_state == LPFC_LINK_DOWN)
8127*4882a593Smuzhiyun piocb->iocb_cmpl = lpfc_cmpl_els_link_down;
8128*4882a593Smuzhiyun }
8129*4882a593Smuzhiyun if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR)
8130*4882a593Smuzhiyun list_add_tail(&piocb->dlist, &abort_list);
8131*4882a593Smuzhiyun }
8132*4882a593Smuzhiyun
8133*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
8134*4882a593Smuzhiyun spin_unlock(&pring->ring_lock);
8135*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
8136*4882a593Smuzhiyun
8137*4882a593Smuzhiyun /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
8138*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
8139*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflags);
8140*4882a593Smuzhiyun list_del_init(&piocb->dlist);
8141*4882a593Smuzhiyun lpfc_sli_issue_abort_iotag(phba, pring, piocb);
8142*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
8143*4882a593Smuzhiyun }
8144*4882a593Smuzhiyun if (!list_empty(&abort_list))
8145*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8146*4882a593Smuzhiyun "3387 abort list for txq not empty\n");
8147*4882a593Smuzhiyun INIT_LIST_HEAD(&abort_list);
8148*4882a593Smuzhiyun
8149*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflags);
8150*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
8151*4882a593Smuzhiyun spin_lock(&pring->ring_lock);
8152*4882a593Smuzhiyun
8153*4882a593Smuzhiyun /* No need to abort the txq list,
8154*4882a593Smuzhiyun * just queue them up for lpfc_sli_cancel_iocbs
8155*4882a593Smuzhiyun */
8156*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
8157*4882a593Smuzhiyun cmd = &piocb->iocb;
8158*4882a593Smuzhiyun
8159*4882a593Smuzhiyun if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
8160*4882a593Smuzhiyun continue;
8161*4882a593Smuzhiyun }
8162*4882a593Smuzhiyun
8163*4882a593Smuzhiyun /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
8164*4882a593Smuzhiyun if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
8165*4882a593Smuzhiyun cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
8166*4882a593Smuzhiyun cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
8167*4882a593Smuzhiyun cmd->ulpCommand == CMD_ABORT_XRI_CN)
8168*4882a593Smuzhiyun continue;
8169*4882a593Smuzhiyun
8170*4882a593Smuzhiyun if (piocb->vport != vport)
8171*4882a593Smuzhiyun continue;
8172*4882a593Smuzhiyun
8173*4882a593Smuzhiyun list_del_init(&piocb->list);
8174*4882a593Smuzhiyun list_add_tail(&piocb->list, &abort_list);
8175*4882a593Smuzhiyun }
8176*4882a593Smuzhiyun
8177*4882a593Smuzhiyun /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
8178*4882a593Smuzhiyun if (vport == phba->pport) {
8179*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb,
8180*4882a593Smuzhiyun &phba->fabric_iocb_list, list) {
8181*4882a593Smuzhiyun cmd = &piocb->iocb;
8182*4882a593Smuzhiyun list_del_init(&piocb->list);
8183*4882a593Smuzhiyun list_add_tail(&piocb->list, &abort_list);
8184*4882a593Smuzhiyun }
8185*4882a593Smuzhiyun }
8186*4882a593Smuzhiyun
8187*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
8188*4882a593Smuzhiyun spin_unlock(&pring->ring_lock);
8189*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
8190*4882a593Smuzhiyun
8191*4882a593Smuzhiyun /* Cancel all the IOCBs from the completions list */
8192*4882a593Smuzhiyun lpfc_sli_cancel_iocbs(phba, &abort_list,
8193*4882a593Smuzhiyun IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
8194*4882a593Smuzhiyun
8195*4882a593Smuzhiyun return;
8196*4882a593Smuzhiyun }
8197*4882a593Smuzhiyun
8198*4882a593Smuzhiyun /**
8199*4882a593Smuzhiyun * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
8200*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
8201*4882a593Smuzhiyun *
8202*4882a593Smuzhiyun * This routine is used to clean up all the outstanding ELS commands on a
8203*4882a593Smuzhiyun * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
8204*4882a593Smuzhiyun * routine. After that, it walks the ELS transmit queue to remove all the
8205*4882a593Smuzhiyun * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
8206*4882a593Smuzhiyun * the IOCBs with the completion callback function associated, the callback
8207*4882a593Smuzhiyun * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
8208*4882a593Smuzhiyun * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
8209*4882a593Smuzhiyun * callback function associated, the IOCB will simply be released. Finally,
8210*4882a593Smuzhiyun * it walks the ELS transmit completion queue to issue an abort IOCB to any
8211*4882a593Smuzhiyun * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
8212*4882a593Smuzhiyun * management plane IOCBs that are not part of the discovery state machine)
8213*4882a593Smuzhiyun * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
8214*4882a593Smuzhiyun **/
8215*4882a593Smuzhiyun void
lpfc_els_flush_all_cmd(struct lpfc_hba * phba)8216*4882a593Smuzhiyun lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
8217*4882a593Smuzhiyun {
8218*4882a593Smuzhiyun struct lpfc_vport *vport;
8219*4882a593Smuzhiyun
8220*4882a593Smuzhiyun spin_lock_irq(&phba->port_list_lock);
8221*4882a593Smuzhiyun list_for_each_entry(vport, &phba->port_list, listentry)
8222*4882a593Smuzhiyun lpfc_els_flush_cmd(vport);
8223*4882a593Smuzhiyun spin_unlock_irq(&phba->port_list_lock);
8224*4882a593Smuzhiyun
8225*4882a593Smuzhiyun return;
8226*4882a593Smuzhiyun }
8227*4882a593Smuzhiyun
8228*4882a593Smuzhiyun /**
8229*4882a593Smuzhiyun * lpfc_send_els_failure_event - Posts an ELS command failure event
8230*4882a593Smuzhiyun * @phba: Pointer to hba context object.
8231*4882a593Smuzhiyun * @cmdiocbp: Pointer to command iocb which reported error.
8232*4882a593Smuzhiyun * @rspiocbp: Pointer to response iocb which reported error.
8233*4882a593Smuzhiyun *
8234*4882a593Smuzhiyun * This function sends an event when there is an ELS command
8235*4882a593Smuzhiyun * failure.
8236*4882a593Smuzhiyun **/
8237*4882a593Smuzhiyun void
lpfc_send_els_failure_event(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocbp,struct lpfc_iocbq * rspiocbp)8238*4882a593Smuzhiyun lpfc_send_els_failure_event(struct lpfc_hba *phba,
8239*4882a593Smuzhiyun struct lpfc_iocbq *cmdiocbp,
8240*4882a593Smuzhiyun struct lpfc_iocbq *rspiocbp)
8241*4882a593Smuzhiyun {
8242*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocbp->vport;
8243*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8244*4882a593Smuzhiyun struct lpfc_lsrjt_event lsrjt_event;
8245*4882a593Smuzhiyun struct lpfc_fabric_event_header fabric_event;
8246*4882a593Smuzhiyun struct ls_rjt stat;
8247*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
8248*4882a593Smuzhiyun uint32_t *pcmd;
8249*4882a593Smuzhiyun
8250*4882a593Smuzhiyun ndlp = cmdiocbp->context1;
8251*4882a593Smuzhiyun if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
8252*4882a593Smuzhiyun return;
8253*4882a593Smuzhiyun
8254*4882a593Smuzhiyun if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
8255*4882a593Smuzhiyun lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
8256*4882a593Smuzhiyun lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
8257*4882a593Smuzhiyun memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
8258*4882a593Smuzhiyun sizeof(struct lpfc_name));
8259*4882a593Smuzhiyun memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
8260*4882a593Smuzhiyun sizeof(struct lpfc_name));
8261*4882a593Smuzhiyun pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
8262*4882a593Smuzhiyun cmdiocbp->context2)->virt);
8263*4882a593Smuzhiyun lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
8264*4882a593Smuzhiyun stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
8265*4882a593Smuzhiyun lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
8266*4882a593Smuzhiyun lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
8267*4882a593Smuzhiyun fc_host_post_vendor_event(shost,
8268*4882a593Smuzhiyun fc_get_event_number(),
8269*4882a593Smuzhiyun sizeof(lsrjt_event),
8270*4882a593Smuzhiyun (char *)&lsrjt_event,
8271*4882a593Smuzhiyun LPFC_NL_VENDOR_ID);
8272*4882a593Smuzhiyun return;
8273*4882a593Smuzhiyun }
8274*4882a593Smuzhiyun if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
8275*4882a593Smuzhiyun (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
8276*4882a593Smuzhiyun fabric_event.event_type = FC_REG_FABRIC_EVENT;
8277*4882a593Smuzhiyun if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
8278*4882a593Smuzhiyun fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
8279*4882a593Smuzhiyun else
8280*4882a593Smuzhiyun fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
8281*4882a593Smuzhiyun memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
8282*4882a593Smuzhiyun sizeof(struct lpfc_name));
8283*4882a593Smuzhiyun memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
8284*4882a593Smuzhiyun sizeof(struct lpfc_name));
8285*4882a593Smuzhiyun fc_host_post_vendor_event(shost,
8286*4882a593Smuzhiyun fc_get_event_number(),
8287*4882a593Smuzhiyun sizeof(fabric_event),
8288*4882a593Smuzhiyun (char *)&fabric_event,
8289*4882a593Smuzhiyun LPFC_NL_VENDOR_ID);
8290*4882a593Smuzhiyun return;
8291*4882a593Smuzhiyun }
8292*4882a593Smuzhiyun
8293*4882a593Smuzhiyun }
8294*4882a593Smuzhiyun
8295*4882a593Smuzhiyun /**
8296*4882a593Smuzhiyun * lpfc_send_els_event - Posts unsolicited els event
8297*4882a593Smuzhiyun * @vport: Pointer to vport object.
8298*4882a593Smuzhiyun * @ndlp: Pointer FC node object.
8299*4882a593Smuzhiyun * @payload: ELS command code type.
8300*4882a593Smuzhiyun *
8301*4882a593Smuzhiyun * This function posts an event when there is an incoming
8302*4882a593Smuzhiyun * unsolicited ELS command.
8303*4882a593Smuzhiyun **/
8304*4882a593Smuzhiyun static void
lpfc_send_els_event(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint32_t * payload)8305*4882a593Smuzhiyun lpfc_send_els_event(struct lpfc_vport *vport,
8306*4882a593Smuzhiyun struct lpfc_nodelist *ndlp,
8307*4882a593Smuzhiyun uint32_t *payload)
8308*4882a593Smuzhiyun {
8309*4882a593Smuzhiyun struct lpfc_els_event_header *els_data = NULL;
8310*4882a593Smuzhiyun struct lpfc_logo_event *logo_data = NULL;
8311*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8312*4882a593Smuzhiyun
8313*4882a593Smuzhiyun if (*payload == ELS_CMD_LOGO) {
8314*4882a593Smuzhiyun logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
8315*4882a593Smuzhiyun if (!logo_data) {
8316*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8317*4882a593Smuzhiyun "0148 Failed to allocate memory "
8318*4882a593Smuzhiyun "for LOGO event\n");
8319*4882a593Smuzhiyun return;
8320*4882a593Smuzhiyun }
8321*4882a593Smuzhiyun els_data = &logo_data->header;
8322*4882a593Smuzhiyun } else {
8323*4882a593Smuzhiyun els_data = kmalloc(sizeof(struct lpfc_els_event_header),
8324*4882a593Smuzhiyun GFP_KERNEL);
8325*4882a593Smuzhiyun if (!els_data) {
8326*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8327*4882a593Smuzhiyun "0149 Failed to allocate memory "
8328*4882a593Smuzhiyun "for ELS event\n");
8329*4882a593Smuzhiyun return;
8330*4882a593Smuzhiyun }
8331*4882a593Smuzhiyun }
8332*4882a593Smuzhiyun els_data->event_type = FC_REG_ELS_EVENT;
8333*4882a593Smuzhiyun switch (*payload) {
8334*4882a593Smuzhiyun case ELS_CMD_PLOGI:
8335*4882a593Smuzhiyun els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
8336*4882a593Smuzhiyun break;
8337*4882a593Smuzhiyun case ELS_CMD_PRLO:
8338*4882a593Smuzhiyun els_data->subcategory = LPFC_EVENT_PRLO_RCV;
8339*4882a593Smuzhiyun break;
8340*4882a593Smuzhiyun case ELS_CMD_ADISC:
8341*4882a593Smuzhiyun els_data->subcategory = LPFC_EVENT_ADISC_RCV;
8342*4882a593Smuzhiyun break;
8343*4882a593Smuzhiyun case ELS_CMD_LOGO:
8344*4882a593Smuzhiyun els_data->subcategory = LPFC_EVENT_LOGO_RCV;
8345*4882a593Smuzhiyun /* Copy the WWPN in the LOGO payload */
8346*4882a593Smuzhiyun memcpy(logo_data->logo_wwpn, &payload[2],
8347*4882a593Smuzhiyun sizeof(struct lpfc_name));
8348*4882a593Smuzhiyun break;
8349*4882a593Smuzhiyun default:
8350*4882a593Smuzhiyun kfree(els_data);
8351*4882a593Smuzhiyun return;
8352*4882a593Smuzhiyun }
8353*4882a593Smuzhiyun memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
8354*4882a593Smuzhiyun memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
8355*4882a593Smuzhiyun if (*payload == ELS_CMD_LOGO) {
8356*4882a593Smuzhiyun fc_host_post_vendor_event(shost,
8357*4882a593Smuzhiyun fc_get_event_number(),
8358*4882a593Smuzhiyun sizeof(struct lpfc_logo_event),
8359*4882a593Smuzhiyun (char *)logo_data,
8360*4882a593Smuzhiyun LPFC_NL_VENDOR_ID);
8361*4882a593Smuzhiyun kfree(logo_data);
8362*4882a593Smuzhiyun } else {
8363*4882a593Smuzhiyun fc_host_post_vendor_event(shost,
8364*4882a593Smuzhiyun fc_get_event_number(),
8365*4882a593Smuzhiyun sizeof(struct lpfc_els_event_header),
8366*4882a593Smuzhiyun (char *)els_data,
8367*4882a593Smuzhiyun LPFC_NL_VENDOR_ID);
8368*4882a593Smuzhiyun kfree(els_data);
8369*4882a593Smuzhiyun }
8370*4882a593Smuzhiyun
8371*4882a593Smuzhiyun return;
8372*4882a593Smuzhiyun }
8373*4882a593Smuzhiyun
8374*4882a593Smuzhiyun
8375*4882a593Smuzhiyun DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm, fc_ls_tlv_dtag,
8376*4882a593Smuzhiyun FC_LS_TLV_DTAG_INIT);
8377*4882a593Smuzhiyun
8378*4882a593Smuzhiyun DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm, fc_fpin_li_event_types,
8379*4882a593Smuzhiyun FC_FPIN_LI_EVT_TYPES_INIT);
8380*4882a593Smuzhiyun
8381*4882a593Smuzhiyun /**
8382*4882a593Smuzhiyun * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
8383*4882a593Smuzhiyun * @vport: Pointer to vport object.
8384*4882a593Smuzhiyun * @tlv: Pointer to the Link Integrity Notification Descriptor.
8385*4882a593Smuzhiyun *
8386*4882a593Smuzhiyun * This function processes a link integrity FPIN event by
8387*4882a593Smuzhiyun * logging a message
8388*4882a593Smuzhiyun **/
8389*4882a593Smuzhiyun static void
lpfc_els_rcv_fpin_li(struct lpfc_vport * vport,struct fc_tlv_desc * tlv)8390*4882a593Smuzhiyun lpfc_els_rcv_fpin_li(struct lpfc_vport *vport, struct fc_tlv_desc *tlv)
8391*4882a593Smuzhiyun {
8392*4882a593Smuzhiyun struct fc_fn_li_desc *li = (struct fc_fn_li_desc *)tlv;
8393*4882a593Smuzhiyun const char *li_evt_str;
8394*4882a593Smuzhiyun u32 li_evt;
8395*4882a593Smuzhiyun
8396*4882a593Smuzhiyun li_evt = be16_to_cpu(li->event_type);
8397*4882a593Smuzhiyun li_evt_str = lpfc_get_fpin_li_event_nm(li_evt);
8398*4882a593Smuzhiyun
8399*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8400*4882a593Smuzhiyun "4680 FPIN Link Integrity %s (x%x) "
8401*4882a593Smuzhiyun "Detecting PN x%016llx Attached PN x%016llx "
8402*4882a593Smuzhiyun "Duration %d mSecs Count %d Port Cnt %d\n",
8403*4882a593Smuzhiyun li_evt_str, li_evt,
8404*4882a593Smuzhiyun be64_to_cpu(li->detecting_wwpn),
8405*4882a593Smuzhiyun be64_to_cpu(li->attached_wwpn),
8406*4882a593Smuzhiyun be32_to_cpu(li->event_threshold),
8407*4882a593Smuzhiyun be32_to_cpu(li->event_count),
8408*4882a593Smuzhiyun be32_to_cpu(li->pname_count));
8409*4882a593Smuzhiyun }
8410*4882a593Smuzhiyun
8411*4882a593Smuzhiyun static void
lpfc_els_rcv_fpin(struct lpfc_vport * vport,struct fc_els_fpin * fpin,u32 fpin_length)8412*4882a593Smuzhiyun lpfc_els_rcv_fpin(struct lpfc_vport *vport, struct fc_els_fpin *fpin,
8413*4882a593Smuzhiyun u32 fpin_length)
8414*4882a593Smuzhiyun {
8415*4882a593Smuzhiyun struct fc_tlv_desc *tlv;
8416*4882a593Smuzhiyun const char *dtag_nm;
8417*4882a593Smuzhiyun uint32_t desc_cnt = 0, bytes_remain;
8418*4882a593Smuzhiyun u32 dtag;
8419*4882a593Smuzhiyun
8420*4882a593Smuzhiyun /* FPINs handled only if we are in the right discovery state */
8421*4882a593Smuzhiyun if (vport->port_state < LPFC_DISC_AUTH)
8422*4882a593Smuzhiyun return;
8423*4882a593Smuzhiyun
8424*4882a593Smuzhiyun /* make sure there is the full fpin header */
8425*4882a593Smuzhiyun if (fpin_length < sizeof(struct fc_els_fpin))
8426*4882a593Smuzhiyun return;
8427*4882a593Smuzhiyun
8428*4882a593Smuzhiyun tlv = (struct fc_tlv_desc *)&fpin->fpin_desc[0];
8429*4882a593Smuzhiyun bytes_remain = fpin_length - offsetof(struct fc_els_fpin, fpin_desc);
8430*4882a593Smuzhiyun bytes_remain = min_t(u32, bytes_remain, be32_to_cpu(fpin->desc_len));
8431*4882a593Smuzhiyun
8432*4882a593Smuzhiyun /* process each descriptor */
8433*4882a593Smuzhiyun while (bytes_remain >= FC_TLV_DESC_HDR_SZ &&
8434*4882a593Smuzhiyun bytes_remain >= FC_TLV_DESC_SZ_FROM_LENGTH(tlv)) {
8435*4882a593Smuzhiyun
8436*4882a593Smuzhiyun dtag = be32_to_cpu(tlv->desc_tag);
8437*4882a593Smuzhiyun switch (dtag) {
8438*4882a593Smuzhiyun case ELS_DTAG_LNK_INTEGRITY:
8439*4882a593Smuzhiyun lpfc_els_rcv_fpin_li(vport, tlv);
8440*4882a593Smuzhiyun break;
8441*4882a593Smuzhiyun default:
8442*4882a593Smuzhiyun dtag_nm = lpfc_get_tlv_dtag_nm(dtag);
8443*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8444*4882a593Smuzhiyun "4678 skipped FPIN descriptor[%d]: "
8445*4882a593Smuzhiyun "tag x%x (%s)\n",
8446*4882a593Smuzhiyun desc_cnt, dtag, dtag_nm);
8447*4882a593Smuzhiyun break;
8448*4882a593Smuzhiyun }
8449*4882a593Smuzhiyun
8450*4882a593Smuzhiyun desc_cnt++;
8451*4882a593Smuzhiyun bytes_remain -= FC_TLV_DESC_SZ_FROM_LENGTH(tlv);
8452*4882a593Smuzhiyun tlv = fc_tlv_next_desc(tlv);
8453*4882a593Smuzhiyun }
8454*4882a593Smuzhiyun
8455*4882a593Smuzhiyun fc_host_fpin_rcv(lpfc_shost_from_vport(vport), fpin_length,
8456*4882a593Smuzhiyun (char *)fpin);
8457*4882a593Smuzhiyun }
8458*4882a593Smuzhiyun
8459*4882a593Smuzhiyun /**
8460*4882a593Smuzhiyun * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
8461*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
8462*4882a593Smuzhiyun * @pring: pointer to a SLI ring.
8463*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
8464*4882a593Smuzhiyun * @elsiocb: pointer to lpfc els command iocb data structure.
8465*4882a593Smuzhiyun *
8466*4882a593Smuzhiyun * This routine is used for processing the IOCB associated with a unsolicited
8467*4882a593Smuzhiyun * event. It first determines whether there is an existing ndlp that matches
8468*4882a593Smuzhiyun * the DID from the unsolicited IOCB. If not, it will create a new one with
8469*4882a593Smuzhiyun * the DID from the unsolicited IOCB. The ELS command from the unsolicited
8470*4882a593Smuzhiyun * IOCB is then used to invoke the proper routine and to set up proper state
8471*4882a593Smuzhiyun * of the discovery state machine.
8472*4882a593Smuzhiyun **/
8473*4882a593Smuzhiyun static void
lpfc_els_unsol_buffer(struct lpfc_hba * phba,struct lpfc_sli_ring * pring,struct lpfc_vport * vport,struct lpfc_iocbq * elsiocb)8474*4882a593Smuzhiyun lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8475*4882a593Smuzhiyun struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
8476*4882a593Smuzhiyun {
8477*4882a593Smuzhiyun struct Scsi_Host *shost;
8478*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
8479*4882a593Smuzhiyun struct ls_rjt stat;
8480*4882a593Smuzhiyun uint32_t *payload, payload_len;
8481*4882a593Smuzhiyun uint32_t cmd, did, newnode;
8482*4882a593Smuzhiyun uint8_t rjt_exp, rjt_err = 0, init_link = 0;
8483*4882a593Smuzhiyun IOCB_t *icmd = &elsiocb->iocb;
8484*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
8485*4882a593Smuzhiyun
8486*4882a593Smuzhiyun if (!vport || !(elsiocb->context2))
8487*4882a593Smuzhiyun goto dropit;
8488*4882a593Smuzhiyun
8489*4882a593Smuzhiyun newnode = 0;
8490*4882a593Smuzhiyun payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
8491*4882a593Smuzhiyun payload_len = elsiocb->iocb.unsli3.rcvsli3.acc_len;
8492*4882a593Smuzhiyun cmd = *payload;
8493*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
8494*4882a593Smuzhiyun lpfc_post_buffer(phba, pring, 1);
8495*4882a593Smuzhiyun
8496*4882a593Smuzhiyun did = icmd->un.rcvels.remoteID;
8497*4882a593Smuzhiyun if (icmd->ulpStatus) {
8498*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8499*4882a593Smuzhiyun "RCV Unsol ELS: status:x%x/x%x did:x%x",
8500*4882a593Smuzhiyun icmd->ulpStatus, icmd->un.ulpWord[4], did);
8501*4882a593Smuzhiyun goto dropit;
8502*4882a593Smuzhiyun }
8503*4882a593Smuzhiyun
8504*4882a593Smuzhiyun /* Check to see if link went down during discovery */
8505*4882a593Smuzhiyun if (lpfc_els_chk_latt(vport))
8506*4882a593Smuzhiyun goto dropit;
8507*4882a593Smuzhiyun
8508*4882a593Smuzhiyun /* Ignore traffic received during vport shutdown. */
8509*4882a593Smuzhiyun if (vport->load_flag & FC_UNLOADING)
8510*4882a593Smuzhiyun goto dropit;
8511*4882a593Smuzhiyun
8512*4882a593Smuzhiyun /* If NPort discovery is delayed drop incoming ELS */
8513*4882a593Smuzhiyun if ((vport->fc_flag & FC_DISC_DELAYED) &&
8514*4882a593Smuzhiyun (cmd != ELS_CMD_PLOGI))
8515*4882a593Smuzhiyun goto dropit;
8516*4882a593Smuzhiyun
8517*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, did);
8518*4882a593Smuzhiyun if (!ndlp) {
8519*4882a593Smuzhiyun /* Cannot find existing Fabric ndlp, so allocate a new one */
8520*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, did);
8521*4882a593Smuzhiyun if (!ndlp)
8522*4882a593Smuzhiyun goto dropit;
8523*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8524*4882a593Smuzhiyun newnode = 1;
8525*4882a593Smuzhiyun if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8526*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
8527*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8528*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp,
8529*4882a593Smuzhiyun NLP_STE_UNUSED_NODE);
8530*4882a593Smuzhiyun if (!ndlp)
8531*4882a593Smuzhiyun goto dropit;
8532*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8533*4882a593Smuzhiyun newnode = 1;
8534*4882a593Smuzhiyun if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
8535*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
8536*4882a593Smuzhiyun } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
8537*4882a593Smuzhiyun /* This is similar to the new node path */
8538*4882a593Smuzhiyun ndlp = lpfc_nlp_get(ndlp);
8539*4882a593Smuzhiyun if (!ndlp)
8540*4882a593Smuzhiyun goto dropit;
8541*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
8542*4882a593Smuzhiyun newnode = 1;
8543*4882a593Smuzhiyun }
8544*4882a593Smuzhiyun
8545*4882a593Smuzhiyun phba->fc_stat.elsRcvFrame++;
8546*4882a593Smuzhiyun
8547*4882a593Smuzhiyun /*
8548*4882a593Smuzhiyun * Do not process any unsolicited ELS commands
8549*4882a593Smuzhiyun * if the ndlp is in DEV_LOSS
8550*4882a593Smuzhiyun */
8551*4882a593Smuzhiyun shost = lpfc_shost_from_vport(vport);
8552*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
8553*4882a593Smuzhiyun if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
8554*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
8555*4882a593Smuzhiyun if (newnode)
8556*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8557*4882a593Smuzhiyun goto dropit;
8558*4882a593Smuzhiyun }
8559*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
8560*4882a593Smuzhiyun
8561*4882a593Smuzhiyun elsiocb->context1 = lpfc_nlp_get(ndlp);
8562*4882a593Smuzhiyun elsiocb->vport = vport;
8563*4882a593Smuzhiyun
8564*4882a593Smuzhiyun if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
8565*4882a593Smuzhiyun cmd &= ELS_CMD_MASK;
8566*4882a593Smuzhiyun }
8567*4882a593Smuzhiyun /* ELS command <elsCmd> received from NPORT <did> */
8568*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8569*4882a593Smuzhiyun "0112 ELS command x%x received from NPORT x%x "
8570*4882a593Smuzhiyun "Data: x%x x%x x%x x%x\n",
8571*4882a593Smuzhiyun cmd, did, vport->port_state, vport->fc_flag,
8572*4882a593Smuzhiyun vport->fc_myDID, vport->fc_prevDID);
8573*4882a593Smuzhiyun
8574*4882a593Smuzhiyun /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
8575*4882a593Smuzhiyun if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
8576*4882a593Smuzhiyun (cmd != ELS_CMD_FLOGI) &&
8577*4882a593Smuzhiyun !((cmd == ELS_CMD_PLOGI) && (vport->fc_flag & FC_PT2PT))) {
8578*4882a593Smuzhiyun rjt_err = LSRJT_LOGICAL_BSY;
8579*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8580*4882a593Smuzhiyun goto lsrjt;
8581*4882a593Smuzhiyun }
8582*4882a593Smuzhiyun
8583*4882a593Smuzhiyun switch (cmd) {
8584*4882a593Smuzhiyun case ELS_CMD_PLOGI:
8585*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8586*4882a593Smuzhiyun "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
8587*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8588*4882a593Smuzhiyun
8589*4882a593Smuzhiyun phba->fc_stat.elsRcvPLOGI++;
8590*4882a593Smuzhiyun ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
8591*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
8592*4882a593Smuzhiyun (phba->pport->fc_flag & FC_PT2PT)) {
8593*4882a593Smuzhiyun vport->fc_prevDID = vport->fc_myDID;
8594*4882a593Smuzhiyun /* Our DID needs to be updated before registering
8595*4882a593Smuzhiyun * the vfi. This is done in lpfc_rcv_plogi but
8596*4882a593Smuzhiyun * that is called after the reg_vfi.
8597*4882a593Smuzhiyun */
8598*4882a593Smuzhiyun vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
8599*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8600*4882a593Smuzhiyun "3312 Remote port assigned DID x%x "
8601*4882a593Smuzhiyun "%x\n", vport->fc_myDID,
8602*4882a593Smuzhiyun vport->fc_prevDID);
8603*4882a593Smuzhiyun }
8604*4882a593Smuzhiyun
8605*4882a593Smuzhiyun lpfc_send_els_event(vport, ndlp, payload);
8606*4882a593Smuzhiyun
8607*4882a593Smuzhiyun /* If Nport discovery is delayed, reject PLOGIs */
8608*4882a593Smuzhiyun if (vport->fc_flag & FC_DISC_DELAYED) {
8609*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8610*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8611*4882a593Smuzhiyun break;
8612*4882a593Smuzhiyun }
8613*4882a593Smuzhiyun
8614*4882a593Smuzhiyun if (vport->port_state < LPFC_DISC_AUTH) {
8615*4882a593Smuzhiyun if (!(phba->pport->fc_flag & FC_PT2PT) ||
8616*4882a593Smuzhiyun (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
8617*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8618*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8619*4882a593Smuzhiyun break;
8620*4882a593Smuzhiyun }
8621*4882a593Smuzhiyun }
8622*4882a593Smuzhiyun
8623*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
8624*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
8625*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
8626*4882a593Smuzhiyun
8627*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, elsiocb,
8628*4882a593Smuzhiyun NLP_EVT_RCV_PLOGI);
8629*4882a593Smuzhiyun
8630*4882a593Smuzhiyun break;
8631*4882a593Smuzhiyun case ELS_CMD_FLOGI:
8632*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8633*4882a593Smuzhiyun "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
8634*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8635*4882a593Smuzhiyun
8636*4882a593Smuzhiyun phba->fc_stat.elsRcvFLOGI++;
8637*4882a593Smuzhiyun
8638*4882a593Smuzhiyun /* If the driver believes fabric discovery is done and is ready,
8639*4882a593Smuzhiyun * bounce the link. There is some descrepancy.
8640*4882a593Smuzhiyun */
8641*4882a593Smuzhiyun if (vport->port_state >= LPFC_LOCAL_CFG_LINK &&
8642*4882a593Smuzhiyun vport->fc_flag & FC_PT2PT &&
8643*4882a593Smuzhiyun vport->rcv_flogi_cnt >= 1) {
8644*4882a593Smuzhiyun rjt_err = LSRJT_LOGICAL_BSY;
8645*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8646*4882a593Smuzhiyun init_link++;
8647*4882a593Smuzhiyun goto lsrjt;
8648*4882a593Smuzhiyun }
8649*4882a593Smuzhiyun
8650*4882a593Smuzhiyun lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
8651*4882a593Smuzhiyun if (newnode)
8652*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8653*4882a593Smuzhiyun break;
8654*4882a593Smuzhiyun case ELS_CMD_LOGO:
8655*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8656*4882a593Smuzhiyun "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8657*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8658*4882a593Smuzhiyun
8659*4882a593Smuzhiyun phba->fc_stat.elsRcvLOGO++;
8660*4882a593Smuzhiyun lpfc_send_els_event(vport, ndlp, payload);
8661*4882a593Smuzhiyun if (vport->port_state < LPFC_DISC_AUTH) {
8662*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8663*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8664*4882a593Smuzhiyun break;
8665*4882a593Smuzhiyun }
8666*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
8667*4882a593Smuzhiyun break;
8668*4882a593Smuzhiyun case ELS_CMD_PRLO:
8669*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8670*4882a593Smuzhiyun "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8671*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8672*4882a593Smuzhiyun
8673*4882a593Smuzhiyun phba->fc_stat.elsRcvPRLO++;
8674*4882a593Smuzhiyun lpfc_send_els_event(vport, ndlp, payload);
8675*4882a593Smuzhiyun if (vport->port_state < LPFC_DISC_AUTH) {
8676*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8677*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8678*4882a593Smuzhiyun break;
8679*4882a593Smuzhiyun }
8680*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
8681*4882a593Smuzhiyun break;
8682*4882a593Smuzhiyun case ELS_CMD_LCB:
8683*4882a593Smuzhiyun phba->fc_stat.elsRcvLCB++;
8684*4882a593Smuzhiyun lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
8685*4882a593Smuzhiyun break;
8686*4882a593Smuzhiyun case ELS_CMD_RDP:
8687*4882a593Smuzhiyun phba->fc_stat.elsRcvRDP++;
8688*4882a593Smuzhiyun lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
8689*4882a593Smuzhiyun break;
8690*4882a593Smuzhiyun case ELS_CMD_RSCN:
8691*4882a593Smuzhiyun phba->fc_stat.elsRcvRSCN++;
8692*4882a593Smuzhiyun lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
8693*4882a593Smuzhiyun if (newnode)
8694*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8695*4882a593Smuzhiyun break;
8696*4882a593Smuzhiyun case ELS_CMD_ADISC:
8697*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8698*4882a593Smuzhiyun "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8699*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8700*4882a593Smuzhiyun
8701*4882a593Smuzhiyun lpfc_send_els_event(vport, ndlp, payload);
8702*4882a593Smuzhiyun phba->fc_stat.elsRcvADISC++;
8703*4882a593Smuzhiyun if (vport->port_state < LPFC_DISC_AUTH) {
8704*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8705*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8706*4882a593Smuzhiyun break;
8707*4882a593Smuzhiyun }
8708*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, elsiocb,
8709*4882a593Smuzhiyun NLP_EVT_RCV_ADISC);
8710*4882a593Smuzhiyun break;
8711*4882a593Smuzhiyun case ELS_CMD_PDISC:
8712*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8713*4882a593Smuzhiyun "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8714*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8715*4882a593Smuzhiyun
8716*4882a593Smuzhiyun phba->fc_stat.elsRcvPDISC++;
8717*4882a593Smuzhiyun if (vport->port_state < LPFC_DISC_AUTH) {
8718*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8719*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8720*4882a593Smuzhiyun break;
8721*4882a593Smuzhiyun }
8722*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, elsiocb,
8723*4882a593Smuzhiyun NLP_EVT_RCV_PDISC);
8724*4882a593Smuzhiyun break;
8725*4882a593Smuzhiyun case ELS_CMD_FARPR:
8726*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8727*4882a593Smuzhiyun "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8728*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8729*4882a593Smuzhiyun
8730*4882a593Smuzhiyun phba->fc_stat.elsRcvFARPR++;
8731*4882a593Smuzhiyun lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
8732*4882a593Smuzhiyun break;
8733*4882a593Smuzhiyun case ELS_CMD_FARP:
8734*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8735*4882a593Smuzhiyun "RCV FARP: did:x%x/ste:x%x flg:x%x",
8736*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8737*4882a593Smuzhiyun
8738*4882a593Smuzhiyun phba->fc_stat.elsRcvFARP++;
8739*4882a593Smuzhiyun lpfc_els_rcv_farp(vport, elsiocb, ndlp);
8740*4882a593Smuzhiyun break;
8741*4882a593Smuzhiyun case ELS_CMD_FAN:
8742*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8743*4882a593Smuzhiyun "RCV FAN: did:x%x/ste:x%x flg:x%x",
8744*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8745*4882a593Smuzhiyun
8746*4882a593Smuzhiyun phba->fc_stat.elsRcvFAN++;
8747*4882a593Smuzhiyun lpfc_els_rcv_fan(vport, elsiocb, ndlp);
8748*4882a593Smuzhiyun break;
8749*4882a593Smuzhiyun case ELS_CMD_PRLI:
8750*4882a593Smuzhiyun case ELS_CMD_NVMEPRLI:
8751*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8752*4882a593Smuzhiyun "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8753*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8754*4882a593Smuzhiyun
8755*4882a593Smuzhiyun phba->fc_stat.elsRcvPRLI++;
8756*4882a593Smuzhiyun if ((vport->port_state < LPFC_DISC_AUTH) &&
8757*4882a593Smuzhiyun (vport->fc_flag & FC_FABRIC)) {
8758*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8759*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8760*4882a593Smuzhiyun break;
8761*4882a593Smuzhiyun }
8762*4882a593Smuzhiyun lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
8763*4882a593Smuzhiyun break;
8764*4882a593Smuzhiyun case ELS_CMD_LIRR:
8765*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8766*4882a593Smuzhiyun "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8767*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8768*4882a593Smuzhiyun
8769*4882a593Smuzhiyun phba->fc_stat.elsRcvLIRR++;
8770*4882a593Smuzhiyun lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
8771*4882a593Smuzhiyun if (newnode)
8772*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8773*4882a593Smuzhiyun break;
8774*4882a593Smuzhiyun case ELS_CMD_RLS:
8775*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8776*4882a593Smuzhiyun "RCV RLS: did:x%x/ste:x%x flg:x%x",
8777*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8778*4882a593Smuzhiyun
8779*4882a593Smuzhiyun phba->fc_stat.elsRcvRLS++;
8780*4882a593Smuzhiyun lpfc_els_rcv_rls(vport, elsiocb, ndlp);
8781*4882a593Smuzhiyun if (newnode)
8782*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8783*4882a593Smuzhiyun break;
8784*4882a593Smuzhiyun case ELS_CMD_RPL:
8785*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8786*4882a593Smuzhiyun "RCV RPL: did:x%x/ste:x%x flg:x%x",
8787*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8788*4882a593Smuzhiyun
8789*4882a593Smuzhiyun phba->fc_stat.elsRcvRPL++;
8790*4882a593Smuzhiyun lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
8791*4882a593Smuzhiyun if (newnode)
8792*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8793*4882a593Smuzhiyun break;
8794*4882a593Smuzhiyun case ELS_CMD_RNID:
8795*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8796*4882a593Smuzhiyun "RCV RNID: did:x%x/ste:x%x flg:x%x",
8797*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8798*4882a593Smuzhiyun
8799*4882a593Smuzhiyun phba->fc_stat.elsRcvRNID++;
8800*4882a593Smuzhiyun lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
8801*4882a593Smuzhiyun if (newnode)
8802*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8803*4882a593Smuzhiyun break;
8804*4882a593Smuzhiyun case ELS_CMD_RTV:
8805*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8806*4882a593Smuzhiyun "RCV RTV: did:x%x/ste:x%x flg:x%x",
8807*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8808*4882a593Smuzhiyun phba->fc_stat.elsRcvRTV++;
8809*4882a593Smuzhiyun lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
8810*4882a593Smuzhiyun if (newnode)
8811*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8812*4882a593Smuzhiyun break;
8813*4882a593Smuzhiyun case ELS_CMD_RRQ:
8814*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8815*4882a593Smuzhiyun "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8816*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8817*4882a593Smuzhiyun
8818*4882a593Smuzhiyun phba->fc_stat.elsRcvRRQ++;
8819*4882a593Smuzhiyun lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
8820*4882a593Smuzhiyun if (newnode)
8821*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8822*4882a593Smuzhiyun break;
8823*4882a593Smuzhiyun case ELS_CMD_ECHO:
8824*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8825*4882a593Smuzhiyun "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8826*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8827*4882a593Smuzhiyun
8828*4882a593Smuzhiyun phba->fc_stat.elsRcvECHO++;
8829*4882a593Smuzhiyun lpfc_els_rcv_echo(vport, elsiocb, ndlp);
8830*4882a593Smuzhiyun if (newnode)
8831*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8832*4882a593Smuzhiyun break;
8833*4882a593Smuzhiyun case ELS_CMD_REC:
8834*4882a593Smuzhiyun /* receive this due to exchange closed */
8835*4882a593Smuzhiyun rjt_err = LSRJT_UNABLE_TPC;
8836*4882a593Smuzhiyun rjt_exp = LSEXP_INVALID_OX_RX;
8837*4882a593Smuzhiyun break;
8838*4882a593Smuzhiyun case ELS_CMD_FPIN:
8839*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8840*4882a593Smuzhiyun "RCV FPIN: did:x%x/ste:x%x flg:x%x",
8841*4882a593Smuzhiyun did, vport->port_state, ndlp->nlp_flag);
8842*4882a593Smuzhiyun
8843*4882a593Smuzhiyun lpfc_els_rcv_fpin(vport, (struct fc_els_fpin *)payload,
8844*4882a593Smuzhiyun payload_len);
8845*4882a593Smuzhiyun
8846*4882a593Smuzhiyun /* There are no replies, so no rjt codes */
8847*4882a593Smuzhiyun break;
8848*4882a593Smuzhiyun default:
8849*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
8850*4882a593Smuzhiyun "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8851*4882a593Smuzhiyun cmd, did, vport->port_state);
8852*4882a593Smuzhiyun
8853*4882a593Smuzhiyun /* Unsupported ELS command, reject */
8854*4882a593Smuzhiyun rjt_err = LSRJT_CMD_UNSUPPORTED;
8855*4882a593Smuzhiyun rjt_exp = LSEXP_NOTHING_MORE;
8856*4882a593Smuzhiyun
8857*4882a593Smuzhiyun /* Unknown ELS command <elsCmd> received from NPORT <did> */
8858*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8859*4882a593Smuzhiyun "0115 Unknown ELS command x%x "
8860*4882a593Smuzhiyun "received from NPORT x%x\n", cmd, did);
8861*4882a593Smuzhiyun if (newnode)
8862*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
8863*4882a593Smuzhiyun break;
8864*4882a593Smuzhiyun }
8865*4882a593Smuzhiyun
8866*4882a593Smuzhiyun lsrjt:
8867*4882a593Smuzhiyun /* check if need to LS_RJT received ELS cmd */
8868*4882a593Smuzhiyun if (rjt_err) {
8869*4882a593Smuzhiyun memset(&stat, 0, sizeof(stat));
8870*4882a593Smuzhiyun stat.un.b.lsRjtRsnCode = rjt_err;
8871*4882a593Smuzhiyun stat.un.b.lsRjtRsnCodeExp = rjt_exp;
8872*4882a593Smuzhiyun lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
8873*4882a593Smuzhiyun NULL);
8874*4882a593Smuzhiyun }
8875*4882a593Smuzhiyun
8876*4882a593Smuzhiyun lpfc_nlp_put(elsiocb->context1);
8877*4882a593Smuzhiyun elsiocb->context1 = NULL;
8878*4882a593Smuzhiyun
8879*4882a593Smuzhiyun /* Special case. Driver received an unsolicited command that
8880*4882a593Smuzhiyun * unsupportable given the driver's current state. Reset the
8881*4882a593Smuzhiyun * link and start over.
8882*4882a593Smuzhiyun */
8883*4882a593Smuzhiyun if (init_link) {
8884*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8885*4882a593Smuzhiyun if (!mbox)
8886*4882a593Smuzhiyun return;
8887*4882a593Smuzhiyun lpfc_linkdown(phba);
8888*4882a593Smuzhiyun lpfc_init_link(phba, mbox,
8889*4882a593Smuzhiyun phba->cfg_topology,
8890*4882a593Smuzhiyun phba->cfg_link_speed);
8891*4882a593Smuzhiyun mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
8892*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
8893*4882a593Smuzhiyun mbox->vport = vport;
8894*4882a593Smuzhiyun if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
8895*4882a593Smuzhiyun MBX_NOT_FINISHED)
8896*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
8897*4882a593Smuzhiyun }
8898*4882a593Smuzhiyun
8899*4882a593Smuzhiyun return;
8900*4882a593Smuzhiyun
8901*4882a593Smuzhiyun dropit:
8902*4882a593Smuzhiyun if (vport && !(vport->load_flag & FC_UNLOADING))
8903*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
8904*4882a593Smuzhiyun "0111 Dropping received ELS cmd "
8905*4882a593Smuzhiyun "Data: x%x x%x x%x\n",
8906*4882a593Smuzhiyun icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
8907*4882a593Smuzhiyun phba->fc_stat.elsRcvDrop++;
8908*4882a593Smuzhiyun }
8909*4882a593Smuzhiyun
8910*4882a593Smuzhiyun /**
8911*4882a593Smuzhiyun * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8912*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
8913*4882a593Smuzhiyun * @pring: pointer to a SLI ring.
8914*4882a593Smuzhiyun * @elsiocb: pointer to lpfc els iocb data structure.
8915*4882a593Smuzhiyun *
8916*4882a593Smuzhiyun * This routine is used to process an unsolicited event received from a SLI
8917*4882a593Smuzhiyun * (Service Level Interface) ring. The actual processing of the data buffer
8918*4882a593Smuzhiyun * associated with the unsolicited event is done by invoking the routine
8919*4882a593Smuzhiyun * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8920*4882a593Smuzhiyun * SLI ring on which the unsolicited event was received.
8921*4882a593Smuzhiyun **/
8922*4882a593Smuzhiyun void
lpfc_els_unsol_event(struct lpfc_hba * phba,struct lpfc_sli_ring * pring,struct lpfc_iocbq * elsiocb)8923*4882a593Smuzhiyun lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
8924*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb)
8925*4882a593Smuzhiyun {
8926*4882a593Smuzhiyun struct lpfc_vport *vport = phba->pport;
8927*4882a593Smuzhiyun IOCB_t *icmd = &elsiocb->iocb;
8928*4882a593Smuzhiyun dma_addr_t paddr;
8929*4882a593Smuzhiyun struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
8930*4882a593Smuzhiyun struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
8931*4882a593Smuzhiyun
8932*4882a593Smuzhiyun elsiocb->context1 = NULL;
8933*4882a593Smuzhiyun elsiocb->context2 = NULL;
8934*4882a593Smuzhiyun elsiocb->context3 = NULL;
8935*4882a593Smuzhiyun
8936*4882a593Smuzhiyun if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
8937*4882a593Smuzhiyun lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
8938*4882a593Smuzhiyun } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
8939*4882a593Smuzhiyun (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
8940*4882a593Smuzhiyun IOERR_RCV_BUFFER_WAITING) {
8941*4882a593Smuzhiyun phba->fc_stat.NoRcvBuf++;
8942*4882a593Smuzhiyun /* Not enough posted buffers; Try posting more buffers */
8943*4882a593Smuzhiyun if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
8944*4882a593Smuzhiyun lpfc_post_buffer(phba, pring, 0);
8945*4882a593Smuzhiyun return;
8946*4882a593Smuzhiyun }
8947*4882a593Smuzhiyun
8948*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
8949*4882a593Smuzhiyun (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
8950*4882a593Smuzhiyun icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
8951*4882a593Smuzhiyun if (icmd->unsli3.rcvsli3.vpi == 0xffff)
8952*4882a593Smuzhiyun vport = phba->pport;
8953*4882a593Smuzhiyun else
8954*4882a593Smuzhiyun vport = lpfc_find_vport_by_vpid(phba,
8955*4882a593Smuzhiyun icmd->unsli3.rcvsli3.vpi);
8956*4882a593Smuzhiyun }
8957*4882a593Smuzhiyun
8958*4882a593Smuzhiyun /* If there are no BDEs associated
8959*4882a593Smuzhiyun * with this IOCB, there is nothing to do.
8960*4882a593Smuzhiyun */
8961*4882a593Smuzhiyun if (icmd->ulpBdeCount == 0)
8962*4882a593Smuzhiyun return;
8963*4882a593Smuzhiyun
8964*4882a593Smuzhiyun /* type of ELS cmd is first 32bit word
8965*4882a593Smuzhiyun * in packet
8966*4882a593Smuzhiyun */
8967*4882a593Smuzhiyun if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
8968*4882a593Smuzhiyun elsiocb->context2 = bdeBuf1;
8969*4882a593Smuzhiyun } else {
8970*4882a593Smuzhiyun paddr = getPaddr(icmd->un.cont64[0].addrHigh,
8971*4882a593Smuzhiyun icmd->un.cont64[0].addrLow);
8972*4882a593Smuzhiyun elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
8973*4882a593Smuzhiyun paddr);
8974*4882a593Smuzhiyun }
8975*4882a593Smuzhiyun
8976*4882a593Smuzhiyun lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8977*4882a593Smuzhiyun /*
8978*4882a593Smuzhiyun * The different unsolicited event handlers would tell us
8979*4882a593Smuzhiyun * if they are done with "mp" by setting context2 to NULL.
8980*4882a593Smuzhiyun */
8981*4882a593Smuzhiyun if (elsiocb->context2) {
8982*4882a593Smuzhiyun lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
8983*4882a593Smuzhiyun elsiocb->context2 = NULL;
8984*4882a593Smuzhiyun }
8985*4882a593Smuzhiyun
8986*4882a593Smuzhiyun /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8987*4882a593Smuzhiyun if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
8988*4882a593Smuzhiyun icmd->ulpBdeCount == 2) {
8989*4882a593Smuzhiyun elsiocb->context2 = bdeBuf2;
8990*4882a593Smuzhiyun lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
8991*4882a593Smuzhiyun /* free mp if we are done with it */
8992*4882a593Smuzhiyun if (elsiocb->context2) {
8993*4882a593Smuzhiyun lpfc_in_buf_free(phba, elsiocb->context2);
8994*4882a593Smuzhiyun elsiocb->context2 = NULL;
8995*4882a593Smuzhiyun }
8996*4882a593Smuzhiyun }
8997*4882a593Smuzhiyun }
8998*4882a593Smuzhiyun
8999*4882a593Smuzhiyun static void
lpfc_start_fdmi(struct lpfc_vport * vport)9000*4882a593Smuzhiyun lpfc_start_fdmi(struct lpfc_vport *vport)
9001*4882a593Smuzhiyun {
9002*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
9003*4882a593Smuzhiyun
9004*4882a593Smuzhiyun /* If this is the first time, allocate an ndlp and initialize
9005*4882a593Smuzhiyun * it. Otherwise, make sure the node is enabled and then do the
9006*4882a593Smuzhiyun * login.
9007*4882a593Smuzhiyun */
9008*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, FDMI_DID);
9009*4882a593Smuzhiyun if (!ndlp) {
9010*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, FDMI_DID);
9011*4882a593Smuzhiyun if (ndlp) {
9012*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
9013*4882a593Smuzhiyun } else {
9014*4882a593Smuzhiyun return;
9015*4882a593Smuzhiyun }
9016*4882a593Smuzhiyun }
9017*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp))
9018*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
9019*4882a593Smuzhiyun
9020*4882a593Smuzhiyun if (ndlp) {
9021*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9022*4882a593Smuzhiyun lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
9023*4882a593Smuzhiyun }
9024*4882a593Smuzhiyun }
9025*4882a593Smuzhiyun
9026*4882a593Smuzhiyun /**
9027*4882a593Smuzhiyun * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
9028*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9029*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
9030*4882a593Smuzhiyun *
9031*4882a593Smuzhiyun * This routine issues a Port Login (PLOGI) to the Name Server with
9032*4882a593Smuzhiyun * State Change Request (SCR) for a @vport. This routine will create an
9033*4882a593Smuzhiyun * ndlp for the Name Server associated to the @vport if such node does
9034*4882a593Smuzhiyun * not already exist. The PLOGI to Name Server is issued by invoking the
9035*4882a593Smuzhiyun * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
9036*4882a593Smuzhiyun * (FDMI) is configured to the @vport, a FDMI node will be created and
9037*4882a593Smuzhiyun * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
9038*4882a593Smuzhiyun **/
9039*4882a593Smuzhiyun void
lpfc_do_scr_ns_plogi(struct lpfc_hba * phba,struct lpfc_vport * vport)9040*4882a593Smuzhiyun lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
9041*4882a593Smuzhiyun {
9042*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
9043*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9044*4882a593Smuzhiyun
9045*4882a593Smuzhiyun /*
9046*4882a593Smuzhiyun * If lpfc_delay_discovery parameter is set and the clean address
9047*4882a593Smuzhiyun * bit is cleared and fc fabric parameters chenged, delay FC NPort
9048*4882a593Smuzhiyun * discovery.
9049*4882a593Smuzhiyun */
9050*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9051*4882a593Smuzhiyun if (vport->fc_flag & FC_DISC_DELAYED) {
9052*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9053*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
9054*4882a593Smuzhiyun "3334 Delay fc port discovery for %d seconds\n",
9055*4882a593Smuzhiyun phba->fc_ratov);
9056*4882a593Smuzhiyun mod_timer(&vport->delayed_disc_tmo,
9057*4882a593Smuzhiyun jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
9058*4882a593Smuzhiyun return;
9059*4882a593Smuzhiyun }
9060*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9061*4882a593Smuzhiyun
9062*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vport, NameServer_DID);
9063*4882a593Smuzhiyun if (!ndlp) {
9064*4882a593Smuzhiyun ndlp = lpfc_nlp_init(vport, NameServer_DID);
9065*4882a593Smuzhiyun if (!ndlp) {
9066*4882a593Smuzhiyun if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9067*4882a593Smuzhiyun lpfc_disc_start(vport);
9068*4882a593Smuzhiyun return;
9069*4882a593Smuzhiyun }
9070*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9071*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9072*4882a593Smuzhiyun "0251 NameServer login: no memory\n");
9073*4882a593Smuzhiyun return;
9074*4882a593Smuzhiyun }
9075*4882a593Smuzhiyun } else if (!NLP_CHK_NODE_ACT(ndlp)) {
9076*4882a593Smuzhiyun ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
9077*4882a593Smuzhiyun if (!ndlp) {
9078*4882a593Smuzhiyun if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
9079*4882a593Smuzhiyun lpfc_disc_start(vport);
9080*4882a593Smuzhiyun return;
9081*4882a593Smuzhiyun }
9082*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9083*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9084*4882a593Smuzhiyun "0348 NameServer login: node freed\n");
9085*4882a593Smuzhiyun return;
9086*4882a593Smuzhiyun }
9087*4882a593Smuzhiyun }
9088*4882a593Smuzhiyun ndlp->nlp_type |= NLP_FABRIC;
9089*4882a593Smuzhiyun
9090*4882a593Smuzhiyun lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
9091*4882a593Smuzhiyun
9092*4882a593Smuzhiyun if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
9093*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9094*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9095*4882a593Smuzhiyun "0252 Cannot issue NameServer login\n");
9096*4882a593Smuzhiyun return;
9097*4882a593Smuzhiyun }
9098*4882a593Smuzhiyun
9099*4882a593Smuzhiyun if ((phba->cfg_enable_SmartSAN ||
9100*4882a593Smuzhiyun (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
9101*4882a593Smuzhiyun (vport->load_flag & FC_ALLOW_FDMI))
9102*4882a593Smuzhiyun lpfc_start_fdmi(vport);
9103*4882a593Smuzhiyun }
9104*4882a593Smuzhiyun
9105*4882a593Smuzhiyun /**
9106*4882a593Smuzhiyun * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
9107*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9108*4882a593Smuzhiyun * @pmb: pointer to the driver internal queue element for mailbox command.
9109*4882a593Smuzhiyun *
9110*4882a593Smuzhiyun * This routine is the completion callback function to register new vport
9111*4882a593Smuzhiyun * mailbox command. If the new vport mailbox command completes successfully,
9112*4882a593Smuzhiyun * the fabric registration login shall be performed on physical port (the
9113*4882a593Smuzhiyun * new vport created is actually a physical port, with VPI 0) or the port
9114*4882a593Smuzhiyun * login to Name Server for State Change Request (SCR) will be performed
9115*4882a593Smuzhiyun * on virtual port (real virtual port, with VPI greater than 0).
9116*4882a593Smuzhiyun **/
9117*4882a593Smuzhiyun static void
lpfc_cmpl_reg_new_vport(struct lpfc_hba * phba,LPFC_MBOXQ_t * pmb)9118*4882a593Smuzhiyun lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
9119*4882a593Smuzhiyun {
9120*4882a593Smuzhiyun struct lpfc_vport *vport = pmb->vport;
9121*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9122*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *)pmb->ctx_ndlp;
9123*4882a593Smuzhiyun MAILBOX_t *mb = &pmb->u.mb;
9124*4882a593Smuzhiyun int rc;
9125*4882a593Smuzhiyun
9126*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9127*4882a593Smuzhiyun vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9128*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9129*4882a593Smuzhiyun
9130*4882a593Smuzhiyun if (mb->mbxStatus) {
9131*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9132*4882a593Smuzhiyun "0915 Register VPI failed : Status: x%x"
9133*4882a593Smuzhiyun " upd bit: x%x \n", mb->mbxStatus,
9134*4882a593Smuzhiyun mb->un.varRegVpi.upd);
9135*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4 &&
9136*4882a593Smuzhiyun mb->un.varRegVpi.upd)
9137*4882a593Smuzhiyun goto mbox_err_exit ;
9138*4882a593Smuzhiyun
9139*4882a593Smuzhiyun switch (mb->mbxStatus) {
9140*4882a593Smuzhiyun case 0x11: /* unsupported feature */
9141*4882a593Smuzhiyun case 0x9603: /* max_vpi exceeded */
9142*4882a593Smuzhiyun case 0x9602: /* Link event since CLEAR_LA */
9143*4882a593Smuzhiyun /* giving up on vport registration */
9144*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9145*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9146*4882a593Smuzhiyun vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
9147*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9148*4882a593Smuzhiyun lpfc_can_disctmo(vport);
9149*4882a593Smuzhiyun break;
9150*4882a593Smuzhiyun /* If reg_vpi fail with invalid VPI status, re-init VPI */
9151*4882a593Smuzhiyun case 0x20:
9152*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9153*4882a593Smuzhiyun vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9154*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9155*4882a593Smuzhiyun lpfc_init_vpi(phba, pmb, vport->vpi);
9156*4882a593Smuzhiyun pmb->vport = vport;
9157*4882a593Smuzhiyun pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
9158*4882a593Smuzhiyun rc = lpfc_sli_issue_mbox(phba, pmb,
9159*4882a593Smuzhiyun MBX_NOWAIT);
9160*4882a593Smuzhiyun if (rc == MBX_NOT_FINISHED) {
9161*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR,
9162*4882a593Smuzhiyun LOG_TRACE_EVENT,
9163*4882a593Smuzhiyun "2732 Failed to issue INIT_VPI"
9164*4882a593Smuzhiyun " mailbox command\n");
9165*4882a593Smuzhiyun } else {
9166*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
9167*4882a593Smuzhiyun return;
9168*4882a593Smuzhiyun }
9169*4882a593Smuzhiyun fallthrough;
9170*4882a593Smuzhiyun default:
9171*4882a593Smuzhiyun /* Try to recover from this error */
9172*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
9173*4882a593Smuzhiyun lpfc_sli4_unreg_all_rpis(vport);
9174*4882a593Smuzhiyun lpfc_mbx_unreg_vpi(vport);
9175*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9176*4882a593Smuzhiyun vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9177*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9178*4882a593Smuzhiyun if (mb->mbxStatus == MBX_NOT_FINISHED)
9179*4882a593Smuzhiyun break;
9180*4882a593Smuzhiyun if ((vport->port_type == LPFC_PHYSICAL_PORT) &&
9181*4882a593Smuzhiyun !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG)) {
9182*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
9183*4882a593Smuzhiyun lpfc_issue_init_vfi(vport);
9184*4882a593Smuzhiyun else
9185*4882a593Smuzhiyun lpfc_initial_flogi(vport);
9186*4882a593Smuzhiyun } else {
9187*4882a593Smuzhiyun lpfc_initial_fdisc(vport);
9188*4882a593Smuzhiyun }
9189*4882a593Smuzhiyun break;
9190*4882a593Smuzhiyun }
9191*4882a593Smuzhiyun } else {
9192*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9193*4882a593Smuzhiyun vport->vpi_state |= LPFC_VPI_REGISTERED;
9194*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9195*4882a593Smuzhiyun if (vport == phba->pport) {
9196*4882a593Smuzhiyun if (phba->sli_rev < LPFC_SLI_REV4)
9197*4882a593Smuzhiyun lpfc_issue_fabric_reglogin(vport);
9198*4882a593Smuzhiyun else {
9199*4882a593Smuzhiyun /*
9200*4882a593Smuzhiyun * If the physical port is instantiated using
9201*4882a593Smuzhiyun * FDISC, do not start vport discovery.
9202*4882a593Smuzhiyun */
9203*4882a593Smuzhiyun if (vport->port_state != LPFC_FDISC)
9204*4882a593Smuzhiyun lpfc_start_fdiscs(phba);
9205*4882a593Smuzhiyun lpfc_do_scr_ns_plogi(phba, vport);
9206*4882a593Smuzhiyun }
9207*4882a593Smuzhiyun } else
9208*4882a593Smuzhiyun lpfc_do_scr_ns_plogi(phba, vport);
9209*4882a593Smuzhiyun }
9210*4882a593Smuzhiyun mbox_err_exit:
9211*4882a593Smuzhiyun /* Now, we decrement the ndlp reference count held for this
9212*4882a593Smuzhiyun * callback function
9213*4882a593Smuzhiyun */
9214*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
9215*4882a593Smuzhiyun
9216*4882a593Smuzhiyun mempool_free(pmb, phba->mbox_mem_pool);
9217*4882a593Smuzhiyun return;
9218*4882a593Smuzhiyun }
9219*4882a593Smuzhiyun
9220*4882a593Smuzhiyun /**
9221*4882a593Smuzhiyun * lpfc_register_new_vport - Register a new vport with a HBA
9222*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9223*4882a593Smuzhiyun * @vport: pointer to a host virtual N_Port data structure.
9224*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
9225*4882a593Smuzhiyun *
9226*4882a593Smuzhiyun * This routine registers the @vport as a new virtual port with a HBA.
9227*4882a593Smuzhiyun * It is done through a registering vpi mailbox command.
9228*4882a593Smuzhiyun **/
9229*4882a593Smuzhiyun void
lpfc_register_new_vport(struct lpfc_hba * phba,struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)9230*4882a593Smuzhiyun lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
9231*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
9232*4882a593Smuzhiyun {
9233*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9234*4882a593Smuzhiyun LPFC_MBOXQ_t *mbox;
9235*4882a593Smuzhiyun
9236*4882a593Smuzhiyun mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
9237*4882a593Smuzhiyun if (mbox) {
9238*4882a593Smuzhiyun lpfc_reg_vpi(vport, mbox);
9239*4882a593Smuzhiyun mbox->vport = vport;
9240*4882a593Smuzhiyun mbox->ctx_ndlp = lpfc_nlp_get(ndlp);
9241*4882a593Smuzhiyun mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
9242*4882a593Smuzhiyun if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
9243*4882a593Smuzhiyun == MBX_NOT_FINISHED) {
9244*4882a593Smuzhiyun /* mailbox command not success, decrement ndlp
9245*4882a593Smuzhiyun * reference count for this command
9246*4882a593Smuzhiyun */
9247*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
9248*4882a593Smuzhiyun mempool_free(mbox, phba->mbox_mem_pool);
9249*4882a593Smuzhiyun
9250*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9251*4882a593Smuzhiyun "0253 Register VPI: Can't send mbox\n");
9252*4882a593Smuzhiyun goto mbox_err_exit;
9253*4882a593Smuzhiyun }
9254*4882a593Smuzhiyun } else {
9255*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9256*4882a593Smuzhiyun "0254 Register VPI: no memory\n");
9257*4882a593Smuzhiyun goto mbox_err_exit;
9258*4882a593Smuzhiyun }
9259*4882a593Smuzhiyun return;
9260*4882a593Smuzhiyun
9261*4882a593Smuzhiyun mbox_err_exit:
9262*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9263*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9264*4882a593Smuzhiyun vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
9265*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9266*4882a593Smuzhiyun return;
9267*4882a593Smuzhiyun }
9268*4882a593Smuzhiyun
9269*4882a593Smuzhiyun /**
9270*4882a593Smuzhiyun * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
9271*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9272*4882a593Smuzhiyun *
9273*4882a593Smuzhiyun * This routine cancels the retry delay timers to all the vports.
9274*4882a593Smuzhiyun **/
9275*4882a593Smuzhiyun void
lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba * phba)9276*4882a593Smuzhiyun lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
9277*4882a593Smuzhiyun {
9278*4882a593Smuzhiyun struct lpfc_vport **vports;
9279*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
9280*4882a593Smuzhiyun uint32_t link_state;
9281*4882a593Smuzhiyun int i;
9282*4882a593Smuzhiyun
9283*4882a593Smuzhiyun /* Treat this failure as linkdown for all vports */
9284*4882a593Smuzhiyun link_state = phba->link_state;
9285*4882a593Smuzhiyun lpfc_linkdown(phba);
9286*4882a593Smuzhiyun phba->link_state = link_state;
9287*4882a593Smuzhiyun
9288*4882a593Smuzhiyun vports = lpfc_create_vport_work_array(phba);
9289*4882a593Smuzhiyun
9290*4882a593Smuzhiyun if (vports) {
9291*4882a593Smuzhiyun for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
9292*4882a593Smuzhiyun ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
9293*4882a593Smuzhiyun if (ndlp)
9294*4882a593Smuzhiyun lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
9295*4882a593Smuzhiyun lpfc_els_flush_cmd(vports[i]);
9296*4882a593Smuzhiyun }
9297*4882a593Smuzhiyun lpfc_destroy_vport_work_array(phba, vports);
9298*4882a593Smuzhiyun }
9299*4882a593Smuzhiyun }
9300*4882a593Smuzhiyun
9301*4882a593Smuzhiyun /**
9302*4882a593Smuzhiyun * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
9303*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9304*4882a593Smuzhiyun *
9305*4882a593Smuzhiyun * This routine abort all pending discovery commands and
9306*4882a593Smuzhiyun * start a timer to retry FLOGI for the physical port
9307*4882a593Smuzhiyun * discovery.
9308*4882a593Smuzhiyun **/
9309*4882a593Smuzhiyun void
lpfc_retry_pport_discovery(struct lpfc_hba * phba)9310*4882a593Smuzhiyun lpfc_retry_pport_discovery(struct lpfc_hba *phba)
9311*4882a593Smuzhiyun {
9312*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
9313*4882a593Smuzhiyun struct Scsi_Host *shost;
9314*4882a593Smuzhiyun
9315*4882a593Smuzhiyun /* Cancel the all vports retry delay retry timers */
9316*4882a593Smuzhiyun lpfc_cancel_all_vport_retry_delay_timer(phba);
9317*4882a593Smuzhiyun
9318*4882a593Smuzhiyun /* If fabric require FLOGI, then re-instantiate physical login */
9319*4882a593Smuzhiyun ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
9320*4882a593Smuzhiyun if (!ndlp)
9321*4882a593Smuzhiyun return;
9322*4882a593Smuzhiyun
9323*4882a593Smuzhiyun shost = lpfc_shost_from_vport(phba->pport);
9324*4882a593Smuzhiyun mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
9325*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9326*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_DELAY_TMO;
9327*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9328*4882a593Smuzhiyun ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
9329*4882a593Smuzhiyun phba->pport->port_state = LPFC_FLOGI;
9330*4882a593Smuzhiyun return;
9331*4882a593Smuzhiyun }
9332*4882a593Smuzhiyun
9333*4882a593Smuzhiyun /**
9334*4882a593Smuzhiyun * lpfc_fabric_login_reqd - Check if FLOGI required.
9335*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9336*4882a593Smuzhiyun * @cmdiocb: pointer to FDISC command iocb.
9337*4882a593Smuzhiyun * @rspiocb: pointer to FDISC response iocb.
9338*4882a593Smuzhiyun *
9339*4882a593Smuzhiyun * This routine checks if a FLOGI is reguired for FDISC
9340*4882a593Smuzhiyun * to succeed.
9341*4882a593Smuzhiyun **/
9342*4882a593Smuzhiyun static int
lpfc_fabric_login_reqd(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)9343*4882a593Smuzhiyun lpfc_fabric_login_reqd(struct lpfc_hba *phba,
9344*4882a593Smuzhiyun struct lpfc_iocbq *cmdiocb,
9345*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
9346*4882a593Smuzhiyun {
9347*4882a593Smuzhiyun
9348*4882a593Smuzhiyun if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
9349*4882a593Smuzhiyun (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
9350*4882a593Smuzhiyun return 0;
9351*4882a593Smuzhiyun else
9352*4882a593Smuzhiyun return 1;
9353*4882a593Smuzhiyun }
9354*4882a593Smuzhiyun
9355*4882a593Smuzhiyun /**
9356*4882a593Smuzhiyun * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
9357*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9358*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
9359*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
9360*4882a593Smuzhiyun *
9361*4882a593Smuzhiyun * This routine is the completion callback function to a Fabric Discover
9362*4882a593Smuzhiyun * (FDISC) ELS command. Since all the FDISC ELS commands are issued
9363*4882a593Smuzhiyun * single threaded, each FDISC completion callback function will reset
9364*4882a593Smuzhiyun * the discovery timer for all vports such that the timers will not get
9365*4882a593Smuzhiyun * unnecessary timeout. The function checks the FDISC IOCB status. If error
9366*4882a593Smuzhiyun * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
9367*4882a593Smuzhiyun * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
9368*4882a593Smuzhiyun * assigned to the vport has been changed with the completion of the FDISC
9369*4882a593Smuzhiyun * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
9370*4882a593Smuzhiyun * are unregistered from the HBA, and then the lpfc_register_new_vport()
9371*4882a593Smuzhiyun * routine is invoked to register new vport with the HBA. Otherwise, the
9372*4882a593Smuzhiyun * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
9373*4882a593Smuzhiyun * Server for State Change Request (SCR).
9374*4882a593Smuzhiyun **/
9375*4882a593Smuzhiyun static void
lpfc_cmpl_els_fdisc(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)9376*4882a593Smuzhiyun lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9377*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
9378*4882a593Smuzhiyun {
9379*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
9380*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9381*4882a593Smuzhiyun struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
9382*4882a593Smuzhiyun struct lpfc_nodelist *np;
9383*4882a593Smuzhiyun struct lpfc_nodelist *next_np;
9384*4882a593Smuzhiyun IOCB_t *irsp = &rspiocb->iocb;
9385*4882a593Smuzhiyun struct lpfc_iocbq *piocb;
9386*4882a593Smuzhiyun struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
9387*4882a593Smuzhiyun struct serv_parm *sp;
9388*4882a593Smuzhiyun uint8_t fabric_param_changed;
9389*4882a593Smuzhiyun
9390*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9391*4882a593Smuzhiyun "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
9392*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4],
9393*4882a593Smuzhiyun vport->fc_prevDID);
9394*4882a593Smuzhiyun /* Since all FDISCs are being single threaded, we
9395*4882a593Smuzhiyun * must reset the discovery timer for ALL vports
9396*4882a593Smuzhiyun * waiting to send FDISC when one completes.
9397*4882a593Smuzhiyun */
9398*4882a593Smuzhiyun list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
9399*4882a593Smuzhiyun lpfc_set_disctmo(piocb->vport);
9400*4882a593Smuzhiyun }
9401*4882a593Smuzhiyun
9402*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9403*4882a593Smuzhiyun "FDISC cmpl: status:x%x/x%x prevdid:x%x",
9404*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
9405*4882a593Smuzhiyun
9406*4882a593Smuzhiyun if (irsp->ulpStatus) {
9407*4882a593Smuzhiyun
9408*4882a593Smuzhiyun if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
9409*4882a593Smuzhiyun lpfc_retry_pport_discovery(phba);
9410*4882a593Smuzhiyun goto out;
9411*4882a593Smuzhiyun }
9412*4882a593Smuzhiyun
9413*4882a593Smuzhiyun /* Check for retry */
9414*4882a593Smuzhiyun if (lpfc_els_retry(phba, cmdiocb, rspiocb))
9415*4882a593Smuzhiyun goto out;
9416*4882a593Smuzhiyun /* FDISC failed */
9417*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9418*4882a593Smuzhiyun "0126 FDISC failed. (x%x/x%x)\n",
9419*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4]);
9420*4882a593Smuzhiyun goto fdisc_failed;
9421*4882a593Smuzhiyun }
9422*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9423*4882a593Smuzhiyun vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
9424*4882a593Smuzhiyun vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
9425*4882a593Smuzhiyun vport->fc_flag |= FC_FABRIC;
9426*4882a593Smuzhiyun if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
9427*4882a593Smuzhiyun vport->fc_flag |= FC_PUBLIC_LOOP;
9428*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9429*4882a593Smuzhiyun
9430*4882a593Smuzhiyun vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
9431*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
9432*4882a593Smuzhiyun prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
9433*4882a593Smuzhiyun if (!prsp)
9434*4882a593Smuzhiyun goto out;
9435*4882a593Smuzhiyun sp = prsp->virt + sizeof(uint32_t);
9436*4882a593Smuzhiyun fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
9437*4882a593Smuzhiyun memcpy(&vport->fabric_portname, &sp->portName,
9438*4882a593Smuzhiyun sizeof(struct lpfc_name));
9439*4882a593Smuzhiyun memcpy(&vport->fabric_nodename, &sp->nodeName,
9440*4882a593Smuzhiyun sizeof(struct lpfc_name));
9441*4882a593Smuzhiyun if (fabric_param_changed &&
9442*4882a593Smuzhiyun !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9443*4882a593Smuzhiyun /* If our NportID changed, we need to ensure all
9444*4882a593Smuzhiyun * remaining NPORTs get unreg_login'ed so we can
9445*4882a593Smuzhiyun * issue unreg_vpi.
9446*4882a593Smuzhiyun */
9447*4882a593Smuzhiyun list_for_each_entry_safe(np, next_np,
9448*4882a593Smuzhiyun &vport->fc_nodes, nlp_listp) {
9449*4882a593Smuzhiyun if (!NLP_CHK_NODE_ACT(ndlp) ||
9450*4882a593Smuzhiyun (np->nlp_state != NLP_STE_NPR_NODE) ||
9451*4882a593Smuzhiyun !(np->nlp_flag & NLP_NPR_ADISC))
9452*4882a593Smuzhiyun continue;
9453*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9454*4882a593Smuzhiyun np->nlp_flag &= ~NLP_NPR_ADISC;
9455*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9456*4882a593Smuzhiyun lpfc_unreg_rpi(vport, np);
9457*4882a593Smuzhiyun }
9458*4882a593Smuzhiyun lpfc_cleanup_pending_mbox(vport);
9459*4882a593Smuzhiyun
9460*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
9461*4882a593Smuzhiyun lpfc_sli4_unreg_all_rpis(vport);
9462*4882a593Smuzhiyun
9463*4882a593Smuzhiyun lpfc_mbx_unreg_vpi(vport);
9464*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9465*4882a593Smuzhiyun vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
9466*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV4)
9467*4882a593Smuzhiyun vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
9468*4882a593Smuzhiyun else
9469*4882a593Smuzhiyun vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
9470*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9471*4882a593Smuzhiyun } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
9472*4882a593Smuzhiyun !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
9473*4882a593Smuzhiyun /*
9474*4882a593Smuzhiyun * Driver needs to re-reg VPI in order for f/w
9475*4882a593Smuzhiyun * to update the MAC address.
9476*4882a593Smuzhiyun */
9477*4882a593Smuzhiyun lpfc_register_new_vport(phba, vport, ndlp);
9478*4882a593Smuzhiyun goto out;
9479*4882a593Smuzhiyun }
9480*4882a593Smuzhiyun
9481*4882a593Smuzhiyun if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
9482*4882a593Smuzhiyun lpfc_issue_init_vpi(vport);
9483*4882a593Smuzhiyun else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
9484*4882a593Smuzhiyun lpfc_register_new_vport(phba, vport, ndlp);
9485*4882a593Smuzhiyun else
9486*4882a593Smuzhiyun lpfc_do_scr_ns_plogi(phba, vport);
9487*4882a593Smuzhiyun goto out;
9488*4882a593Smuzhiyun fdisc_failed:
9489*4882a593Smuzhiyun if (vport->fc_vport &&
9490*4882a593Smuzhiyun (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS))
9491*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9492*4882a593Smuzhiyun /* Cancel discovery timer */
9493*4882a593Smuzhiyun lpfc_can_disctmo(vport);
9494*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
9495*4882a593Smuzhiyun out:
9496*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
9497*4882a593Smuzhiyun }
9498*4882a593Smuzhiyun
9499*4882a593Smuzhiyun /**
9500*4882a593Smuzhiyun * lpfc_issue_els_fdisc - Issue a fdisc iocb command
9501*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
9502*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
9503*4882a593Smuzhiyun * @retry: number of retries to the command IOCB.
9504*4882a593Smuzhiyun *
9505*4882a593Smuzhiyun * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
9506*4882a593Smuzhiyun * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
9507*4882a593Smuzhiyun * routine to issue the IOCB, which makes sure only one outstanding fabric
9508*4882a593Smuzhiyun * IOCB will be sent off HBA at any given time.
9509*4882a593Smuzhiyun *
9510*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9511*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
9512*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
9513*4882a593Smuzhiyun * callback function to the FDISC ELS command.
9514*4882a593Smuzhiyun *
9515*4882a593Smuzhiyun * Return code
9516*4882a593Smuzhiyun * 0 - Successfully issued fdisc iocb command
9517*4882a593Smuzhiyun * 1 - Failed to issue fdisc iocb command
9518*4882a593Smuzhiyun **/
9519*4882a593Smuzhiyun static int
lpfc_issue_els_fdisc(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp,uint8_t retry)9520*4882a593Smuzhiyun lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
9521*4882a593Smuzhiyun uint8_t retry)
9522*4882a593Smuzhiyun {
9523*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
9524*4882a593Smuzhiyun IOCB_t *icmd;
9525*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
9526*4882a593Smuzhiyun struct serv_parm *sp;
9527*4882a593Smuzhiyun uint8_t *pcmd;
9528*4882a593Smuzhiyun uint16_t cmdsize;
9529*4882a593Smuzhiyun int did = ndlp->nlp_DID;
9530*4882a593Smuzhiyun int rc;
9531*4882a593Smuzhiyun
9532*4882a593Smuzhiyun vport->port_state = LPFC_FDISC;
9533*4882a593Smuzhiyun vport->fc_myDID = 0;
9534*4882a593Smuzhiyun cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
9535*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
9536*4882a593Smuzhiyun ELS_CMD_FDISC);
9537*4882a593Smuzhiyun if (!elsiocb) {
9538*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9539*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9540*4882a593Smuzhiyun "0255 Issue FDISC: no IOCB\n");
9541*4882a593Smuzhiyun return 1;
9542*4882a593Smuzhiyun }
9543*4882a593Smuzhiyun
9544*4882a593Smuzhiyun icmd = &elsiocb->iocb;
9545*4882a593Smuzhiyun icmd->un.elsreq64.myID = 0;
9546*4882a593Smuzhiyun icmd->un.elsreq64.fl = 1;
9547*4882a593Smuzhiyun
9548*4882a593Smuzhiyun /*
9549*4882a593Smuzhiyun * SLI3 ports require a different context type value than SLI4.
9550*4882a593Smuzhiyun * Catch SLI3 ports here and override the prep.
9551*4882a593Smuzhiyun */
9552*4882a593Smuzhiyun if (phba->sli_rev == LPFC_SLI_REV3) {
9553*4882a593Smuzhiyun icmd->ulpCt_h = 1;
9554*4882a593Smuzhiyun icmd->ulpCt_l = 0;
9555*4882a593Smuzhiyun }
9556*4882a593Smuzhiyun
9557*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9558*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
9559*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* CSP Word 1 */
9560*4882a593Smuzhiyun memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
9561*4882a593Smuzhiyun sp = (struct serv_parm *) pcmd;
9562*4882a593Smuzhiyun /* Setup CSPs accordingly for Fabric */
9563*4882a593Smuzhiyun sp->cmn.e_d_tov = 0;
9564*4882a593Smuzhiyun sp->cmn.w2.r_a_tov = 0;
9565*4882a593Smuzhiyun sp->cmn.virtual_fabric_support = 0;
9566*4882a593Smuzhiyun sp->cls1.classValid = 0;
9567*4882a593Smuzhiyun sp->cls2.seqDelivery = 1;
9568*4882a593Smuzhiyun sp->cls3.seqDelivery = 1;
9569*4882a593Smuzhiyun
9570*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* CSP Word 2 */
9571*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* CSP Word 3 */
9572*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* CSP Word 4 */
9573*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* Port Name */
9574*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_portname, 8);
9575*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* Node Name */
9576*4882a593Smuzhiyun pcmd += sizeof(uint32_t); /* Node Name */
9577*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_nodename, 8);
9578*4882a593Smuzhiyun sp->cmn.valid_vendor_ver_level = 0;
9579*4882a593Smuzhiyun memset(sp->un.vendorVersion, 0, sizeof(sp->un.vendorVersion));
9580*4882a593Smuzhiyun lpfc_set_disctmo(vport);
9581*4882a593Smuzhiyun
9582*4882a593Smuzhiyun phba->fc_stat.elsXmitFDISC++;
9583*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
9584*4882a593Smuzhiyun
9585*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9586*4882a593Smuzhiyun "Issue FDISC: did:x%x",
9587*4882a593Smuzhiyun did, 0, 0);
9588*4882a593Smuzhiyun
9589*4882a593Smuzhiyun rc = lpfc_issue_fabric_iocb(phba, elsiocb);
9590*4882a593Smuzhiyun if (rc == IOCB_ERROR) {
9591*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
9592*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_FAILED);
9593*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
9594*4882a593Smuzhiyun "0256 Issue FDISC: Cannot send IOCB\n");
9595*4882a593Smuzhiyun return 1;
9596*4882a593Smuzhiyun }
9597*4882a593Smuzhiyun lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
9598*4882a593Smuzhiyun return 0;
9599*4882a593Smuzhiyun }
9600*4882a593Smuzhiyun
9601*4882a593Smuzhiyun /**
9602*4882a593Smuzhiyun * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
9603*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9604*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
9605*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
9606*4882a593Smuzhiyun *
9607*4882a593Smuzhiyun * This routine is the completion callback function to the issuing of a LOGO
9608*4882a593Smuzhiyun * ELS command off a vport. It frees the command IOCB and then decrement the
9609*4882a593Smuzhiyun * reference count held on ndlp for this completion function, indicating that
9610*4882a593Smuzhiyun * the reference to the ndlp is no long needed. Note that the
9611*4882a593Smuzhiyun * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
9612*4882a593Smuzhiyun * callback function and an additional explicit ndlp reference decrementation
9613*4882a593Smuzhiyun * will trigger the actual release of the ndlp.
9614*4882a593Smuzhiyun **/
9615*4882a593Smuzhiyun static void
lpfc_cmpl_els_npiv_logo(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)9616*4882a593Smuzhiyun lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9617*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
9618*4882a593Smuzhiyun {
9619*4882a593Smuzhiyun struct lpfc_vport *vport = cmdiocb->vport;
9620*4882a593Smuzhiyun IOCB_t *irsp;
9621*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
9622*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9623*4882a593Smuzhiyun
9624*4882a593Smuzhiyun ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
9625*4882a593Smuzhiyun irsp = &rspiocb->iocb;
9626*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9627*4882a593Smuzhiyun "LOGO npiv cmpl: status:x%x/x%x did:x%x",
9628*4882a593Smuzhiyun irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
9629*4882a593Smuzhiyun
9630*4882a593Smuzhiyun lpfc_els_free_iocb(phba, cmdiocb);
9631*4882a593Smuzhiyun vport->unreg_vpi_cmpl = VPORT_ERROR;
9632*4882a593Smuzhiyun
9633*4882a593Smuzhiyun /* Trigger the release of the ndlp after logo */
9634*4882a593Smuzhiyun lpfc_nlp_put(ndlp);
9635*4882a593Smuzhiyun
9636*4882a593Smuzhiyun /* NPIV LOGO completes to NPort <nlp_DID> */
9637*4882a593Smuzhiyun lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
9638*4882a593Smuzhiyun "2928 NPIV LOGO completes to NPort x%x "
9639*4882a593Smuzhiyun "Data: x%x x%x x%x x%x\n",
9640*4882a593Smuzhiyun ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
9641*4882a593Smuzhiyun irsp->ulpTimeout, vport->num_disc_nodes);
9642*4882a593Smuzhiyun
9643*4882a593Smuzhiyun if (irsp->ulpStatus == IOSTAT_SUCCESS) {
9644*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9645*4882a593Smuzhiyun vport->fc_flag &= ~FC_NDISC_ACTIVE;
9646*4882a593Smuzhiyun vport->fc_flag &= ~FC_FABRIC;
9647*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9648*4882a593Smuzhiyun lpfc_can_disctmo(vport);
9649*4882a593Smuzhiyun }
9650*4882a593Smuzhiyun }
9651*4882a593Smuzhiyun
9652*4882a593Smuzhiyun /**
9653*4882a593Smuzhiyun * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9654*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
9655*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
9656*4882a593Smuzhiyun *
9657*4882a593Smuzhiyun * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9658*4882a593Smuzhiyun *
9659*4882a593Smuzhiyun * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9660*4882a593Smuzhiyun * will be incremented by 1 for holding the ndlp and the reference to ndlp
9661*4882a593Smuzhiyun * will be stored into the context1 field of the IOCB for the completion
9662*4882a593Smuzhiyun * callback function to the LOGO ELS command.
9663*4882a593Smuzhiyun *
9664*4882a593Smuzhiyun * Return codes
9665*4882a593Smuzhiyun * 0 - Successfully issued logo off the @vport
9666*4882a593Smuzhiyun * 1 - Failed to issue logo off the @vport
9667*4882a593Smuzhiyun **/
9668*4882a593Smuzhiyun int
lpfc_issue_els_npiv_logo(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)9669*4882a593Smuzhiyun lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
9670*4882a593Smuzhiyun {
9671*4882a593Smuzhiyun struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
9672*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
9673*4882a593Smuzhiyun struct lpfc_iocbq *elsiocb;
9674*4882a593Smuzhiyun uint8_t *pcmd;
9675*4882a593Smuzhiyun uint16_t cmdsize;
9676*4882a593Smuzhiyun
9677*4882a593Smuzhiyun cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
9678*4882a593Smuzhiyun elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
9679*4882a593Smuzhiyun ELS_CMD_LOGO);
9680*4882a593Smuzhiyun if (!elsiocb)
9681*4882a593Smuzhiyun return 1;
9682*4882a593Smuzhiyun
9683*4882a593Smuzhiyun pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
9684*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
9685*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
9686*4882a593Smuzhiyun
9687*4882a593Smuzhiyun /* Fill in LOGO payload */
9688*4882a593Smuzhiyun *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
9689*4882a593Smuzhiyun pcmd += sizeof(uint32_t);
9690*4882a593Smuzhiyun memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
9691*4882a593Smuzhiyun
9692*4882a593Smuzhiyun lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
9693*4882a593Smuzhiyun "Issue LOGO npiv did:x%x flg:x%x",
9694*4882a593Smuzhiyun ndlp->nlp_DID, ndlp->nlp_flag, 0);
9695*4882a593Smuzhiyun
9696*4882a593Smuzhiyun elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
9697*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9698*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_LOGO_SND;
9699*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9700*4882a593Smuzhiyun if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
9701*4882a593Smuzhiyun IOCB_ERROR) {
9702*4882a593Smuzhiyun spin_lock_irq(shost->host_lock);
9703*4882a593Smuzhiyun ndlp->nlp_flag &= ~NLP_LOGO_SND;
9704*4882a593Smuzhiyun spin_unlock_irq(shost->host_lock);
9705*4882a593Smuzhiyun lpfc_els_free_iocb(phba, elsiocb);
9706*4882a593Smuzhiyun return 1;
9707*4882a593Smuzhiyun }
9708*4882a593Smuzhiyun return 0;
9709*4882a593Smuzhiyun }
9710*4882a593Smuzhiyun
9711*4882a593Smuzhiyun /**
9712*4882a593Smuzhiyun * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9713*4882a593Smuzhiyun * @t: timer context used to obtain the lpfc hba.
9714*4882a593Smuzhiyun *
9715*4882a593Smuzhiyun * This routine is invoked by the fabric iocb block timer after
9716*4882a593Smuzhiyun * timeout. It posts the fabric iocb block timeout event by setting the
9717*4882a593Smuzhiyun * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9718*4882a593Smuzhiyun * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9719*4882a593Smuzhiyun * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9720*4882a593Smuzhiyun * posted event WORKER_FABRIC_BLOCK_TMO.
9721*4882a593Smuzhiyun **/
9722*4882a593Smuzhiyun void
lpfc_fabric_block_timeout(struct timer_list * t)9723*4882a593Smuzhiyun lpfc_fabric_block_timeout(struct timer_list *t)
9724*4882a593Smuzhiyun {
9725*4882a593Smuzhiyun struct lpfc_hba *phba = from_timer(phba, t, fabric_block_timer);
9726*4882a593Smuzhiyun unsigned long iflags;
9727*4882a593Smuzhiyun uint32_t tmo_posted;
9728*4882a593Smuzhiyun
9729*4882a593Smuzhiyun spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
9730*4882a593Smuzhiyun tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
9731*4882a593Smuzhiyun if (!tmo_posted)
9732*4882a593Smuzhiyun phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
9733*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
9734*4882a593Smuzhiyun
9735*4882a593Smuzhiyun if (!tmo_posted)
9736*4882a593Smuzhiyun lpfc_worker_wake_up(phba);
9737*4882a593Smuzhiyun return;
9738*4882a593Smuzhiyun }
9739*4882a593Smuzhiyun
9740*4882a593Smuzhiyun /**
9741*4882a593Smuzhiyun * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9742*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9743*4882a593Smuzhiyun *
9744*4882a593Smuzhiyun * This routine issues one fabric iocb from the driver internal list to
9745*4882a593Smuzhiyun * the HBA. It first checks whether it's ready to issue one fabric iocb to
9746*4882a593Smuzhiyun * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9747*4882a593Smuzhiyun * remove one pending fabric iocb from the driver internal list and invokes
9748*4882a593Smuzhiyun * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9749*4882a593Smuzhiyun **/
9750*4882a593Smuzhiyun static void
lpfc_resume_fabric_iocbs(struct lpfc_hba * phba)9751*4882a593Smuzhiyun lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
9752*4882a593Smuzhiyun {
9753*4882a593Smuzhiyun struct lpfc_iocbq *iocb;
9754*4882a593Smuzhiyun unsigned long iflags;
9755*4882a593Smuzhiyun int ret;
9756*4882a593Smuzhiyun IOCB_t *cmd;
9757*4882a593Smuzhiyun
9758*4882a593Smuzhiyun repeat:
9759*4882a593Smuzhiyun iocb = NULL;
9760*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflags);
9761*4882a593Smuzhiyun /* Post any pending iocb to the SLI layer */
9762*4882a593Smuzhiyun if (atomic_read(&phba->fabric_iocb_count) == 0) {
9763*4882a593Smuzhiyun list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
9764*4882a593Smuzhiyun list);
9765*4882a593Smuzhiyun if (iocb)
9766*4882a593Smuzhiyun /* Increment fabric iocb count to hold the position */
9767*4882a593Smuzhiyun atomic_inc(&phba->fabric_iocb_count);
9768*4882a593Smuzhiyun }
9769*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
9770*4882a593Smuzhiyun if (iocb) {
9771*4882a593Smuzhiyun iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9772*4882a593Smuzhiyun iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9773*4882a593Smuzhiyun iocb->iocb_flag |= LPFC_IO_FABRIC;
9774*4882a593Smuzhiyun
9775*4882a593Smuzhiyun lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9776*4882a593Smuzhiyun "Fabric sched1: ste:x%x",
9777*4882a593Smuzhiyun iocb->vport->port_state, 0, 0);
9778*4882a593Smuzhiyun
9779*4882a593Smuzhiyun ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9780*4882a593Smuzhiyun
9781*4882a593Smuzhiyun if (ret == IOCB_ERROR) {
9782*4882a593Smuzhiyun iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9783*4882a593Smuzhiyun iocb->fabric_iocb_cmpl = NULL;
9784*4882a593Smuzhiyun iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9785*4882a593Smuzhiyun cmd = &iocb->iocb;
9786*4882a593Smuzhiyun cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
9787*4882a593Smuzhiyun cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
9788*4882a593Smuzhiyun iocb->iocb_cmpl(phba, iocb, iocb);
9789*4882a593Smuzhiyun
9790*4882a593Smuzhiyun atomic_dec(&phba->fabric_iocb_count);
9791*4882a593Smuzhiyun goto repeat;
9792*4882a593Smuzhiyun }
9793*4882a593Smuzhiyun }
9794*4882a593Smuzhiyun
9795*4882a593Smuzhiyun return;
9796*4882a593Smuzhiyun }
9797*4882a593Smuzhiyun
9798*4882a593Smuzhiyun /**
9799*4882a593Smuzhiyun * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9800*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9801*4882a593Smuzhiyun *
9802*4882a593Smuzhiyun * This routine unblocks the issuing fabric iocb command. The function
9803*4882a593Smuzhiyun * will clear the fabric iocb block bit and then invoke the routine
9804*4882a593Smuzhiyun * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9805*4882a593Smuzhiyun * from the driver internal fabric iocb list.
9806*4882a593Smuzhiyun **/
9807*4882a593Smuzhiyun void
lpfc_unblock_fabric_iocbs(struct lpfc_hba * phba)9808*4882a593Smuzhiyun lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
9809*4882a593Smuzhiyun {
9810*4882a593Smuzhiyun clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9811*4882a593Smuzhiyun
9812*4882a593Smuzhiyun lpfc_resume_fabric_iocbs(phba);
9813*4882a593Smuzhiyun return;
9814*4882a593Smuzhiyun }
9815*4882a593Smuzhiyun
9816*4882a593Smuzhiyun /**
9817*4882a593Smuzhiyun * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9818*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9819*4882a593Smuzhiyun *
9820*4882a593Smuzhiyun * This routine blocks the issuing fabric iocb for a specified amount of
9821*4882a593Smuzhiyun * time (currently 100 ms). This is done by set the fabric iocb block bit
9822*4882a593Smuzhiyun * and set up a timeout timer for 100ms. When the block bit is set, no more
9823*4882a593Smuzhiyun * fabric iocb will be issued out of the HBA.
9824*4882a593Smuzhiyun **/
9825*4882a593Smuzhiyun static void
lpfc_block_fabric_iocbs(struct lpfc_hba * phba)9826*4882a593Smuzhiyun lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
9827*4882a593Smuzhiyun {
9828*4882a593Smuzhiyun int blocked;
9829*4882a593Smuzhiyun
9830*4882a593Smuzhiyun blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9831*4882a593Smuzhiyun /* Start a timer to unblock fabric iocbs after 100ms */
9832*4882a593Smuzhiyun if (!blocked)
9833*4882a593Smuzhiyun mod_timer(&phba->fabric_block_timer,
9834*4882a593Smuzhiyun jiffies + msecs_to_jiffies(100));
9835*4882a593Smuzhiyun
9836*4882a593Smuzhiyun return;
9837*4882a593Smuzhiyun }
9838*4882a593Smuzhiyun
9839*4882a593Smuzhiyun /**
9840*4882a593Smuzhiyun * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9841*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9842*4882a593Smuzhiyun * @cmdiocb: pointer to lpfc command iocb data structure.
9843*4882a593Smuzhiyun * @rspiocb: pointer to lpfc response iocb data structure.
9844*4882a593Smuzhiyun *
9845*4882a593Smuzhiyun * This routine is the callback function that is put to the fabric iocb's
9846*4882a593Smuzhiyun * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9847*4882a593Smuzhiyun * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9848*4882a593Smuzhiyun * function first restores and invokes the original iocb's callback function
9849*4882a593Smuzhiyun * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9850*4882a593Smuzhiyun * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9851*4882a593Smuzhiyun **/
9852*4882a593Smuzhiyun static void
lpfc_cmpl_fabric_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * cmdiocb,struct lpfc_iocbq * rspiocb)9853*4882a593Smuzhiyun lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
9854*4882a593Smuzhiyun struct lpfc_iocbq *rspiocb)
9855*4882a593Smuzhiyun {
9856*4882a593Smuzhiyun struct ls_rjt stat;
9857*4882a593Smuzhiyun
9858*4882a593Smuzhiyun BUG_ON((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC);
9859*4882a593Smuzhiyun
9860*4882a593Smuzhiyun switch (rspiocb->iocb.ulpStatus) {
9861*4882a593Smuzhiyun case IOSTAT_NPORT_RJT:
9862*4882a593Smuzhiyun case IOSTAT_FABRIC_RJT:
9863*4882a593Smuzhiyun if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
9864*4882a593Smuzhiyun lpfc_block_fabric_iocbs(phba);
9865*4882a593Smuzhiyun }
9866*4882a593Smuzhiyun break;
9867*4882a593Smuzhiyun
9868*4882a593Smuzhiyun case IOSTAT_NPORT_BSY:
9869*4882a593Smuzhiyun case IOSTAT_FABRIC_BSY:
9870*4882a593Smuzhiyun lpfc_block_fabric_iocbs(phba);
9871*4882a593Smuzhiyun break;
9872*4882a593Smuzhiyun
9873*4882a593Smuzhiyun case IOSTAT_LS_RJT:
9874*4882a593Smuzhiyun stat.un.lsRjtError =
9875*4882a593Smuzhiyun be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
9876*4882a593Smuzhiyun if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
9877*4882a593Smuzhiyun (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
9878*4882a593Smuzhiyun lpfc_block_fabric_iocbs(phba);
9879*4882a593Smuzhiyun break;
9880*4882a593Smuzhiyun }
9881*4882a593Smuzhiyun
9882*4882a593Smuzhiyun BUG_ON(atomic_read(&phba->fabric_iocb_count) == 0);
9883*4882a593Smuzhiyun
9884*4882a593Smuzhiyun cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
9885*4882a593Smuzhiyun cmdiocb->fabric_iocb_cmpl = NULL;
9886*4882a593Smuzhiyun cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
9887*4882a593Smuzhiyun cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
9888*4882a593Smuzhiyun
9889*4882a593Smuzhiyun atomic_dec(&phba->fabric_iocb_count);
9890*4882a593Smuzhiyun if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
9891*4882a593Smuzhiyun /* Post any pending iocbs to HBA */
9892*4882a593Smuzhiyun lpfc_resume_fabric_iocbs(phba);
9893*4882a593Smuzhiyun }
9894*4882a593Smuzhiyun }
9895*4882a593Smuzhiyun
9896*4882a593Smuzhiyun /**
9897*4882a593Smuzhiyun * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9898*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
9899*4882a593Smuzhiyun * @iocb: pointer to lpfc command iocb data structure.
9900*4882a593Smuzhiyun *
9901*4882a593Smuzhiyun * This routine is used as the top-level API for issuing a fabric iocb command
9902*4882a593Smuzhiyun * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9903*4882a593Smuzhiyun * function makes sure that only one fabric bound iocb will be outstanding at
9904*4882a593Smuzhiyun * any given time. As such, this function will first check to see whether there
9905*4882a593Smuzhiyun * is already an outstanding fabric iocb on the wire. If so, it will put the
9906*4882a593Smuzhiyun * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9907*4882a593Smuzhiyun * issued later. Otherwise, it will issue the iocb on the wire and update the
9908*4882a593Smuzhiyun * fabric iocb count it indicate that there is one fabric iocb on the wire.
9909*4882a593Smuzhiyun *
9910*4882a593Smuzhiyun * Note, this implementation has a potential sending out fabric IOCBs out of
9911*4882a593Smuzhiyun * order. The problem is caused by the construction of the "ready" boolen does
9912*4882a593Smuzhiyun * not include the condition that the internal fabric IOCB list is empty. As
9913*4882a593Smuzhiyun * such, it is possible a fabric IOCB issued by this routine might be "jump"
9914*4882a593Smuzhiyun * ahead of the fabric IOCBs in the internal list.
9915*4882a593Smuzhiyun *
9916*4882a593Smuzhiyun * Return code
9917*4882a593Smuzhiyun * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9918*4882a593Smuzhiyun * IOCB_ERROR - failed to issue fabric iocb
9919*4882a593Smuzhiyun **/
9920*4882a593Smuzhiyun static int
lpfc_issue_fabric_iocb(struct lpfc_hba * phba,struct lpfc_iocbq * iocb)9921*4882a593Smuzhiyun lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
9922*4882a593Smuzhiyun {
9923*4882a593Smuzhiyun unsigned long iflags;
9924*4882a593Smuzhiyun int ready;
9925*4882a593Smuzhiyun int ret;
9926*4882a593Smuzhiyun
9927*4882a593Smuzhiyun BUG_ON(atomic_read(&phba->fabric_iocb_count) > 1);
9928*4882a593Smuzhiyun
9929*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflags);
9930*4882a593Smuzhiyun ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
9931*4882a593Smuzhiyun !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
9932*4882a593Smuzhiyun
9933*4882a593Smuzhiyun if (ready)
9934*4882a593Smuzhiyun /* Increment fabric iocb count to hold the position */
9935*4882a593Smuzhiyun atomic_inc(&phba->fabric_iocb_count);
9936*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
9937*4882a593Smuzhiyun if (ready) {
9938*4882a593Smuzhiyun iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
9939*4882a593Smuzhiyun iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
9940*4882a593Smuzhiyun iocb->iocb_flag |= LPFC_IO_FABRIC;
9941*4882a593Smuzhiyun
9942*4882a593Smuzhiyun lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
9943*4882a593Smuzhiyun "Fabric sched2: ste:x%x",
9944*4882a593Smuzhiyun iocb->vport->port_state, 0, 0);
9945*4882a593Smuzhiyun
9946*4882a593Smuzhiyun ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
9947*4882a593Smuzhiyun
9948*4882a593Smuzhiyun if (ret == IOCB_ERROR) {
9949*4882a593Smuzhiyun iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
9950*4882a593Smuzhiyun iocb->fabric_iocb_cmpl = NULL;
9951*4882a593Smuzhiyun iocb->iocb_flag &= ~LPFC_IO_FABRIC;
9952*4882a593Smuzhiyun atomic_dec(&phba->fabric_iocb_count);
9953*4882a593Smuzhiyun }
9954*4882a593Smuzhiyun } else {
9955*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflags);
9956*4882a593Smuzhiyun list_add_tail(&iocb->list, &phba->fabric_iocb_list);
9957*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflags);
9958*4882a593Smuzhiyun ret = IOCB_SUCCESS;
9959*4882a593Smuzhiyun }
9960*4882a593Smuzhiyun return ret;
9961*4882a593Smuzhiyun }
9962*4882a593Smuzhiyun
9963*4882a593Smuzhiyun /**
9964*4882a593Smuzhiyun * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9965*4882a593Smuzhiyun * @vport: pointer to a virtual N_Port data structure.
9966*4882a593Smuzhiyun *
9967*4882a593Smuzhiyun * This routine aborts all the IOCBs associated with a @vport from the
9968*4882a593Smuzhiyun * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9969*4882a593Smuzhiyun * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9970*4882a593Smuzhiyun * list, removes each IOCB associated with the @vport off the list, set the
9971*4882a593Smuzhiyun * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9972*4882a593Smuzhiyun * associated with the IOCB.
9973*4882a593Smuzhiyun **/
lpfc_fabric_abort_vport(struct lpfc_vport * vport)9974*4882a593Smuzhiyun static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
9975*4882a593Smuzhiyun {
9976*4882a593Smuzhiyun LIST_HEAD(completions);
9977*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
9978*4882a593Smuzhiyun struct lpfc_iocbq *tmp_iocb, *piocb;
9979*4882a593Smuzhiyun
9980*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
9981*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9982*4882a593Smuzhiyun list) {
9983*4882a593Smuzhiyun
9984*4882a593Smuzhiyun if (piocb->vport != vport)
9985*4882a593Smuzhiyun continue;
9986*4882a593Smuzhiyun
9987*4882a593Smuzhiyun list_move_tail(&piocb->list, &completions);
9988*4882a593Smuzhiyun }
9989*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
9990*4882a593Smuzhiyun
9991*4882a593Smuzhiyun /* Cancel all the IOCBs from the completions list */
9992*4882a593Smuzhiyun lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9993*4882a593Smuzhiyun IOERR_SLI_ABORTED);
9994*4882a593Smuzhiyun }
9995*4882a593Smuzhiyun
9996*4882a593Smuzhiyun /**
9997*4882a593Smuzhiyun * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9998*4882a593Smuzhiyun * @ndlp: pointer to a node-list data structure.
9999*4882a593Smuzhiyun *
10000*4882a593Smuzhiyun * This routine aborts all the IOCBs associated with an @ndlp from the
10001*4882a593Smuzhiyun * driver internal fabric IOCB list. The list contains fabric IOCBs to be
10002*4882a593Smuzhiyun * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
10003*4882a593Smuzhiyun * list, removes each IOCB associated with the @ndlp off the list, set the
10004*4882a593Smuzhiyun * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
10005*4882a593Smuzhiyun * associated with the IOCB.
10006*4882a593Smuzhiyun **/
lpfc_fabric_abort_nport(struct lpfc_nodelist * ndlp)10007*4882a593Smuzhiyun void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
10008*4882a593Smuzhiyun {
10009*4882a593Smuzhiyun LIST_HEAD(completions);
10010*4882a593Smuzhiyun struct lpfc_hba *phba = ndlp->phba;
10011*4882a593Smuzhiyun struct lpfc_iocbq *tmp_iocb, *piocb;
10012*4882a593Smuzhiyun struct lpfc_sli_ring *pring;
10013*4882a593Smuzhiyun
10014*4882a593Smuzhiyun pring = lpfc_phba_elsring(phba);
10015*4882a593Smuzhiyun
10016*4882a593Smuzhiyun if (unlikely(!pring))
10017*4882a593Smuzhiyun return;
10018*4882a593Smuzhiyun
10019*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
10020*4882a593Smuzhiyun list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
10021*4882a593Smuzhiyun list) {
10022*4882a593Smuzhiyun if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
10023*4882a593Smuzhiyun
10024*4882a593Smuzhiyun list_move_tail(&piocb->list, &completions);
10025*4882a593Smuzhiyun }
10026*4882a593Smuzhiyun }
10027*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
10028*4882a593Smuzhiyun
10029*4882a593Smuzhiyun /* Cancel all the IOCBs from the completions list */
10030*4882a593Smuzhiyun lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10031*4882a593Smuzhiyun IOERR_SLI_ABORTED);
10032*4882a593Smuzhiyun }
10033*4882a593Smuzhiyun
10034*4882a593Smuzhiyun /**
10035*4882a593Smuzhiyun * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
10036*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
10037*4882a593Smuzhiyun *
10038*4882a593Smuzhiyun * This routine aborts all the IOCBs currently on the driver internal
10039*4882a593Smuzhiyun * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
10040*4882a593Smuzhiyun * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
10041*4882a593Smuzhiyun * list, removes IOCBs off the list, set the status feild to
10042*4882a593Smuzhiyun * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
10043*4882a593Smuzhiyun * the IOCB.
10044*4882a593Smuzhiyun **/
lpfc_fabric_abort_hba(struct lpfc_hba * phba)10045*4882a593Smuzhiyun void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
10046*4882a593Smuzhiyun {
10047*4882a593Smuzhiyun LIST_HEAD(completions);
10048*4882a593Smuzhiyun
10049*4882a593Smuzhiyun spin_lock_irq(&phba->hbalock);
10050*4882a593Smuzhiyun list_splice_init(&phba->fabric_iocb_list, &completions);
10051*4882a593Smuzhiyun spin_unlock_irq(&phba->hbalock);
10052*4882a593Smuzhiyun
10053*4882a593Smuzhiyun /* Cancel all the IOCBs from the completions list */
10054*4882a593Smuzhiyun lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
10055*4882a593Smuzhiyun IOERR_SLI_ABORTED);
10056*4882a593Smuzhiyun }
10057*4882a593Smuzhiyun
10058*4882a593Smuzhiyun /**
10059*4882a593Smuzhiyun * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
10060*4882a593Smuzhiyun * @vport: pointer to lpfc vport data structure.
10061*4882a593Smuzhiyun *
10062*4882a593Smuzhiyun * This routine is invoked by the vport cleanup for deletions and the cleanup
10063*4882a593Smuzhiyun * for an ndlp on removal.
10064*4882a593Smuzhiyun **/
10065*4882a593Smuzhiyun void
lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport * vport)10066*4882a593Smuzhiyun lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
10067*4882a593Smuzhiyun {
10068*4882a593Smuzhiyun struct lpfc_hba *phba = vport->phba;
10069*4882a593Smuzhiyun struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10070*4882a593Smuzhiyun unsigned long iflag = 0;
10071*4882a593Smuzhiyun
10072*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflag);
10073*4882a593Smuzhiyun spin_lock(&phba->sli4_hba.sgl_list_lock);
10074*4882a593Smuzhiyun list_for_each_entry_safe(sglq_entry, sglq_next,
10075*4882a593Smuzhiyun &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10076*4882a593Smuzhiyun if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
10077*4882a593Smuzhiyun sglq_entry->ndlp = NULL;
10078*4882a593Smuzhiyun }
10079*4882a593Smuzhiyun spin_unlock(&phba->sli4_hba.sgl_list_lock);
10080*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflag);
10081*4882a593Smuzhiyun return;
10082*4882a593Smuzhiyun }
10083*4882a593Smuzhiyun
10084*4882a593Smuzhiyun /**
10085*4882a593Smuzhiyun * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
10086*4882a593Smuzhiyun * @phba: pointer to lpfc hba data structure.
10087*4882a593Smuzhiyun * @axri: pointer to the els xri abort wcqe structure.
10088*4882a593Smuzhiyun *
10089*4882a593Smuzhiyun * This routine is invoked by the worker thread to process a SLI4 slow-path
10090*4882a593Smuzhiyun * ELS aborted xri.
10091*4882a593Smuzhiyun **/
10092*4882a593Smuzhiyun void
lpfc_sli4_els_xri_aborted(struct lpfc_hba * phba,struct sli4_wcqe_xri_aborted * axri)10093*4882a593Smuzhiyun lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
10094*4882a593Smuzhiyun struct sli4_wcqe_xri_aborted *axri)
10095*4882a593Smuzhiyun {
10096*4882a593Smuzhiyun uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
10097*4882a593Smuzhiyun uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
10098*4882a593Smuzhiyun uint16_t lxri = 0;
10099*4882a593Smuzhiyun
10100*4882a593Smuzhiyun struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
10101*4882a593Smuzhiyun unsigned long iflag = 0;
10102*4882a593Smuzhiyun struct lpfc_nodelist *ndlp;
10103*4882a593Smuzhiyun struct lpfc_sli_ring *pring;
10104*4882a593Smuzhiyun
10105*4882a593Smuzhiyun pring = lpfc_phba_elsring(phba);
10106*4882a593Smuzhiyun
10107*4882a593Smuzhiyun spin_lock_irqsave(&phba->hbalock, iflag);
10108*4882a593Smuzhiyun spin_lock(&phba->sli4_hba.sgl_list_lock);
10109*4882a593Smuzhiyun list_for_each_entry_safe(sglq_entry, sglq_next,
10110*4882a593Smuzhiyun &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
10111*4882a593Smuzhiyun if (sglq_entry->sli4_xritag == xri) {
10112*4882a593Smuzhiyun list_del(&sglq_entry->list);
10113*4882a593Smuzhiyun ndlp = sglq_entry->ndlp;
10114*4882a593Smuzhiyun sglq_entry->ndlp = NULL;
10115*4882a593Smuzhiyun list_add_tail(&sglq_entry->list,
10116*4882a593Smuzhiyun &phba->sli4_hba.lpfc_els_sgl_list);
10117*4882a593Smuzhiyun sglq_entry->state = SGL_FREED;
10118*4882a593Smuzhiyun spin_unlock(&phba->sli4_hba.sgl_list_lock);
10119*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflag);
10120*4882a593Smuzhiyun lpfc_set_rrq_active(phba, ndlp,
10121*4882a593Smuzhiyun sglq_entry->sli4_lxritag,
10122*4882a593Smuzhiyun rxid, 1);
10123*4882a593Smuzhiyun
10124*4882a593Smuzhiyun /* Check if TXQ queue needs to be serviced */
10125*4882a593Smuzhiyun if (pring && !list_empty(&pring->txq))
10126*4882a593Smuzhiyun lpfc_worker_wake_up(phba);
10127*4882a593Smuzhiyun return;
10128*4882a593Smuzhiyun }
10129*4882a593Smuzhiyun }
10130*4882a593Smuzhiyun spin_unlock(&phba->sli4_hba.sgl_list_lock);
10131*4882a593Smuzhiyun lxri = lpfc_sli4_xri_inrange(phba, xri);
10132*4882a593Smuzhiyun if (lxri == NO_XRI) {
10133*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflag);
10134*4882a593Smuzhiyun return;
10135*4882a593Smuzhiyun }
10136*4882a593Smuzhiyun spin_lock(&phba->sli4_hba.sgl_list_lock);
10137*4882a593Smuzhiyun sglq_entry = __lpfc_get_active_sglq(phba, lxri);
10138*4882a593Smuzhiyun if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
10139*4882a593Smuzhiyun spin_unlock(&phba->sli4_hba.sgl_list_lock);
10140*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflag);
10141*4882a593Smuzhiyun return;
10142*4882a593Smuzhiyun }
10143*4882a593Smuzhiyun sglq_entry->state = SGL_XRI_ABORTED;
10144*4882a593Smuzhiyun spin_unlock(&phba->sli4_hba.sgl_list_lock);
10145*4882a593Smuzhiyun spin_unlock_irqrestore(&phba->hbalock, iflag);
10146*4882a593Smuzhiyun return;
10147*4882a593Smuzhiyun }
10148*4882a593Smuzhiyun
10149*4882a593Smuzhiyun /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
10150*4882a593Smuzhiyun * @vport: pointer to virtual port object.
10151*4882a593Smuzhiyun * @ndlp: nodelist pointer for the impacted node.
10152*4882a593Smuzhiyun *
10153*4882a593Smuzhiyun * The driver calls this routine in response to an SLI4 XRI ABORT CQE
10154*4882a593Smuzhiyun * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
10155*4882a593Smuzhiyun * the driver is required to send a LOGO to the remote node before it
10156*4882a593Smuzhiyun * attempts to recover its login to the remote node.
10157*4882a593Smuzhiyun */
10158*4882a593Smuzhiyun void
lpfc_sli_abts_recover_port(struct lpfc_vport * vport,struct lpfc_nodelist * ndlp)10159*4882a593Smuzhiyun lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
10160*4882a593Smuzhiyun struct lpfc_nodelist *ndlp)
10161*4882a593Smuzhiyun {
10162*4882a593Smuzhiyun struct Scsi_Host *shost;
10163*4882a593Smuzhiyun struct lpfc_hba *phba;
10164*4882a593Smuzhiyun unsigned long flags = 0;
10165*4882a593Smuzhiyun
10166*4882a593Smuzhiyun shost = lpfc_shost_from_vport(vport);
10167*4882a593Smuzhiyun phba = vport->phba;
10168*4882a593Smuzhiyun if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
10169*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_INFO,
10170*4882a593Smuzhiyun LOG_SLI, "3093 No rport recovery needed. "
10171*4882a593Smuzhiyun "rport in state 0x%x\n", ndlp->nlp_state);
10172*4882a593Smuzhiyun return;
10173*4882a593Smuzhiyun }
10174*4882a593Smuzhiyun lpfc_printf_log(phba, KERN_ERR, LOG_TRACE_EVENT,
10175*4882a593Smuzhiyun "3094 Start rport recovery on shost id 0x%x "
10176*4882a593Smuzhiyun "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
10177*4882a593Smuzhiyun "flags 0x%x\n",
10178*4882a593Smuzhiyun shost->host_no, ndlp->nlp_DID,
10179*4882a593Smuzhiyun vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
10180*4882a593Smuzhiyun ndlp->nlp_flag);
10181*4882a593Smuzhiyun /*
10182*4882a593Smuzhiyun * The rport is not responding. Remove the FCP-2 flag to prevent
10183*4882a593Smuzhiyun * an ADISC in the follow-up recovery code.
10184*4882a593Smuzhiyun */
10185*4882a593Smuzhiyun spin_lock_irqsave(shost->host_lock, flags);
10186*4882a593Smuzhiyun ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
10187*4882a593Smuzhiyun ndlp->nlp_flag |= NLP_ISSUE_LOGO;
10188*4882a593Smuzhiyun spin_unlock_irqrestore(shost->host_lock, flags);
10189*4882a593Smuzhiyun lpfc_unreg_rpi(vport, ndlp);
10190*4882a593Smuzhiyun }
10191*4882a593Smuzhiyun
10192