blob: 861270edd84a49294aa98ebe1eba8eecf9d630f7 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart50611572016-03-31 14:12:34 -07004 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smarte74c03c2013-04-17 20:15:19 -040032
James Smartda0436e2009-05-22 14:51:39 -040033#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_hw.h"
35#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040036#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040037#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050038#include "lpfc_disc.h"
39#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050044#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050045
46static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
47 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050048static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
49 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010050static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
51static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp, uint8_t retry);
53static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
54 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050055
dea31012005-04-17 16:05:31 -050056static int lpfc_max_els_tries = 3;
57
James Smarte59058c2008-08-24 21:49:00 -040058/**
James Smart3621a712009-04-06 18:47:14 -040059 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040060 * @vport: pointer to a host virtual N_Port data structure.
61 *
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
69 * had happened.
70 *
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
75 *
76 * Return codes
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
79 **/
James Smart858c9f62007-06-17 19:56:39 -050080int
James Smart2e0fef82007-06-17 19:56:36 -050081lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050082{
James Smart2e0fef82007-06-17 19:56:36 -050083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
84 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050085 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050086
James Smart2e0fef82007-06-17 19:56:36 -050087 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040088 phba->link_state == LPFC_LINK_DOWN ||
89 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050090 return 0;
91
92 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050093 if (lpfc_readl(phba->HAregaddr, &ha_copy))
94 return 1;
dea31012005-04-17 16:05:31 -050095
96 if (!(ha_copy & HA_LATT))
97 return 0;
98
99 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -0400100 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500104
105 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300106 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
109 * events.
110 */
James Smart2e0fef82007-06-17 19:56:36 -0500111 spin_lock_irq(shost->host_lock);
112 vport->fc_flag |= FC_ABORT_DISCOVERY;
113 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500114
James Smart92d7f7b2007-06-17 19:56:38 -0500115 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500116 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500117
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500118 return 1;
dea31012005-04-17 16:05:31 -0500119}
120
James Smarte59058c2008-08-24 21:49:00 -0400121/**
James Smart3621a712009-04-06 18:47:14 -0400122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
130 *
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
144 *
145 * Return code
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
148 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400149struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500150lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
151 uint16_t cmdSize, uint8_t retry,
152 struct lpfc_nodelist *ndlp, uint32_t did,
153 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500154{
James Smart2e0fef82007-06-17 19:56:36 -0500155 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400156 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500157 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
158 struct ulp_bde64 *bpl;
159 IOCB_t *icmd;
160
dea31012005-04-17 16:05:31 -0500161
James Smart2e0fef82007-06-17 19:56:36 -0500162 if (!lpfc_is_link_up(phba))
163 return NULL;
dea31012005-04-17 16:05:31 -0500164
dea31012005-04-17 16:05:31 -0500165 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400166 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500167
168 if (elsiocb == NULL)
169 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500170
James Smart0c287582009-06-10 17:22:56 -0400171 /*
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
174 */
175 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400176 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400177 ((elscmd == ELS_CMD_FLOGI) ||
178 (elscmd == ELS_CMD_FDISC) ||
179 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500180 switch (elscmd) {
181 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400182 elsiocb->iocb_flag |=
183 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500184 & LPFC_FIP_ELS_ID_MASK);
185 break;
186 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400187 elsiocb->iocb_flag |=
188 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500189 & LPFC_FIP_ELS_ID_MASK);
190 break;
191 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400192 elsiocb->iocb_flag |=
193 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500194 & LPFC_FIP_ELS_ID_MASK);
195 break;
196 }
James Smart0c287582009-06-10 17:22:56 -0400197 else
James Smartc8685952009-11-18 15:39:16 -0500198 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400199
dea31012005-04-17 16:05:31 -0500200 icmd = &elsiocb->iocb;
201
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400204 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
205 if (pcmd)
206 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500207 if (!pcmd || !pcmd->virt)
208 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500209
210 INIT_LIST_HEAD(&pcmd->list);
211
212 /* Allocate buffer for response payload */
213 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500214 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500215 if (prsp)
216 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
217 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500218 if (!prsp || !prsp->virt)
219 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500220 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500221 } else
dea31012005-04-17 16:05:31 -0500222 prsp = NULL;
dea31012005-04-17 16:05:31 -0500223
224 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500225 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500226 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500227 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
228 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500229 if (!pbuflist || !pbuflist->virt)
230 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500231
232 INIT_LIST_HEAD(&pbuflist->list);
233
dea31012005-04-17 16:05:31 -0500234 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400235 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
236 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
237 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500238 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400239
240 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500241 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart88f43a02013-04-17 20:19:44 -0400242 if (elscmd == ELS_CMD_FLOGI)
243 icmd->ulpTimeout = FF_DEF_RATOV * 2;
244 else
245 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500246 } else {
James Smart939723a2012-05-09 21:19:03 -0400247 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
248 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
249 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
250 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
251 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500252 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
253 }
dea31012005-04-17 16:05:31 -0500254 icmd->ulpBdeCount = 1;
255 icmd->ulpLe = 1;
256 icmd->ulpClass = CLASS3;
257
James Smart939723a2012-05-09 21:19:03 -0400258 /*
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
262 */
263 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
264 ((phba->sli_rev == LPFC_SLI_REV4) &&
265 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500266
James Smart939723a2012-05-09 21:19:03 -0400267 if (expectRsp) {
268 icmd->un.elsreq64.myID = vport->fc_myDID;
269
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd->ulpContext = phba->vpi_ids[vport->vpi];
272 }
273
James Smart92d7f7b2007-06-17 19:56:38 -0500274 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd == ELS_CMD_ECHO)
277 icmd->ulpCt_l = 0; /* context = invalid RPI */
278 else
279 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500280 }
281
dea31012005-04-17 16:05:31 -0500282 bpl = (struct ulp_bde64 *) pbuflist->virt;
283 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
284 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
285 bpl->tus.f.bdeSize = cmdSize;
286 bpl->tus.f.bdeFlags = 0;
287 bpl->tus.w = le32_to_cpu(bpl->tus.w);
288
289 if (expectRsp) {
290 bpl++;
291 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
292 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
293 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400294 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500295 bpl->tus.w = le32_to_cpu(bpl->tus.w);
296 }
297
James Smartfa4066b2008-01-11 01:53:27 -0500298 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400299 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500300 if (!elsiocb->context1)
301 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400302 elsiocb->context2 = pcmd;
303 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500304 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500305 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500306 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
307
308 if (prsp) {
309 list_add(&prsp->list, &pcmd->list);
310 }
dea31012005-04-17 16:05:31 -0500311 if (expectRsp) {
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400313 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
314 "0116 Xmit ELS command x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400315 "NPORT x%x I/O tag: x%x, port state:x%x"
316 " fc_flag:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400317 elscmd, did, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400318 vport->port_state,
319 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500320 } else {
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400322 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
323 "0117 Xmit ELS response x%x to remote "
James Smarte74c03c2013-04-17 20:15:19 -0400324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400326 elscmd, ndlp->nlp_DID, elsiocb->iotag,
James Smarte74c03c2013-04-17 20:15:19 -0400327 cmdSize, vport->port_state,
328 vport->fc_flag);
dea31012005-04-17 16:05:31 -0500329 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500330 return elsiocb;
dea31012005-04-17 16:05:31 -0500331
James Smartfa4066b2008-01-11 01:53:27 -0500332els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500333 if (expectRsp)
334 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500335 kfree(pbuflist);
336
337els_iocb_free_prsp_exit:
338 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
339 kfree(prsp);
340
341els_iocb_free_pcmb_exit:
342 kfree(pcmd);
343 lpfc_sli_release_iocbq(phba, elsiocb);
344 return NULL;
345}
dea31012005-04-17 16:05:31 -0500346
James Smarte59058c2008-08-24 21:49:00 -0400347/**
James Smart3621a712009-04-06 18:47:14 -0400348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400349 * @vport: pointer to a host virtual N_Port data structure.
350 *
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
357 * with the @vport.
358 *
359 * Return code
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
362 **/
James Smart3772a992009-05-22 14:50:54 -0400363int
James Smart92d7f7b2007-06-17 19:56:38 -0500364lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
365{
366 struct lpfc_hba *phba = vport->phba;
367 LPFC_MBOXQ_t *mbox;
368 struct lpfc_dmabuf *mp;
369 struct lpfc_nodelist *ndlp;
370 struct serv_parm *sp;
371 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400372 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500373
374 sp = &phba->fc_fabparam;
375 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500376 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400377 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400379 }
James Smart92d7f7b2007-06-17 19:56:38 -0500380
381 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400382 if (!mbox) {
383 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500384 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400385 }
James Smart92d7f7b2007-06-17 19:56:38 -0500386
387 vport->port_state = LPFC_FABRIC_CFG_LINK;
388 lpfc_config_link(phba, mbox);
389 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
390 mbox->vport = vport;
391
James Smart0b727fe2007-10-27 13:37:25 -0400392 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400393 if (rc == MBX_NOT_FINISHED) {
394 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500395 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400396 }
James Smart92d7f7b2007-06-17 19:56:38 -0500397
398 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400399 if (!mbox) {
400 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500401 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400402 }
James Smart40426292010-12-15 17:58:10 -0500403 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
404 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400405 if (rc) {
406 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500407 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400408 }
James Smart92d7f7b2007-06-17 19:56:38 -0500409
410 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
411 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
414 */
James Smart92d7f7b2007-06-17 19:56:38 -0500415 mbox->context2 = lpfc_nlp_get(ndlp);
416
James Smart0b727fe2007-10-27 13:37:25 -0400417 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400418 if (rc == MBX_NOT_FINISHED) {
419 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500420 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400421 }
James Smart92d7f7b2007-06-17 19:56:38 -0500422
423 return 0;
424
425fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
428 */
James Smart92d7f7b2007-06-17 19:56:38 -0500429 lpfc_nlp_put(ndlp);
430 mp = (struct lpfc_dmabuf *) mbox->context1;
431 lpfc_mbuf_free(phba, mp->virt, mp->phys);
432 kfree(mp);
433fail_free_mbox:
434 mempool_free(mbox, phba->mbox_mem_pool);
435
436fail:
437 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400439 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500440 return -ENXIO;
441}
442
James Smarte59058c2008-08-24 21:49:00 -0400443/**
James Smart6fb120a2009-05-22 14:52:59 -0400444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
446 *
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500448 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400449 *
450 * Return code
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
453 **/
James Smart1b511972011-12-13 13:23:09 -0500454int
James Smart6fb120a2009-05-22 14:52:59 -0400455lpfc_issue_reg_vfi(struct lpfc_vport *vport)
456{
457 struct lpfc_hba *phba = vport->phba;
James Smartd6de08c2015-12-16 18:11:53 -0500458 LPFC_MBOXQ_t *mboxq = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400459 struct lpfc_nodelist *ndlp;
James Smartd6de08c2015-12-16 18:11:53 -0500460 struct lpfc_dmabuf *dmabuf = NULL;
James Smart6fb120a2009-05-22 14:52:59 -0400461 int rc = 0;
462
James Smart939723a2012-05-09 21:19:03 -0400463 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500464 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400465 !(phba->link_flag & LS_LOOPBACK_MODE) &&
466 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500467 ndlp = lpfc_findnode_did(vport, Fabric_DID);
468 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
469 rc = -ENODEV;
470 goto fail;
471 }
James Smart6fb120a2009-05-22 14:52:59 -0400472 }
473
James Smart6fb120a2009-05-22 14:52:59 -0400474 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
475 if (!mboxq) {
476 rc = -ENOMEM;
James Smartd6de08c2015-12-16 18:11:53 -0500477 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400478 }
James Smartd6de08c2015-12-16 18:11:53 -0500479
480 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
481 if ((vport->fc_flag & FC_FABRIC) || (vport->fc_flag & FC_PT2PT)) {
482 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
483 if (!dmabuf) {
484 rc = -ENOMEM;
485 goto fail;
486 }
487 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
488 if (!dmabuf->virt) {
489 rc = -ENOMEM;
490 goto fail;
491 }
492 memcpy(dmabuf->virt, &phba->fc_fabparam,
493 sizeof(struct serv_parm));
494 }
495
James Smart6fb120a2009-05-22 14:52:59 -0400496 vport->port_state = LPFC_FABRIC_CFG_LINK;
James Smartd6de08c2015-12-16 18:11:53 -0500497 if (dmabuf)
498 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
499 else
500 lpfc_reg_vfi(mboxq, vport, 0);
James Smartae05ebe2013-03-01 16:35:38 -0500501
James Smart6fb120a2009-05-22 14:52:59 -0400502 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
503 mboxq->vport = vport;
504 mboxq->context1 = dmabuf;
505 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
506 if (rc == MBX_NOT_FINISHED) {
507 rc = -ENXIO;
James Smartd6de08c2015-12-16 18:11:53 -0500508 goto fail;
James Smart6fb120a2009-05-22 14:52:59 -0400509 }
510 return 0;
511
James Smart6fb120a2009-05-22 14:52:59 -0400512fail:
James Smartd6de08c2015-12-16 18:11:53 -0500513 if (mboxq)
514 mempool_free(mboxq, phba->mbox_mem_pool);
515 if (dmabuf) {
516 if (dmabuf->virt)
517 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
518 kfree(dmabuf);
519 }
520
James Smart6fb120a2009-05-22 14:52:59 -0400521 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
522 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
523 "0289 Issue Register VFI failed: Err %d\n", rc);
524 return rc;
525}
526
527/**
James Smart1b511972011-12-13 13:23:09 -0500528 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
529 * @vport: pointer to a host virtual N_Port data structure.
530 *
531 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
532 * the @vport. This mailbox command is necessary for SLI4 port only.
533 *
534 * Return code
535 * 0 - successfully issued REG_VFI for @vport
536 * A failure code otherwise.
537 **/
538int
539lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
540{
541 struct lpfc_hba *phba = vport->phba;
542 struct Scsi_Host *shost;
543 LPFC_MBOXQ_t *mboxq;
544 int rc;
545
546 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
547 if (!mboxq) {
548 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
549 "2556 UNREG_VFI mbox allocation failed"
550 "HBA state x%x\n", phba->pport->port_state);
551 return -ENOMEM;
552 }
553
554 lpfc_unreg_vfi(mboxq, vport);
555 mboxq->vport = vport;
556 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
557
558 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
559 if (rc == MBX_NOT_FINISHED) {
560 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
561 "2557 UNREG_VFI issue mbox failed rc x%x "
562 "HBA state x%x\n",
563 rc, phba->pport->port_state);
564 mempool_free(mboxq, phba->mbox_mem_pool);
565 return -EIO;
566 }
567
568 shost = lpfc_shost_from_vport(vport);
569 spin_lock_irq(shost->host_lock);
570 vport->fc_flag &= ~FC_VFI_REGISTERED;
571 spin_unlock_irq(shost->host_lock);
572 return 0;
573}
574
575/**
James Smart92494142011-02-16 12:39:44 -0500576 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
577 * @vport: pointer to a host virtual N_Port data structure.
578 * @sp: pointer to service parameter data structure.
579 *
580 * This routine is called from FLOGI/FDISC completion handler functions.
581 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
582 * node nodename is changed in the completion service parameter else return
583 * 0. This function also set flag in the vport data structure to delay
584 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
585 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
586 * node nodename is changed in the completion service parameter.
587 *
588 * Return code
589 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
590 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
591 *
592 **/
593static uint8_t
594lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
595 struct serv_parm *sp)
596{
597 uint8_t fabric_param_changed = 0;
598 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
599
600 if ((vport->fc_prevDID != vport->fc_myDID) ||
601 memcmp(&vport->fabric_portname, &sp->portName,
602 sizeof(struct lpfc_name)) ||
603 memcmp(&vport->fabric_nodename, &sp->nodeName,
604 sizeof(struct lpfc_name)))
605 fabric_param_changed = 1;
606
607 /*
608 * Word 1 Bit 31 in common service parameter is overloaded.
609 * Word 1 Bit 31 in FLOGI request is multiple NPort request
610 * Word 1 Bit 31 in FLOGI response is clean address bit
611 *
612 * If fabric parameter is changed and clean address bit is
613 * cleared delay nport discovery if
614 * - vport->fc_prevDID != 0 (not initial discovery) OR
615 * - lpfc_delay_discovery module parameter is set.
616 */
617 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
618 (vport->fc_prevDID || lpfc_delay_discovery)) {
619 spin_lock_irq(shost->host_lock);
620 vport->fc_flag |= FC_DISC_DELAYED;
621 spin_unlock_irq(shost->host_lock);
622 }
623
624 return fabric_param_changed;
625}
626
627
628/**
James Smart3621a712009-04-06 18:47:14 -0400629 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400630 * @vport: pointer to a host virtual N_Port data structure.
631 * @ndlp: pointer to a node-list data structure.
632 * @sp: pointer to service parameter data structure.
633 * @irsp: pointer to the IOCB within the lpfc response IOCB.
634 *
635 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
636 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
637 * port in a fabric topology. It properly sets up the parameters to the @ndlp
638 * from the IOCB response. It also check the newly assigned N_Port ID to the
639 * @vport against the previously assigned N_Port ID. If it is different from
640 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
641 * is invoked on all the remaining nodes with the @vport to unregister the
642 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
643 * is invoked to register login to the fabric.
644 *
645 * Return code
646 * 0 - Success (currently, always return 0)
647 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500648static int
James Smart2e0fef82007-06-17 19:56:36 -0500649lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
650 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500651{
James Smart2e0fef82007-06-17 19:56:36 -0500652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
653 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500654 struct lpfc_nodelist *np;
655 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500656 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500657
James Smart2e0fef82007-06-17 19:56:36 -0500658 spin_lock_irq(shost->host_lock);
659 vport->fc_flag |= FC_FABRIC;
660 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500661
662 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
663 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
664 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
665
James Smart12265f62010-10-22 11:05:53 -0400666 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500667 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
668
James Smart76a95d72010-11-20 23:11:48 -0500669 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500670 spin_lock_irq(shost->host_lock);
671 vport->fc_flag |= FC_PUBLIC_LOOP;
672 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500673 }
674
James Smart2e0fef82007-06-17 19:56:36 -0500675 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500676 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500677 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500678 ndlp->nlp_class_sup = 0;
679 if (sp->cls1.classValid)
680 ndlp->nlp_class_sup |= FC_COS_CLASS1;
681 if (sp->cls2.classValid)
682 ndlp->nlp_class_sup |= FC_COS_CLASS2;
683 if (sp->cls3.classValid)
684 ndlp->nlp_class_sup |= FC_COS_CLASS3;
685 if (sp->cls4.classValid)
686 ndlp->nlp_class_sup |= FC_COS_CLASS4;
687 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
688 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500689
690 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
James Smart4258e982015-12-16 18:11:58 -0500691 if (fabric_param_changed) {
692 /* Reset FDMI attribute masks based on config parameter */
James Smart8663cbb2016-03-31 14:12:33 -0700693 if (phba->cfg_enable_SmartSAN ||
694 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) {
James Smart4258e982015-12-16 18:11:58 -0500695 /* Setup appropriate attribute masks */
696 vport->fdmi_hba_mask = LPFC_FDMI2_HBA_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700697 if (phba->cfg_enable_SmartSAN)
James Smart4258e982015-12-16 18:11:58 -0500698 vport->fdmi_port_mask = LPFC_FDMI2_SMART_ATTR;
699 else
700 vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
James Smart8663cbb2016-03-31 14:12:33 -0700701 } else {
702 vport->fdmi_hba_mask = 0;
703 vport->fdmi_port_mask = 0;
James Smart4258e982015-12-16 18:11:58 -0500704 }
705
706 }
James Smart92494142011-02-16 12:39:44 -0500707 memcpy(&vport->fabric_portname, &sp->portName,
708 sizeof(struct lpfc_name));
709 memcpy(&vport->fabric_nodename, &sp->nodeName,
710 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500711 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
712
James Smart92d7f7b2007-06-17 19:56:38 -0500713 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
714 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400715 lpfc_printf_vlog(vport, KERN_WARNING,
716 LOG_ELS | LOG_VPORT,
717 "1816 FLOGI NPIV supported, "
718 "response data 0x%x\n",
719 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500720 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500721 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500722 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500723 } else {
724 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400725 to call reg_vnpid atleast for the physcial host */
726 lpfc_printf_vlog(vport, KERN_WARNING,
727 LOG_ELS | LOG_VPORT,
728 "1817 Fabric does not support NPIV "
729 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500730 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500731 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500732 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500733 }
734 }
735
James Smartae05ebe2013-03-01 16:35:38 -0500736 /*
737 * For FC we need to do some special processing because of the SLI
738 * Port's default settings of the Common Service Parameters.
739 */
James Smartd6de08c2015-12-16 18:11:53 -0500740 if ((phba->sli_rev == LPFC_SLI_REV4) &&
741 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500742 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500743 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500744 lpfc_unregister_fcf_prep(phba);
745
746 /* This should just update the VFI CSPs*/
747 if (vport->fc_flag & FC_VFI_REGISTERED)
748 lpfc_issue_reg_vfi(vport);
749 }
750
James Smart92494142011-02-16 12:39:44 -0500751 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500752 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
753
754 /* If our NportID changed, we need to ensure all
755 * remaining NPORTs get unreg_login'ed.
756 */
757 list_for_each_entry_safe(np, next_np,
758 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400759 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500760 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500761 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
762 !(np->nlp_flag & NLP_NPR_ADISC))
763 continue;
764 spin_lock_irq(shost->host_lock);
765 np->nlp_flag &= ~NLP_NPR_ADISC;
766 spin_unlock_irq(shost->host_lock);
767 lpfc_unreg_rpi(vport, np);
768 }
James Smart78730cf2010-04-06 15:06:30 -0400769 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400770
James Smart5248a742011-07-22 18:37:06 -0400771 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400772 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500773 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500774 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500775 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
776 spin_unlock_irq(shost->host_lock);
777 }
James Smart27aa1b72012-05-09 21:18:49 -0400778
779 /*
780 * For SLI3 and SLI4, the VPI needs to be reregistered in
781 * response to this fabric parameter change event.
782 */
783 spin_lock_irq(shost->host_lock);
784 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
785 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400786 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
787 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
788 /*
789 * Driver needs to re-reg VPI in order for f/w
790 * to update the MAC address.
791 */
James Smart9589b0622011-04-16 11:03:17 -0400792 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400793 lpfc_register_new_vport(phba, vport, ndlp);
794 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500795 }
796
James Smart6fb120a2009-05-22 14:52:59 -0400797 if (phba->sli_rev < LPFC_SLI_REV4) {
798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
799 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
800 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
801 lpfc_register_new_vport(phba, vport, ndlp);
802 else
803 lpfc_issue_fabric_reglogin(vport);
804 } else {
805 ndlp->nlp_type |= NLP_FABRIC;
806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500807 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
808 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400809 lpfc_start_fdiscs(phba);
810 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500811 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500812 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500813 else {
814 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
815 "3135 Need register VFI: (x%x/%x)\n",
816 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400817 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500818 }
James Smart92d7f7b2007-06-17 19:56:38 -0500819 }
dea31012005-04-17 16:05:31 -0500820 return 0;
dea31012005-04-17 16:05:31 -0500821}
James Smart1b511972011-12-13 13:23:09 -0500822
James Smarte59058c2008-08-24 21:49:00 -0400823/**
James Smart3621a712009-04-06 18:47:14 -0400824 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400825 * @vport: pointer to a host virtual N_Port data structure.
826 * @ndlp: pointer to a node-list data structure.
827 * @sp: pointer to service parameter data structure.
828 *
829 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
830 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
831 * in a point-to-point topology. First, the @vport's N_Port Name is compared
832 * with the received N_Port Name: if the @vport's N_Port Name is greater than
833 * the received N_Port Name lexicographically, this node shall assign local
834 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
835 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
836 * this node shall just wait for the remote node to issue PLOGI and assign
837 * N_Port IDs.
838 *
839 * Return code
840 * 0 - Success
841 * -ENXIO - Fail
842 **/
dea31012005-04-17 16:05:31 -0500843static int
James Smart2e0fef82007-06-17 19:56:36 -0500844lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
845 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500846{
James Smart2e0fef82007-06-17 19:56:36 -0500847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
848 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500849 LPFC_MBOXQ_t *mbox;
850 int rc;
851
James Smart2e0fef82007-06-17 19:56:36 -0500852 spin_lock_irq(shost->host_lock);
853 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500854 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500855 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500856
James Smartd6de08c2015-12-16 18:11:53 -0500857 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
858 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
859 lpfc_unregister_fcf_prep(phba);
860
861 spin_lock_irq(shost->host_lock);
862 vport->fc_flag &= ~FC_VFI_REGISTERED;
863 spin_unlock_irq(shost->host_lock);
864 phba->fc_topology_changed = 0;
865 }
866
James Smart2e0fef82007-06-17 19:56:36 -0500867 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500868 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400869
dea31012005-04-17 16:05:31 -0500870 if (rc >= 0) {
871 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500872 spin_lock_irq(shost->host_lock);
873 vport->fc_flag |= FC_PT2PT_PLOGI;
874 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500875
876 /*
James Smartd6de08c2015-12-16 18:11:53 -0500877 * N_Port ID cannot be 0, set our Id to LocalID
878 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500879 */
880
881 /* not equal */
882 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500883 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500884
James Smarte47c9092008-02-08 18:49:26 -0500885 /* Decrement ndlp reference count indicating that ndlp can be
886 * safely released when other references to it are done.
887 */
James Smart329f9bc2007-04-25 09:53:01 -0400888 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500889
James Smart2e0fef82007-06-17 19:56:36 -0500890 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500891 if (!ndlp) {
892 /*
893 * Cannot find existing Fabric ndlp, so allocate a
894 * new one
895 */
896 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
897 if (!ndlp)
898 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500899 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500900 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
901 ndlp = lpfc_enable_node(vport, ndlp,
902 NLP_STE_UNUSED_NODE);
903 if(!ndlp)
904 goto fail;
dea31012005-04-17 16:05:31 -0500905 }
906
907 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500908 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500909 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500910 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500911 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500912 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
913 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500914 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500915 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500916 } else
917 /* This side will wait for the PLOGI, decrement ndlp reference
918 * count indicating that ndlp can be released when other
919 * references to it are done.
920 */
James Smart329f9bc2007-04-25 09:53:01 -0400921 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500922
James Smart09372822008-01-11 01:52:54 -0500923 /* If we are pt2pt with another NPort, force NPIV off! */
924 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
925
James Smartd6de08c2015-12-16 18:11:53 -0500926 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
927 if (!mbox)
928 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400929
James Smartd6de08c2015-12-16 18:11:53 -0500930 lpfc_config_link(phba, mbox);
931
932 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
933 mbox->vport = vport;
934 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
935 if (rc == MBX_NOT_FINISHED) {
936 mempool_free(mbox, phba->mbox_mem_pool);
937 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400938 }
dea31012005-04-17 16:05:31 -0500939
dea31012005-04-17 16:05:31 -0500940 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500941fail:
dea31012005-04-17 16:05:31 -0500942 return -ENXIO;
943}
944
James Smarte59058c2008-08-24 21:49:00 -0400945/**
James Smart3621a712009-04-06 18:47:14 -0400946 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400947 * @phba: pointer to lpfc hba data structure.
948 * @cmdiocb: pointer to lpfc command iocb data structure.
949 * @rspiocb: pointer to lpfc response iocb data structure.
950 *
951 * This routine is the top-level completion callback function for issuing
952 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
953 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
954 * retry has been made (either immediately or delayed with lpfc_els_retry()
955 * returning 1), the command IOCB will be released and function returned.
956 * If the retry attempt has been given up (possibly reach the maximum
957 * number of retries), one additional decrement of ndlp reference shall be
958 * invoked before going out after releasing the command IOCB. This will
959 * actually release the remote node (Note, lpfc_els_free_iocb() will also
960 * invoke one decrement of ndlp reference count). If no error reported in
961 * the IOCB status, the command Port ID field is used to determine whether
962 * this is a point-to-point topology or a fabric topology: if the Port ID
963 * field is assigned, it is a fabric topology; otherwise, it is a
964 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
965 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
966 * specific topology completion conditions.
967 **/
dea31012005-04-17 16:05:31 -0500968static void
James Smart329f9bc2007-04-25 09:53:01 -0400969lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
970 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500971{
James Smart2e0fef82007-06-17 19:56:36 -0500972 struct lpfc_vport *vport = cmdiocb->vport;
973 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500974 IOCB_t *irsp = &rspiocb->iocb;
975 struct lpfc_nodelist *ndlp = cmdiocb->context1;
976 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
977 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500978 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500979 int rc;
980
981 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500982 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500983 /* One additional decrement on node reference count to
984 * trigger the release of the node
985 */
James Smart329f9bc2007-04-25 09:53:01 -0400986 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500987 goto out;
988 }
989
James Smart858c9f62007-06-17 19:56:39 -0500990 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
991 "FLOGI cmpl: status:x%x/x%x state:x%x",
992 irsp->ulpStatus, irsp->un.ulpWord[4],
993 vport->port_state);
994
dea31012005-04-17 16:05:31 -0500995 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500996 /*
James Smarta93ff372010-10-22 11:06:08 -0400997 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500998 * due to new FCF discovery
999 */
1000 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -05001001 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
1002 if (phba->link_state < LPFC_LINK_UP)
1003 goto stop_rr_fcf_flogi;
1004 if ((phba->fcoe_cvl_eventtag_attn ==
1005 phba->fcoe_cvl_eventtag) &&
1006 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -04001007 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
1008 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -05001009 goto stop_rr_fcf_flogi;
1010 else
1011 phba->fcoe_cvl_eventtag_attn =
1012 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -05001013 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001014 "2611 FLOGI failed on FCF (x%x), "
1015 "status:x%x/x%x, tmo:x%x, perform "
1016 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001017 phba->fcf.current_rec.fcf_indx,
1018 irsp->ulpStatus, irsp->un.ulpWord[4],
1019 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001020 lpfc_sli4_set_fcf_flogi_fail(phba,
1021 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001022 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001023 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1024 if (rc)
1025 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001026 }
1027
James Smart80c17842012-03-01 22:35:45 -05001028stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001029 /* FLOGI failure */
1030 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart8fe5c162015-08-31 16:48:19 -04001031 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1032 "Data x%x x%x\n",
James Smart38b92ef2010-08-04 16:11:39 -04001033 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart8fe5c162015-08-31 16:48:19 -04001034 irsp->ulpTimeout, phba->hba_flag,
1035 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001036
dea31012005-04-17 16:05:31 -05001037 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001038 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001039 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001040
James Smart76a95d72010-11-20 23:11:48 -05001041 /* FLOGI failure */
1042 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1043 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1044 irsp->ulpStatus, irsp->un.ulpWord[4],
1045 irsp->ulpTimeout);
1046
dea31012005-04-17 16:05:31 -05001047 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001048 spin_lock_irq(shost->host_lock);
1049 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1050 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001051
James Smart329f9bc2007-04-25 09:53:01 -04001052 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001053 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1054 * alpa map would take too long otherwise.
1055 */
James Smart1b511972011-12-13 13:23:09 -05001056 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001057 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001058 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1059 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001060 (vport->fc_prevDID != vport->fc_myDID) ||
1061 phba->fc_topology_changed)) {
1062 if (vport->fc_flag & FC_VFI_REGISTERED) {
1063 if (phba->fc_topology_changed) {
1064 lpfc_unregister_fcf_prep(phba);
1065 spin_lock_irq(shost->host_lock);
1066 vport->fc_flag &= ~FC_VFI_REGISTERED;
1067 spin_unlock_irq(shost->host_lock);
1068 phba->fc_topology_changed = 0;
1069 } else {
1070 lpfc_sli4_unreg_all_rpis(vport);
1071 }
1072 }
James Smart342b59c2016-03-31 14:12:31 -07001073
1074 /* Do not register VFI if the driver aborted FLOGI */
1075 if (!lpfc_error_lost_link(irsp))
1076 lpfc_issue_reg_vfi(vport);
James Smartff78d8f2011-12-13 13:21:35 -05001077 lpfc_nlp_put(ndlp);
1078 goto out;
dea31012005-04-17 16:05:31 -05001079 }
dea31012005-04-17 16:05:31 -05001080 goto flogifail;
1081 }
James Smart695a8142010-01-26 23:08:03 -05001082 spin_lock_irq(shost->host_lock);
1083 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001084 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001085 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001086
1087 /*
1088 * The FLogI succeeded. Sync the data for the CPU before
1089 * accessing it.
1090 */
1091 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001092 if (!prsp)
1093 goto out;
dea31012005-04-17 16:05:31 -05001094 sp = prsp->virt + sizeof(uint32_t);
1095
1096 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001097 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001098 "0101 FLOGI completes successfully, I/O tag:x%x, "
1099 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001100 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001101 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1102 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001103
James Smart2e0fef82007-06-17 19:56:36 -05001104 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001105 /*
1106 * If Common Service Parameters indicate Nport
1107 * we are point to point, if Fport we are Fabric.
1108 */
1109 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001110 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001111 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001112 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001113 else {
1114 lpfc_printf_vlog(vport, KERN_ERR,
1115 LOG_FIP | LOG_ELS,
1116 "2831 FLOGI response with cleared Fabric "
1117 "bit fcf_index 0x%x "
1118 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1119 "Fabric Name "
1120 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1121 phba->fcf.current_rec.fcf_indx,
1122 phba->fcf.current_rec.switch_name[0],
1123 phba->fcf.current_rec.switch_name[1],
1124 phba->fcf.current_rec.switch_name[2],
1125 phba->fcf.current_rec.switch_name[3],
1126 phba->fcf.current_rec.switch_name[4],
1127 phba->fcf.current_rec.switch_name[5],
1128 phba->fcf.current_rec.switch_name[6],
1129 phba->fcf.current_rec.switch_name[7],
1130 phba->fcf.current_rec.fabric_name[0],
1131 phba->fcf.current_rec.fabric_name[1],
1132 phba->fcf.current_rec.fabric_name[2],
1133 phba->fcf.current_rec.fabric_name[3],
1134 phba->fcf.current_rec.fabric_name[4],
1135 phba->fcf.current_rec.fabric_name[5],
1136 phba->fcf.current_rec.fabric_name[6],
1137 phba->fcf.current_rec.fabric_name[7]);
1138 lpfc_nlp_put(ndlp);
1139 spin_lock_irq(&phba->hbalock);
1140 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001141 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001142 spin_unlock_irq(&phba->hbalock);
1143 goto out;
1144 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001145 if (!rc) {
1146 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001147 if (phba->hba_flag & HBA_FIP_SUPPORT)
1148 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1149 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001150 "2769 FLOGI to FCF (x%x) "
1151 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001152 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001153 spin_lock_irq(&phba->hbalock);
1154 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001155 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001156 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001157 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001158 }
dea31012005-04-17 16:05:31 -05001159 }
1160
1161flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001162 spin_lock_irq(&phba->hbalock);
1163 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1164 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001165
James Smart329f9bc2007-04-25 09:53:01 -04001166 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001167
James Smart858c9f62007-06-17 19:56:39 -05001168 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001169 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001170 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001171
1172 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001173 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001174 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001175 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1176 IOERR_SLI_ABORTED) &&
1177 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1178 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001179 (phba->link_state != LPFC_CLEAR_LA)) {
1180 /* If FLOGI failed enable link interrupt. */
1181 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001182 }
dea31012005-04-17 16:05:31 -05001183out:
1184 lpfc_els_free_iocb(phba, cmdiocb);
1185}
1186
James Smarte59058c2008-08-24 21:49:00 -04001187/**
James Smart3621a712009-04-06 18:47:14 -04001188 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001189 * @vport: pointer to a host virtual N_Port data structure.
1190 * @ndlp: pointer to a node-list data structure.
1191 * @retry: number of retries to the command IOCB.
1192 *
1193 * This routine issues a Fabric Login (FLOGI) Request ELS command
1194 * for a @vport. The initiator service parameters are put into the payload
1195 * of the FLOGI Request IOCB and the top-level callback function pointer
1196 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1197 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1198 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1199 *
1200 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1201 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1202 * will be stored into the context1 field of the IOCB for the completion
1203 * callback function to the FLOGI ELS command.
1204 *
1205 * Return code
1206 * 0 - successfully issued flogi iocb for @vport
1207 * 1 - failed to issue flogi iocb for @vport
1208 **/
dea31012005-04-17 16:05:31 -05001209static int
James Smart2e0fef82007-06-17 19:56:36 -05001210lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001211 uint8_t retry)
1212{
James Smart2e0fef82007-06-17 19:56:36 -05001213 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001214 struct serv_parm *sp;
1215 IOCB_t *icmd;
1216 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001217 uint8_t *pcmd;
1218 uint16_t cmdsize;
1219 uint32_t tmo;
1220 int rc;
1221
James Smart92d7f7b2007-06-17 19:56:38 -05001222 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001223 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1224 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001225
James Smart488d1462006-03-07 15:02:37 -05001226 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001227 return 1;
dea31012005-04-17 16:05:31 -05001228
1229 icmd = &elsiocb->iocb;
1230 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1231
1232 /* For FLOGI request, remainder of payload is service parameters */
1233 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001234 pcmd += sizeof(uint32_t);
1235 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001236 sp = (struct serv_parm *) pcmd;
1237
1238 /* Setup CSPs accordingly for Fabric */
1239 sp->cmn.e_d_tov = 0;
1240 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001241 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001242 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001243 if (sp->cmn.fcphLow < FC_PH3)
1244 sp->cmn.fcphLow = FC_PH3;
1245 if (sp->cmn.fcphHigh < FC_PH3)
1246 sp->cmn.fcphHigh = FC_PH3;
1247
James Smartc31098c2011-04-16 11:03:33 -04001248 if (phba->sli_rev == LPFC_SLI_REV4) {
1249 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1250 LPFC_SLI_INTF_IF_TYPE_0) {
1251 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1252 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1253 /* FLOGI needs to be 3 for WQE FCFI */
1254 /* Set the fcfi to the fcfi we registered with */
1255 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1256 }
James Smart0f378872012-10-31 14:45:01 -04001257 /* Can't do SLI4 class2 without support sequence coalescing */
1258 sp->cls2.classValid = 0;
1259 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001260 } else {
James Smart0f378872012-10-31 14:45:01 -04001261 /* Historical, setting sequential-delivery bit for SLI3 */
1262 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1263 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001264 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1265 sp->cmn.request_multiple_Nport = 1;
1266 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1267 icmd->ulpCt_h = 1;
1268 icmd->ulpCt_l = 0;
1269 } else
1270 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001271 }
1272
James Smart76a95d72010-11-20 23:11:48 -05001273 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001274 icmd->un.elsreq64.myID = 0;
1275 icmd->un.elsreq64.fl = 1;
1276 }
1277
dea31012005-04-17 16:05:31 -05001278 tmo = phba->fc_ratov;
1279 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001280 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001281 phba->fc_ratov = tmo;
1282
1283 phba->fc_stat.elsXmitFLOGI++;
1284 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001285
1286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1287 "Issue FLOGI: opt:x%x",
1288 phba->sli3_options, 0, 0);
1289
James Smart92d7f7b2007-06-17 19:56:38 -05001290 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001291 if (rc == IOCB_ERROR) {
1292 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001293 return 1;
dea31012005-04-17 16:05:31 -05001294 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001295 return 0;
dea31012005-04-17 16:05:31 -05001296}
1297
James Smarte59058c2008-08-24 21:49:00 -04001298/**
James Smart3621a712009-04-06 18:47:14 -04001299 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001300 * @phba: pointer to lpfc hba data structure.
1301 *
1302 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1303 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1304 * list and issues an abort IOCB commond on each outstanding IOCB that
1305 * contains a active Fabric_DID ndlp. Note that this function is to issue
1306 * the abort IOCB command on all the outstanding IOCBs, thus when this
1307 * function returns, it does not guarantee all the IOCBs are actually aborted.
1308 *
1309 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001310 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001311 **/
dea31012005-04-17 16:05:31 -05001312int
James Smart2e0fef82007-06-17 19:56:36 -05001313lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001314{
1315 struct lpfc_sli_ring *pring;
1316 struct lpfc_iocbq *iocb, *next_iocb;
1317 struct lpfc_nodelist *ndlp;
1318 IOCB_t *icmd;
1319
1320 /* Abort outstanding I/O on NPort <nlp_DID> */
1321 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001322 "0201 Abort outstanding I/O on NPort x%x\n",
1323 Fabric_DID);
dea31012005-04-17 16:05:31 -05001324
1325 pring = &phba->sli.ring[LPFC_ELS_RING];
1326
1327 /*
1328 * Check the txcmplq for an iocb that matches the nport the driver is
1329 * searching for.
1330 */
James Smart2e0fef82007-06-17 19:56:36 -05001331 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001332 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1333 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001334 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001335 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001336 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1337 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001338 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001339 }
1340 }
James Smart2e0fef82007-06-17 19:56:36 -05001341 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001342
1343 return 0;
1344}
1345
James Smarte59058c2008-08-24 21:49:00 -04001346/**
James Smart3621a712009-04-06 18:47:14 -04001347 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001348 * @vport: pointer to a host virtual N_Port data structure.
1349 *
1350 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1351 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1352 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1353 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1354 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1355 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1356 * @vport.
1357 *
1358 * Return code
1359 * 0 - failed to issue initial flogi for @vport
1360 * 1 - successfully issued initial flogi for @vport
1361 **/
dea31012005-04-17 16:05:31 -05001362int
James Smart2e0fef82007-06-17 19:56:36 -05001363lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001364{
James Smart2e0fef82007-06-17 19:56:36 -05001365 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001366 struct lpfc_nodelist *ndlp;
1367
James Smart98c9ea52007-10-27 13:37:33 -04001368 vport->port_state = LPFC_FLOGI;
1369 lpfc_set_disctmo(vport);
1370
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001371 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001372 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001373 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001374 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001375 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1376 if (!ndlp)
1377 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001378 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001379 /* Set the node type */
1380 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001381 /* Put ndlp onto node list */
1382 lpfc_enqueue_node(vport, ndlp);
1383 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1384 /* re-setup ndlp without removing from node list */
1385 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1386 if (!ndlp)
1387 return 0;
dea31012005-04-17 16:05:31 -05001388 }
James Smart87af33f2007-10-27 13:37:43 -04001389
James Smart5ac6b302010-10-22 11:05:36 -04001390 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001391 /* This decrement of reference count to node shall kick off
1392 * the release of the node.
1393 */
James Smart329f9bc2007-04-25 09:53:01 -04001394 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001395 return 0;
1396 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001397 return 1;
dea31012005-04-17 16:05:31 -05001398}
1399
James Smarte59058c2008-08-24 21:49:00 -04001400/**
James Smart3621a712009-04-06 18:47:14 -04001401 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001402 * @vport: pointer to a host virtual N_Port data structure.
1403 *
1404 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1405 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1406 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1407 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1408 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1409 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1410 * @vport.
1411 *
1412 * Return code
1413 * 0 - failed to issue initial fdisc for @vport
1414 * 1 - successfully issued initial fdisc for @vport
1415 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001416int
1417lpfc_initial_fdisc(struct lpfc_vport *vport)
1418{
1419 struct lpfc_hba *phba = vport->phba;
1420 struct lpfc_nodelist *ndlp;
1421
1422 /* First look for the Fabric ndlp */
1423 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1424 if (!ndlp) {
1425 /* Cannot find existing Fabric ndlp, so allocate a new one */
1426 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1427 if (!ndlp)
1428 return 0;
1429 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001430 /* Put ndlp onto node list */
1431 lpfc_enqueue_node(vport, ndlp);
1432 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1433 /* re-setup ndlp without removing from node list */
1434 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1435 if (!ndlp)
1436 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001437 }
James Smarte47c9092008-02-08 18:49:26 -05001438
James Smart92d7f7b2007-06-17 19:56:38 -05001439 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001440 /* decrement node reference count to trigger the release of
1441 * the node.
1442 */
James Smart92d7f7b2007-06-17 19:56:38 -05001443 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001444 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001445 }
1446 return 1;
1447}
James Smart87af33f2007-10-27 13:37:43 -04001448
James Smarte59058c2008-08-24 21:49:00 -04001449/**
James Smart3621a712009-04-06 18:47:14 -04001450 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001451 * @vport: pointer to a host virtual N_Port data structure.
1452 *
1453 * This routine checks whether there are more remaining Port Logins
1454 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1455 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1456 * to issue ELS PLOGIs up to the configured discover threads with the
1457 * @vport (@vport->cfg_discovery_threads). The function also decrement
1458 * the @vport's num_disc_node by 1 if it is not already 0.
1459 **/
James Smart87af33f2007-10-27 13:37:43 -04001460void
James Smart2e0fef82007-06-17 19:56:36 -05001461lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001462{
James Smart2e0fef82007-06-17 19:56:36 -05001463 if (vport->num_disc_nodes)
1464 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001465
1466 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001467 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1468 "0232 Continue discovery with %d PLOGIs to go "
1469 "Data: x%x x%x x%x\n",
1470 vport->num_disc_nodes, vport->fc_plogi_cnt,
1471 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001472 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001473 if (vport->fc_flag & FC_NLP_MORE)
1474 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001475 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001476
dea31012005-04-17 16:05:31 -05001477 return;
1478}
1479
James Smarte59058c2008-08-24 21:49:00 -04001480/**
James Smart3621a712009-04-06 18:47:14 -04001481 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001482 * @phba: pointer to lpfc hba data structure.
1483 * @prsp: pointer to response IOCB payload.
1484 * @ndlp: pointer to a node-list data structure.
1485 *
1486 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1487 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1488 * The following cases are considered N_Port confirmed:
1489 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1490 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1491 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1492 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1493 * 1) if there is a node on vport list other than the @ndlp with the same
1494 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1495 * on that node to release the RPI associated with the node; 2) if there is
1496 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1497 * into, a new node shall be allocated (or activated). In either case, the
1498 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1499 * be released and the new_ndlp shall be put on to the vport node list and
1500 * its pointer returned as the confirmed node.
1501 *
1502 * Note that before the @ndlp got "released", the keepDID from not-matching
1503 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1504 * of the @ndlp. This is because the release of @ndlp is actually to put it
1505 * into an inactive state on the vport node list and the vport node list
1506 * management algorithm does not allow two node with a same DID.
1507 *
1508 * Return code
1509 * pointer to the PLOGI N_Port @ndlp
1510 **/
James Smart488d1462006-03-07 15:02:37 -05001511static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001512lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001513 struct lpfc_nodelist *ndlp)
1514{
James Smart2e0fef82007-06-17 19:56:36 -05001515 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001516 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001517 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001518 struct lpfc_rport_data *rdata;
1519 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001520 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001521 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001522 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001523 uint16_t keep_nlp_state;
James Smart38b92ef2010-08-04 16:11:39 -04001524 int put_node;
1525 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001526 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001527
James Smart2fb9bd82006-12-02 13:33:57 -05001528 /* Fabric nodes can have the same WWPN so we don't bother searching
1529 * by WWPN. Just return the ndlp that was given to us.
1530 */
1531 if (ndlp->nlp_type & NLP_FABRIC)
1532 return ndlp;
1533
James Smart92d7f7b2007-06-17 19:56:38 -05001534 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001535 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001536
James Smart685f0bf2007-04-25 09:53:08 -04001537 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001538 * we have for that ndlp. If not, we have some work to do.
1539 */
James Smart2e0fef82007-06-17 19:56:36 -05001540 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001541
James Smarte47c9092008-02-08 18:49:26 -05001542 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001543 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001544 if (phba->sli_rev == LPFC_SLI_REV4) {
1545 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1546 GFP_KERNEL);
1547 if (active_rrqs_xri_bitmap)
1548 memset(active_rrqs_xri_bitmap, 0,
1549 phba->cfg_rrq_xri_bitmap_sz);
1550 }
James Smart488d1462006-03-07 15:02:37 -05001551
James Smart34f5ad82012-08-03 12:35:03 -04001552 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1553 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1554 ndlp, ndlp->nlp_DID, new_ndlp);
1555
James Smart488d1462006-03-07 15:02:37 -05001556 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001557 rc = memcmp(&ndlp->nlp_portname, name,
1558 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001559 if (!rc) {
1560 if (active_rrqs_xri_bitmap)
1561 mempool_free(active_rrqs_xri_bitmap,
1562 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001563 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001564 }
James Smart488d1462006-03-07 15:02:37 -05001565 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
James Smartcff261f2013-12-17 20:29:47 -05001566 if (!new_ndlp) {
1567 if (active_rrqs_xri_bitmap)
1568 mempool_free(active_rrqs_xri_bitmap,
1569 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001570 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001571 }
James Smart2e0fef82007-06-17 19:56:36 -05001572 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001573 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001574 rc = memcmp(&ndlp->nlp_portname, name,
1575 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001576 if (!rc) {
1577 if (active_rrqs_xri_bitmap)
1578 mempool_free(active_rrqs_xri_bitmap,
1579 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001580 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001581 }
James Smarte47c9092008-02-08 18:49:26 -05001582 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1583 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001584 if (!new_ndlp) {
1585 if (active_rrqs_xri_bitmap)
1586 mempool_free(active_rrqs_xri_bitmap,
1587 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001588 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001589 }
James Smart58da1ff2008-04-07 10:15:56 -04001590 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001591 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1592 memcpy(active_rrqs_xri_bitmap,
1593 new_ndlp->active_rrqs_xri_bitmap,
1594 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001595 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001596 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001597 if (phba->sli_rev == LPFC_SLI_REV4 &&
1598 active_rrqs_xri_bitmap)
1599 memcpy(active_rrqs_xri_bitmap,
1600 new_ndlp->active_rrqs_xri_bitmap,
1601 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001602 }
James Smart488d1462006-03-07 15:02:37 -05001603
James Smart2e0fef82007-06-17 19:56:36 -05001604 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001605 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001606 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001607 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001608 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1609 ndlp->active_rrqs_xri_bitmap,
1610 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001611
James Smart953ceed2015-05-22 10:42:37 -04001612 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001613 keep_nlp_flag = new_ndlp->nlp_flag;
1614 new_ndlp->nlp_flag = ndlp->nlp_flag;
1615 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001616 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001617
James Smart953ceed2015-05-22 10:42:37 -04001618 /* Set nlp_states accordingly */
1619 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001620 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001621
James Smart2e0fef82007-06-17 19:56:36 -05001622 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001623 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1624 /* The new_ndlp is replacing ndlp totally, so we need
1625 * to put ndlp on UNUSED list and try to free it.
1626 */
James Smart34f5ad82012-08-03 12:35:03 -04001627 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1628 "3179 PLOGI confirm NEW: %x %x\n",
1629 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001630
1631 /* Fix up the rport accordingly */
1632 rport = ndlp->rport;
1633 if (rport) {
1634 rdata = rport->dd_data;
1635 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001636 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001637 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001638 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001639 rdata->pnode = lpfc_nlp_get(new_ndlp);
1640 new_ndlp->rport = rport;
1641 }
1642 new_ndlp->nlp_type = ndlp->nlp_type;
1643 }
James Smart58da1ff2008-04-07 10:15:56 -04001644 /* We shall actually free the ndlp with both nlp_DID and
1645 * nlp_portname fields equals 0 to avoid any ndlp on the
1646 * nodelist never to be used.
1647 */
1648 if (ndlp->nlp_DID == 0) {
1649 spin_lock_irq(&phba->ndlp_lock);
1650 NLP_SET_FREE_REQ(ndlp);
1651 spin_unlock_irq(&phba->ndlp_lock);
1652 }
James Smart0ff10d42008-01-11 01:52:36 -05001653
James Smart58da1ff2008-04-07 10:15:56 -04001654 /* Two ndlps cannot have the same did on the nodelist */
1655 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001656 if (phba->sli_rev == LPFC_SLI_REV4 &&
1657 active_rrqs_xri_bitmap)
1658 memcpy(ndlp->active_rrqs_xri_bitmap,
1659 active_rrqs_xri_bitmap,
1660 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001661
1662 if (!NLP_CHK_NODE_ACT(ndlp))
1663 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001664 }
James Smart92795652006-07-06 15:50:02 -04001665 else {
James Smart34f5ad82012-08-03 12:35:03 -04001666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1667 "3180 PLOGI confirm SWAP: %x %x\n",
1668 new_ndlp->nlp_DID, keepDID);
1669
James Smart2e0fef82007-06-17 19:56:36 -05001670 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001671
James Smart58da1ff2008-04-07 10:15:56 -04001672 /* Two ndlps cannot have the same did */
1673 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001674 if (phba->sli_rev == LPFC_SLI_REV4 &&
1675 active_rrqs_xri_bitmap)
1676 memcpy(ndlp->active_rrqs_xri_bitmap,
1677 active_rrqs_xri_bitmap,
1678 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001679
James Smart953ceed2015-05-22 10:42:37 -04001680 /* Since we are switching over to the new_ndlp,
1681 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001682 */
1683 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1684 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001685 keep_nlp_state = NLP_STE_NPR_NODE;
1686 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001687
James Smart38b92ef2010-08-04 16:11:39 -04001688 /* Fix up the rport accordingly */
1689 rport = ndlp->rport;
1690 if (rport) {
1691 rdata = rport->dd_data;
1692 put_node = rdata->pnode != NULL;
1693 put_rport = ndlp->rport != NULL;
1694 rdata->pnode = NULL;
1695 ndlp->rport = NULL;
1696 if (put_node)
1697 lpfc_nlp_put(ndlp);
1698 if (put_rport)
1699 put_device(&rport->dev);
1700 }
James Smart92795652006-07-06 15:50:02 -04001701 }
James Smartcff261f2013-12-17 20:29:47 -05001702 if (phba->sli_rev == LPFC_SLI_REV4 &&
1703 active_rrqs_xri_bitmap)
1704 mempool_free(active_rrqs_xri_bitmap,
1705 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001706 return new_ndlp;
1707}
1708
James Smarte59058c2008-08-24 21:49:00 -04001709/**
James Smart3621a712009-04-06 18:47:14 -04001710 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001711 * @vport: pointer to a host virtual N_Port data structure.
1712 *
1713 * This routine checks whether more Registration State Change
1714 * Notifications (RSCNs) came in while the discovery state machine was in
1715 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1716 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1717 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1718 * handling the RSCNs.
1719 **/
James Smart87af33f2007-10-27 13:37:43 -04001720void
1721lpfc_end_rscn(struct lpfc_vport *vport)
1722{
1723 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1724
1725 if (vport->fc_flag & FC_RSCN_MODE) {
1726 /*
1727 * Check to see if more RSCNs came in while we were
1728 * processing this one.
1729 */
1730 if (vport->fc_rscn_id_cnt ||
1731 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1732 lpfc_els_handle_rscn(vport);
1733 else {
1734 spin_lock_irq(shost->host_lock);
1735 vport->fc_flag &= ~FC_RSCN_MODE;
1736 spin_unlock_irq(shost->host_lock);
1737 }
1738 }
1739}
1740
James Smarte59058c2008-08-24 21:49:00 -04001741/**
James Smart19ca7602010-11-20 23:11:55 -05001742 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1743 * @phba: pointer to lpfc hba data structure.
1744 * @cmdiocb: pointer to lpfc command iocb data structure.
1745 * @rspiocb: pointer to lpfc response iocb data structure.
1746 *
1747 * This routine will call the clear rrq function to free the rrq and
1748 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1749 * exist then the clear_rrq is still called because the rrq needs to
1750 * be freed.
1751 **/
1752
1753static void
1754lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1755 struct lpfc_iocbq *rspiocb)
1756{
1757 struct lpfc_vport *vport = cmdiocb->vport;
1758 IOCB_t *irsp;
1759 struct lpfc_nodelist *ndlp;
1760 struct lpfc_node_rrq *rrq;
1761
1762 /* we pass cmdiocb to state machine which needs rspiocb as well */
1763 rrq = cmdiocb->context_un.rrq;
1764 cmdiocb->context_un.rsp_iocb = rspiocb;
1765
1766 irsp = &rspiocb->iocb;
1767 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1768 "RRQ cmpl: status:x%x/x%x did:x%x",
1769 irsp->ulpStatus, irsp->un.ulpWord[4],
1770 irsp->un.elsreq64.remoteID);
1771
1772 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1773 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1774 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1775 "2882 RRQ completes to NPort x%x "
1776 "with no ndlp. Data: x%x x%x x%x\n",
1777 irsp->un.elsreq64.remoteID,
1778 irsp->ulpStatus, irsp->un.ulpWord[4],
1779 irsp->ulpIoTag);
1780 goto out;
1781 }
1782
1783 /* rrq completes to NPort <nlp_DID> */
1784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1785 "2880 RRQ completes to NPort x%x "
1786 "Data: x%x x%x x%x x%x x%x\n",
1787 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1788 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1789
1790 if (irsp->ulpStatus) {
1791 /* Check for retry */
1792 /* RRQ failed Don't print the vport to vport rjts */
1793 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1794 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1795 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1796 (phba)->pport->cfg_log_verbose & LOG_ELS)
1797 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1798 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1799 ndlp->nlp_DID, irsp->ulpStatus,
1800 irsp->un.ulpWord[4]);
1801 }
1802out:
1803 if (rrq)
1804 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1805 lpfc_els_free_iocb(phba, cmdiocb);
1806 return;
1807}
1808/**
James Smart3621a712009-04-06 18:47:14 -04001809 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001810 * @phba: pointer to lpfc hba data structure.
1811 * @cmdiocb: pointer to lpfc command iocb data structure.
1812 * @rspiocb: pointer to lpfc response iocb data structure.
1813 *
1814 * This routine is the completion callback function for issuing the Port
1815 * Login (PLOGI) command. For PLOGI completion, there must be an active
1816 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001817 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001818 * ignored and command IOCB released. The PLOGI response IOCB status is
1819 * checked for error conditons. If there is error status reported, PLOGI
1820 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1821 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1822 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1823 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1824 * there are additional N_Port nodes with the vport that need to perform
1825 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1826 * PLOGIs.
1827 **/
dea31012005-04-17 16:05:31 -05001828static void
James Smart2e0fef82007-06-17 19:56:36 -05001829lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1830 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001831{
James Smart2e0fef82007-06-17 19:56:36 -05001832 struct lpfc_vport *vport = cmdiocb->vport;
1833 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001834 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001835 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001836 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001837 int disc, rc;
dea31012005-04-17 16:05:31 -05001838
dea31012005-04-17 16:05:31 -05001839 /* we pass cmdiocb to state machine which needs rspiocb as well */
1840 cmdiocb->context_un.rsp_iocb = rspiocb;
1841
1842 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001843 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1844 "PLOGI cmpl: status:x%x/x%x did:x%x",
1845 irsp->ulpStatus, irsp->un.ulpWord[4],
1846 irsp->un.elsreq64.remoteID);
1847
James Smart2e0fef82007-06-17 19:56:36 -05001848 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001849 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1851 "0136 PLOGI completes to NPort x%x "
1852 "with no ndlp. Data: x%x x%x x%x\n",
1853 irsp->un.elsreq64.remoteID,
1854 irsp->ulpStatus, irsp->un.ulpWord[4],
1855 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001856 goto out;
James Smarted957682007-06-17 19:56:37 -05001857 }
dea31012005-04-17 16:05:31 -05001858
1859 /* Since ndlp can be freed in the disc state machine, note if this node
1860 * is being used during discovery.
1861 */
James Smart2e0fef82007-06-17 19:56:36 -05001862 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001863 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001864 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001865 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001866 rc = 0;
1867
1868 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001869 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1870 "0102 PLOGI completes to NPort x%x "
1871 "Data: x%x x%x x%x x%x x%x\n",
1872 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1873 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001874 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001875 if (lpfc_els_chk_latt(vport)) {
1876 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001877 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001878 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001879 goto out;
1880 }
1881
dea31012005-04-17 16:05:31 -05001882 if (irsp->ulpStatus) {
1883 /* Check for retry */
1884 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1885 /* ELS command is being retried */
1886 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001887 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001888 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001889 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001890 }
1891 goto out;
1892 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001893 /* PLOGI failed Don't print the vport to vport rjts */
1894 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1895 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1896 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1897 (phba)->pport->cfg_log_verbose & LOG_ELS)
1898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001899 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1900 ndlp->nlp_DID, irsp->ulpStatus,
1901 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001902 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001903 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001904 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001905 else
James Smart2e0fef82007-06-17 19:56:36 -05001906 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001907 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001908 } else {
1909 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001910 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001911 cmdiocb->context2)->list.next,
1912 struct lpfc_dmabuf, list);
1913 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001914 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001915 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001916 }
1917
James Smart2e0fef82007-06-17 19:56:36 -05001918 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001919 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001920 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001921
James Smart2e0fef82007-06-17 19:56:36 -05001922 if (vport->num_disc_nodes == 0) {
1923 spin_lock_irq(shost->host_lock);
1924 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1925 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001926
James Smart2e0fef82007-06-17 19:56:36 -05001927 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001928 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001929 }
1930 }
1931
1932out:
1933 lpfc_els_free_iocb(phba, cmdiocb);
1934 return;
1935}
1936
James Smarte59058c2008-08-24 21:49:00 -04001937/**
James Smart3621a712009-04-06 18:47:14 -04001938 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001939 * @vport: pointer to a host virtual N_Port data structure.
1940 * @did: destination port identifier.
1941 * @retry: number of retries to the command IOCB.
1942 *
1943 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1944 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1945 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1946 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1947 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1948 *
1949 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1950 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1951 * will be stored into the context1 field of the IOCB for the completion
1952 * callback function to the PLOGI ELS command.
1953 *
1954 * Return code
1955 * 0 - Successfully issued a plogi for @vport
1956 * 1 - failed to issue a plogi for @vport
1957 **/
dea31012005-04-17 16:05:31 -05001958int
James Smart2e0fef82007-06-17 19:56:36 -05001959lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001960{
James Smart2e0fef82007-06-17 19:56:36 -05001961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001962 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04001963 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001964 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001965 uint8_t *pcmd;
1966 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001967 int ret;
dea31012005-04-17 16:05:31 -05001968
James Smart98c9ea52007-10-27 13:37:33 -04001969 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001970 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1971 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001972
James Smarte47c9092008-02-08 18:49:26 -05001973 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001974 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001975 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001976 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001977 if (!elsiocb)
1978 return 1;
dea31012005-04-17 16:05:31 -05001979
dea31012005-04-17 16:05:31 -05001980 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1981
1982 /* For PLOGI request, remainder of payload is service parameters */
1983 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001984 pcmd += sizeof(uint32_t);
1985 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001986 sp = (struct serv_parm *) pcmd;
1987
James Smart5ac6b302010-10-22 11:05:36 -04001988 /*
1989 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1990 * to device on remote loops work.
1991 */
1992 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1993 sp->cmn.altBbCredit = 1;
1994
dea31012005-04-17 16:05:31 -05001995 if (sp->cmn.fcphLow < FC_PH_4_3)
1996 sp->cmn.fcphLow = FC_PH_4_3;
1997
1998 if (sp->cmn.fcphHigh < FC_PH3)
1999 sp->cmn.fcphHigh = FC_PH3;
2000
James Smart858c9f62007-06-17 19:56:39 -05002001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2002 "Issue PLOGI: did:x%x",
2003 did, 0, 0);
2004
dea31012005-04-17 16:05:31 -05002005 phba->fc_stat.elsXmitPLOGI++;
2006 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04002007 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002008
2009 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05002010 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002011 return 1;
dea31012005-04-17 16:05:31 -05002012 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002013 return 0;
dea31012005-04-17 16:05:31 -05002014}
2015
James Smarte59058c2008-08-24 21:49:00 -04002016/**
James Smart3621a712009-04-06 18:47:14 -04002017 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04002018 * @phba: pointer to lpfc hba data structure.
2019 * @cmdiocb: pointer to lpfc command iocb data structure.
2020 * @rspiocb: pointer to lpfc response iocb data structure.
2021 *
2022 * This routine is the completion callback function for a Process Login
2023 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2024 * status. If there is error status reported, PRLI retry shall be attempted
2025 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2026 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2027 * ndlp to mark the PRLI completion.
2028 **/
dea31012005-04-17 16:05:31 -05002029static void
James Smart2e0fef82007-06-17 19:56:36 -05002030lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2031 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002032{
James Smart2e0fef82007-06-17 19:56:36 -05002033 struct lpfc_vport *vport = cmdiocb->vport;
2034 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002035 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002036 struct lpfc_nodelist *ndlp;
2037
dea31012005-04-17 16:05:31 -05002038 /* we pass cmdiocb to state machine which needs rspiocb as well */
2039 cmdiocb->context_un.rsp_iocb = rspiocb;
2040
2041 irsp = &(rspiocb->iocb);
2042 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002043 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002044 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002045 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002046
James Smart858c9f62007-06-17 19:56:39 -05002047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2048 "PRLI cmpl: status:x%x/x%x did:x%x",
2049 irsp->ulpStatus, irsp->un.ulpWord[4],
2050 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002051 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002052 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2053 "0103 PRLI completes to NPort x%x "
2054 "Data: x%x x%x x%x x%x\n",
2055 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2056 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002057
James Smart2e0fef82007-06-17 19:56:36 -05002058 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05002059 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002060 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002061 goto out;
2062
2063 if (irsp->ulpStatus) {
2064 /* Check for retry */
2065 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2066 /* ELS command is being retried */
2067 goto out;
2068 }
2069 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002070 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2071 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2072 ndlp->nlp_DID, irsp->ulpStatus,
2073 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002074 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002075 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002076 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002077 else
James Smart2e0fef82007-06-17 19:56:36 -05002078 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002079 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002080 } else
dea31012005-04-17 16:05:31 -05002081 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002082 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002083 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002084out:
2085 lpfc_els_free_iocb(phba, cmdiocb);
2086 return;
2087}
2088
James Smarte59058c2008-08-24 21:49:00 -04002089/**
James Smart3621a712009-04-06 18:47:14 -04002090 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002091 * @vport: pointer to a host virtual N_Port data structure.
2092 * @ndlp: pointer to a node-list data structure.
2093 * @retry: number of retries to the command IOCB.
2094 *
2095 * This routine issues a Process Login (PRLI) ELS command for the
2096 * @vport. The PRLI service parameters are set up in the payload of the
2097 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2098 * is put to the IOCB completion callback func field before invoking the
2099 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2100 *
2101 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2102 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2103 * will be stored into the context1 field of the IOCB for the completion
2104 * callback function to the PRLI ELS command.
2105 *
2106 * Return code
2107 * 0 - successfully issued prli iocb command for @vport
2108 * 1 - failed to issue prli iocb command for @vport
2109 **/
dea31012005-04-17 16:05:31 -05002110int
James Smart2e0fef82007-06-17 19:56:36 -05002111lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002112 uint8_t retry)
2113{
James Smart2e0fef82007-06-17 19:56:36 -05002114 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2115 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002116 PRLI *npr;
dea31012005-04-17 16:05:31 -05002117 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002118 uint8_t *pcmd;
2119 uint16_t cmdsize;
2120
James Smart92d7f7b2007-06-17 19:56:38 -05002121 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002122 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2123 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002124 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002125 return 1;
dea31012005-04-17 16:05:31 -05002126
dea31012005-04-17 16:05:31 -05002127 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2128
2129 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002130 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002131 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002132 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002133
2134 /* For PRLI, remainder of payload is PRLI parameter page */
2135 npr = (PRLI *) pcmd;
2136 /*
2137 * If our firmware version is 3.20 or later,
2138 * set the following bits for FC-TAPE support.
2139 */
2140 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2141 npr->ConfmComplAllowed = 1;
2142 npr->Retry = 1;
2143 npr->TaskRetryIdReq = 1;
2144 }
2145 npr->estabImagePair = 1;
2146 npr->readXferRdyDis = 1;
James Smart3cb01c52013-07-15 18:35:04 -04002147 if (vport->cfg_first_burst_size)
2148 npr->writeXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05002149
2150 /* For FCP support */
2151 npr->prliType = PRLI_FCP_TYPE;
2152 npr->initiatorFunc = 1;
2153
James Smart858c9f62007-06-17 19:56:39 -05002154 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2155 "Issue PRLI: did:x%x",
2156 ndlp->nlp_DID, 0, 0);
2157
dea31012005-04-17 16:05:31 -05002158 phba->fc_stat.elsXmitPRLI++;
2159 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002160 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002161 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002162 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002163 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2164 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002165 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002166 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002167 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002168 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002169 return 1;
dea31012005-04-17 16:05:31 -05002170 }
James Smart2e0fef82007-06-17 19:56:36 -05002171 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002172 return 0;
dea31012005-04-17 16:05:31 -05002173}
2174
James Smarte59058c2008-08-24 21:49:00 -04002175/**
James Smart3621a712009-04-06 18:47:14 -04002176 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002177 * @vport: pointer to a host virtual N_Port data structure.
2178 *
2179 * This routine performs Registration State Change Notification (RSCN)
2180 * discovery for a @vport. If the @vport's node port recovery count is not
2181 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2182 * the nodes that need recovery. If none of the PLOGI were needed through
2183 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2184 * invoked to check and handle possible more RSCN came in during the period
2185 * of processing the current ones.
2186 **/
2187static void
2188lpfc_rscn_disc(struct lpfc_vport *vport)
2189{
2190 lpfc_can_disctmo(vport);
2191
2192 /* RSCN discovery */
2193 /* go thru NPR nodes and issue ELS PLOGIs */
2194 if (vport->fc_npr_cnt)
2195 if (lpfc_els_disc_plogi(vport))
2196 return;
2197
2198 lpfc_end_rscn(vport);
2199}
2200
2201/**
James Smart3621a712009-04-06 18:47:14 -04002202 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002203 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2204 *
2205 * This function is called when the final ADISC is completed during discovery.
2206 * This function handles clearing link attention or issuing reg_vpi depending
2207 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2208 * discovery.
2209 * This function is called with no locks held.
2210 **/
2211static void
2212lpfc_adisc_done(struct lpfc_vport *vport)
2213{
2214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2215 struct lpfc_hba *phba = vport->phba;
2216
2217 /*
2218 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2219 * and continue discovery.
2220 */
2221 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002222 !(vport->fc_flag & FC_RSCN_MODE) &&
2223 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002224 /* The ADISCs are complete. Doesn't matter if they
2225 * succeeded or failed because the ADISC completion
2226 * routine guarantees to call the state machine and
2227 * the RPI is either unregistered (failed ADISC response)
2228 * or the RPI is still valid and the node is marked
2229 * mapped for a target. The exchanges should be in the
2230 * correct state. This code is specific to SLI3.
2231 */
2232 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002233 lpfc_issue_reg_vpi(phba, vport);
2234 return;
2235 }
2236 /*
2237 * For SLI2, we need to set port_state to READY
2238 * and continue discovery.
2239 */
2240 if (vport->port_state < LPFC_VPORT_READY) {
2241 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002242 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002243 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2244 vport->num_disc_nodes = 0;
2245 /* go thru NPR list, issue ELS PLOGIs */
2246 if (vport->fc_npr_cnt)
2247 lpfc_els_disc_plogi(vport);
2248 if (!vport->num_disc_nodes) {
2249 spin_lock_irq(shost->host_lock);
2250 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2251 spin_unlock_irq(shost->host_lock);
2252 lpfc_can_disctmo(vport);
2253 lpfc_end_rscn(vport);
2254 }
2255 }
2256 vport->port_state = LPFC_VPORT_READY;
2257 } else
2258 lpfc_rscn_disc(vport);
2259}
2260
2261/**
James Smart3621a712009-04-06 18:47:14 -04002262 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002263 * @vport: pointer to a host virtual N_Port data structure.
2264 *
2265 * This routine determines whether there are more ndlps on a @vport
2266 * node list need to have Address Discover (ADISC) issued. If so, it will
2267 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2268 * remaining nodes which need to have ADISC sent.
2269 **/
James Smart0ff10d42008-01-11 01:52:36 -05002270void
James Smart2e0fef82007-06-17 19:56:36 -05002271lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002272{
James Smart2e0fef82007-06-17 19:56:36 -05002273 if (vport->num_disc_nodes)
2274 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002275 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002276 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2277 "0210 Continue discovery with %d ADISCs to go "
2278 "Data: x%x x%x x%x\n",
2279 vport->num_disc_nodes, vport->fc_adisc_cnt,
2280 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002281 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002282 if (vport->fc_flag & FC_NLP_MORE) {
2283 lpfc_set_disctmo(vport);
2284 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002285 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002286 }
James Smart90160e02008-08-24 21:49:45 -04002287 if (!vport->num_disc_nodes)
2288 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002289 return;
2290}
2291
James Smarte59058c2008-08-24 21:49:00 -04002292/**
James Smart3621a712009-04-06 18:47:14 -04002293 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002294 * @phba: pointer to lpfc hba data structure.
2295 * @cmdiocb: pointer to lpfc command iocb data structure.
2296 * @rspiocb: pointer to lpfc response iocb data structure.
2297 *
2298 * This routine is the completion function for issuing the Address Discover
2299 * (ADISC) command. It first checks to see whether link went down during
2300 * the discovery process. If so, the node will be marked as node port
2301 * recovery for issuing discover IOCB by the link attention handler and
2302 * exit. Otherwise, the response status is checked. If error was reported
2303 * in the response status, the ADISC command shall be retried by invoking
2304 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2305 * the response status, the state machine is invoked to set transition
2306 * with respect to NLP_EVT_CMPL_ADISC event.
2307 **/
dea31012005-04-17 16:05:31 -05002308static void
James Smart2e0fef82007-06-17 19:56:36 -05002309lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2310 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002311{
James Smart2e0fef82007-06-17 19:56:36 -05002312 struct lpfc_vport *vport = cmdiocb->vport;
2313 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002314 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002315 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002316 int disc;
dea31012005-04-17 16:05:31 -05002317
2318 /* we pass cmdiocb to state machine which needs rspiocb as well */
2319 cmdiocb->context_un.rsp_iocb = rspiocb;
2320
2321 irsp = &(rspiocb->iocb);
2322 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002323
James Smart858c9f62007-06-17 19:56:39 -05002324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2325 "ADISC cmpl: status:x%x/x%x did:x%x",
2326 irsp->ulpStatus, irsp->un.ulpWord[4],
2327 ndlp->nlp_DID);
2328
dea31012005-04-17 16:05:31 -05002329 /* Since ndlp can be freed in the disc state machine, note if this node
2330 * is being used during discovery.
2331 */
James Smart2e0fef82007-06-17 19:56:36 -05002332 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002333 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002334 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002335 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002336 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002337 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2338 "0104 ADISC completes to NPort x%x "
2339 "Data: x%x x%x x%x x%x x%x\n",
2340 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2341 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002342 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002343 if (lpfc_els_chk_latt(vport)) {
2344 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002345 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002346 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002347 goto out;
2348 }
2349
2350 if (irsp->ulpStatus) {
2351 /* Check for retry */
2352 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2353 /* ELS command is being retried */
2354 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002355 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002356 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_unlock_irq(shost->host_lock);
2358 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002359 }
2360 goto out;
2361 }
2362 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002363 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2364 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2365 ndlp->nlp_DID, irsp->ulpStatus,
2366 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002367 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002368 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002369 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002370 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002371 } else
dea31012005-04-17 16:05:31 -05002372 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002373 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002374 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002375
James Smart90160e02008-08-24 21:49:45 -04002376 /* Check to see if there are more ADISCs to be sent */
2377 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002378 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002379out:
2380 lpfc_els_free_iocb(phba, cmdiocb);
2381 return;
2382}
2383
James Smarte59058c2008-08-24 21:49:00 -04002384/**
James Smart3621a712009-04-06 18:47:14 -04002385 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002386 * @vport: pointer to a virtual N_Port data structure.
2387 * @ndlp: pointer to a node-list data structure.
2388 * @retry: number of retries to the command IOCB.
2389 *
2390 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2391 * @vport. It prepares the payload of the ADISC ELS command, updates the
2392 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2393 * to issue the ADISC ELS command.
2394 *
2395 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2396 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2397 * will be stored into the context1 field of the IOCB for the completion
2398 * callback function to the ADISC ELS command.
2399 *
2400 * Return code
2401 * 0 - successfully issued adisc
2402 * 1 - failed to issue adisc
2403 **/
dea31012005-04-17 16:05:31 -05002404int
James Smart2e0fef82007-06-17 19:56:36 -05002405lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002406 uint8_t retry)
2407{
James Smart2e0fef82007-06-17 19:56:36 -05002408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2409 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002410 ADISC *ap;
dea31012005-04-17 16:05:31 -05002411 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002412 uint8_t *pcmd;
2413 uint16_t cmdsize;
2414
James Smart92d7f7b2007-06-17 19:56:38 -05002415 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002416 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2417 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002418 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002419 return 1;
dea31012005-04-17 16:05:31 -05002420
dea31012005-04-17 16:05:31 -05002421 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2422
2423 /* For ADISC request, remainder of payload is service parameters */
2424 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002425 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002426
2427 /* Fill in ADISC payload */
2428 ap = (ADISC *) pcmd;
2429 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002430 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2431 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002432 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002433
James Smart858c9f62007-06-17 19:56:39 -05002434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2435 "Issue ADISC: did:x%x",
2436 ndlp->nlp_DID, 0, 0);
2437
dea31012005-04-17 16:05:31 -05002438 phba->fc_stat.elsXmitADISC++;
2439 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002440 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002441 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002442 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002443 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2444 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002445 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002446 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002447 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002448 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002449 return 1;
dea31012005-04-17 16:05:31 -05002450 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002451 return 0;
dea31012005-04-17 16:05:31 -05002452}
2453
James Smarte59058c2008-08-24 21:49:00 -04002454/**
James Smart3621a712009-04-06 18:47:14 -04002455 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002456 * @phba: pointer to lpfc hba data structure.
2457 * @cmdiocb: pointer to lpfc command iocb data structure.
2458 * @rspiocb: pointer to lpfc response iocb data structure.
2459 *
2460 * This routine is the completion function for issuing the ELS Logout (LOGO)
2461 * command. If no error status was reported from the LOGO response, the
2462 * state machine of the associated ndlp shall be invoked for transition with
2463 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2464 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2465 **/
dea31012005-04-17 16:05:31 -05002466static void
James Smart2e0fef82007-06-17 19:56:36 -05002467lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2468 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002469{
James Smart2e0fef82007-06-17 19:56:36 -05002470 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2471 struct lpfc_vport *vport = ndlp->vport;
2472 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002473 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002474 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002475 unsigned long flags;
2476 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002477
dea31012005-04-17 16:05:31 -05002478 /* we pass cmdiocb to state machine which needs rspiocb as well */
2479 cmdiocb->context_un.rsp_iocb = rspiocb;
2480
2481 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002482 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002483 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002484 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002485
James Smart858c9f62007-06-17 19:56:39 -05002486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2487 "LOGO cmpl: status:x%x/x%x did:x%x",
2488 irsp->ulpStatus, irsp->un.ulpWord[4],
2489 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002490
dea31012005-04-17 16:05:31 -05002491 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002492 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2493 "0105 LOGO completes to NPort x%x "
2494 "Data: x%x x%x x%x x%x\n",
2495 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2496 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002497
James Smart086a3452012-08-14 14:25:21 -04002498 if (lpfc_els_chk_latt(vport)) {
2499 skip_recovery = 1;
2500 goto out;
2501 }
2502
2503 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002504 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2505 /* NLP_EVT_DEVICE_RM should unregister the RPI
2506 * which should abort all outstanding IOs.
2507 */
2508 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2509 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002510 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002511 goto out;
2512 }
2513
dea31012005-04-17 16:05:31 -05002514 if (irsp->ulpStatus) {
2515 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002516 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002517 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002518 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002519 goto out;
James Smart086a3452012-08-14 14:25:21 -04002520 }
dea31012005-04-17 16:05:31 -05002521 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002522 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2523 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2524 ndlp->nlp_DID, irsp->ulpStatus,
2525 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002526 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002527 if (lpfc_error_lost_link(irsp)) {
2528 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002529 goto out;
James Smart086a3452012-08-14 14:25:21 -04002530 }
2531 }
2532
2533 /* Call state machine. This will unregister the rpi if needed. */
2534 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2535
dea31012005-04-17 16:05:31 -05002536out:
2537 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002538 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2539 if ((vport->fc_flag & FC_PT2PT) &&
2540 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2541 phba->pport->fc_myDID = 0;
2542 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2543 if (mbox) {
2544 lpfc_config_link(phba, mbox);
2545 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2546 mbox->vport = vport;
2547 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2548 MBX_NOT_FINISHED) {
2549 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002550 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002551 }
2552 }
2553 }
James Smart086a3452012-08-14 14:25:21 -04002554
2555 /*
2556 * If the node is a target, the handling attempts to recover the port.
2557 * For any other port type, the rpi is unregistered as an implicit
2558 * LOGO.
2559 */
2560 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2561 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2562 spin_lock_irqsave(shost->host_lock, flags);
2563 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2564 spin_unlock_irqrestore(shost->host_lock, flags);
2565
2566 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2567 "3187 LOGO completes to NPort x%x: Start "
2568 "Recovery Data: x%x x%x x%x x%x\n",
2569 ndlp->nlp_DID, irsp->ulpStatus,
2570 irsp->un.ulpWord[4], irsp->ulpTimeout,
2571 vport->num_disc_nodes);
2572 lpfc_disc_start(vport);
2573 }
dea31012005-04-17 16:05:31 -05002574 return;
2575}
2576
James Smarte59058c2008-08-24 21:49:00 -04002577/**
James Smart3621a712009-04-06 18:47:14 -04002578 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002579 * @vport: pointer to a virtual N_Port data structure.
2580 * @ndlp: pointer to a node-list data structure.
2581 * @retry: number of retries to the command IOCB.
2582 *
2583 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2584 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2585 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2586 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2587 *
2588 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2589 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2590 * will be stored into the context1 field of the IOCB for the completion
2591 * callback function to the LOGO ELS command.
2592 *
2593 * Return code
2594 * 0 - successfully issued logo
2595 * 1 - failed to issue logo
2596 **/
dea31012005-04-17 16:05:31 -05002597int
James Smart2e0fef82007-06-17 19:56:36 -05002598lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002599 uint8_t retry)
2600{
James Smart2e0fef82007-06-17 19:56:36 -05002601 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2602 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002603 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002604 uint8_t *pcmd;
2605 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002606 int rc;
dea31012005-04-17 16:05:31 -05002607
James Smart98c9ea52007-10-27 13:37:33 -04002608 spin_lock_irq(shost->host_lock);
2609 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2610 spin_unlock_irq(shost->host_lock);
2611 return 0;
2612 }
2613 spin_unlock_irq(shost->host_lock);
2614
James Smart92d7f7b2007-06-17 19:56:38 -05002615 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002616 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2617 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002618 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002619 return 1;
dea31012005-04-17 16:05:31 -05002620
dea31012005-04-17 16:05:31 -05002621 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2622 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002623 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002624
2625 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002626 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002627 pcmd += sizeof(uint32_t);
2628 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002629
James Smart858c9f62007-06-17 19:56:39 -05002630 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2631 "Issue LOGO: did:x%x",
2632 ndlp->nlp_DID, 0, 0);
2633
James Smart086a3452012-08-14 14:25:21 -04002634 /*
2635 * If we are issuing a LOGO, we may try to recover the remote NPort
2636 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2637 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2638 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2639 * for that ELS cmd. To avoid this situation, lets get rid of the
2640 * RPI right now, before any ELS cmds are sent.
2641 */
2642 spin_lock_irq(shost->host_lock);
2643 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2644 spin_unlock_irq(shost->host_lock);
2645 if (lpfc_unreg_rpi(vport, ndlp)) {
2646 lpfc_els_free_iocb(phba, elsiocb);
2647 return 0;
2648 }
2649
dea31012005-04-17 16:05:31 -05002650 phba->fc_stat.elsXmitLOGO++;
2651 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002652 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002653 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002654 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002655 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002656 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002657
2658 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002659 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002660 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002661 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002662 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002663 return 1;
dea31012005-04-17 16:05:31 -05002664 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002665 return 0;
dea31012005-04-17 16:05:31 -05002666}
2667
James Smarte59058c2008-08-24 21:49:00 -04002668/**
James Smart3621a712009-04-06 18:47:14 -04002669 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002670 * @phba: pointer to lpfc hba data structure.
2671 * @cmdiocb: pointer to lpfc command iocb data structure.
2672 * @rspiocb: pointer to lpfc response iocb data structure.
2673 *
2674 * This routine is a generic completion callback function for ELS commands.
2675 * Specifically, it is the callback function which does not need to perform
2676 * any command specific operations. It is currently used by the ELS command
2677 * issuing routines for the ELS State Change Request (SCR),
2678 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2679 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2680 * certain debug loggings, this callback function simply invokes the
2681 * lpfc_els_chk_latt() routine to check whether link went down during the
2682 * discovery process.
2683 **/
dea31012005-04-17 16:05:31 -05002684static void
James Smart2e0fef82007-06-17 19:56:36 -05002685lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2686 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002687{
James Smart2e0fef82007-06-17 19:56:36 -05002688 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002689 IOCB_t *irsp;
2690
2691 irsp = &rspiocb->iocb;
2692
James Smart858c9f62007-06-17 19:56:39 -05002693 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2694 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2695 irsp->ulpStatus, irsp->un.ulpWord[4],
2696 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002697 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2699 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2700 irsp->ulpIoTag, irsp->ulpStatus,
2701 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002702 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002703 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002704 lpfc_els_free_iocb(phba, cmdiocb);
2705 return;
2706}
2707
James Smarte59058c2008-08-24 21:49:00 -04002708/**
James Smart3621a712009-04-06 18:47:14 -04002709 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002710 * @vport: pointer to a host virtual N_Port data structure.
2711 * @nportid: N_Port identifier to the remote node.
2712 * @retry: number of retries to the command IOCB.
2713 *
2714 * This routine issues a State Change Request (SCR) to a fabric node
2715 * on a @vport. The remote node @nportid is passed into the function. It
2716 * first search the @vport node list to find the matching ndlp. If no such
2717 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2718 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2719 * routine is invoked to send the SCR IOCB.
2720 *
2721 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2722 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2723 * will be stored into the context1 field of the IOCB for the completion
2724 * callback function to the SCR ELS command.
2725 *
2726 * Return code
2727 * 0 - Successfully issued scr command
2728 * 1 - Failed to issue scr command
2729 **/
dea31012005-04-17 16:05:31 -05002730int
James Smart2e0fef82007-06-17 19:56:36 -05002731lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002732{
James Smart2e0fef82007-06-17 19:56:36 -05002733 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002734 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002735 uint8_t *pcmd;
2736 uint16_t cmdsize;
2737 struct lpfc_nodelist *ndlp;
2738
James Smart92d7f7b2007-06-17 19:56:38 -05002739 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002740
James Smarte47c9092008-02-08 18:49:26 -05002741 ndlp = lpfc_findnode_did(vport, nportid);
2742 if (!ndlp) {
2743 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2744 if (!ndlp)
2745 return 1;
2746 lpfc_nlp_init(vport, ndlp, nportid);
2747 lpfc_enqueue_node(vport, ndlp);
2748 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2749 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2750 if (!ndlp)
2751 return 1;
2752 }
dea31012005-04-17 16:05:31 -05002753
James Smart2e0fef82007-06-17 19:56:36 -05002754 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2755 ndlp->nlp_DID, ELS_CMD_SCR);
2756
James Smart488d1462006-03-07 15:02:37 -05002757 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002758 /* This will trigger the release of the node just
2759 * allocated
2760 */
James Smart329f9bc2007-04-25 09:53:01 -04002761 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002762 return 1;
dea31012005-04-17 16:05:31 -05002763 }
2764
dea31012005-04-17 16:05:31 -05002765 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2766
2767 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002768 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002769
2770 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002771 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002772 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2773
James Smart858c9f62007-06-17 19:56:39 -05002774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2775 "Issue SCR: did:x%x",
2776 ndlp->nlp_DID, 0, 0);
2777
dea31012005-04-17 16:05:31 -05002778 phba->fc_stat.elsXmitSCR++;
2779 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002780 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2781 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002782 /* The additional lpfc_nlp_put will cause the following
2783 * lpfc_els_free_iocb routine to trigger the rlease of
2784 * the node.
2785 */
James Smart329f9bc2007-04-25 09:53:01 -04002786 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002787 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002788 return 1;
dea31012005-04-17 16:05:31 -05002789 }
James Smartfa4066b2008-01-11 01:53:27 -05002790 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2791 * trigger the release of node.
2792 */
James Smartcff261f2013-12-17 20:29:47 -05002793
James Smart329f9bc2007-04-25 09:53:01 -04002794 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002795 return 0;
dea31012005-04-17 16:05:31 -05002796}
2797
James Smarte59058c2008-08-24 21:49:00 -04002798/**
James Smart3621a712009-04-06 18:47:14 -04002799 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002800 * @vport: pointer to a host virtual N_Port data structure.
2801 * @nportid: N_Port identifier to the remote node.
2802 * @retry: number of retries to the command IOCB.
2803 *
2804 * This routine issues a Fibre Channel Address Resolution Response
2805 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2806 * is passed into the function. It first search the @vport node list to find
2807 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2808 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2809 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2810 *
2811 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2812 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2813 * will be stored into the context1 field of the IOCB for the completion
2814 * callback function to the PARPR ELS command.
2815 *
2816 * Return code
2817 * 0 - Successfully issued farpr command
2818 * 1 - Failed to issue farpr command
2819 **/
dea31012005-04-17 16:05:31 -05002820static int
James Smart2e0fef82007-06-17 19:56:36 -05002821lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002822{
James Smart2e0fef82007-06-17 19:56:36 -05002823 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002824 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002825 FARP *fp;
2826 uint8_t *pcmd;
2827 uint32_t *lp;
2828 uint16_t cmdsize;
2829 struct lpfc_nodelist *ondlp;
2830 struct lpfc_nodelist *ndlp;
2831
James Smart92d7f7b2007-06-17 19:56:38 -05002832 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002833
James Smarte47c9092008-02-08 18:49:26 -05002834 ndlp = lpfc_findnode_did(vport, nportid);
2835 if (!ndlp) {
2836 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2837 if (!ndlp)
2838 return 1;
2839 lpfc_nlp_init(vport, ndlp, nportid);
2840 lpfc_enqueue_node(vport, ndlp);
2841 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2842 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2843 if (!ndlp)
2844 return 1;
2845 }
James Smart2e0fef82007-06-17 19:56:36 -05002846
2847 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2848 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002849 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002850 /* This will trigger the release of the node just
2851 * allocated
2852 */
James Smart329f9bc2007-04-25 09:53:01 -04002853 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002854 return 1;
dea31012005-04-17 16:05:31 -05002855 }
2856
dea31012005-04-17 16:05:31 -05002857 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2858
2859 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002860 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002861
2862 /* Fill in FARPR payload */
2863 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002864 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002865 lp = (uint32_t *) pcmd;
2866 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002867 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002868 fp->Rflags = 0;
2869 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2870
James Smart92d7f7b2007-06-17 19:56:38 -05002871 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2872 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002873 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002874 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002875 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002876 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002877 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002878 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002879 }
2880
James Smart858c9f62007-06-17 19:56:39 -05002881 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2882 "Issue FARPR: did:x%x",
2883 ndlp->nlp_DID, 0, 0);
2884
dea31012005-04-17 16:05:31 -05002885 phba->fc_stat.elsXmitFARPR++;
2886 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002887 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2888 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002889 /* The additional lpfc_nlp_put will cause the following
2890 * lpfc_els_free_iocb routine to trigger the release of
2891 * the node.
2892 */
James Smart329f9bc2007-04-25 09:53:01 -04002893 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002894 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002895 return 1;
dea31012005-04-17 16:05:31 -05002896 }
James Smartfa4066b2008-01-11 01:53:27 -05002897 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2898 * trigger the release of the node.
2899 */
James Smart329f9bc2007-04-25 09:53:01 -04002900 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002901 return 0;
dea31012005-04-17 16:05:31 -05002902}
2903
James Smarte59058c2008-08-24 21:49:00 -04002904/**
James Smart3621a712009-04-06 18:47:14 -04002905 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002906 * @vport: pointer to a host virtual N_Port data structure.
2907 * @nlp: pointer to a node-list data structure.
2908 *
2909 * This routine cancels the timer with a delayed IOCB-command retry for
2910 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2911 * removes the ELS retry event if it presents. In addition, if the
2912 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2913 * commands are sent for the @vport's nodes that require issuing discovery
2914 * ADISC.
2915 **/
dea31012005-04-17 16:05:31 -05002916void
James Smart2e0fef82007-06-17 19:56:36 -05002917lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002918{
James Smart2e0fef82007-06-17 19:56:36 -05002919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002920 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002921
James Smart0d2b6b82008-06-14 22:52:47 -04002922 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2923 return;
James Smart2e0fef82007-06-17 19:56:36 -05002924 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002925 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002926 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002927 del_timer_sync(&nlp->nlp_delayfunc);
2928 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002929 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002930 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002931 /* Decrement nlp reference count held for the delayed retry */
2932 evtp = &nlp->els_retry_evt;
2933 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2934 }
James Smartfdcebe22006-03-07 15:04:01 -05002935 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002936 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002937 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002938 spin_unlock_irq(shost->host_lock);
2939 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002940 if (vport->port_state < LPFC_VPORT_READY) {
2941 /* Check if there are more ADISCs to be sent */
2942 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002943 } else {
2944 /* Check if there are more PLOGIs to be sent */
2945 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002946 if (vport->num_disc_nodes == 0) {
2947 spin_lock_irq(shost->host_lock);
2948 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2949 spin_unlock_irq(shost->host_lock);
2950 lpfc_can_disctmo(vport);
2951 lpfc_end_rscn(vport);
2952 }
James Smartfdcebe22006-03-07 15:04:01 -05002953 }
2954 }
2955 }
2956 return;
2957}
2958
James Smarte59058c2008-08-24 21:49:00 -04002959/**
James Smart3621a712009-04-06 18:47:14 -04002960 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002961 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2962 *
2963 * This routine is invoked by the ndlp delayed-function timer to check
2964 * whether there is any pending ELS retry event(s) with the node. If not, it
2965 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2966 * adds the delayed events to the HBA work list and invokes the
2967 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2968 * event. Note that lpfc_nlp_get() is called before posting the event to
2969 * the work list to hold reference count of ndlp so that it guarantees the
2970 * reference to ndlp will still be available when the worker thread gets
2971 * to the event associated with the ndlp.
2972 **/
James Smartfdcebe22006-03-07 15:04:01 -05002973void
dea31012005-04-17 16:05:31 -05002974lpfc_els_retry_delay(unsigned long ptr)
2975{
James Smart2e0fef82007-06-17 19:56:36 -05002976 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2977 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002978 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002979 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002980 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002981
James Smart92d7f7b2007-06-17 19:56:38 -05002982 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002983 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002984 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002985 return;
2986 }
2987
James Smartfa4066b2008-01-11 01:53:27 -05002988 /* We need to hold the node by incrementing the reference
2989 * count until the queued work is done
2990 */
2991 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002992 if (evtp->evt_arg1) {
2993 evtp->evt = LPFC_EVT_ELS_RETRY;
2994 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002995 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002996 }
James Smart92d7f7b2007-06-17 19:56:38 -05002997 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002998 return;
2999}
3000
James Smarte59058c2008-08-24 21:49:00 -04003001/**
James Smart3621a712009-04-06 18:47:14 -04003002 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04003003 * @ndlp: pointer to a node-list data structure.
3004 *
3005 * This routine is the worker-thread handler for processing the @ndlp delayed
3006 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3007 * the last ELS command from the associated ndlp and invokes the proper ELS
3008 * function according to the delayed ELS command to retry the command.
3009 **/
dea31012005-04-17 16:05:31 -05003010void
3011lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
3012{
James Smart2e0fef82007-06-17 19:56:36 -05003013 struct lpfc_vport *vport = ndlp->vport;
3014 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04003015 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05003016
James Smart2e0fef82007-06-17 19:56:36 -05003017 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003018 cmd = ndlp->nlp_last_elscmd;
3019 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003020
3021 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003022 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003023 return;
3024 }
3025
3026 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003027 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003028 /*
3029 * If a discovery event readded nlp_delayfunc after timer
3030 * firing and before processing the timer, cancel the
3031 * nlp_delayfunc.
3032 */
3033 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003034 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003035 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003036
3037 switch (cmd) {
3038 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003039 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003040 break;
3041 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003042 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003043 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003044 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003045 }
dea31012005-04-17 16:05:31 -05003046 break;
3047 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003048 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003049 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003051 }
dea31012005-04-17 16:05:31 -05003052 break;
3053 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003054 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003055 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003056 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003057 }
dea31012005-04-17 16:05:31 -05003058 break;
3059 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003060 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003061 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003062 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003063 }
dea31012005-04-17 16:05:31 -05003064 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003065 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003066 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3067 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003068 break;
dea31012005-04-17 16:05:31 -05003069 }
3070 return;
3071}
3072
James Smarte59058c2008-08-24 21:49:00 -04003073/**
James Smart3621a712009-04-06 18:47:14 -04003074 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003075 * @phba: pointer to lpfc hba data structure.
3076 * @cmdiocb: pointer to lpfc command iocb data structure.
3077 * @rspiocb: pointer to lpfc response iocb data structure.
3078 *
3079 * This routine makes a retry decision on an ELS command IOCB, which has
3080 * failed. The following ELS IOCBs use this function for retrying the command
3081 * when previously issued command responsed with error status: FLOGI, PLOGI,
3082 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3083 * returned error status, it makes the decision whether a retry shall be
3084 * issued for the command, and whether a retry shall be made immediately or
3085 * delayed. In the former case, the corresponding ELS command issuing-function
3086 * is called to retry the command. In the later case, the ELS command shall
3087 * be posted to the ndlp delayed event and delayed function timer set to the
3088 * ndlp for the delayed command issusing.
3089 *
3090 * Return code
3091 * 0 - No retry of els command is made
3092 * 1 - Immediate or delayed retry of els command is made
3093 **/
dea31012005-04-17 16:05:31 -05003094static int
James Smart2e0fef82007-06-17 19:56:36 -05003095lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3096 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003097{
James Smart2e0fef82007-06-17 19:56:36 -05003098 struct lpfc_vport *vport = cmdiocb->vport;
3099 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3100 IOCB_t *irsp = &rspiocb->iocb;
3101 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3102 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003103 uint32_t *elscmd;
3104 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003105 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003106 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003107 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003108 uint32_t did;
dea31012005-04-17 16:05:31 -05003109
James Smart488d1462006-03-07 15:02:37 -05003110
dea31012005-04-17 16:05:31 -05003111 /* Note: context2 may be 0 for internal driver abort
3112 * of delays ELS command.
3113 */
3114
3115 if (pcmd && pcmd->virt) {
3116 elscmd = (uint32_t *) (pcmd->virt);
3117 cmd = *elscmd++;
3118 }
3119
James Smarte47c9092008-02-08 18:49:26 -05003120 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003121 did = ndlp->nlp_DID;
3122 else {
3123 /* We should only hit this case for retrying PLOGI */
3124 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003125 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003126 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3127 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003128 return 1;
3129 }
3130
James Smart858c9f62007-06-17 19:56:39 -05003131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3132 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3133 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3134
dea31012005-04-17 16:05:31 -05003135 switch (irsp->ulpStatus) {
3136 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003137 break;
James Smart1151e3e2011-02-16 12:39:35 -05003138 case IOSTAT_REMOTE_STOP:
3139 if (phba->sli_rev == LPFC_SLI_REV4) {
3140 /* This IO was aborted by the target, we don't
3141 * know the rxid and because we did not send the
3142 * ABTS we cannot generate and RRQ.
3143 */
3144 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003145 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003146 }
3147 break;
dea31012005-04-17 16:05:31 -05003148 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003149 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003150 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003151 if (cmd == ELS_CMD_FLOGI) {
3152 if (PCI_DEVICE_ID_HORNET ==
3153 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003154 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003155 phba->pport->fc_myDID = 0;
3156 phba->alpa_map[0] = 0;
3157 phba->alpa_map[1] = 0;
3158 }
3159 }
James Smart2e0fef82007-06-17 19:56:36 -05003160 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003161 delay = 1000;
dea31012005-04-17 16:05:31 -05003162 retry = 1;
3163 break;
3164
James Smart92d7f7b2007-06-17 19:56:38 -05003165 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003166 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3167 "0124 Retry illegal cmd x%x "
3168 "retry:x%x delay:x%x\n",
3169 cmd, cmdiocb->retry, delay);
3170 retry = 1;
3171 /* All command's retry policy */
3172 maxretry = 8;
3173 if (cmdiocb->retry > 2)
3174 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003175 break;
3176
dea31012005-04-17 16:05:31 -05003177 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003178 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003179 retry = 1;
3180 if (cmdiocb->retry > 100)
3181 delay = 100;
3182 maxretry = 250;
3183 break;
3184
3185 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003186 delay = 100;
dea31012005-04-17 16:05:31 -05003187 retry = 1;
3188 break;
3189
James Smart858c9f62007-06-17 19:56:39 -05003190 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003191 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003192 if (cmd == ELS_CMD_PLOGI &&
3193 did == NameServer_DID) {
3194 /* Continue forever if plogi to */
3195 /* the nameserver fails */
3196 maxretry = 0;
3197 delay = 100;
3198 }
dea31012005-04-17 16:05:31 -05003199 retry = 1;
3200 break;
3201 }
3202 break;
3203
3204 case IOSTAT_NPORT_RJT:
3205 case IOSTAT_FABRIC_RJT:
3206 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3207 retry = 1;
3208 break;
3209 }
3210 break;
3211
3212 case IOSTAT_NPORT_BSY:
3213 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003214 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003215 retry = 1;
3216 break;
3217
3218 case IOSTAT_LS_RJT:
3219 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3220 /* Added for Vendor specifc support
3221 * Just keep retrying for these Rsn / Exp codes
3222 */
3223 switch (stat.un.b.lsRjtRsnCode) {
3224 case LSRJT_UNABLE_TPC:
3225 if (stat.un.b.lsRjtRsnCodeExp ==
3226 LSEXP_CMD_IN_PROGRESS) {
3227 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003228 delay = 1000;
dea31012005-04-17 16:05:31 -05003229 maxretry = 48;
3230 }
3231 retry = 1;
3232 break;
3233 }
James Smartffc95492010-06-07 15:23:17 -04003234 if (stat.un.b.lsRjtRsnCodeExp ==
3235 LSEXP_CANT_GIVE_DATA) {
3236 if (cmd == ELS_CMD_PLOGI) {
3237 delay = 1000;
3238 maxretry = 48;
3239 }
3240 retry = 1;
3241 break;
3242 }
James Smart4c1b64b2012-09-29 11:31:11 -04003243 if ((cmd == ELS_CMD_PLOGI) ||
3244 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003245 delay = 1000;
dea31012005-04-17 16:05:31 -05003246 maxretry = lpfc_max_els_tries + 1;
3247 retry = 1;
3248 break;
3249 }
James Smart92d7f7b2007-06-17 19:56:38 -05003250 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3251 (cmd == ELS_CMD_FDISC) &&
3252 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003253 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3254 "0125 FDISC Failed (x%x). "
3255 "Fabric out of resources\n",
3256 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003257 lpfc_vport_set_state(vport,
3258 FC_VPORT_NO_FABRIC_RSCS);
3259 }
dea31012005-04-17 16:05:31 -05003260 break;
3261
3262 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003263 if ((cmd == ELS_CMD_PLOGI) ||
3264 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003265 delay = 1000;
dea31012005-04-17 16:05:31 -05003266 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003267 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003268 /* FDISC retry policy */
3269 maxretry = 48;
3270 if (cmdiocb->retry >= 32)
3271 delay = 1000;
dea31012005-04-17 16:05:31 -05003272 }
3273 retry = 1;
3274 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003275
3276 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003277 /* There are some cases where switches return this
3278 * error when they are not ready and should be returning
3279 * Logical Busy. We should delay every time.
3280 */
3281 if (cmd == ELS_CMD_FDISC &&
3282 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3283 maxretry = 3;
3284 delay = 1000;
3285 retry = 1;
3286 break;
3287 }
James Smart92d7f7b2007-06-17 19:56:38 -05003288 case LSRJT_PROTOCOL_ERR:
3289 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3290 (cmd == ELS_CMD_FDISC) &&
3291 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3292 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3293 ) {
James Smarte8b62012007-08-02 11:10:09 -04003294 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003295 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003296 "Fabric Detected Bad WWN\n",
3297 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003298 lpfc_vport_set_state(vport,
3299 FC_VPORT_FABRIC_REJ_WWN);
3300 }
3301 break;
dea31012005-04-17 16:05:31 -05003302 }
3303 break;
3304
3305 case IOSTAT_INTERMED_RSP:
3306 case IOSTAT_BA_RJT:
3307 break;
3308
3309 default:
3310 break;
3311 }
3312
James Smart488d1462006-03-07 15:02:37 -05003313 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003314 retry = 1;
dea31012005-04-17 16:05:31 -05003315
James Smartdf9e1b52011-12-13 13:22:17 -05003316 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003317 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003318 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003319 /* FLOGI retry policy */
3320 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003321 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003322 if (phba->link_flag != LS_LOOPBACK_MODE)
3323 maxretry = 0;
3324 else
3325 maxretry = 2;
3326
James Smart6669f9b2009-10-02 15:16:45 -04003327 if (cmdiocb->retry >= 100)
3328 delay = 5000;
3329 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003330 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003331 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3332 /* retry FDISCs every second up to devloss */
3333 retry = 1;
3334 maxretry = vport->cfg_devloss_tmo;
3335 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003336 }
3337
James Smart6669f9b2009-10-02 15:16:45 -04003338 cmdiocb->retry++;
3339 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003340 phba->fc_stat.elsRetryExceeded++;
3341 retry = 0;
3342 }
3343
James Smarted957682007-06-17 19:56:37 -05003344 if ((vport->load_flag & FC_UNLOADING) != 0)
3345 retry = 0;
3346
dea31012005-04-17 16:05:31 -05003347 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003348 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3349 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3350 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3352 "2849 Stop retry ELS command "
3353 "x%x to remote NPORT x%x, "
3354 "Data: x%x x%x\n", cmd, did,
3355 cmdiocb->retry, delay);
3356 return 0;
3357 }
3358 }
dea31012005-04-17 16:05:31 -05003359
3360 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003361 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3362 "0107 Retry ELS command x%x to remote "
3363 "NPORT x%x Data: x%x x%x\n",
3364 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003365
James Smart858c9f62007-06-17 19:56:39 -05003366 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3367 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003368 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3369 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003370 /* Don't reset timer for no resources */
3371
dea31012005-04-17 16:05:31 -05003372 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003373 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003374 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003375 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003376 }
3377
3378 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003379 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003380 phba->fc_stat.elsDelayRetry++;
3381 ndlp->nlp_retry = cmdiocb->retry;
3382
James Smart92d7f7b2007-06-17 19:56:38 -05003383 /* delay is specified in milliseconds */
3384 mod_timer(&ndlp->nlp_delayfunc,
3385 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003386 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003387 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003388 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003389
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003390 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003391 if (cmd == ELS_CMD_PRLI)
3392 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003393 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003394 else
3395 lpfc_nlp_set_state(vport, ndlp,
3396 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003397 ndlp->nlp_last_elscmd = cmd;
3398
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003399 return 1;
dea31012005-04-17 16:05:31 -05003400 }
3401 switch (cmd) {
3402 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003403 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003404 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003405 case ELS_CMD_FDISC:
3406 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3407 return 1;
dea31012005-04-17 16:05:31 -05003408 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003409 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003410 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003411 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003412 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003413 }
James Smart2e0fef82007-06-17 19:56:36 -05003414 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003415 return 1;
dea31012005-04-17 16:05:31 -05003416 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003417 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003418 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3419 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003420 return 1;
dea31012005-04-17 16:05:31 -05003421 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003422 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3424 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003425 return 1;
dea31012005-04-17 16:05:31 -05003426 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003427 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003428 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003429 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003430 return 1;
dea31012005-04-17 16:05:31 -05003431 }
3432 }
dea31012005-04-17 16:05:31 -05003433 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003434 if (logerr) {
3435 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3436 "0137 No retry ELS command x%x to remote "
3437 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3438 cmd, did, irsp->ulpStatus,
3439 irsp->un.ulpWord[4]);
3440 }
3441 else {
3442 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003443 "0108 No retry ELS command x%x to remote "
3444 "NPORT x%x Retried:%d Error:x%x/%x\n",
3445 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3446 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003447 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003448 return 0;
dea31012005-04-17 16:05:31 -05003449}
3450
James Smarte59058c2008-08-24 21:49:00 -04003451/**
James Smart3621a712009-04-06 18:47:14 -04003452 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003453 * @phba: pointer to lpfc hba data structure.
3454 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3455 *
3456 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3457 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3458 * checks to see whether there is a lpfc DMA buffer associated with the
3459 * response of the command IOCB. If so, it will be released before releasing
3460 * the lpfc DMA buffer associated with the IOCB itself.
3461 *
3462 * Return code
3463 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3464 **/
James Smart09372822008-01-11 01:52:54 -05003465static int
James Smart87af33f2007-10-27 13:37:43 -04003466lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3467{
3468 struct lpfc_dmabuf *buf_ptr;
3469
James Smarte59058c2008-08-24 21:49:00 -04003470 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003471 if (!list_empty(&buf_ptr1->list)) {
3472 list_remove_head(&buf_ptr1->list, buf_ptr,
3473 struct lpfc_dmabuf,
3474 list);
3475 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3476 kfree(buf_ptr);
3477 }
3478 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3479 kfree(buf_ptr1);
3480 return 0;
3481}
3482
James Smarte59058c2008-08-24 21:49:00 -04003483/**
James Smart3621a712009-04-06 18:47:14 -04003484 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003485 * @phba: pointer to lpfc hba data structure.
3486 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3487 *
3488 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3489 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3490 * pool.
3491 *
3492 * Return code
3493 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3494 **/
James Smart09372822008-01-11 01:52:54 -05003495static int
James Smart87af33f2007-10-27 13:37:43 -04003496lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3497{
3498 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3499 kfree(buf_ptr);
3500 return 0;
3501}
3502
James Smarte59058c2008-08-24 21:49:00 -04003503/**
James Smart3621a712009-04-06 18:47:14 -04003504 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003505 * @phba: pointer to lpfc hba data structure.
3506 * @elsiocb: pointer to lpfc els command iocb data structure.
3507 *
3508 * This routine frees a command IOCB and its associated resources. The
3509 * command IOCB data structure contains the reference to various associated
3510 * resources, these fields must be set to NULL if the associated reference
3511 * not present:
3512 * context1 - reference to ndlp
3513 * context2 - reference to cmd
3514 * context2->next - reference to rsp
3515 * context3 - reference to bpl
3516 *
3517 * It first properly decrements the reference count held on ndlp for the
3518 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3519 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3520 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3521 * adds the DMA buffer the @phba data structure for the delayed release.
3522 * If reference to the Buffer Pointer List (BPL) is present, the
3523 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3524 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3525 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3526 *
3527 * Return code
3528 * 0 - Success (currently, always return 0)
3529 **/
James Smart87af33f2007-10-27 13:37:43 -04003530int
James Smart329f9bc2007-04-25 09:53:01 -04003531lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003532{
3533 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003534 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003535
James Smarta8adb832007-10-27 13:37:53 -04003536 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3537 if (ndlp) {
3538 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3539 lpfc_nlp_put(ndlp);
3540
3541 /* If the ndlp is not being used by another discovery
3542 * thread, free it.
3543 */
3544 if (!lpfc_nlp_not_used(ndlp)) {
3545 /* If ndlp is being used by another discovery
3546 * thread, just clear NLP_DEFER_RM
3547 */
3548 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3549 }
3550 }
3551 else
3552 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003553 elsiocb->context1 = NULL;
3554 }
dea31012005-04-17 16:05:31 -05003555 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3556 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003557 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3558 /* Firmware could still be in progress of DMAing
3559 * payload, so don't free data buffer till after
3560 * a hbeat.
3561 */
3562 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3563 buf_ptr = elsiocb->context2;
3564 elsiocb->context2 = NULL;
3565 if (buf_ptr) {
3566 buf_ptr1 = NULL;
3567 spin_lock_irq(&phba->hbalock);
3568 if (!list_empty(&buf_ptr->list)) {
3569 list_remove_head(&buf_ptr->list,
3570 buf_ptr1, struct lpfc_dmabuf,
3571 list);
3572 INIT_LIST_HEAD(&buf_ptr1->list);
3573 list_add_tail(&buf_ptr1->list,
3574 &phba->elsbuf);
3575 phba->elsbuf_cnt++;
3576 }
3577 INIT_LIST_HEAD(&buf_ptr->list);
3578 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3579 phba->elsbuf_cnt++;
3580 spin_unlock_irq(&phba->hbalock);
3581 }
3582 } else {
3583 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3584 lpfc_els_free_data(phba, buf_ptr1);
3585 }
dea31012005-04-17 16:05:31 -05003586 }
3587
3588 if (elsiocb->context3) {
3589 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003590 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003591 }
James Bottomley604a3e32005-10-29 10:28:33 -05003592 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003593 return 0;
3594}
3595
James Smarte59058c2008-08-24 21:49:00 -04003596/**
James Smart3621a712009-04-06 18:47:14 -04003597 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003598 * @phba: pointer to lpfc hba data structure.
3599 * @cmdiocb: pointer to lpfc command iocb data structure.
3600 * @rspiocb: pointer to lpfc response iocb data structure.
3601 *
3602 * This routine is the completion callback function to the Logout (LOGO)
3603 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3604 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3605 * release the ndlp if it has the last reference remaining (reference count
3606 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3607 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3608 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3609 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3610 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3611 * IOCB data structure.
3612 **/
dea31012005-04-17 16:05:31 -05003613static void
James Smart2e0fef82007-06-17 19:56:36 -05003614lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3615 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003616{
James Smart2e0fef82007-06-17 19:56:36 -05003617 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3618 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003619 IOCB_t *irsp;
3620
3621 irsp = &rspiocb->iocb;
3622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3623 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3624 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003625 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003626 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3627 "0109 ACC to LOGO completes to NPort x%x "
3628 "Data: x%x x%x x%x\n",
3629 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3630 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003631
3632 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3633 /* NPort Recovery mode or node is just allocated */
3634 if (!lpfc_nlp_not_used(ndlp)) {
3635 /* If the ndlp is being used by another discovery
3636 * thread, just unregister the RPI.
3637 */
3638 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003639 } else {
3640 /* Indicate the node has already released, should
3641 * not reference to it from within lpfc_els_free_iocb.
3642 */
3643 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003644 }
dea31012005-04-17 16:05:31 -05003645 }
James Smart73d91e52011-10-10 21:32:10 -04003646
3647 /*
3648 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003649 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003650 */
dea31012005-04-17 16:05:31 -05003651 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003652}
3653
James Smarte59058c2008-08-24 21:49:00 -04003654/**
James Smart3621a712009-04-06 18:47:14 -04003655 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003656 * @phba: pointer to lpfc hba data structure.
3657 * @pmb: pointer to the driver internal queue element for mailbox command.
3658 *
3659 * This routine is the completion callback function for unregister default
3660 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3661 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3662 * decrements the ndlp reference count held for this completion callback
3663 * function. After that, it invokes the lpfc_nlp_not_used() to check
3664 * whether there is only one reference left on the ndlp. If so, it will
3665 * perform one more decrement and trigger the release of the ndlp.
3666 **/
James Smart858c9f62007-06-17 19:56:39 -05003667void
3668lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3669{
3670 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3671 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3672
3673 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003674 pmb->context2 = NULL;
3675
James Smart858c9f62007-06-17 19:56:39 -05003676 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3677 kfree(mp);
3678 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003679 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003680 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3681 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3682 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3683 atomic_read(&ndlp->kref.refcount),
3684 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003685 if (NLP_CHK_NODE_ACT(ndlp)) {
3686 lpfc_nlp_put(ndlp);
3687 /* This is the end of the default RPI cleanup logic for
3688 * this ndlp. If no other discovery threads are using
3689 * this ndlp, free all resources associated with it.
3690 */
3691 lpfc_nlp_not_used(ndlp);
3692 } else {
3693 lpfc_drop_node(ndlp->vport, ndlp);
3694 }
James Smarta8adb832007-10-27 13:37:53 -04003695 }
James Smart3772a992009-05-22 14:50:54 -04003696
James Smart858c9f62007-06-17 19:56:39 -05003697 return;
3698}
3699
James Smarte59058c2008-08-24 21:49:00 -04003700/**
James Smart3621a712009-04-06 18:47:14 -04003701 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003702 * @phba: pointer to lpfc hba data structure.
3703 * @cmdiocb: pointer to lpfc command iocb data structure.
3704 * @rspiocb: pointer to lpfc response iocb data structure.
3705 *
3706 * This routine is the completion callback function for ELS Response IOCB
3707 * command. In normal case, this callback function just properly sets the
3708 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3709 * field in the command IOCB is not NULL, the referred mailbox command will
3710 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3711 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3712 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3713 * routine shall be invoked trying to release the ndlp if no other threads
3714 * are currently referring it.
3715 **/
dea31012005-04-17 16:05:31 -05003716static void
James Smart858c9f62007-06-17 19:56:39 -05003717lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003718 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003719{
James Smart2e0fef82007-06-17 19:56:36 -05003720 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3721 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3722 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003723 IOCB_t *irsp;
3724 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003725 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003726 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003727 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003728
James Smart33ccf8d2006-08-17 11:57:58 -04003729 irsp = &rspiocb->iocb;
3730
dea31012005-04-17 16:05:31 -05003731 if (cmdiocb->context_un.mbox)
3732 mbox = cmdiocb->context_un.mbox;
3733
James Smartfa4066b2008-01-11 01:53:27 -05003734 /* First determine if this is a LS_RJT cmpl. Note, this callback
3735 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3736 */
James Smart87af33f2007-10-27 13:37:43 -04003737 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003738 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3739 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003740 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003741 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003742 */
3743 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3744 ls_rjt = 1;
3745 }
3746
dea31012005-04-17 16:05:31 -05003747 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003748 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003749 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003750 mp = (struct lpfc_dmabuf *) mbox->context1;
3751 if (mp) {
3752 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3753 kfree(mp);
3754 }
James Smart329f9bc2007-04-25 09:53:01 -04003755 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003756 }
James Smart58da1ff2008-04-07 10:15:56 -04003757 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3758 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003759 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003760 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003761 /* Indicate the node has already released,
3762 * should not reference to it from within
3763 * the routine lpfc_els_free_iocb.
3764 */
3765 cmdiocb->context1 = NULL;
3766 }
dea31012005-04-17 16:05:31 -05003767 goto out;
3768 }
3769
James Smart858c9f62007-06-17 19:56:39 -05003770 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003771 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003772 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003773 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003774 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3776 "0110 ELS response tag x%x completes "
3777 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3778 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3779 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3780 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3781 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003782 if (mbox) {
3783 if ((rspiocb->iocb.ulpStatus == 0)
3784 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003785 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003786 /* Increment reference count to ndlp to hold the
3787 * reference to ndlp for the callback function.
3788 */
James Smart329f9bc2007-04-25 09:53:01 -04003789 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003790 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003791 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3792 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3793 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3794 }
3795 else {
3796 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3797 ndlp->nlp_prev_state = ndlp->nlp_state;
3798 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003799 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003800 }
James Smart4b7789b2015-12-16 18:11:55 -05003801
3802 ndlp->nlp_flag |= NLP_REG_LOGIN_SEND;
James Smart0b727fe2007-10-27 13:37:25 -04003803 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003804 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003805 goto out;
James Smart4b7789b2015-12-16 18:11:55 -05003806
3807 /* Decrement the ndlp reference count we
3808 * set for this failed mailbox command.
3809 */
3810 lpfc_nlp_put(ndlp);
3811 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
James Smart98c9ea52007-10-27 13:37:33 -04003812
3813 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3814 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3815 "0138 ELS rsp: Cannot issue reg_login for x%x "
3816 "Data: x%x x%x x%x\n",
3817 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3818 ndlp->nlp_rpi);
3819
James Smartfa4066b2008-01-11 01:53:27 -05003820 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003821 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003822 /* Indicate node has already been released,
3823 * should not reference to it from within
3824 * the routine lpfc_els_free_iocb.
3825 */
3826 cmdiocb->context1 = NULL;
3827 }
dea31012005-04-17 16:05:31 -05003828 } else {
James Smart858c9f62007-06-17 19:56:39 -05003829 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3830 if (!lpfc_error_lost_link(irsp) &&
3831 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003832 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003833 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003834 /* Indicate node has already been
3835 * released, should not reference
3836 * to it from within the routine
3837 * lpfc_els_free_iocb.
3838 */
3839 cmdiocb->context1 = NULL;
3840 }
dea31012005-04-17 16:05:31 -05003841 }
3842 }
James Smart14691152006-12-02 13:34:28 -05003843 mp = (struct lpfc_dmabuf *) mbox->context1;
3844 if (mp) {
3845 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3846 kfree(mp);
3847 }
3848 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003849 }
3850out:
James Smart58da1ff2008-04-07 10:15:56 -04003851 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003852 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003853 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003854 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003855
3856 /* If the node is not being used by another discovery thread,
3857 * and we are sending a reject, we are done with it.
3858 * Release driver reference count here and free associated
3859 * resources.
3860 */
3861 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003862 if (lpfc_nlp_not_used(ndlp))
3863 /* Indicate node has already been released,
3864 * should not reference to it from within
3865 * the routine lpfc_els_free_iocb.
3866 */
3867 cmdiocb->context1 = NULL;
James Smart4b7789b2015-12-16 18:11:55 -05003868
dea31012005-04-17 16:05:31 -05003869 }
James Smart87af33f2007-10-27 13:37:43 -04003870
dea31012005-04-17 16:05:31 -05003871 lpfc_els_free_iocb(phba, cmdiocb);
3872 return;
3873}
3874
James Smarte59058c2008-08-24 21:49:00 -04003875/**
James Smart3621a712009-04-06 18:47:14 -04003876 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003877 * @vport: pointer to a host virtual N_Port data structure.
3878 * @flag: the els command code to be accepted.
3879 * @oldiocb: pointer to the original lpfc command iocb data structure.
3880 * @ndlp: pointer to a node-list data structure.
3881 * @mbox: pointer to the driver internal queue element for mailbox command.
3882 *
3883 * This routine prepares and issues an Accept (ACC) response IOCB
3884 * command. It uses the @flag to properly set up the IOCB field for the
3885 * specific ACC response command to be issued and invokes the
3886 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3887 * @mbox pointer is passed in, it will be put into the context_un.mbox
3888 * field of the IOCB for the completion callback function to issue the
3889 * mailbox command to the HBA later when callback is invoked.
3890 *
3891 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3892 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3893 * will be stored into the context1 field of the IOCB for the completion
3894 * callback function to the corresponding response ELS IOCB command.
3895 *
3896 * Return code
3897 * 0 - Successfully issued acc response
3898 * 1 - Failed to issue acc response
3899 **/
dea31012005-04-17 16:05:31 -05003900int
James Smart2e0fef82007-06-17 19:56:36 -05003901lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3902 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003903 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003904{
James Smart2e0fef82007-06-17 19:56:36 -05003905 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3906 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003907 IOCB_t *icmd;
3908 IOCB_t *oldcmd;
3909 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003910 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05003911 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05003912 uint16_t cmdsize;
3913 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003914 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003915
dea31012005-04-17 16:05:31 -05003916 oldcmd = &oldiocb->iocb;
3917
3918 switch (flag) {
3919 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003920 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003921 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3922 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003923 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003924 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003925 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003926 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003927 return 1;
dea31012005-04-17 16:05:31 -05003928 }
James Smart2e0fef82007-06-17 19:56:36 -05003929
dea31012005-04-17 16:05:31 -05003930 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003931 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3932 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003933 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3934 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003935 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003936
3937 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3938 "Issue ACC: did:x%x flg:x%x",
3939 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003940 break;
James Smartd6de08c2015-12-16 18:11:53 -05003941 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05003942 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003943 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003944 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3945 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003946 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003947 return 1;
James Smart488d1462006-03-07 15:02:37 -05003948
dea31012005-04-17 16:05:31 -05003949 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003950 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3951 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003952 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3953
3954 if (mbox)
3955 elsiocb->context_un.mbox = mbox;
3956
3957 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003958 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05003959 sp = (struct serv_parm *)pcmd;
3960
3961 if (flag == ELS_CMD_FLOGI) {
3962 /* Copy the received service parameters back */
3963 memcpy(sp, &phba->fc_fabparam,
3964 sizeof(struct serv_parm));
3965
3966 /* Clear the F_Port bit */
3967 sp->cmn.fPort = 0;
3968
3969 /* Mark all class service parameters as invalid */
3970 sp->cls1.classValid = 0;
3971 sp->cls2.classValid = 0;
3972 sp->cls3.classValid = 0;
3973 sp->cls4.classValid = 0;
3974
3975 /* Copy our worldwide names */
3976 memcpy(&sp->portName, &vport->fc_sparam.portName,
3977 sizeof(struct lpfc_name));
3978 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
3979 sizeof(struct lpfc_name));
3980 } else {
3981 memcpy(pcmd, &vport->fc_sparam,
3982 sizeof(struct serv_parm));
3983 }
James Smart858c9f62007-06-17 19:56:39 -05003984
3985 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05003986 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003987 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003988 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003989 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003990 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003991 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003992 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3993 if (!elsiocb)
3994 return 1;
3995
3996 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003997 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3998 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003999 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4000
4001 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05004002 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04004003 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
4004 els_pkt_ptr = (ELS_PKT *) pcmd;
4005 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05004006
4007 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4008 "Issue ACC PRLO: did:x%x flg:x%x",
4009 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04004010 break;
dea31012005-04-17 16:05:31 -05004011 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004012 return 1;
dea31012005-04-17 16:05:31 -05004013 }
dea31012005-04-17 16:05:31 -05004014 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004015 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4016 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04004017 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4018 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04004019 elsiocb->iotag, elsiocb->iocb.ulpContext,
4020 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04004021 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05004022 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004023 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004024 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4025 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4026 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004027 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004028 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4029 } else {
James Smart858c9f62007-06-17 19:56:39 -05004030 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004031 }
4032
4033 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004034 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004035 if (rc == IOCB_ERROR) {
4036 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004037 return 1;
dea31012005-04-17 16:05:31 -05004038 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004039 return 0;
dea31012005-04-17 16:05:31 -05004040}
4041
James Smarte59058c2008-08-24 21:49:00 -04004042/**
James Smart3621a712009-04-06 18:47:14 -04004043 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004044 * @vport: pointer to a virtual N_Port data structure.
4045 * @rejectError:
4046 * @oldiocb: pointer to the original lpfc command iocb data structure.
4047 * @ndlp: pointer to a node-list data structure.
4048 * @mbox: pointer to the driver internal queue element for mailbox command.
4049 *
4050 * This routine prepares and issue an Reject (RJT) response IOCB
4051 * command. If a @mbox pointer is passed in, it will be put into the
4052 * context_un.mbox field of the IOCB for the completion callback function
4053 * to issue to the HBA later.
4054 *
4055 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4056 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4057 * will be stored into the context1 field of the IOCB for the completion
4058 * callback function to the reject response ELS IOCB command.
4059 *
4060 * Return code
4061 * 0 - Successfully issued reject response
4062 * 1 - Failed to issue reject response
4063 **/
dea31012005-04-17 16:05:31 -05004064int
James Smart2e0fef82007-06-17 19:56:36 -05004065lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004066 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4067 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004068{
James Smart2e0fef82007-06-17 19:56:36 -05004069 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004070 IOCB_t *icmd;
4071 IOCB_t *oldcmd;
4072 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004073 uint8_t *pcmd;
4074 uint16_t cmdsize;
4075 int rc;
4076
James Smart92d7f7b2007-06-17 19:56:38 -05004077 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004078 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4079 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004080 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004081 return 1;
dea31012005-04-17 16:05:31 -05004082
4083 icmd = &elsiocb->iocb;
4084 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004085 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4086 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004087 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4088
4089 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004090 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004091 *((uint32_t *) (pcmd)) = rejectError;
4092
James Smart51ef4c22007-08-02 11:10:31 -04004093 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004094 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004095
dea31012005-04-17 16:05:31 -05004096 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004097 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4098 "0129 Xmit ELS RJT x%x response tag x%x "
4099 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4100 "rpi x%x\n",
4101 rejectError, elsiocb->iotag,
4102 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4103 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004104 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4105 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4106 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4107
dea31012005-04-17 16:05:31 -05004108 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004109 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004110 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004111
dea31012005-04-17 16:05:31 -05004112 if (rc == IOCB_ERROR) {
4113 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004114 return 1;
dea31012005-04-17 16:05:31 -05004115 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004116 return 0;
dea31012005-04-17 16:05:31 -05004117}
4118
James Smarte59058c2008-08-24 21:49:00 -04004119/**
James Smart3621a712009-04-06 18:47:14 -04004120 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004121 * @vport: pointer to a virtual N_Port data structure.
4122 * @oldiocb: pointer to the original lpfc command iocb data structure.
4123 * @ndlp: pointer to a node-list data structure.
4124 *
4125 * This routine prepares and issues an Accept (ACC) response to Address
4126 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4127 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4128 *
4129 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4130 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4131 * will be stored into the context1 field of the IOCB for the completion
4132 * callback function to the ADISC Accept response ELS IOCB command.
4133 *
4134 * Return code
4135 * 0 - Successfully issued acc adisc response
4136 * 1 - Failed to issue adisc acc response
4137 **/
dea31012005-04-17 16:05:31 -05004138int
James Smart2e0fef82007-06-17 19:56:36 -05004139lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4140 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004141{
James Smart2e0fef82007-06-17 19:56:36 -05004142 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004143 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004144 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004145 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004146 uint8_t *pcmd;
4147 uint16_t cmdsize;
4148 int rc;
4149
James Smart92d7f7b2007-06-17 19:56:38 -05004150 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004151 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4152 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004153 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004154 return 1;
dea31012005-04-17 16:05:31 -05004155
dea31012005-04-17 16:05:31 -05004156 icmd = &elsiocb->iocb;
4157 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004158 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4159 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004160
4161 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004162 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4163 "0130 Xmit ADISC ACC response iotag x%x xri: "
4164 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4165 elsiocb->iotag, elsiocb->iocb.ulpContext,
4166 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4167 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4169
4170 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004171 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004172
4173 ap = (ADISC *) (pcmd);
4174 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004175 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4176 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004177 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004178
James Smart858c9f62007-06-17 19:56:39 -05004179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4180 "Issue ACC ADISC: did:x%x flg:x%x",
4181 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4182
dea31012005-04-17 16:05:31 -05004183 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004184 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004185 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004186 if (rc == IOCB_ERROR) {
4187 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004188 return 1;
dea31012005-04-17 16:05:31 -05004189 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004190 return 0;
dea31012005-04-17 16:05:31 -05004191}
4192
James Smarte59058c2008-08-24 21:49:00 -04004193/**
James Smart3621a712009-04-06 18:47:14 -04004194 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004195 * @vport: pointer to a virtual N_Port data structure.
4196 * @oldiocb: pointer to the original lpfc command iocb data structure.
4197 * @ndlp: pointer to a node-list data structure.
4198 *
4199 * This routine prepares and issues an Accept (ACC) response to Process
4200 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4201 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4202 *
4203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4205 * will be stored into the context1 field of the IOCB for the completion
4206 * callback function to the PRLI Accept response ELS IOCB command.
4207 *
4208 * Return code
4209 * 0 - Successfully issued acc prli response
4210 * 1 - Failed to issue acc prli response
4211 **/
dea31012005-04-17 16:05:31 -05004212int
James Smart2e0fef82007-06-17 19:56:36 -05004213lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004214 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004215{
James Smart2e0fef82007-06-17 19:56:36 -05004216 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004217 PRLI *npr;
4218 lpfc_vpd_t *vpd;
4219 IOCB_t *icmd;
4220 IOCB_t *oldcmd;
4221 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004222 uint8_t *pcmd;
4223 uint16_t cmdsize;
4224 int rc;
4225
James Smart92d7f7b2007-06-17 19:56:38 -05004226 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004227 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004228 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004229 if (!elsiocb)
4230 return 1;
dea31012005-04-17 16:05:31 -05004231
dea31012005-04-17 16:05:31 -05004232 icmd = &elsiocb->iocb;
4233 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004234 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4235 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4236
James Smart5b8bd0c2007-04-25 09:52:49 -04004237 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4239 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4240 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4241 elsiocb->iotag, elsiocb->iocb.ulpContext,
4242 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4243 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004244 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4245
4246 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004247 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004248
4249 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004250 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004251
4252 npr = (PRLI *) pcmd;
4253 vpd = &phba->vpd;
4254 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004255 * If the remote port is a target and our firmware version is 3.20 or
4256 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004257 */
James Smart0d2b6b82008-06-14 22:52:47 -04004258 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4259 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004260 npr->ConfmComplAllowed = 1;
4261 npr->Retry = 1;
4262 npr->TaskRetryIdReq = 1;
4263 }
4264
4265 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4266 npr->estabImagePair = 1;
4267 npr->readXferRdyDis = 1;
4268 npr->ConfmComplAllowed = 1;
4269
4270 npr->prliType = PRLI_FCP_TYPE;
4271 npr->initiatorFunc = 1;
4272
James Smart858c9f62007-06-17 19:56:39 -05004273 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4274 "Issue ACC PRLI: did:x%x flg:x%x",
4275 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4276
dea31012005-04-17 16:05:31 -05004277 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004278 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004279
James Smart3772a992009-05-22 14:50:54 -04004280 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004281 if (rc == IOCB_ERROR) {
4282 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004283 return 1;
dea31012005-04-17 16:05:31 -05004284 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004285 return 0;
dea31012005-04-17 16:05:31 -05004286}
4287
James Smarte59058c2008-08-24 21:49:00 -04004288/**
James Smart3621a712009-04-06 18:47:14 -04004289 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004290 * @vport: pointer to a virtual N_Port data structure.
4291 * @format: rnid command format.
4292 * @oldiocb: pointer to the original lpfc command iocb data structure.
4293 * @ndlp: pointer to a node-list data structure.
4294 *
4295 * This routine issues a Request Node Identification Data (RNID) Accept
4296 * (ACC) response. It constructs the RNID ACC response command according to
4297 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4298 * issue the response. Note that this command does not need to hold the ndlp
4299 * reference count for the callback. So, the ndlp reference count taken by
4300 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4301 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4302 * there is no ndlp reference available.
4303 *
4304 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4305 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4306 * will be stored into the context1 field of the IOCB for the completion
4307 * callback function. However, for the RNID Accept Response ELS command,
4308 * this is undone later by this routine after the IOCB is allocated.
4309 *
4310 * Return code
4311 * 0 - Successfully issued acc rnid response
4312 * 1 - Failed to issue acc rnid response
4313 **/
dea31012005-04-17 16:05:31 -05004314static int
James Smart2e0fef82007-06-17 19:56:36 -05004315lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004316 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004317{
James Smart2e0fef82007-06-17 19:56:36 -05004318 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004319 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004320 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004321 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004322 uint8_t *pcmd;
4323 uint16_t cmdsize;
4324 int rc;
4325
James Smart92d7f7b2007-06-17 19:56:38 -05004326 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4327 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004328 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004329 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004330
James Smart2e0fef82007-06-17 19:56:36 -05004331 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4332 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004333 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004334 return 1;
dea31012005-04-17 16:05:31 -05004335
dea31012005-04-17 16:05:31 -05004336 icmd = &elsiocb->iocb;
4337 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004338 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4339 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4340
James Smart5b8bd0c2007-04-25 09:52:49 -04004341 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4343 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4344 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004345 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004346 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004347 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004348
James Smart92d7f7b2007-06-17 19:56:38 -05004349 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004350 rn = (RNID *) (pcmd);
4351 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004352 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4353 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4354 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004355 switch (format) {
4356 case 0:
4357 rn->SpecificLen = 0;
4358 break;
4359 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004360 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004361 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004362 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004363 rn->un.topologyDisc.unitType = RNID_HBA;
4364 rn->un.topologyDisc.physPort = 0;
4365 rn->un.topologyDisc.attachedNodes = 0;
4366 break;
4367 default:
4368 rn->CommonLen = 0;
4369 rn->SpecificLen = 0;
4370 break;
4371 }
4372
James Smart858c9f62007-06-17 19:56:39 -05004373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4374 "Issue ACC RNID: did:x%x flg:x%x",
4375 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4376
dea31012005-04-17 16:05:31 -05004377 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004378 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004379
James Smart3772a992009-05-22 14:50:54 -04004380 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004381 if (rc == IOCB_ERROR) {
4382 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004383 return 1;
dea31012005-04-17 16:05:31 -05004384 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004385 return 0;
dea31012005-04-17 16:05:31 -05004386}
4387
James Smarte59058c2008-08-24 21:49:00 -04004388/**
James Smart19ca7602010-11-20 23:11:55 -05004389 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4390 * @vport: pointer to a virtual N_Port data structure.
4391 * @iocb: pointer to the lpfc command iocb data structure.
4392 * @ndlp: pointer to a node-list data structure.
4393 *
4394 * Return
4395 **/
4396static void
4397lpfc_els_clear_rrq(struct lpfc_vport *vport,
4398 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4399{
4400 struct lpfc_hba *phba = vport->phba;
4401 uint8_t *pcmd;
4402 struct RRQ *rrq;
4403 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004404 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004405 struct lpfc_node_rrq *prrq;
4406
4407
4408 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4409 pcmd += sizeof(uint32_t);
4410 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004411 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004412 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004413
4414 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4415 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4416 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004417 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004418 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004419 rxid,
4420 iocb->iotag, iocb->iocb.ulpContext);
4421
4422 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4423 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4424 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004425 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004426 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004427 else
4428 xri = rxid;
4429 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004430 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004431 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004432 return;
4433}
4434
4435/**
James Smart12265f62010-10-22 11:05:53 -04004436 * lpfc_els_rsp_echo_acc - Issue echo acc response
4437 * @vport: pointer to a virtual N_Port data structure.
4438 * @data: pointer to echo data to return in the accept.
4439 * @oldiocb: pointer to the original lpfc command iocb data structure.
4440 * @ndlp: pointer to a node-list data structure.
4441 *
4442 * Return code
4443 * 0 - Successfully issued acc echo response
4444 * 1 - Failed to issue acc echo response
4445 **/
4446static int
4447lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4448 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4449{
4450 struct lpfc_hba *phba = vport->phba;
4451 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04004452 uint8_t *pcmd;
4453 uint16_t cmdsize;
4454 int rc;
4455
James Smart12265f62010-10-22 11:05:53 -04004456 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4457
James Smartbf086112011-08-21 21:48:13 -04004458 /* The accumulated length can exceed the BPL_SIZE. For
4459 * now, use this as the limit
4460 */
4461 if (cmdsize > LPFC_BPL_SIZE)
4462 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004463 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4464 ndlp->nlp_DID, ELS_CMD_ACC);
4465 if (!elsiocb)
4466 return 1;
4467
James Smart7851fe22011-07-22 18:36:52 -04004468 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4469 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4470
James Smart12265f62010-10-22 11:05:53 -04004471 /* Xmit ECHO ACC response tag <ulpIoTag> */
4472 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4473 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4474 elsiocb->iotag, elsiocb->iocb.ulpContext);
4475 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4476 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4477 pcmd += sizeof(uint32_t);
4478 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4479
4480 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4481 "Issue ACC ECHO: did:x%x flg:x%x",
4482 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4483
4484 phba->fc_stat.elsXmitACC++;
4485 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004486
4487 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4488 if (rc == IOCB_ERROR) {
4489 lpfc_els_free_iocb(phba, elsiocb);
4490 return 1;
4491 }
4492 return 0;
4493}
4494
4495/**
James Smart3621a712009-04-06 18:47:14 -04004496 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004497 * @vport: pointer to a host virtual N_Port data structure.
4498 *
4499 * This routine issues Address Discover (ADISC) ELS commands to those
4500 * N_Ports which are in node port recovery state and ADISC has not been issued
4501 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4502 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4503 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4504 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4505 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4506 * IOCBs quit for later pick up. On the other hand, after walking through
4507 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4508 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4509 * no more ADISC need to be sent.
4510 *
4511 * Return code
4512 * The number of N_Ports with adisc issued.
4513 **/
dea31012005-04-17 16:05:31 -05004514int
James Smart2e0fef82007-06-17 19:56:36 -05004515lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004516{
James Smart2e0fef82007-06-17 19:56:36 -05004517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004518 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004519 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004520
James Smart685f0bf2007-04-25 09:53:08 -04004521 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004522 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004523 if (!NLP_CHK_NODE_ACT(ndlp))
4524 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004525 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4526 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4527 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004528 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004529 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004530 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004531 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004532 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4533 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004534 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004535 vport->num_disc_nodes++;
4536 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004537 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004538 spin_lock_irq(shost->host_lock);
4539 vport->fc_flag |= FC_NLP_MORE;
4540 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004541 break;
dea31012005-04-17 16:05:31 -05004542 }
4543 }
4544 }
4545 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004546 spin_lock_irq(shost->host_lock);
4547 vport->fc_flag &= ~FC_NLP_MORE;
4548 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004549 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004550 return sentadisc;
dea31012005-04-17 16:05:31 -05004551}
4552
James Smarte59058c2008-08-24 21:49:00 -04004553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004555 * @vport: pointer to a host virtual N_Port data structure.
4556 *
4557 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4558 * which are in node port recovery state, with a @vport. Each time an ELS
4559 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4560 * the per @vport number of discover count (num_disc_nodes) shall be
4561 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4562 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4563 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4564 * later pick up. On the other hand, after walking through all the ndlps with
4565 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4566 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4567 * PLOGI need to be sent.
4568 *
4569 * Return code
4570 * The number of N_Ports with plogi issued.
4571 **/
dea31012005-04-17 16:05:31 -05004572int
James Smart2e0fef82007-06-17 19:56:36 -05004573lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004574{
James Smart2e0fef82007-06-17 19:56:36 -05004575 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004576 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004577 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004578
James Smart2e0fef82007-06-17 19:56:36 -05004579 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4580 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004581 if (!NLP_CHK_NODE_ACT(ndlp))
4582 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004583 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004584 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4585 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4586 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004587 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004588 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4589 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004590 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004591 vport->num_disc_nodes++;
4592 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004593 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004594 spin_lock_irq(shost->host_lock);
4595 vport->fc_flag |= FC_NLP_MORE;
4596 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004597 break;
dea31012005-04-17 16:05:31 -05004598 }
4599 }
4600 }
James Smart87af33f2007-10-27 13:37:43 -04004601 if (sentplogi) {
4602 lpfc_set_disctmo(vport);
4603 }
4604 else {
James Smart2e0fef82007-06-17 19:56:36 -05004605 spin_lock_irq(shost->host_lock);
4606 vport->fc_flag &= ~FC_NLP_MORE;
4607 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004608 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004609 return sentplogi;
dea31012005-04-17 16:05:31 -05004610}
4611
James Smart6c92d1d2016-07-06 12:35:55 -07004612uint32_t
James Smart86478872015-05-21 13:55:21 -04004613lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4614 uint32_t word0)
4615{
4616
4617 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4618 desc->payload.els_req = word0;
4619 desc->length = cpu_to_be32(sizeof(desc->payload));
James Smart6c92d1d2016-07-06 12:35:55 -07004620
4621 return sizeof(struct fc_rdp_link_service_desc);
James Smart86478872015-05-21 13:55:21 -04004622}
4623
James Smart6c92d1d2016-07-06 12:35:55 -07004624uint32_t
James Smart86478872015-05-21 13:55:21 -04004625lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4626 uint8_t *page_a0, uint8_t *page_a2)
4627{
4628 uint16_t wavelength;
4629 uint16_t temperature;
4630 uint16_t rx_power;
4631 uint16_t tx_bias;
4632 uint16_t tx_power;
4633 uint16_t vcc;
4634 uint16_t flag = 0;
4635 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4636 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4637
4638 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4639
4640 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4641 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4642 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4643 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4644
4645 if ((trasn_code_byte4->fc_sw_laser) ||
4646 (trasn_code_byte5->fc_sw_laser_sl) ||
4647 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4648 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4649 } else if (trasn_code_byte4->fc_lw_laser) {
4650 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4651 page_a0[SSF_WAVELENGTH_B0];
4652 if (wavelength == SFP_WAVELENGTH_LC1310)
4653 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4654 if (wavelength == SFP_WAVELENGTH_LL1550)
4655 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4656 }
4657 /* check if its SFP+ */
4658 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4659 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4660 << SFP_FLAG_CT_SHIFT;
4661
4662 /* check if its OPTICAL */
4663 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4664 SFP_FLAG_IS_OPTICAL_PORT : 0)
4665 << SFP_FLAG_IS_OPTICAL_SHIFT;
4666
4667 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4668 page_a2[SFF_TEMPERATURE_B0]);
4669 vcc = (page_a2[SFF_VCC_B1] << 8 |
4670 page_a2[SFF_VCC_B0]);
4671 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4672 page_a2[SFF_TXPOWER_B0]);
4673 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4674 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4675 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4676 page_a2[SFF_RXPOWER_B0]);
4677 desc->sfp_info.temperature = cpu_to_be16(temperature);
4678 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4679 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4680 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4681 desc->sfp_info.vcc = cpu_to_be16(vcc);
4682
4683 desc->sfp_info.flags = cpu_to_be16(flag);
4684 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004685
4686 return sizeof(struct fc_rdp_sfp_desc);
James Smart86478872015-05-21 13:55:21 -04004687}
4688
James Smart6c92d1d2016-07-06 12:35:55 -07004689uint32_t
James Smart86478872015-05-21 13:55:21 -04004690lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4691 READ_LNK_VAR *stat)
4692{
4693 uint32_t type;
4694
4695 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4696
4697 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4698
4699 desc->info.port_type = cpu_to_be32(type);
4700
4701 desc->info.link_status.link_failure_cnt =
4702 cpu_to_be32(stat->linkFailureCnt);
4703 desc->info.link_status.loss_of_synch_cnt =
4704 cpu_to_be32(stat->lossSyncCnt);
4705 desc->info.link_status.loss_of_signal_cnt =
4706 cpu_to_be32(stat->lossSignalCnt);
4707 desc->info.link_status.primitive_seq_proto_err =
4708 cpu_to_be32(stat->primSeqErrCnt);
4709 desc->info.link_status.invalid_trans_word =
4710 cpu_to_be32(stat->invalidXmitWord);
4711 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4712
4713 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07004714
4715 return sizeof(struct fc_rdp_link_error_status_desc);
James Smart86478872015-05-21 13:55:21 -04004716}
4717
James Smart6c92d1d2016-07-06 12:35:55 -07004718uint32_t
James Smart56204982016-03-31 14:12:32 -07004719lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc *desc, READ_LNK_VAR *stat,
4720 struct lpfc_vport *vport)
4721{
James Smart3aaaa312016-07-06 12:35:57 -07004722 uint32_t bbCredit;
4723
James Smart56204982016-03-31 14:12:32 -07004724 desc->tag = cpu_to_be32(RDP_BBC_DESC_TAG);
4725
James Smart3aaaa312016-07-06 12:35:57 -07004726 bbCredit = vport->fc_sparam.cmn.bbCreditLsb |
4727 (vport->fc_sparam.cmn.bbCreditMsb << 8);
4728 desc->bbc_info.port_bbc = cpu_to_be32(bbCredit);
4729 if (vport->phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
4730 bbCredit = vport->phba->fc_fabparam.cmn.bbCreditLsb |
4731 (vport->phba->fc_fabparam.cmn.bbCreditMsb << 8);
4732 desc->bbc_info.attached_port_bbc = cpu_to_be32(bbCredit);
4733 } else {
James Smart56204982016-03-31 14:12:32 -07004734 desc->bbc_info.attached_port_bbc = 0;
James Smart3aaaa312016-07-06 12:35:57 -07004735 }
James Smart56204982016-03-31 14:12:32 -07004736
4737 desc->bbc_info.rtt = 0;
4738 desc->length = cpu_to_be32(sizeof(desc->bbc_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004739
4740 return sizeof(struct fc_rdp_bbc_desc);
James Smart56204982016-03-31 14:12:32 -07004741}
4742
James Smart6c92d1d2016-07-06 12:35:55 -07004743uint32_t
James Smart310429e2016-07-06 12:35:54 -07004744lpfc_rdp_res_oed_temp_desc(struct lpfc_hba *phba,
4745 struct fc_rdp_oed_sfp_desc *desc, uint8_t *page_a2)
James Smart56204982016-03-31 14:12:32 -07004746{
James Smart310429e2016-07-06 12:35:54 -07004747 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004748
4749 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4750
James Smart3aaaa312016-07-06 12:35:57 -07004751 desc->oed_info.hi_alarm = page_a2[SSF_TEMP_HIGH_ALARM];
4752 desc->oed_info.lo_alarm = page_a2[SSF_TEMP_LOW_ALARM];
4753 desc->oed_info.hi_warning = page_a2[SSF_TEMP_HIGH_WARNING];
4754 desc->oed_info.lo_warning = page_a2[SSF_TEMP_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004755
4756 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4757 flags |= RDP_OET_HIGH_ALARM;
4758 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4759 flags |= RDP_OET_LOW_ALARM;
4760 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TEMPERATURE)
4761 flags |= RDP_OET_HIGH_WARNING;
4762 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TEMPERATURE)
4763 flags |= RDP_OET_LOW_WARNING;
4764
James Smart56204982016-03-31 14:12:32 -07004765 flags |= ((0xf & RDP_OED_TEMPERATURE) << RDP_OED_TYPE_SHIFT);
4766 desc->oed_info.function_flags = cpu_to_be32(flags);
4767 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004768 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004769}
4770
James Smart6c92d1d2016-07-06 12:35:55 -07004771uint32_t
James Smart310429e2016-07-06 12:35:54 -07004772lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba *phba,
4773 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004774 uint8_t *page_a2)
4775{
James Smart310429e2016-07-06 12:35:54 -07004776 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004777
4778 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4779
James Smart3aaaa312016-07-06 12:35:57 -07004780 desc->oed_info.hi_alarm = page_a2[SSF_VOLTAGE_HIGH_ALARM];
4781 desc->oed_info.lo_alarm = page_a2[SSF_VOLTAGE_LOW_ALARM];
4782 desc->oed_info.hi_warning = page_a2[SSF_VOLTAGE_HIGH_WARNING];
4783 desc->oed_info.lo_warning = page_a2[SSF_VOLTAGE_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004784
4785 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4786 flags |= RDP_OET_HIGH_ALARM;
4787 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4788 flags |= RDP_OET_LOW_ALARM;
4789 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_VOLTAGE)
4790 flags |= RDP_OET_HIGH_WARNING;
4791 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_VOLTAGE)
4792 flags |= RDP_OET_LOW_WARNING;
4793
James Smart56204982016-03-31 14:12:32 -07004794 flags |= ((0xf & RDP_OED_VOLTAGE) << RDP_OED_TYPE_SHIFT);
4795 desc->oed_info.function_flags = cpu_to_be32(flags);
4796 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004797 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004798}
4799
James Smart6c92d1d2016-07-06 12:35:55 -07004800uint32_t
James Smart310429e2016-07-06 12:35:54 -07004801lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba *phba,
4802 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004803 uint8_t *page_a2)
4804{
James Smart310429e2016-07-06 12:35:54 -07004805 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004806
4807 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4808
James Smart3aaaa312016-07-06 12:35:57 -07004809 desc->oed_info.hi_alarm = page_a2[SSF_BIAS_HIGH_ALARM];
4810 desc->oed_info.lo_alarm = page_a2[SSF_BIAS_LOW_ALARM];
4811 desc->oed_info.hi_warning = page_a2[SSF_BIAS_HIGH_WARNING];
4812 desc->oed_info.lo_warning = page_a2[SSF_BIAS_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004813
4814 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXBIAS)
4815 flags |= RDP_OET_HIGH_ALARM;
4816 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXBIAS)
4817 flags |= RDP_OET_LOW_ALARM;
4818 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXBIAS)
4819 flags |= RDP_OET_HIGH_WARNING;
4820 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXBIAS)
4821 flags |= RDP_OET_LOW_WARNING;
4822
James Smart56204982016-03-31 14:12:32 -07004823 flags |= ((0xf & RDP_OED_TXBIAS) << RDP_OED_TYPE_SHIFT);
4824 desc->oed_info.function_flags = cpu_to_be32(flags);
4825 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004826 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004827}
4828
James Smart6c92d1d2016-07-06 12:35:55 -07004829uint32_t
James Smart310429e2016-07-06 12:35:54 -07004830lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba *phba,
4831 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004832 uint8_t *page_a2)
4833{
James Smart310429e2016-07-06 12:35:54 -07004834 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004835
4836 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4837
James Smart3aaaa312016-07-06 12:35:57 -07004838 desc->oed_info.hi_alarm = page_a2[SSF_TXPOWER_HIGH_ALARM];
4839 desc->oed_info.lo_alarm = page_a2[SSF_TXPOWER_LOW_ALARM];
4840 desc->oed_info.hi_warning = page_a2[SSF_TXPOWER_HIGH_WARNING];
4841 desc->oed_info.lo_warning = page_a2[SSF_TXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004842
4843 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_TXPOWER)
4844 flags |= RDP_OET_HIGH_ALARM;
4845 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_TXPOWER)
4846 flags |= RDP_OET_LOW_ALARM;
4847 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_TXPOWER)
4848 flags |= RDP_OET_HIGH_WARNING;
4849 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_TXPOWER)
4850 flags |= RDP_OET_LOW_WARNING;
4851
James Smart56204982016-03-31 14:12:32 -07004852 flags |= ((0xf & RDP_OED_TXPOWER) << RDP_OED_TYPE_SHIFT);
4853 desc->oed_info.function_flags = cpu_to_be32(flags);
4854 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004855 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004856}
4857
4858
James Smart6c92d1d2016-07-06 12:35:55 -07004859uint32_t
James Smart310429e2016-07-06 12:35:54 -07004860lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba *phba,
4861 struct fc_rdp_oed_sfp_desc *desc,
James Smart56204982016-03-31 14:12:32 -07004862 uint8_t *page_a2)
4863{
James Smart310429e2016-07-06 12:35:54 -07004864 uint32_t flags = 0;
James Smart56204982016-03-31 14:12:32 -07004865
4866 desc->tag = cpu_to_be32(RDP_OED_DESC_TAG);
4867
James Smart3aaaa312016-07-06 12:35:57 -07004868 desc->oed_info.hi_alarm = page_a2[SSF_RXPOWER_HIGH_ALARM];
4869 desc->oed_info.lo_alarm = page_a2[SSF_RXPOWER_LOW_ALARM];
4870 desc->oed_info.hi_warning = page_a2[SSF_RXPOWER_HIGH_WARNING];
4871 desc->oed_info.lo_warning = page_a2[SSF_RXPOWER_LOW_WARNING];
James Smart310429e2016-07-06 12:35:54 -07004872
4873 if (phba->sfp_alarm & LPFC_TRANSGRESSION_HIGH_RXPOWER)
4874 flags |= RDP_OET_HIGH_ALARM;
4875 if (phba->sfp_alarm & LPFC_TRANSGRESSION_LOW_RXPOWER)
4876 flags |= RDP_OET_LOW_ALARM;
4877 if (phba->sfp_warning & LPFC_TRANSGRESSION_HIGH_RXPOWER)
4878 flags |= RDP_OET_HIGH_WARNING;
4879 if (phba->sfp_warning & LPFC_TRANSGRESSION_LOW_RXPOWER)
4880 flags |= RDP_OET_LOW_WARNING;
4881
James Smart56204982016-03-31 14:12:32 -07004882 flags |= ((0xf & RDP_OED_RXPOWER) << RDP_OED_TYPE_SHIFT);
4883 desc->oed_info.function_flags = cpu_to_be32(flags);
4884 desc->length = cpu_to_be32(sizeof(desc->oed_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004885 return sizeof(struct fc_rdp_oed_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004886}
4887
James Smart6c92d1d2016-07-06 12:35:55 -07004888uint32_t
James Smart56204982016-03-31 14:12:32 -07004889lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc *desc,
4890 uint8_t *page_a0, struct lpfc_vport *vport)
4891{
4892 desc->tag = cpu_to_be32(RDP_OPD_DESC_TAG);
4893 memcpy(desc->opd_info.vendor_name, &page_a0[SSF_VENDOR_NAME], 16);
4894 memcpy(desc->opd_info.model_number, &page_a0[SSF_VENDOR_PN], 16);
4895 memcpy(desc->opd_info.serial_number, &page_a0[SSF_VENDOR_SN], 16);
4896 memcpy(desc->opd_info.revision, &page_a0[SSF_VENDOR_REV], 2);
4897 memcpy(desc->opd_info.date, &page_a0[SSF_DATE_CODE], 8);
4898 desc->length = cpu_to_be32(sizeof(desc->opd_info));
James Smart6c92d1d2016-07-06 12:35:55 -07004899 return sizeof(struct fc_rdp_opd_sfp_desc);
James Smart56204982016-03-31 14:12:32 -07004900}
4901
James Smart6c92d1d2016-07-06 12:35:55 -07004902uint32_t
James Smart4258e982015-12-16 18:11:58 -05004903lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc *desc, READ_LNK_VAR *stat)
4904{
4905 if (bf_get(lpfc_read_link_stat_gec2, stat) == 0)
4906 return 0;
4907 desc->tag = cpu_to_be32(RDP_FEC_DESC_TAG);
4908
4909 desc->info.CorrectedBlocks =
4910 cpu_to_be32(stat->fecCorrBlkCount);
4911 desc->info.UncorrectableBlocks =
4912 cpu_to_be32(stat->fecUncorrBlkCount);
4913
4914 desc->length = cpu_to_be32(sizeof(desc->info));
4915
4916 return sizeof(struct fc_fec_rdp_desc);
4917}
4918
James Smart6c92d1d2016-07-06 12:35:55 -07004919uint32_t
James Smart86478872015-05-21 13:55:21 -04004920lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
4921{
4922 uint16_t rdp_cap = 0;
4923 uint16_t rdp_speed;
4924
4925 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
4926
James Smart81e75172015-12-16 18:11:59 -05004927 switch (phba->fc_linkspeed) {
4928 case LPFC_LINK_SPEED_1GHZ:
James Smart86478872015-05-21 13:55:21 -04004929 rdp_speed = RDP_PS_1GB;
4930 break;
James Smart81e75172015-12-16 18:11:59 -05004931 case LPFC_LINK_SPEED_2GHZ:
James Smart86478872015-05-21 13:55:21 -04004932 rdp_speed = RDP_PS_2GB;
4933 break;
James Smart81e75172015-12-16 18:11:59 -05004934 case LPFC_LINK_SPEED_4GHZ:
James Smart86478872015-05-21 13:55:21 -04004935 rdp_speed = RDP_PS_4GB;
4936 break;
James Smart81e75172015-12-16 18:11:59 -05004937 case LPFC_LINK_SPEED_8GHZ:
James Smart86478872015-05-21 13:55:21 -04004938 rdp_speed = RDP_PS_8GB;
4939 break;
James Smart81e75172015-12-16 18:11:59 -05004940 case LPFC_LINK_SPEED_10GHZ:
James Smart86478872015-05-21 13:55:21 -04004941 rdp_speed = RDP_PS_10GB;
4942 break;
James Smart81e75172015-12-16 18:11:59 -05004943 case LPFC_LINK_SPEED_16GHZ:
James Smart86478872015-05-21 13:55:21 -04004944 rdp_speed = RDP_PS_16GB;
4945 break;
James Smarta085e872015-12-16 18:12:02 -05004946 case LPFC_LINK_SPEED_32GHZ:
4947 rdp_speed = RDP_PS_32GB;
4948 break;
James Smart86478872015-05-21 13:55:21 -04004949 default:
4950 rdp_speed = RDP_PS_UNKNOWN;
4951 break;
4952 }
4953
4954 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
4955
James Smartd38dd522015-08-31 16:48:17 -04004956 if (phba->lmt & LMT_32Gb)
4957 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04004958 if (phba->lmt & LMT_16Gb)
4959 rdp_cap |= RDP_PS_16GB;
4960 if (phba->lmt & LMT_10Gb)
4961 rdp_cap |= RDP_PS_10GB;
4962 if (phba->lmt & LMT_8Gb)
4963 rdp_cap |= RDP_PS_8GB;
4964 if (phba->lmt & LMT_4Gb)
4965 rdp_cap |= RDP_PS_4GB;
4966 if (phba->lmt & LMT_2Gb)
4967 rdp_cap |= RDP_PS_2GB;
4968 if (phba->lmt & LMT_1Gb)
4969 rdp_cap |= RDP_PS_1GB;
4970
4971 if (rdp_cap == 0)
4972 rdp_cap = RDP_CAP_UNKNOWN;
James Smart56204982016-03-31 14:12:32 -07004973 if (phba->cfg_link_speed != LPFC_USER_LINK_SPEED_AUTO)
4974 rdp_cap |= RDP_CAP_USER_CONFIGURED;
James Smart86478872015-05-21 13:55:21 -04004975
4976 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
4977 desc->length = cpu_to_be32(sizeof(desc->info));
James Smart6c92d1d2016-07-06 12:35:55 -07004978 return sizeof(struct fc_rdp_port_speed_desc);
James Smart86478872015-05-21 13:55:21 -04004979}
4980
James Smart6c92d1d2016-07-06 12:35:55 -07004981uint32_t
James Smart86478872015-05-21 13:55:21 -04004982lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
4983 struct lpfc_hba *phba)
4984{
4985
4986 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4987
4988 memcpy(desc->port_names.wwnn, phba->wwnn,
4989 sizeof(desc->port_names.wwnn));
4990
4991 memcpy(desc->port_names.wwpn, &phba->wwpn,
4992 sizeof(desc->port_names.wwpn));
4993
4994 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07004995 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04004996}
4997
James Smart6c92d1d2016-07-06 12:35:55 -07004998uint32_t
James Smart86478872015-05-21 13:55:21 -04004999lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
5000 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5001{
5002
5003 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
5004 if (vport->fc_flag & FC_FABRIC) {
5005 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
5006 sizeof(desc->port_names.wwnn));
5007
5008 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
5009 sizeof(desc->port_names.wwpn));
5010 } else { /* Point to Point */
5011 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
5012 sizeof(desc->port_names.wwnn));
5013
5014 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
5015 sizeof(desc->port_names.wwpn));
5016 }
5017
5018 desc->length = cpu_to_be32(sizeof(desc->port_names));
James Smart6c92d1d2016-07-06 12:35:55 -07005019 return sizeof(struct fc_rdp_port_name_desc);
James Smart86478872015-05-21 13:55:21 -04005020}
5021
5022void
5023lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
5024 int status)
5025{
5026 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
5027 struct lpfc_vport *vport = ndlp->vport;
5028 struct lpfc_iocbq *elsiocb;
James Smarteb8d68c2015-12-16 18:12:00 -05005029 struct ulp_bde64 *bpl;
James Smart86478872015-05-21 13:55:21 -04005030 IOCB_t *icmd;
5031 uint8_t *pcmd;
5032 struct ls_rjt *stat;
5033 struct fc_rdp_res_frame *rdp_res;
James Smart6c92d1d2016-07-06 12:35:55 -07005034 uint32_t cmdsize, len;
James Smart310429e2016-07-06 12:35:54 -07005035 uint16_t *flag_ptr;
James Smart6c92d1d2016-07-06 12:35:55 -07005036 int rc;
James Smart86478872015-05-21 13:55:21 -04005037
5038 if (status != SUCCESS)
5039 goto error;
James Smarteb8d68c2015-12-16 18:12:00 -05005040
5041 /* This will change once we know the true size of the RDP payload */
James Smart86478872015-05-21 13:55:21 -04005042 cmdsize = sizeof(struct fc_rdp_res_frame);
5043
5044 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
5045 lpfc_max_els_tries, rdp_context->ndlp,
5046 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
5047 lpfc_nlp_put(ndlp);
5048 if (!elsiocb)
5049 goto free_rdp_context;
5050
5051 icmd = &elsiocb->iocb;
5052 icmd->ulpContext = rdp_context->rx_id;
5053 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5054
5055 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5056 "2171 Xmit RDP response tag x%x xri x%x, "
5057 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5058 elsiocb->iotag, elsiocb->iocb.ulpContext,
5059 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5060 ndlp->nlp_rpi);
5061 rdp_res = (struct fc_rdp_res_frame *)
5062 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5063 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5064 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
5065 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5066
James Smart310429e2016-07-06 12:35:54 -07005067 /* Update Alarm and Warning */
5068 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_ALARM_FLAGS);
5069 phba->sfp_alarm |= *flag_ptr;
5070 flag_ptr = (uint16_t *)(rdp_context->page_a2 + SSF_WARNING_FLAGS);
5071 phba->sfp_warning |= *flag_ptr;
5072
James Smart86478872015-05-21 13:55:21 -04005073 /* For RDP payload */
James Smart6c92d1d2016-07-06 12:35:55 -07005074 len = 8;
5075 len += lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc *)
5076 (len + pcmd), ELS_CMD_RDP);
James Smart86478872015-05-21 13:55:21 -04005077
James Smart6c92d1d2016-07-06 12:35:55 -07005078 len += lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc *)(len + pcmd),
James Smart86478872015-05-21 13:55:21 -04005079 rdp_context->page_a0, rdp_context->page_a2);
James Smart6c92d1d2016-07-06 12:35:55 -07005080 len += lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc *)(len + pcmd),
5081 phba);
5082 len += lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc *)
5083 (len + pcmd), &rdp_context->link_stat);
5084 len += lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc *)
5085 (len + pcmd), phba);
5086 len += lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc *)
5087 (len + pcmd), vport, ndlp);
5088 len += lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc *)(len + pcmd),
James Smart4258e982015-12-16 18:11:58 -05005089 &rdp_context->link_stat);
James Smart6c92d1d2016-07-06 12:35:55 -07005090 /* Check if nport is logged, BZ190632 */
5091 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED))
5092 goto lpfc_skip_descriptor;
5093
5094 len += lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc *)(len + pcmd),
5095 &rdp_context->link_stat, vport);
5096 len += lpfc_rdp_res_oed_temp_desc(phba,
5097 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5098 rdp_context->page_a2);
5099 len += lpfc_rdp_res_oed_voltage_desc(phba,
5100 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5101 rdp_context->page_a2);
5102 len += lpfc_rdp_res_oed_txbias_desc(phba,
5103 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5104 rdp_context->page_a2);
5105 len += lpfc_rdp_res_oed_txpower_desc(phba,
5106 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5107 rdp_context->page_a2);
5108 len += lpfc_rdp_res_oed_rxpower_desc(phba,
5109 (struct fc_rdp_oed_sfp_desc *)(len + pcmd),
5110 rdp_context->page_a2);
5111 len += lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc *)(len + pcmd),
5112 rdp_context->page_a0, vport);
5113
5114lpfc_skip_descriptor:
5115 rdp_res->length = cpu_to_be32(len - 8);
James Smart86478872015-05-21 13:55:21 -04005116 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5117
James Smarteb8d68c2015-12-16 18:12:00 -05005118 /* Now that we know the true size of the payload, update the BPL */
5119 bpl = (struct ulp_bde64 *)
5120 (((struct lpfc_dmabuf *)(elsiocb->context3))->virt);
James Smart6c92d1d2016-07-06 12:35:55 -07005121 bpl->tus.f.bdeSize = len;
James Smarteb8d68c2015-12-16 18:12:00 -05005122 bpl->tus.f.bdeFlags = 0;
5123 bpl->tus.w = le32_to_cpu(bpl->tus.w);
5124
James Smart86478872015-05-21 13:55:21 -04005125 phba->fc_stat.elsXmitACC++;
5126 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5127 if (rc == IOCB_ERROR)
5128 lpfc_els_free_iocb(phba, elsiocb);
5129
5130 kfree(rdp_context);
5131
5132 return;
5133error:
5134 cmdsize = 2 * sizeof(uint32_t);
5135 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
5136 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
5137 lpfc_nlp_put(ndlp);
5138 if (!elsiocb)
5139 goto free_rdp_context;
5140
5141 icmd = &elsiocb->iocb;
5142 icmd->ulpContext = rdp_context->rx_id;
5143 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
5144 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5145
5146 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
5147 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5148 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5149
5150 phba->fc_stat.elsXmitLSRJT++;
5151 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5152 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5153
5154 if (rc == IOCB_ERROR)
5155 lpfc_els_free_iocb(phba, elsiocb);
5156free_rdp_context:
5157 kfree(rdp_context);
5158}
5159
5160int
5161lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
5162{
5163 LPFC_MBOXQ_t *mbox = NULL;
5164 int rc;
5165
5166 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5167 if (!mbox) {
5168 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
5169 "7105 failed to allocate mailbox memory");
5170 return 1;
5171 }
5172
5173 if (lpfc_sli4_dump_page_a0(phba, mbox))
5174 goto prep_mbox_fail;
5175 mbox->vport = rdp_context->ndlp->vport;
5176 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
5177 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
5178 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5179 if (rc == MBX_NOT_FINISHED)
5180 goto issue_mbox_fail;
5181
5182 return 0;
5183
5184prep_mbox_fail:
5185issue_mbox_fail:
5186 mempool_free(mbox, phba->mbox_mem_pool);
5187 return 1;
5188}
5189
5190/*
5191 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5192 * @vport: pointer to a host virtual N_Port data structure.
5193 * @cmdiocb: pointer to lpfc command iocb data structure.
5194 * @ndlp: pointer to a node-list data structure.
5195 *
5196 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5197 * IOCB. First, the payload of the unsolicited RDP is checked.
5198 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5199 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5200 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5201 * gather all data and send RDP response.
5202 *
5203 * Return code
5204 * 0 - Sent the acc response
5205 * 1 - Sent the reject response.
5206 */
5207static int
5208lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5209 struct lpfc_nodelist *ndlp)
5210{
5211 struct lpfc_hba *phba = vport->phba;
5212 struct lpfc_dmabuf *pcmd;
5213 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
5214 struct fc_rdp_req_frame *rdp_req;
5215 struct lpfc_rdp_context *rdp_context;
5216 IOCB_t *cmd = NULL;
5217 struct ls_rjt stat;
5218
5219 if (phba->sli_rev < LPFC_SLI_REV4 ||
5220 (bf_get(lpfc_sli_intf_if_type,
5221 &phba->sli4_hba.sli_intf) !=
5222 LPFC_SLI_INTF_IF_TYPE_2)) {
5223 rjt_err = LSRJT_UNABLE_TPC;
5224 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5225 goto error;
5226 }
5227
5228 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
5229 rjt_err = LSRJT_UNABLE_TPC;
5230 rjt_expl = LSEXP_REQ_UNSUPPORTED;
5231 goto error;
5232 }
5233
5234 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5235 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
5236
5237
5238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5239 "2422 ELS RDP Request "
5240 "dec len %d tag x%x port_id %d len %d\n",
5241 be32_to_cpu(rdp_req->rdp_des_length),
5242 be32_to_cpu(rdp_req->nport_id_desc.tag),
5243 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
5244 be32_to_cpu(rdp_req->nport_id_desc.length));
5245
James Smart7d933312016-07-06 12:35:58 -07005246 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED) &&
5247 !phba->cfg_enable_SmartSAN) {
5248 rjt_err = LSRJT_UNABLE_TPC;
5249 rjt_expl = LSEXP_PORT_LOGIN_REQ;
5250 goto error;
5251 }
James Smart86478872015-05-21 13:55:21 -04005252 if (sizeof(struct fc_rdp_nport_desc) !=
5253 be32_to_cpu(rdp_req->rdp_des_length))
5254 goto rjt_logerr;
5255 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
5256 goto rjt_logerr;
5257 if (RDP_NPORT_ID_SIZE !=
5258 be32_to_cpu(rdp_req->nport_id_desc.length))
5259 goto rjt_logerr;
Punit Vara699acd62015-12-16 18:12:07 -05005260 rdp_context = kzalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
James Smart86478872015-05-21 13:55:21 -04005261 if (!rdp_context) {
5262 rjt_err = LSRJT_UNABLE_TPC;
5263 goto error;
5264 }
5265
James Smart86478872015-05-21 13:55:21 -04005266 cmd = &cmdiocb->iocb;
5267 rdp_context->ndlp = lpfc_nlp_get(ndlp);
5268 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
5269 rdp_context->rx_id = cmd->ulpContext;
5270 rdp_context->cmpl = lpfc_els_rdp_cmpl;
5271 if (lpfc_get_rdp_info(phba, rdp_context)) {
5272 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
5273 "2423 Unable to send mailbox");
5274 kfree(rdp_context);
5275 rjt_err = LSRJT_UNABLE_TPC;
5276 lpfc_nlp_put(ndlp);
5277 goto error;
5278 }
5279
5280 return 0;
5281
5282rjt_logerr:
5283 rjt_err = LSRJT_LOGICAL_ERR;
5284
5285error:
5286 memset(&stat, 0, sizeof(stat));
5287 stat.un.b.lsRjtRsnCode = rjt_err;
5288 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5289 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5290 return 1;
5291}
5292
5293
James Smart8b017a32015-05-21 13:55:18 -04005294static void
5295lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5296{
5297 MAILBOX_t *mb;
5298 IOCB_t *icmd;
5299 uint8_t *pcmd;
5300 struct lpfc_iocbq *elsiocb;
5301 struct lpfc_nodelist *ndlp;
5302 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005303 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005304 struct lpfc_lcb_context *lcb_context;
5305 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005306 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005307 int rc;
5308
5309 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005310 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5311 ndlp = lcb_context->ndlp;
5312 pmb->context1 = NULL;
5313 pmb->context2 = NULL;
5314
James Smart481ad962015-05-22 10:42:35 -04005315 shdr = (union lpfc_sli4_cfg_shdr *)
5316 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5317 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5318 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5319
5320 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5321 "0194 SET_BEACON_CONFIG mailbox "
5322 "completed with status x%x add_status x%x,"
5323 " mbx status x%x\n",
5324 shdr_status, shdr_add_status, mb->mbxStatus);
5325
5326 if (mb->mbxStatus && !(shdr_status &&
5327 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005328 mempool_free(pmb, phba->mbox_mem_pool);
5329 goto error;
5330 }
5331
5332 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005333 cmdsize = sizeof(struct fc_lcb_res_frame);
5334 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5335 lpfc_max_els_tries, ndlp,
5336 ndlp->nlp_DID, ELS_CMD_ACC);
5337
5338 /* Decrement the ndlp reference count from previous mbox command */
5339 lpfc_nlp_put(ndlp);
5340
5341 if (!elsiocb)
5342 goto free_lcb_context;
5343
5344 lcb_res = (struct fc_lcb_res_frame *)
5345 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5346
5347 icmd = &elsiocb->iocb;
5348 icmd->ulpContext = lcb_context->rx_id;
5349 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5350
5351 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5352 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5353 lcb_res->lcb_sub_command = lcb_context->sub_command;
5354 lcb_res->lcb_type = lcb_context->type;
5355 lcb_res->lcb_frequency = lcb_context->frequency;
5356 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5357 phba->fc_stat.elsXmitACC++;
5358 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5359 if (rc == IOCB_ERROR)
5360 lpfc_els_free_iocb(phba, elsiocb);
5361
5362 kfree(lcb_context);
5363 return;
5364
5365error:
5366 cmdsize = sizeof(struct fc_lcb_res_frame);
5367 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5368 lpfc_max_els_tries, ndlp,
5369 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5370 lpfc_nlp_put(ndlp);
5371 if (!elsiocb)
5372 goto free_lcb_context;
5373
5374 icmd = &elsiocb->iocb;
5375 icmd->ulpContext = lcb_context->rx_id;
5376 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5377 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5378
5379 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5380 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5381 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5382
5383 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5384 phba->fc_stat.elsXmitLSRJT++;
5385 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5386 if (rc == IOCB_ERROR)
5387 lpfc_els_free_iocb(phba, elsiocb);
5388free_lcb_context:
5389 kfree(lcb_context);
5390}
5391
5392static int
5393lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5394 struct lpfc_lcb_context *lcb_context,
5395 uint32_t beacon_state)
5396{
5397 struct lpfc_hba *phba = vport->phba;
5398 LPFC_MBOXQ_t *mbox = NULL;
5399 uint32_t len;
5400 int rc;
5401
5402 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5403 if (!mbox)
5404 return 1;
5405
5406 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5407 sizeof(struct lpfc_sli4_cfg_mhdr);
5408 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5409 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5410 LPFC_SLI4_MBX_EMBED);
5411 mbox->context1 = (void *)lcb_context;
5412 mbox->vport = phba->pport;
5413 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5414 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5415 phba->sli4_hba.physical_port);
5416 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5417 beacon_state);
5418 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5419 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5421 if (rc == MBX_NOT_FINISHED) {
5422 mempool_free(mbox, phba->mbox_mem_pool);
5423 return 1;
5424 }
5425
5426 return 0;
5427}
5428
5429
5430/**
5431 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5432 * @vport: pointer to a host virtual N_Port data structure.
5433 * @cmdiocb: pointer to lpfc command iocb data structure.
5434 * @ndlp: pointer to a node-list data structure.
5435 *
5436 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5437 * First, the payload of the unsolicited LCB is checked.
5438 * Then based on Subcommand beacon will either turn on or off.
5439 *
5440 * Return code
5441 * 0 - Sent the acc response
5442 * 1 - Sent the reject response.
5443 **/
5444static int
5445lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5446 struct lpfc_nodelist *ndlp)
5447{
5448 struct lpfc_hba *phba = vport->phba;
5449 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04005450 uint8_t *lp;
5451 struct fc_lcb_request_frame *beacon;
5452 struct lpfc_lcb_context *lcb_context;
5453 uint8_t state, rjt_err;
5454 struct ls_rjt stat;
5455
James Smart8b017a32015-05-21 13:55:18 -04005456 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5457 lp = (uint8_t *)pcmd->virt;
5458 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5459
5460 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5461 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5462 "type x%x frequency %x duration x%x\n",
5463 lp[0], lp[1], lp[2],
5464 beacon->lcb_command,
5465 beacon->lcb_sub_command,
5466 beacon->lcb_type,
5467 beacon->lcb_frequency,
5468 be16_to_cpu(beacon->lcb_duration));
5469
5470 if (phba->sli_rev < LPFC_SLI_REV4 ||
5471 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5472 LPFC_SLI_INTF_IF_TYPE_2)) {
5473 rjt_err = LSRJT_CMD_UNSUPPORTED;
5474 goto rjt;
5475 }
James Smart8b017a32015-05-21 13:55:18 -04005476
5477 if (phba->hba_flag & HBA_FCOE_MODE) {
5478 rjt_err = LSRJT_CMD_UNSUPPORTED;
5479 goto rjt;
5480 }
5481 if (beacon->lcb_frequency == 0) {
5482 rjt_err = LSRJT_CMD_UNSUPPORTED;
5483 goto rjt;
5484 }
5485 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5486 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5487 rjt_err = LSRJT_CMD_UNSUPPORTED;
5488 goto rjt;
5489 }
5490 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5491 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5492 rjt_err = LSRJT_CMD_UNSUPPORTED;
5493 goto rjt;
5494 }
5495 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5496 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5497 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5498 rjt_err = LSRJT_CMD_UNSUPPORTED;
5499 goto rjt;
5500 }
5501 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5502 rjt_err = LSRJT_CMD_UNSUPPORTED;
5503 goto rjt;
5504 }
5505
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305506 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5507 if (!lcb_context) {
5508 rjt_err = LSRJT_UNABLE_TPC;
5509 goto rjt;
5510 }
5511
James Smart8b017a32015-05-21 13:55:18 -04005512 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5513 lcb_context->sub_command = beacon->lcb_sub_command;
5514 lcb_context->type = beacon->lcb_type;
5515 lcb_context->frequency = beacon->lcb_frequency;
5516 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5517 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5518 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5519 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5520 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5521 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305522 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04005523 lpfc_nlp_put(ndlp);
5524 rjt_err = LSRJT_UNABLE_TPC;
5525 goto rjt;
5526 }
5527 return 0;
5528rjt:
5529 memset(&stat, 0, sizeof(stat));
5530 stat.un.b.lsRjtRsnCode = rjt_err;
5531 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5532 return 1;
5533}
5534
5535
James Smarte59058c2008-08-24 21:49:00 -04005536/**
James Smart3621a712009-04-06 18:47:14 -04005537 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005538 * @vport: pointer to a host virtual N_Port data structure.
5539 *
5540 * This routine cleans up any Registration State Change Notification
5541 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5542 * @vport together with the host_lock is used to prevent multiple thread
5543 * trying to access the RSCN array on a same @vport at the same time.
5544 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005545void
James Smart2e0fef82007-06-17 19:56:36 -05005546lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005547{
James Smart2e0fef82007-06-17 19:56:36 -05005548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5549 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005550 int i;
5551
James Smart7f5f3d02008-02-08 18:50:14 -05005552 spin_lock_irq(shost->host_lock);
5553 if (vport->fc_rscn_flush) {
5554 /* Another thread is walking fc_rscn_id_list on this vport */
5555 spin_unlock_irq(shost->host_lock);
5556 return;
5557 }
5558 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5559 vport->fc_rscn_flush = 1;
5560 spin_unlock_irq(shost->host_lock);
5561
James Smart2e0fef82007-06-17 19:56:36 -05005562 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005563 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005564 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005565 }
James Smart2e0fef82007-06-17 19:56:36 -05005566 spin_lock_irq(shost->host_lock);
5567 vport->fc_rscn_id_cnt = 0;
5568 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5569 spin_unlock_irq(shost->host_lock);
5570 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005571 /* Indicate we are done walking this fc_rscn_id_list */
5572 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005573}
5574
James Smarte59058c2008-08-24 21:49:00 -04005575/**
James Smart3621a712009-04-06 18:47:14 -04005576 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005577 * @vport: pointer to a host virtual N_Port data structure.
5578 * @did: remote destination port identifier.
5579 *
5580 * This routine checks whether there is any pending Registration State
5581 * Configuration Notification (RSCN) to a @did on @vport.
5582 *
5583 * Return code
5584 * None zero - The @did matched with a pending rscn
5585 * 0 - not able to match @did with a pending rscn
5586 **/
dea31012005-04-17 16:05:31 -05005587int
James Smart2e0fef82007-06-17 19:56:36 -05005588lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005589{
5590 D_ID ns_did;
5591 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005592 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005593 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005594 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005595
5596 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005597
5598 /* Never match fabric nodes for RSCNs */
5599 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005600 return 0;
dea31012005-04-17 16:05:31 -05005601
5602 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005603 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005604 return did;
dea31012005-04-17 16:05:31 -05005605
James Smart7f5f3d02008-02-08 18:50:14 -05005606 spin_lock_irq(shost->host_lock);
5607 if (vport->fc_rscn_flush) {
5608 /* Another thread is walking fc_rscn_id_list on this vport */
5609 spin_unlock_irq(shost->host_lock);
5610 return 0;
5611 }
5612 /* Indicate we are walking fc_rscn_id_list on this vport */
5613 vport->fc_rscn_flush = 1;
5614 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005615 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005616 lp = vport->fc_rscn_id_list[i]->virt;
5617 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5618 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005619 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005620 rscn_did.un.word = be32_to_cpu(*lp++);
5621 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005622 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5623 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005624 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5625 && (ns_did.un.b.area == rscn_did.un.b.area)
5626 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005627 goto return_did_out;
dea31012005-04-17 16:05:31 -05005628 break;
James Smarteaf15d52008-12-04 22:39:29 -05005629 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005630 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5631 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005632 goto return_did_out;
dea31012005-04-17 16:05:31 -05005633 break;
James Smarteaf15d52008-12-04 22:39:29 -05005634 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005635 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005636 goto return_did_out;
dea31012005-04-17 16:05:31 -05005637 break;
James Smarteaf15d52008-12-04 22:39:29 -05005638 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005639 goto return_did_out;
dea31012005-04-17 16:05:31 -05005640 }
5641 }
James Smart92d7f7b2007-06-17 19:56:38 -05005642 }
James Smart7f5f3d02008-02-08 18:50:14 -05005643 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5644 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005645 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005646return_did_out:
5647 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5648 vport->fc_rscn_flush = 0;
5649 return did;
dea31012005-04-17 16:05:31 -05005650}
5651
James Smarte59058c2008-08-24 21:49:00 -04005652/**
James Smart3621a712009-04-06 18:47:14 -04005653 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005654 * @vport: pointer to a host virtual N_Port data structure.
5655 *
5656 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5657 * state machine for a @vport's nodes that are with pending RSCN (Registration
5658 * State Change Notification).
5659 *
5660 * Return code
5661 * 0 - Successful (currently alway return 0)
5662 **/
dea31012005-04-17 16:05:31 -05005663static int
James Smart2e0fef82007-06-17 19:56:36 -05005664lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005665{
James Smart685f0bf2007-04-25 09:53:08 -04005666 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005667
James Smart0d2b6b82008-06-14 22:52:47 -04005668 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005669 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005670 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005671 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5672 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005673 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005674 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005675 NLP_EVT_DEVICE_RECOVERY);
5676 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005677 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005678 return 0;
dea31012005-04-17 16:05:31 -05005679}
5680
James Smarte59058c2008-08-24 21:49:00 -04005681/**
James Smart3621a712009-04-06 18:47:14 -04005682 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005683 * @vport: pointer to a host virtual N_Port data structure.
5684 * @cmdiocb: pointer to lpfc command iocb data structure.
5685 *
5686 * lpfc_send_rscn_event sends an RSCN netlink event to management
5687 * applications.
5688 */
5689static void
5690lpfc_send_rscn_event(struct lpfc_vport *vport,
5691 struct lpfc_iocbq *cmdiocb)
5692{
5693 struct lpfc_dmabuf *pcmd;
5694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5695 uint32_t *payload_ptr;
5696 uint32_t payload_len;
5697 struct lpfc_rscn_event_header *rscn_event_data;
5698
5699 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5700 payload_ptr = (uint32_t *) pcmd->virt;
5701 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5702
5703 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5704 payload_len, GFP_KERNEL);
5705 if (!rscn_event_data) {
5706 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5707 "0147 Failed to allocate memory for RSCN event\n");
5708 return;
5709 }
5710 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5711 rscn_event_data->payload_length = payload_len;
5712 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5713 payload_len);
5714
5715 fc_host_post_vendor_event(shost,
5716 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04005717 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05005718 (char *)rscn_event_data,
5719 LPFC_NL_VENDOR_ID);
5720
5721 kfree(rscn_event_data);
5722}
5723
5724/**
James Smart3621a712009-04-06 18:47:14 -04005725 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04005726 * @vport: pointer to a host virtual N_Port data structure.
5727 * @cmdiocb: pointer to lpfc command iocb data structure.
5728 * @ndlp: pointer to a node-list data structure.
5729 *
5730 * This routine processes an unsolicited RSCN (Registration State Change
5731 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5732 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5733 * discover state machine is about to begin discovery, it just accepts the
5734 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5735 * contains N_Port IDs for other vports on this HBA, it just accepts the
5736 * RSCN and ignore processing it. If the state machine is in the recovery
5737 * state, the fc_rscn_id_list of this @vport is walked and the
5738 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5739 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5740 * routine is invoked to handle the RSCN event.
5741 *
5742 * Return code
5743 * 0 - Just sent the acc response
5744 * 1 - Sent the acc response and waited for name server completion
5745 **/
dea31012005-04-17 16:05:31 -05005746static int
James Smart2e0fef82007-06-17 19:56:36 -05005747lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005748 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005749{
James Smart2e0fef82007-06-17 19:56:36 -05005750 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5751 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005752 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005753 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05005754 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005755 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05005756 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04005757 int i;
dea31012005-04-17 16:05:31 -05005758
dea31012005-04-17 16:05:31 -05005759 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5760 lp = (uint32_t *) pcmd->virt;
5761
James Smart92d7f7b2007-06-17 19:56:38 -05005762 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5763 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005764 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04005765 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5766 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05005767 vport->fc_flag, payload_len, *lp,
5768 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05005769
5770 /* Send an RSCN event to the management application */
5771 lpfc_send_rscn_event(vport, cmdiocb);
5772
James Smartd2873e42006-08-18 17:46:43 -04005773 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05005774 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04005775 FCH_EVT_RSCN, lp[i]);
5776
dea31012005-04-17 16:05:31 -05005777 /* If we are about to begin discovery, just ACC the RSCN.
5778 * Discovery processing will satisfy it.
5779 */
James Smart2e0fef82007-06-17 19:56:36 -05005780 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05005781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5782 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5783 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5784
James Smart51ef4c22007-08-02 11:10:31 -04005785 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005786 return 0;
dea31012005-04-17 16:05:31 -05005787 }
5788
James Smart92d7f7b2007-06-17 19:56:38 -05005789 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5790 * just ACC and ignore it.
5791 */
5792 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04005793 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05005794 i = payload_len;
5795 datap = lp;
5796 while (i > 0) {
5797 nportid = *datap++;
5798 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5799 i -= sizeof(uint32_t);
5800 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04005801 if (lpfc_find_vport_by_did(phba, nportid))
5802 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05005803 }
5804 if (rscn_id == hba_id) {
5805 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04005806 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005807 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04005808 "Data: x%x x%x x%x x%x\n",
5809 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05005810 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05005811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5812 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5813 ndlp->nlp_DID, vport->port_state,
5814 ndlp->nlp_flag);
5815
James Smart92d7f7b2007-06-17 19:56:38 -05005816 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005817 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05005818 return 0;
5819 }
5820 }
5821
James Smart7f5f3d02008-02-08 18:50:14 -05005822 spin_lock_irq(shost->host_lock);
5823 if (vport->fc_rscn_flush) {
5824 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05005825 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05005826 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04005827 /* Send back ACC */
5828 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05005829 return 0;
5830 }
5831 /* Indicate we are walking fc_rscn_id_list on this vport */
5832 vport->fc_rscn_flush = 1;
5833 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005834 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05005835 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05005836 /* If we are already processing an RSCN, save the received
5837 * RSCN payload buffer, cmdiocb->context2 to process later.
5838 */
James Smart2e0fef82007-06-17 19:56:36 -05005839 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05005840 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5841 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5842 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5843
James Smart09372822008-01-11 01:52:54 -05005844 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005845 vport->fc_flag |= FC_RSCN_DEFERRED;
5846 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05005847 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005848 vport->fc_flag |= FC_RSCN_MODE;
5849 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005850 if (rscn_cnt) {
5851 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
5852 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
5853 }
5854 if ((rscn_cnt) &&
5855 (payload_len + length <= LPFC_BPL_SIZE)) {
5856 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05005857 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05005858 memcpy(((uint8_t *)cmd) + length, lp,
5859 payload_len);
5860 } else {
5861 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
5862 vport->fc_rscn_id_cnt++;
5863 /* If we zero, cmdiocb->context2, the calling
5864 * routine will not try to free it.
5865 */
5866 cmdiocb->context2 = NULL;
5867 }
dea31012005-04-17 16:05:31 -05005868 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005869 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5870 "0235 Deferred RSCN "
5871 "Data: x%x x%x x%x\n",
5872 vport->fc_rscn_id_cnt, vport->fc_flag,
5873 vport->port_state);
dea31012005-04-17 16:05:31 -05005874 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005875 vport->fc_flag |= FC_RSCN_DISCOVERY;
5876 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005877 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005878 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5879 "0234 ReDiscovery RSCN "
5880 "Data: x%x x%x x%x\n",
5881 vport->fc_rscn_id_cnt, vport->fc_flag,
5882 vport->port_state);
dea31012005-04-17 16:05:31 -05005883 }
James Smart7f5f3d02008-02-08 18:50:14 -05005884 /* Indicate we are done walking fc_rscn_id_list on this vport */
5885 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005886 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005887 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005888 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005889 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05005890 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005891 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05005892 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005893 return 0;
dea31012005-04-17 16:05:31 -05005894 }
James Smart858c9f62007-06-17 19:56:39 -05005895 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5896 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5897 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5898
James Smart2e0fef82007-06-17 19:56:36 -05005899 spin_lock_irq(shost->host_lock);
5900 vport->fc_flag |= FC_RSCN_MODE;
5901 spin_unlock_irq(shost->host_lock);
5902 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005903 /* Indicate we are done walking fc_rscn_id_list on this vport */
5904 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005905 /*
5906 * If we zero, cmdiocb->context2, the calling routine will
5907 * not try to free it.
5908 */
5909 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005910 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005911 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005912 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005913 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005914 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005915 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005916}
5917
James Smarte59058c2008-08-24 21:49:00 -04005918/**
James Smart3621a712009-04-06 18:47:14 -04005919 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04005920 * @vport: pointer to a host virtual N_Port data structure.
5921 *
5922 * This routine handles the Registration State Configuration Notification
5923 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5924 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5925 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5926 * NameServer shall be issued. If CT command to the NameServer fails to be
5927 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5928 * RSCN activities with the @vport.
5929 *
5930 * Return code
5931 * 0 - Cleaned up rscn on the @vport
5932 * 1 - Wait for plogi to name server before proceed
5933 **/
dea31012005-04-17 16:05:31 -05005934int
James Smart2e0fef82007-06-17 19:56:36 -05005935lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005936{
5937 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005938 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005939
James Smart92d7f7b2007-06-17 19:56:38 -05005940 /* Ignore RSCN if the port is being torn down. */
5941 if (vport->load_flag & FC_UNLOADING) {
5942 lpfc_els_flush_rscn(vport);
5943 return 0;
5944 }
5945
dea31012005-04-17 16:05:31 -05005946 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05005947 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005948
5949 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04005950 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5951 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5952 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
5953 vport->port_state);
dea31012005-04-17 16:05:31 -05005954
5955 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005956 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05005957 vport->num_disc_nodes = 0;
5958
James Smart2e0fef82007-06-17 19:56:36 -05005959 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005960 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
5961 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05005962 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05005963 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05005964 /* Wait for NameServer query cmpl before we can
5965 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005966 return 1;
dea31012005-04-17 16:05:31 -05005967 } else {
5968 /* If login to NameServer does not exist, issue one */
5969 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005970 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005971 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05005972 /* Wait for NameServer login cmpl before we can
5973 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005974 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05005975
James Smarte47c9092008-02-08 18:49:26 -05005976 if (ndlp) {
5977 ndlp = lpfc_enable_node(vport, ndlp,
5978 NLP_STE_PLOGI_ISSUE);
5979 if (!ndlp) {
5980 lpfc_els_flush_rscn(vport);
5981 return 0;
5982 }
5983 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05005984 } else {
James Smarte47c9092008-02-08 18:49:26 -05005985 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5986 if (!ndlp) {
5987 lpfc_els_flush_rscn(vport);
5988 return 0;
5989 }
James Smart2e0fef82007-06-17 19:56:36 -05005990 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005991 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05005993 }
James Smarte47c9092008-02-08 18:49:26 -05005994 ndlp->nlp_type |= NLP_FABRIC;
5995 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5996 /* Wait for NameServer login cmpl before we can
5997 * continue
5998 */
5999 return 1;
dea31012005-04-17 16:05:31 -05006000 }
6001
James Smart2e0fef82007-06-17 19:56:36 -05006002 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006003 return 0;
dea31012005-04-17 16:05:31 -05006004}
6005
James Smarte59058c2008-08-24 21:49:00 -04006006/**
James Smart3621a712009-04-06 18:47:14 -04006007 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04006008 * @vport: pointer to a host virtual N_Port data structure.
6009 * @cmdiocb: pointer to lpfc command iocb data structure.
6010 * @ndlp: pointer to a node-list data structure.
6011 *
6012 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6013 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6014 * point topology. As an unsolicited FLOGI should not be received in a loop
6015 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6016 * lpfc_check_sparm() routine is invoked to check the parameters in the
6017 * unsolicited FLOGI. If parameters validation failed, the routine
6018 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6019 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6020 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6021 * will initiate PLOGI. The higher lexicographical value party shall has
6022 * higher priority (as the winning port) and will initiate PLOGI and
6023 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6024 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6025 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6026 *
6027 * Return code
6028 * 0 - Successfully processed the unsolicited flogi
6029 * 1 - Failed to process the unsolicited flogi
6030 **/
dea31012005-04-17 16:05:31 -05006031static int
James Smart2e0fef82007-06-17 19:56:36 -05006032lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04006033 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006034{
James Smart2e0fef82007-06-17 19:56:36 -05006035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006037 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6038 uint32_t *lp = (uint32_t *) pcmd->virt;
6039 IOCB_t *icmd = &cmdiocb->iocb;
6040 struct serv_parm *sp;
6041 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05006042 uint32_t cmd, did;
6043 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04006044 uint32_t fc_flag = 0;
6045 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05006046
6047 cmd = *lp++;
6048 sp = (struct serv_parm *) lp;
6049
6050 /* FLOGI received */
6051
James Smart2e0fef82007-06-17 19:56:36 -05006052 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05006053
James Smart76a95d72010-11-20 23:11:48 -05006054 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05006055 /* We should never receive a FLOGI in loop mode, ignore it */
6056 did = icmd->un.elsreq64.remoteID;
6057
6058 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6059 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04006060 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6061 "0113 An FLOGI ELS command x%x was "
6062 "received from DID x%x in Loop Mode\n",
6063 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006064 return 1;
dea31012005-04-17 16:05:31 -05006065 }
6066
James Smartd6de08c2015-12-16 18:11:53 -05006067 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05006068
dea31012005-04-17 16:05:31 -05006069
James Smartd6de08c2015-12-16 18:11:53 -05006070 /*
6071 * If our portname is greater than the remote portname,
6072 * then we initiate Nport login.
6073 */
6074
6075 rc = memcmp(&vport->fc_portname, &sp->portName,
6076 sizeof(struct lpfc_name));
6077
6078 if (!rc) {
6079 if (phba->sli_rev < LPFC_SLI_REV4) {
6080 mbox = mempool_alloc(phba->mbox_mem_pool,
6081 GFP_KERNEL);
6082 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006083 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05006084 lpfc_linkdown(phba);
6085 lpfc_init_link(phba, mbox,
6086 phba->cfg_topology,
6087 phba->cfg_link_speed);
6088 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
6089 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
6090 mbox->vport = vport;
6091 rc = lpfc_sli_issue_mbox(phba, mbox,
6092 MBX_NOWAIT);
6093 lpfc_set_loopback_flag(phba);
6094 if (rc == MBX_NOT_FINISHED)
6095 mempool_free(mbox, phba->mbox_mem_pool);
6096 return 1;
6097 }
James Smart939723a2012-05-09 21:19:03 -04006098
James Smartd6de08c2015-12-16 18:11:53 -05006099 /* abort the flogi coming back to ourselves
6100 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04006101 */
James Smartd6de08c2015-12-16 18:11:53 -05006102 lpfc_els_abort_flogi(phba);
6103 return 0;
6104
6105 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05006106 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05006107 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05006108 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04006109
James Smartd6de08c2015-12-16 18:11:53 -05006110 /* If we have the high WWPN we can assign our own
6111 * myDID; otherwise, we have to WAIT for a PLOGI
6112 * from the remote NPort to find out what it
6113 * will be.
James Smart939723a2012-05-09 21:19:03 -04006114 */
James Smartd6de08c2015-12-16 18:11:53 -05006115 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05006116 } else {
James Smartd6de08c2015-12-16 18:11:53 -05006117 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05006118 }
6119
James Smartd6de08c2015-12-16 18:11:53 -05006120 /*
6121 * The vport state should go to LPFC_FLOGI only
6122 * AFTER we issue a FLOGI, not receive one.
6123 */
6124 spin_lock_irq(shost->host_lock);
6125 fc_flag = vport->fc_flag;
6126 port_state = vport->port_state;
6127 vport->fc_flag |= FC_PT2PT;
6128 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6129 spin_unlock_irq(shost->host_lock);
6130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6131 "3311 Rcv Flogi PS x%x new PS x%x "
6132 "fc_flag x%x new fc_flag x%x\n",
6133 port_state, vport->port_state,
6134 fc_flag, vport->fc_flag);
6135
6136 /*
6137 * We temporarily set fc_myDID to make it look like we are
6138 * a Fabric. This is done just so we end up with the right
6139 * did / sid on the FLOGI ACC rsp.
6140 */
6141 did = vport->fc_myDID;
6142 vport->fc_myDID = Fabric_DID;
6143
6144 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04006145
dea31012005-04-17 16:05:31 -05006146 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05006147 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006148
James Smart939723a2012-05-09 21:19:03 -04006149 /* Now lets put fc_myDID back to what its supposed to be */
6150 vport->fc_myDID = did;
6151
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006152 return 0;
dea31012005-04-17 16:05:31 -05006153}
6154
James Smarte59058c2008-08-24 21:49:00 -04006155/**
James Smart3621a712009-04-06 18:47:14 -04006156 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04006157 * @vport: pointer to a host virtual N_Port data structure.
6158 * @cmdiocb: pointer to lpfc command iocb data structure.
6159 * @ndlp: pointer to a node-list data structure.
6160 *
6161 * This routine processes Request Node Identification Data (RNID) IOCB
6162 * received as an ELS unsolicited event. Only when the RNID specified format
6163 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6164 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6165 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6166 * rejected by invoking the lpfc_els_rsp_reject() routine.
6167 *
6168 * Return code
6169 * 0 - Successfully processed rnid iocb (currently always return 0)
6170 **/
dea31012005-04-17 16:05:31 -05006171static int
James Smart2e0fef82007-06-17 19:56:36 -05006172lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6173 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006174{
6175 struct lpfc_dmabuf *pcmd;
6176 uint32_t *lp;
dea31012005-04-17 16:05:31 -05006177 RNID *rn;
6178 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04006179 uint32_t cmd;
dea31012005-04-17 16:05:31 -05006180
dea31012005-04-17 16:05:31 -05006181 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6182 lp = (uint32_t *) pcmd->virt;
6183
6184 cmd = *lp++;
6185 rn = (RNID *) lp;
6186
6187 /* RNID received */
6188
6189 switch (rn->Format) {
6190 case 0:
6191 case RNID_TOPOLOGY_DISC:
6192 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05006193 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006194 break;
6195 default:
6196 /* Reject this request because format not supported */
6197 stat.un.b.lsRjtRsvd0 = 0;
6198 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6199 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6200 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006201 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6202 NULL);
dea31012005-04-17 16:05:31 -05006203 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006204 return 0;
dea31012005-04-17 16:05:31 -05006205}
6206
James Smarte59058c2008-08-24 21:49:00 -04006207/**
James Smart12265f62010-10-22 11:05:53 -04006208 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6209 * @vport: pointer to a host virtual N_Port data structure.
6210 * @cmdiocb: pointer to lpfc command iocb data structure.
6211 * @ndlp: pointer to a node-list data structure.
6212 *
6213 * Return code
6214 * 0 - Successfully processed echo iocb (currently always return 0)
6215 **/
6216static int
6217lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6218 struct lpfc_nodelist *ndlp)
6219{
6220 uint8_t *pcmd;
6221
6222 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
6223
6224 /* skip over first word of echo command to find echo data */
6225 pcmd += sizeof(uint32_t);
6226
6227 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
6228 return 0;
6229}
6230
6231/**
James Smart3621a712009-04-06 18:47:14 -04006232 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04006233 * @vport: pointer to a host virtual N_Port data structure.
6234 * @cmdiocb: pointer to lpfc command iocb data structure.
6235 * @ndlp: pointer to a node-list data structure.
6236 *
6237 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6238 * received as an ELS unsolicited event. Currently, this function just invokes
6239 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6240 *
6241 * Return code
6242 * 0 - Successfully processed lirr iocb (currently always return 0)
6243 **/
dea31012005-04-17 16:05:31 -05006244static int
James Smart2e0fef82007-06-17 19:56:36 -05006245lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6246 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006247{
6248 struct ls_rjt stat;
6249
6250 /* For now, unconditionally reject this command */
6251 stat.un.b.lsRjtRsvd0 = 0;
6252 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6253 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6254 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006255 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006256 return 0;
6257}
6258
James Smarte59058c2008-08-24 21:49:00 -04006259/**
James Smart5ffc2662009-11-18 15:39:44 -05006260 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6261 * @vport: pointer to a host virtual N_Port data structure.
6262 * @cmdiocb: pointer to lpfc command iocb data structure.
6263 * @ndlp: pointer to a node-list data structure.
6264 *
6265 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6266 * received as an ELS unsolicited event. A request to RRQ shall only
6267 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6268 * Nx_Port N_Port_ID of the target Exchange is the same as the
6269 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6270 * not accepted, an LS_RJT with reason code "Unable to perform
6271 * command request" and reason code explanation "Invalid Originator
6272 * S_ID" shall be returned. For now, we just unconditionally accept
6273 * RRQ from the target.
6274 **/
6275static void
6276lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6277 struct lpfc_nodelist *ndlp)
6278{
6279 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05006280 if (vport->phba->sli_rev == LPFC_SLI_REV4)
6281 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05006282}
6283
6284/**
James Smart12265f62010-10-22 11:05:53 -04006285 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6286 * @phba: pointer to lpfc hba data structure.
6287 * @pmb: pointer to the driver internal queue element for mailbox command.
6288 *
6289 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6290 * mailbox command. This callback function is to actually send the Accept
6291 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6292 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6293 * mailbox command, constructs the RPS response with the link statistics
6294 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6295 * response to the RPS.
6296 *
6297 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6298 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6299 * will be stored into the context1 field of the IOCB for the completion
6300 * callback function to the RPS Accept Response ELS IOCB command.
6301 *
6302 **/
6303static void
6304lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6305{
6306 MAILBOX_t *mb;
6307 IOCB_t *icmd;
6308 struct RLS_RSP *rls_rsp;
6309 uint8_t *pcmd;
6310 struct lpfc_iocbq *elsiocb;
6311 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006312 uint16_t oxid;
6313 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006314 uint32_t cmdsize;
6315
6316 mb = &pmb->u.mb;
6317
6318 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006319 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6320 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006321 pmb->context1 = NULL;
6322 pmb->context2 = NULL;
6323
6324 if (mb->mbxStatus) {
6325 mempool_free(pmb, phba->mbox_mem_pool);
6326 return;
6327 }
6328
6329 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006330 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6331 lpfc_max_els_tries, ndlp,
6332 ndlp->nlp_DID, ELS_CMD_ACC);
6333
6334 /* Decrement the ndlp reference count from previous mbox command */
6335 lpfc_nlp_put(ndlp);
6336
James Smart37db57e2012-05-09 21:17:16 -04006337 if (!elsiocb) {
6338 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006339 return;
James Smart37db57e2012-05-09 21:17:16 -04006340 }
James Smart12265f62010-10-22 11:05:53 -04006341
6342 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006343 icmd->ulpContext = rxid;
6344 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006345
6346 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6347 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6348 pcmd += sizeof(uint32_t); /* Skip past command */
6349 rls_rsp = (struct RLS_RSP *)pcmd;
6350
6351 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6352 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6353 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6354 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6355 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6356 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006357 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006358 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6359 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6360 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6361 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6362 elsiocb->iotag, elsiocb->iocb.ulpContext,
6363 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6364 ndlp->nlp_rpi);
6365 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6366 phba->fc_stat.elsXmitACC++;
6367 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6368 lpfc_els_free_iocb(phba, elsiocb);
6369}
6370
6371/**
James Smart3621a712009-04-06 18:47:14 -04006372 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006373 * @phba: pointer to lpfc hba data structure.
6374 * @pmb: pointer to the driver internal queue element for mailbox command.
6375 *
6376 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6377 * mailbox command. This callback function is to actually send the Accept
6378 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6379 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6380 * mailbox command, constructs the RPS response with the link statistics
6381 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6382 * response to the RPS.
6383 *
6384 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6385 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6386 * will be stored into the context1 field of the IOCB for the completion
6387 * callback function to the RPS Accept Response ELS IOCB command.
6388 *
6389 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006390static void
James Smart329f9bc2007-04-25 09:53:01 -04006391lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006392{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006393 MAILBOX_t *mb;
6394 IOCB_t *icmd;
6395 RPS_RSP *rps_rsp;
6396 uint8_t *pcmd;
6397 struct lpfc_iocbq *elsiocb;
6398 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006399 uint16_t status;
6400 uint16_t oxid;
6401 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006402 uint32_t cmdsize;
6403
James Smart04c68492009-05-22 14:52:52 -04006404 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006405
6406 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006407 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6408 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006409 pmb->context1 = NULL;
6410 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006411
6412 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006413 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006414 return;
6415 }
6416
6417 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006418 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006419 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6420 lpfc_max_els_tries, ndlp,
6421 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006422
6423 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006424 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006425
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006426 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006427 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006428
6429 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006430 icmd->ulpContext = rxid;
6431 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006432
6433 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6434 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006435 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006436 rps_rsp = (RPS_RSP *)pcmd;
6437
James Smart76a95d72010-11-20 23:11:48 -05006438 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006439 status = 0x10;
6440 else
6441 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006442 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006443 status |= 0x4;
6444
6445 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006446 rps_rsp->portStatus = cpu_to_be16(status);
6447 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6448 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6449 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6450 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6451 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6452 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006453 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006454 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6455 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6456 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6457 elsiocb->iotag, elsiocb->iocb.ulpContext,
6458 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6459 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006460 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006461 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006462 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006463 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006464 return;
6465}
6466
James Smarte59058c2008-08-24 21:49:00 -04006467/**
James Smart12265f62010-10-22 11:05:53 -04006468 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6469 * @vport: pointer to a host virtual N_Port data structure.
6470 * @cmdiocb: pointer to lpfc command iocb data structure.
6471 * @ndlp: pointer to a node-list data structure.
6472 *
6473 * This routine processes Read Port Status (RPL) IOCB received as an
6474 * ELS unsolicited event. It first checks the remote port state. If the
6475 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6476 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6477 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6478 * for reading the HBA link statistics. It is for the callback function,
6479 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6480 * to actually sending out RPL Accept (ACC) response.
6481 *
6482 * Return codes
6483 * 0 - Successfully processed rls iocb (currently always return 0)
6484 **/
6485static int
6486lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6487 struct lpfc_nodelist *ndlp)
6488{
6489 struct lpfc_hba *phba = vport->phba;
6490 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04006491 struct ls_rjt stat;
6492
6493 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6494 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6495 /* reject the unsolicited RPS request and done with it */
6496 goto reject_out;
6497
James Smart12265f62010-10-22 11:05:53 -04006498 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6499 if (mbox) {
6500 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006501 mbox->context1 = (void *)((unsigned long)
6502 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6503 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006504 mbox->context2 = lpfc_nlp_get(ndlp);
6505 mbox->vport = vport;
6506 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6507 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6508 != MBX_NOT_FINISHED)
6509 /* Mbox completion will send ELS Response */
6510 return 0;
6511 /* Decrement reference count used for the failed mbox
6512 * command.
6513 */
6514 lpfc_nlp_put(ndlp);
6515 mempool_free(mbox, phba->mbox_mem_pool);
6516 }
6517reject_out:
6518 /* issue rejection response */
6519 stat.un.b.lsRjtRsvd0 = 0;
6520 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6521 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6522 stat.un.b.vendorUnique = 0;
6523 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6524 return 0;
6525}
6526
6527/**
6528 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6529 * @vport: pointer to a host virtual N_Port data structure.
6530 * @cmdiocb: pointer to lpfc command iocb data structure.
6531 * @ndlp: pointer to a node-list data structure.
6532 *
6533 * This routine processes Read Timout Value (RTV) IOCB received as an
6534 * ELS unsolicited event. It first checks the remote port state. If the
6535 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6536 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6537 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6538 * Value (RTV) unsolicited IOCB event.
6539 *
6540 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6541 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6542 * will be stored into the context1 field of the IOCB for the completion
6543 * callback function to the RPS Accept Response ELS IOCB command.
6544 *
6545 * Return codes
6546 * 0 - Successfully processed rtv iocb (currently always return 0)
6547 **/
6548static int
6549lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6550 struct lpfc_nodelist *ndlp)
6551{
6552 struct lpfc_hba *phba = vport->phba;
6553 struct ls_rjt stat;
6554 struct RTV_RSP *rtv_rsp;
6555 uint8_t *pcmd;
6556 struct lpfc_iocbq *elsiocb;
6557 uint32_t cmdsize;
6558
6559
6560 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6561 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6562 /* reject the unsolicited RPS request and done with it */
6563 goto reject_out;
6564
6565 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6566 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6567 lpfc_max_els_tries, ndlp,
6568 ndlp->nlp_DID, ELS_CMD_ACC);
6569
6570 if (!elsiocb)
6571 return 1;
6572
6573 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6574 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6575 pcmd += sizeof(uint32_t); /* Skip past command */
6576
6577 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006578 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6579 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006580
6581 rtv_rsp = (struct RTV_RSP *)pcmd;
6582
6583 /* populate RTV payload */
6584 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6585 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6586 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6587 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6588 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6589
6590 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6591 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6592 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6593 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6594 "Data: x%x x%x x%x\n",
6595 elsiocb->iotag, elsiocb->iocb.ulpContext,
6596 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6597 ndlp->nlp_rpi,
6598 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6599 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6600 phba->fc_stat.elsXmitACC++;
6601 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6602 lpfc_els_free_iocb(phba, elsiocb);
6603 return 0;
6604
6605reject_out:
6606 /* issue rejection response */
6607 stat.un.b.lsRjtRsvd0 = 0;
6608 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6609 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6610 stat.un.b.vendorUnique = 0;
6611 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6612 return 0;
6613}
6614
6615/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006616 * @vport: pointer to a host virtual N_Port data structure.
6617 * @cmdiocb: pointer to lpfc command iocb data structure.
6618 * @ndlp: pointer to a node-list data structure.
6619 *
6620 * This routine processes Read Port Status (RPS) IOCB received as an
6621 * ELS unsolicited event. It first checks the remote port state. If the
6622 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6623 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6624 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6625 * for reading the HBA link statistics. It is for the callback function,
6626 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6627 * to actually sending out RPS Accept (ACC) response.
6628 *
6629 * Return codes
6630 * 0 - Successfully processed rps iocb (currently always return 0)
6631 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006632static int
James Smart2e0fef82007-06-17 19:56:36 -05006633lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6634 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006635{
James Smart2e0fef82007-06-17 19:56:36 -05006636 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006637 uint32_t *lp;
6638 uint8_t flag;
6639 LPFC_MBOXQ_t *mbox;
6640 struct lpfc_dmabuf *pcmd;
6641 RPS *rps;
6642 struct ls_rjt stat;
6643
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006644 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006645 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6646 /* reject the unsolicited RPS request and done with it */
6647 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006648
6649 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6650 lp = (uint32_t *) pcmd->virt;
6651 flag = (be32_to_cpu(*lp++) & 0xf);
6652 rps = (RPS *) lp;
6653
6654 if ((flag == 0) ||
6655 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006656 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006657 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006658
James Smart92d7f7b2007-06-17 19:56:38 -05006659 printk("Fix me....\n");
6660 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006661 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6662 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006663 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006664 mbox->context1 = (void *)((unsigned long)
6665 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6666 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006667 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006668 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006669 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006670 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006671 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006672 /* Mbox completion will send ELS Response */
6673 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006674 /* Decrement reference count used for the failed mbox
6675 * command.
6676 */
James Smart329f9bc2007-04-25 09:53:01 -04006677 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006678 mempool_free(mbox, phba->mbox_mem_pool);
6679 }
6680 }
James Smart90160e02008-08-24 21:49:45 -04006681
6682reject_out:
6683 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006684 stat.un.b.lsRjtRsvd0 = 0;
6685 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6686 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6687 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006688 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006689 return 0;
6690}
6691
James Smart19ca7602010-11-20 23:11:55 -05006692/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6693 * @vport: pointer to a host virtual N_Port data structure.
6694 * @ndlp: pointer to a node-list data structure.
6695 * @did: DID of the target.
6696 * @rrq: Pointer to the rrq struct.
6697 *
6698 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6699 * Successful the the completion handler will clear the RRQ.
6700 *
6701 * Return codes
6702 * 0 - Successfully sent rrq els iocb.
6703 * 1 - Failed to send rrq els iocb.
6704 **/
6705static int
6706lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6707 uint32_t did, struct lpfc_node_rrq *rrq)
6708{
6709 struct lpfc_hba *phba = vport->phba;
6710 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05006711 struct lpfc_iocbq *elsiocb;
6712 uint8_t *pcmd;
6713 uint16_t cmdsize;
6714 int ret;
6715
6716
6717 if (ndlp != rrq->ndlp)
6718 ndlp = rrq->ndlp;
6719 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6720 return 1;
6721
6722 /* If ndlp is not NULL, we will bump the reference count on it */
6723 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6724 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6725 ELS_CMD_RRQ);
6726 if (!elsiocb)
6727 return 1;
6728
James Smart19ca7602010-11-20 23:11:55 -05006729 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6730
6731 /* For RRQ request, remainder of payload is Exchange IDs */
6732 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6733 pcmd += sizeof(uint32_t);
6734 els_rrq = (struct RRQ *) pcmd;
6735
James Smartee0f4fe2012-05-09 21:19:14 -04006736 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05006737 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6738 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6739 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6740 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6741
6742
6743 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6744 "Issue RRQ: did:x%x",
6745 did, rrq->xritag, rrq->rxid);
6746 elsiocb->context_un.rrq = rrq;
6747 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6748 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6749
6750 if (ret == IOCB_ERROR) {
6751 lpfc_els_free_iocb(phba, elsiocb);
6752 return 1;
6753 }
6754 return 0;
6755}
6756
6757/**
6758 * lpfc_send_rrq - Sends ELS RRQ if needed.
6759 * @phba: pointer to lpfc hba data structure.
6760 * @rrq: pointer to the active rrq.
6761 *
6762 * This routine will call the lpfc_issue_els_rrq if the rrq is
6763 * still active for the xri. If this function returns a failure then
6764 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6765 *
6766 * Returns 0 Success.
6767 * 1 Failure.
6768 **/
6769int
6770lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6771{
6772 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6773 rrq->nlp_DID);
6774 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6775 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6776 rrq->nlp_DID, rrq);
6777 else
6778 return 1;
6779}
6780
James Smarte59058c2008-08-24 21:49:00 -04006781/**
James Smart3621a712009-04-06 18:47:14 -04006782 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04006783 * @vport: pointer to a host virtual N_Port data structure.
6784 * @cmdsize: size of the ELS command.
6785 * @oldiocb: pointer to the original lpfc command iocb data structure.
6786 * @ndlp: pointer to a node-list data structure.
6787 *
6788 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6789 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6790 *
6791 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6792 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6793 * will be stored into the context1 field of the IOCB for the completion
6794 * callback function to the RPL Accept Response ELS command.
6795 *
6796 * Return code
6797 * 0 - Successfully issued ACC RPL ELS command
6798 * 1 - Failed to issue ACC RPL ELS command
6799 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006800static int
James Smart2e0fef82007-06-17 19:56:36 -05006801lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6802 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006803{
James Smart2e0fef82007-06-17 19:56:36 -05006804 struct lpfc_hba *phba = vport->phba;
6805 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006806 RPL_RSP rpl_rsp;
6807 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006808 uint8_t *pcmd;
6809
James Smart2e0fef82007-06-17 19:56:36 -05006810 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6811 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006812
James Smart488d1462006-03-07 15:02:37 -05006813 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006814 return 1;
James Smart488d1462006-03-07 15:02:37 -05006815
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006816 icmd = &elsiocb->iocb;
6817 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006818 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6819 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006820
6821 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6822 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006823 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006824 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
6825 pcmd += sizeof(uint16_t);
6826
6827 /* Setup the RPL ACC payload */
6828 rpl_rsp.listLen = be32_to_cpu(1);
6829 rpl_rsp.index = 0;
6830 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05006831 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
6832 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006833 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006834 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006835 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006836 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6837 "0120 Xmit ELS RPL ACC response tag x%x "
6838 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6839 "rpi x%x\n",
6840 elsiocb->iotag, elsiocb->iocb.ulpContext,
6841 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6842 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006843 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006844 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006845 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6846 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006847 lpfc_els_free_iocb(phba, elsiocb);
6848 return 1;
6849 }
6850 return 0;
6851}
6852
James Smarte59058c2008-08-24 21:49:00 -04006853/**
James Smart3621a712009-04-06 18:47:14 -04006854 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04006855 * @vport: pointer to a host virtual N_Port data structure.
6856 * @cmdiocb: pointer to lpfc command iocb data structure.
6857 * @ndlp: pointer to a node-list data structure.
6858 *
6859 * This routine processes Read Port List (RPL) IOCB received as an ELS
6860 * unsolicited event. It first checks the remote port state. If the remote
6861 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6862 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6863 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6864 * to accept the RPL.
6865 *
6866 * Return code
6867 * 0 - Successfully processed rpl iocb (currently always return 0)
6868 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006869static int
James Smart2e0fef82007-06-17 19:56:36 -05006870lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6871 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006872{
6873 struct lpfc_dmabuf *pcmd;
6874 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006875 uint32_t maxsize;
6876 uint16_t cmdsize;
6877 RPL *rpl;
6878 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05006879
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006880 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6881 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04006882 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006883 stat.un.b.lsRjtRsvd0 = 0;
6884 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6885 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6886 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006887 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6888 NULL);
James Smart90160e02008-08-24 21:49:45 -04006889 /* rejected the unsolicited RPL request and done with it */
6890 return 0;
dea31012005-04-17 16:05:31 -05006891 }
6892
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006893 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6894 lp = (uint32_t *) pcmd->virt;
6895 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006896 maxsize = be32_to_cpu(rpl->maxsize);
6897
6898 /* We support only one port */
6899 if ((rpl->index == 0) &&
6900 ((maxsize == 0) ||
6901 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
6902 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006903 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006904 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
6905 }
James Smart2e0fef82007-06-17 19:56:36 -05006906 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006907
6908 return 0;
6909}
6910
James Smarte59058c2008-08-24 21:49:00 -04006911/**
James Smart3621a712009-04-06 18:47:14 -04006912 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04006913 * @vport: pointer to a virtual N_Port data structure.
6914 * @cmdiocb: pointer to lpfc command iocb data structure.
6915 * @ndlp: pointer to a node-list data structure.
6916 *
6917 * This routine processes Fibre Channel Address Resolution Protocol
6918 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6919 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6920 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6921 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6922 * remote PortName is compared against the FC PortName stored in the @vport
6923 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6924 * compared against the FC NodeName stored in the @vport data structure.
6925 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6926 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6927 * invoked to send out FARP Response to the remote node. Before sending the
6928 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6929 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6930 * routine is invoked to log into the remote port first.
6931 *
6932 * Return code
6933 * 0 - Either the FARP Match Mode not supported or successfully processed
6934 **/
dea31012005-04-17 16:05:31 -05006935static int
James Smart2e0fef82007-06-17 19:56:36 -05006936lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6937 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006938{
6939 struct lpfc_dmabuf *pcmd;
6940 uint32_t *lp;
6941 IOCB_t *icmd;
6942 FARP *fp;
6943 uint32_t cmd, cnt, did;
6944
6945 icmd = &cmdiocb->iocb;
6946 did = icmd->un.elsreq64.remoteID;
6947 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6948 lp = (uint32_t *) pcmd->virt;
6949
6950 cmd = *lp++;
6951 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05006952 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006953 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6954 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006955 /* We will only support match on WWPN or WWNN */
6956 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006957 return 0;
dea31012005-04-17 16:05:31 -05006958 }
6959
6960 cnt = 0;
6961 /* If this FARP command is searching for my portname */
6962 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05006963 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006964 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006965 cnt = 1;
6966 }
6967
6968 /* If this FARP command is searching for my nodename */
6969 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05006970 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05006971 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006972 cnt = 1;
6973 }
6974
6975 if (cnt) {
6976 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6977 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6978 /* Log back into the node before sending the FARP. */
6979 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006980 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006981 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04006982 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05006983 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05006984 }
6985
6986 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05006987 if (fp->Rflags & FARP_REQUEST_FARPR)
6988 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006989 }
6990 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006991 return 0;
dea31012005-04-17 16:05:31 -05006992}
6993
James Smarte59058c2008-08-24 21:49:00 -04006994/**
James Smart3621a712009-04-06 18:47:14 -04006995 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006996 * @vport: pointer to a host virtual N_Port data structure.
6997 * @cmdiocb: pointer to lpfc command iocb data structure.
6998 * @ndlp: pointer to a node-list data structure.
6999 *
7000 * This routine processes Fibre Channel Address Resolution Protocol
7001 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7002 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7003 * the FARP response request.
7004 *
7005 * Return code
7006 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7007 **/
dea31012005-04-17 16:05:31 -05007008static int
James Smart2e0fef82007-06-17 19:56:36 -05007009lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7010 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05007011{
7012 struct lpfc_dmabuf *pcmd;
7013 uint32_t *lp;
7014 IOCB_t *icmd;
7015 uint32_t cmd, did;
7016
7017 icmd = &cmdiocb->iocb;
7018 did = icmd->un.elsreq64.remoteID;
7019 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
7020 lp = (uint32_t *) pcmd->virt;
7021
7022 cmd = *lp++;
7023 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04007024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7025 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05007026 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04007027 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05007028
7029 return 0;
7030}
7031
James Smarte59058c2008-08-24 21:49:00 -04007032/**
James Smart3621a712009-04-06 18:47:14 -04007033 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04007034 * @vport: pointer to a host virtual N_Port data structure.
7035 * @cmdiocb: pointer to lpfc command iocb data structure.
7036 * @fan_ndlp: pointer to a node-list data structure.
7037 *
7038 * This routine processes a Fabric Address Notification (FAN) IOCB
7039 * command received as an ELS unsolicited event. The FAN ELS command will
7040 * only be processed on a physical port (i.e., the @vport represents the
7041 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7042 * compared against those in the phba data structure. If any of those is
7043 * different, the lpfc_initial_flogi() routine is invoked to initialize
7044 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7045 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7046 * is invoked to register login to the fabric.
7047 *
7048 * Return code
7049 * 0 - Successfully processed fan iocb (currently always return 0).
7050 **/
dea31012005-04-17 16:05:31 -05007051static int
James Smart2e0fef82007-06-17 19:56:36 -05007052lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
7053 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05007054{
James Smart2e0fef82007-06-17 19:56:36 -05007055 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04007056 uint32_t *lp;
7057 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007058
James Smart0d2b6b82008-06-14 22:52:47 -04007059 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
7060 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
7061 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007062 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04007063 if ((vport == phba->pport) &&
7064 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007065 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04007066 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05007067 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04007068 sizeof(struct lpfc_name)))) {
7069 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05007070 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04007071 } else {
7072 /* FAN verified - skip FLOGI */
7073 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04007074 if (phba->sli_rev < LPFC_SLI_REV4)
7075 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05007076 else {
7077 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7078 "3138 Need register VFI: (x%x/%x)\n",
7079 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04007080 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05007081 }
dea31012005-04-17 16:05:31 -05007082 }
dea31012005-04-17 16:05:31 -05007083 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007084 return 0;
dea31012005-04-17 16:05:31 -05007085}
7086
James Smarte59058c2008-08-24 21:49:00 -04007087/**
James Smart3621a712009-04-06 18:47:14 -04007088 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04007089 * @ptr: holder for the timer function associated data.
7090 *
7091 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7092 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7093 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7094 * up the worker thread. It is for the worker thread to invoke the routine
7095 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7096 **/
dea31012005-04-17 16:05:31 -05007097void
7098lpfc_els_timeout(unsigned long ptr)
7099{
James Smart2e0fef82007-06-17 19:56:36 -05007100 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
7101 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04007102 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05007103 unsigned long iflag;
7104
James Smart2e0fef82007-06-17 19:56:36 -05007105 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04007106 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05007107 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05007108 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04007109 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05007110
James Smart06918ac2014-02-20 09:57:57 -05007111 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04007112 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05007113 return;
7114}
7115
James Smart2a9bf3d2010-06-07 15:24:45 -04007116
James Smarte59058c2008-08-24 21:49:00 -04007117/**
James Smart3621a712009-04-06 18:47:14 -04007118 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04007119 * @vport: pointer to a virtual N_Port data structure.
7120 *
7121 * This routine is the actual handler function that processes an ELS timeout
7122 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7123 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7124 * invoking the lpfc_sli_issue_abort_iotag() routine.
7125 **/
dea31012005-04-17 16:05:31 -05007126void
James Smart2e0fef82007-06-17 19:56:36 -05007127lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007128{
James Smart2e0fef82007-06-17 19:56:36 -05007129 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05007130 struct lpfc_sli_ring *pring;
7131 struct lpfc_iocbq *tmp_iocb, *piocb;
7132 IOCB_t *cmd = NULL;
7133 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05007134 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05007135 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05007136 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04007137 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05007138
James Smart2a9bf3d2010-06-07 15:24:45 -04007139
dea31012005-04-17 16:05:31 -05007140 timeout = (uint32_t)(phba->fc_ratov << 1);
7141
7142 pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart06918ac2014-02-20 09:57:57 -05007143 if ((phba->pport->load_flag & FC_UNLOADING))
7144 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04007145 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007146 if (phba->sli_rev == LPFC_SLI_REV4)
7147 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04007148
James Smart06918ac2014-02-20 09:57:57 -05007149 if ((phba->pport->load_flag & FC_UNLOADING)) {
7150 if (phba->sli_rev == LPFC_SLI_REV4)
7151 spin_unlock(&pring->ring_lock);
7152 spin_unlock_irq(&phba->hbalock);
7153 return;
7154 }
7155
James Smart0976e1a2013-12-17 20:29:36 -05007156 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05007157 cmd = &piocb->iocb;
7158
James Smart2e0fef82007-06-17 19:56:36 -05007159 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
7160 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
7161 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05007162 continue;
James Smart2e0fef82007-06-17 19:56:36 -05007163
7164 if (piocb->vport != vport)
7165 continue;
7166
dea31012005-04-17 16:05:31 -05007167 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05007168 if (pcmd)
7169 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05007170
James Smart92d7f7b2007-06-17 19:56:38 -05007171 if (els_command == ELS_CMD_FARP ||
7172 els_command == ELS_CMD_FARPR ||
7173 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05007174 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05007175
dea31012005-04-17 16:05:31 -05007176 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05007177 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05007178 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05007179 else
dea31012005-04-17 16:05:31 -05007180 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05007181 continue;
7182 }
7183
James Smart2e0fef82007-06-17 19:56:36 -05007184 remote_ID = 0xffffffff;
7185 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05007186 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05007187 else {
7188 struct lpfc_nodelist *ndlp;
7189 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04007190 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05007191 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05007192 }
James Smart2a9bf3d2010-06-07 15:24:45 -04007193 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05007194 }
James Smart0976e1a2013-12-17 20:29:36 -05007195 if (phba->sli_rev == LPFC_SLI_REV4)
7196 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007197 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04007198
James Smart2a9bf3d2010-06-07 15:24:45 -04007199 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05007200 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04007201 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7202 "0127 ELS timeout Data: x%x x%x x%x "
7203 "x%x\n", els_command,
7204 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
7205 spin_lock_irq(&phba->hbalock);
7206 list_del_init(&piocb->dlist);
7207 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7208 spin_unlock_irq(&phba->hbalock);
7209 }
7210
James Smart0e9bb8d2013-03-01 16:35:12 -05007211 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05007212 if (!(phba->pport->load_flag & FC_UNLOADING))
7213 mod_timer(&vport->els_tmofunc,
7214 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05007215}
7216
James Smarte59058c2008-08-24 21:49:00 -04007217/**
James Smart3621a712009-04-06 18:47:14 -04007218 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04007219 * @vport: pointer to a host virtual N_Port data structure.
7220 *
7221 * This routine is used to clean up all the outstanding ELS commands on a
7222 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7223 * routine. After that, it walks the ELS transmit queue to remove all the
7224 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7225 * the IOCBs with a non-NULL completion callback function, the callback
7226 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7227 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7228 * callback function, the IOCB will simply be released. Finally, it walks
7229 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7230 * completion queue IOCB that is associated with the @vport and is not
7231 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7232 * part of the discovery state machine) out to HBA by invoking the
7233 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7234 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7235 * the IOCBs are aborted when this function returns.
7236 **/
dea31012005-04-17 16:05:31 -05007237void
James Smart2e0fef82007-06-17 19:56:36 -05007238lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05007239{
James Smart0976e1a2013-12-17 20:29:36 -05007240 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05007241 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04007242 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05007243 struct lpfc_iocbq *tmp_iocb, *piocb;
7244 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007245
7246 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05007247 /*
7248 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7249 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7250 * ultimately grabs the ring_lock, the driver must splice the list into
7251 * a working list and release the locks before calling the abort.
7252 */
7253 spin_lock_irq(&phba->hbalock);
7254 if (phba->sli_rev == LPFC_SLI_REV4)
7255 spin_lock(&pring->ring_lock);
7256
7257 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
7258 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
7259 continue;
7260
7261 if (piocb->vport != vport)
7262 continue;
7263 list_add_tail(&piocb->dlist, &abort_list);
7264 }
7265 if (phba->sli_rev == LPFC_SLI_REV4)
7266 spin_unlock(&pring->ring_lock);
7267 spin_unlock_irq(&phba->hbalock);
7268 /* Abort each iocb on the aborted list and remove the dlist links. */
7269 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
7270 spin_lock_irq(&phba->hbalock);
7271 list_del_init(&piocb->dlist);
7272 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
7273 spin_unlock_irq(&phba->hbalock);
7274 }
7275 if (!list_empty(&abort_list))
7276 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7277 "3387 abort list for txq not empty\n");
7278 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05007279
James Smart2e0fef82007-06-17 19:56:36 -05007280 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05007281 if (phba->sli_rev == LPFC_SLI_REV4)
7282 spin_lock(&pring->ring_lock);
7283
dea31012005-04-17 16:05:31 -05007284 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
7285 cmd = &piocb->iocb;
7286
7287 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7288 continue;
7289 }
7290
7291 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007292 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7293 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7294 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7295 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007296 continue;
dea31012005-04-17 16:05:31 -05007297
James Smart2e0fef82007-06-17 19:56:36 -05007298 if (piocb->vport != vport)
7299 continue;
7300
James Smart0976e1a2013-12-17 20:29:36 -05007301 list_del_init(&piocb->list);
7302 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007303 }
James Smart0976e1a2013-12-17 20:29:36 -05007304 if (phba->sli_rev == LPFC_SLI_REV4)
7305 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007306 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007307
James Smarta257bf92009-04-06 18:48:10 -04007308 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007309 lpfc_sli_cancel_iocbs(phba, &abort_list,
7310 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007311
dea31012005-04-17 16:05:31 -05007312 return;
7313}
7314
James Smarte59058c2008-08-24 21:49:00 -04007315/**
James Smart3621a712009-04-06 18:47:14 -04007316 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007317 * @phba: pointer to lpfc hba data structure.
7318 *
7319 * This routine is used to clean up all the outstanding ELS commands on a
7320 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7321 * routine. After that, it walks the ELS transmit queue to remove all the
7322 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7323 * the IOCBs with the completion callback function associated, the callback
7324 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7325 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7326 * callback function associated, the IOCB will simply be released. Finally,
7327 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7328 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7329 * management plane IOCBs that are not part of the discovery state machine)
7330 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7331 **/
James Smart549e55c2007-08-02 11:09:51 -04007332void
7333lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7334{
James Smart0976e1a2013-12-17 20:29:36 -05007335 struct lpfc_vport *vport;
7336 list_for_each_entry(vport, &phba->port_list, listentry)
7337 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007338
James Smart549e55c2007-08-02 11:09:51 -04007339 return;
7340}
7341
James Smarte59058c2008-08-24 21:49:00 -04007342/**
James Smart3621a712009-04-06 18:47:14 -04007343 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007344 * @phba: Pointer to hba context object.
7345 * @cmdiocbp: Pointer to command iocb which reported error.
7346 * @rspiocbp: Pointer to response iocb which reported error.
7347 *
7348 * This function sends an event when there is an ELS command
7349 * failure.
7350 **/
7351void
7352lpfc_send_els_failure_event(struct lpfc_hba *phba,
7353 struct lpfc_iocbq *cmdiocbp,
7354 struct lpfc_iocbq *rspiocbp)
7355{
7356 struct lpfc_vport *vport = cmdiocbp->vport;
7357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7358 struct lpfc_lsrjt_event lsrjt_event;
7359 struct lpfc_fabric_event_header fabric_event;
7360 struct ls_rjt stat;
7361 struct lpfc_nodelist *ndlp;
7362 uint32_t *pcmd;
7363
7364 ndlp = cmdiocbp->context1;
7365 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7366 return;
7367
7368 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7369 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7370 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7371 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7372 sizeof(struct lpfc_name));
7373 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7374 sizeof(struct lpfc_name));
7375 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7376 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007377 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007378 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7379 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7380 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7381 fc_host_post_vendor_event(shost,
7382 fc_get_event_number(),
7383 sizeof(lsrjt_event),
7384 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007385 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007386 return;
7387 }
7388 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7389 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7390 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7391 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7392 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7393 else
7394 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7395 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7396 sizeof(struct lpfc_name));
7397 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7398 sizeof(struct lpfc_name));
7399 fc_host_post_vendor_event(shost,
7400 fc_get_event_number(),
7401 sizeof(fabric_event),
7402 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007403 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007404 return;
7405 }
7406
7407}
7408
7409/**
James Smart3621a712009-04-06 18:47:14 -04007410 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007411 * @vport: Pointer to vport object.
7412 * @ndlp: Pointer FC node object.
7413 * @cmd: ELS command code.
7414 *
7415 * This function posts an event when there is an incoming
7416 * unsolicited ELS command.
7417 **/
7418static void
7419lpfc_send_els_event(struct lpfc_vport *vport,
7420 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007421 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007422{
James Smartddcc50f2008-12-04 22:38:46 -05007423 struct lpfc_els_event_header *els_data = NULL;
7424 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007425 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7426
James Smartddcc50f2008-12-04 22:38:46 -05007427 if (*payload == ELS_CMD_LOGO) {
7428 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7429 if (!logo_data) {
7430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7431 "0148 Failed to allocate memory "
7432 "for LOGO event\n");
7433 return;
7434 }
7435 els_data = &logo_data->header;
7436 } else {
7437 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7438 GFP_KERNEL);
7439 if (!els_data) {
7440 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7441 "0149 Failed to allocate memory "
7442 "for ELS event\n");
7443 return;
7444 }
7445 }
7446 els_data->event_type = FC_REG_ELS_EVENT;
7447 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007448 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007449 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007450 break;
7451 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007452 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007453 break;
7454 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007455 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7456 break;
7457 case ELS_CMD_LOGO:
7458 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7459 /* Copy the WWPN in the LOGO payload */
7460 memcpy(logo_data->logo_wwpn, &payload[2],
7461 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007462 break;
7463 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007464 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007465 return;
7466 }
James Smartddcc50f2008-12-04 22:38:46 -05007467 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7468 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7469 if (*payload == ELS_CMD_LOGO) {
7470 fc_host_post_vendor_event(shost,
7471 fc_get_event_number(),
7472 sizeof(struct lpfc_logo_event),
7473 (char *)logo_data,
7474 LPFC_NL_VENDOR_ID);
7475 kfree(logo_data);
7476 } else {
7477 fc_host_post_vendor_event(shost,
7478 fc_get_event_number(),
7479 sizeof(struct lpfc_els_event_header),
7480 (char *)els_data,
7481 LPFC_NL_VENDOR_ID);
7482 kfree(els_data);
7483 }
James Smartea2151b2008-09-07 11:52:10 -04007484
7485 return;
7486}
7487
7488
7489/**
James Smart3621a712009-04-06 18:47:14 -04007490 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007491 * @phba: pointer to lpfc hba data structure.
7492 * @pring: pointer to a SLI ring.
7493 * @vport: pointer to a host virtual N_Port data structure.
7494 * @elsiocb: pointer to lpfc els command iocb data structure.
7495 *
7496 * This routine is used for processing the IOCB associated with a unsolicited
7497 * event. It first determines whether there is an existing ndlp that matches
7498 * the DID from the unsolicited IOCB. If not, it will create a new one with
7499 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7500 * IOCB is then used to invoke the proper routine and to set up proper state
7501 * of the discovery state machine.
7502 **/
James Smarted957682007-06-17 19:56:37 -05007503static void
7504lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007505 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007506{
James Smart87af33f2007-10-27 13:37:43 -04007507 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007508 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007509 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007510 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007511 uint32_t cmd, did, newnode;
7512 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007513 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007514
James Smarte47c9092008-02-08 18:49:26 -05007515 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007516 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007517
dea31012005-04-17 16:05:31 -05007518 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007519 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7520 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007521 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007522 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007523
James Smart858c9f62007-06-17 19:56:39 -05007524 did = icmd->un.rcvels.remoteID;
7525 if (icmd->ulpStatus) {
7526 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7527 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7528 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007529 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007530 }
dea31012005-04-17 16:05:31 -05007531
7532 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007533 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007534 goto dropit;
dea31012005-04-17 16:05:31 -05007535
James Smartc8685952009-11-18 15:39:16 -05007536 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007537 if (vport->load_flag & FC_UNLOADING)
7538 goto dropit;
7539
James Smart92494142011-02-16 12:39:44 -05007540 /* If NPort discovery is delayed drop incoming ELS */
7541 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7542 (cmd != ELS_CMD_PLOGI))
7543 goto dropit;
7544
James Smart2e0fef82007-06-17 19:56:36 -05007545 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007546 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007547 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05007548 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05007549 if (!ndlp)
dea31012005-04-17 16:05:31 -05007550 goto dropit;
dea31012005-04-17 16:05:31 -05007551
James Smart2e0fef82007-06-17 19:56:36 -05007552 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04007553 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007554 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007555 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007556 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007557 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7558 ndlp = lpfc_enable_node(vport, ndlp,
7559 NLP_STE_UNUSED_NODE);
7560 if (!ndlp)
7561 goto dropit;
7562 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7563 newnode = 1;
7564 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7565 ndlp->nlp_type |= NLP_FABRIC;
7566 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7567 /* This is similar to the new node path */
7568 ndlp = lpfc_nlp_get(ndlp);
7569 if (!ndlp)
7570 goto dropit;
7571 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7572 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007573 }
dea31012005-04-17 16:05:31 -05007574
7575 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007576
James Smart12838e72014-09-03 12:57:19 -04007577 /*
7578 * Do not process any unsolicited ELS commands
7579 * if the ndlp is in DEV_LOSS
7580 */
James Smart466e8402015-05-21 13:55:28 -04007581 shost = lpfc_shost_from_vport(vport);
7582 spin_lock_irq(shost->host_lock);
7583 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7584 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007585 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007586 }
7587 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007588
James Smart329f9bc2007-04-25 09:53:01 -04007589 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007590 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007591
7592 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7593 cmd &= ELS_CMD_MASK;
7594 }
7595 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007596 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7597 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007598 "Data: x%x x%x x%x x%x\n",
7599 cmd, did, vport->port_state, vport->fc_flag,
7600 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04007601
7602 /* reject till our FLOGI completes */
7603 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smartd6de08c2015-12-16 18:11:53 -05007604 (cmd != ELS_CMD_FLOGI)) {
James Smarteec3d312015-08-31 16:48:18 -04007605 rjt_err = LSRJT_UNABLE_TPC;
7606 rjt_exp = LSEXP_NOTHING_MORE;
7607 goto lsrjt;
7608 }
7609
dea31012005-04-17 16:05:31 -05007610 switch (cmd) {
7611 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7613 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7614 did, vport->port_state, ndlp->nlp_flag);
7615
dea31012005-04-17 16:05:31 -05007616 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007617 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007618 if (phba->sli_rev == LPFC_SLI_REV4 &&
7619 (phba->pport->fc_flag & FC_PT2PT)) {
7620 vport->fc_prevDID = vport->fc_myDID;
7621 /* Our DID needs to be updated before registering
7622 * the vfi. This is done in lpfc_rcv_plogi but
7623 * that is called after the reg_vfi.
7624 */
7625 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7626 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7627 "3312 Remote port assigned DID x%x "
7628 "%x\n", vport->fc_myDID,
7629 vport->fc_prevDID);
7630 }
James Smart858c9f62007-06-17 19:56:39 -05007631
James Smartddcc50f2008-12-04 22:38:46 -05007632 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007633
7634 /* If Nport discovery is delayed, reject PLOGIs */
7635 if (vport->fc_flag & FC_DISC_DELAYED) {
7636 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007637 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007638 break;
7639 }
James Smartd6de08c2015-12-16 18:11:53 -05007640
James Smart858c9f62007-06-17 19:56:39 -05007641 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007642 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7643 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7644 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007645 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007646 break;
7647 }
dea31012005-04-17 16:05:31 -05007648 }
James Smart87af33f2007-10-27 13:37:43 -04007649
James Smart87af33f2007-10-27 13:37:43 -04007650 spin_lock_irq(shost->host_lock);
7651 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7652 spin_unlock_irq(shost->host_lock);
7653
James Smart2e0fef82007-06-17 19:56:36 -05007654 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7655 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007656
dea31012005-04-17 16:05:31 -05007657 break;
7658 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007659 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7660 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7661 did, vport->port_state, ndlp->nlp_flag);
7662
dea31012005-04-17 16:05:31 -05007663 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007664 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007665 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007666 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007667 break;
7668 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007669 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7670 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7671 did, vport->port_state, ndlp->nlp_flag);
7672
dea31012005-04-17 16:05:31 -05007673 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007674 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007675 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007676 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007677 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007678 break;
7679 }
James Smart2e0fef82007-06-17 19:56:36 -05007680 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007681 break;
7682 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7684 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7685 did, vport->port_state, ndlp->nlp_flag);
7686
dea31012005-04-17 16:05:31 -05007687 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007688 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007689 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007690 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007691 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007692 break;
7693 }
James Smart2e0fef82007-06-17 19:56:36 -05007694 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05007695 break;
James Smart8b017a32015-05-21 13:55:18 -04007696 case ELS_CMD_LCB:
7697 phba->fc_stat.elsRcvLCB++;
7698 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7699 break;
James Smart86478872015-05-21 13:55:21 -04007700 case ELS_CMD_RDP:
7701 phba->fc_stat.elsRcvRDP++;
7702 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7703 break;
dea31012005-04-17 16:05:31 -05007704 case ELS_CMD_RSCN:
7705 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04007706 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007707 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007708 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007709 break;
7710 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05007711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7712 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7713 did, vport->port_state, ndlp->nlp_flag);
7714
James Smartddcc50f2008-12-04 22:38:46 -05007715 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05007716 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007717 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007718 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007719 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007720 break;
7721 }
James Smart2e0fef82007-06-17 19:56:36 -05007722 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7723 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05007724 break;
7725 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05007726 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7727 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7728 did, vport->port_state, ndlp->nlp_flag);
7729
dea31012005-04-17 16:05:31 -05007730 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007731 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007732 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007733 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007734 break;
7735 }
James Smart2e0fef82007-06-17 19:56:36 -05007736 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7737 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05007738 break;
7739 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05007740 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7741 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7742 did, vport->port_state, ndlp->nlp_flag);
7743
dea31012005-04-17 16:05:31 -05007744 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05007745 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007746 break;
7747 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05007748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7749 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7750 did, vport->port_state, ndlp->nlp_flag);
7751
dea31012005-04-17 16:05:31 -05007752 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05007753 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007754 break;
7755 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05007756 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7757 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7758 did, vport->port_state, ndlp->nlp_flag);
7759
dea31012005-04-17 16:05:31 -05007760 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05007761 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007762 break;
dea31012005-04-17 16:05:31 -05007763 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05007764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7765 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7766 did, vport->port_state, ndlp->nlp_flag);
7767
dea31012005-04-17 16:05:31 -05007768 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05007769 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007770 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007771 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007772 break;
7773 }
James Smart2e0fef82007-06-17 19:56:36 -05007774 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05007775 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007776 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05007777 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7778 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7779 did, vport->port_state, ndlp->nlp_flag);
7780
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007781 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05007782 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007783 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007784 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007785 break;
James Smart12265f62010-10-22 11:05:53 -04007786 case ELS_CMD_RLS:
7787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7788 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7789 did, vport->port_state, ndlp->nlp_flag);
7790
7791 phba->fc_stat.elsRcvRLS++;
7792 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7793 if (newnode)
7794 lpfc_nlp_put(ndlp);
7795 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007796 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05007797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7798 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7799 did, vport->port_state, ndlp->nlp_flag);
7800
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007801 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05007802 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007803 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007804 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007805 break;
7806 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05007807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7808 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7809 did, vport->port_state, ndlp->nlp_flag);
7810
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007811 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05007812 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007813 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007814 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007815 break;
dea31012005-04-17 16:05:31 -05007816 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05007817 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7818 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7819 did, vport->port_state, ndlp->nlp_flag);
7820
dea31012005-04-17 16:05:31 -05007821 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05007822 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007823 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007824 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007825 break;
James Smart12265f62010-10-22 11:05:53 -04007826 case ELS_CMD_RTV:
7827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7828 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7829 did, vport->port_state, ndlp->nlp_flag);
7830 phba->fc_stat.elsRcvRTV++;
7831 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
7832 if (newnode)
7833 lpfc_nlp_put(ndlp);
7834 break;
James Smart5ffc2662009-11-18 15:39:44 -05007835 case ELS_CMD_RRQ:
7836 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7837 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7838 did, vport->port_state, ndlp->nlp_flag);
7839
7840 phba->fc_stat.elsRcvRRQ++;
7841 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
7842 if (newnode)
7843 lpfc_nlp_put(ndlp);
7844 break;
James Smart12265f62010-10-22 11:05:53 -04007845 case ELS_CMD_ECHO:
7846 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7847 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7848 did, vport->port_state, ndlp->nlp_flag);
7849
7850 phba->fc_stat.elsRcvECHO++;
7851 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
7852 if (newnode)
7853 lpfc_nlp_put(ndlp);
7854 break;
James Smart303f2f92013-01-03 15:43:11 -05007855 case ELS_CMD_REC:
7856 /* receive this due to exchange closed */
7857 rjt_err = LSRJT_UNABLE_TPC;
7858 rjt_exp = LSEXP_INVALID_OX_RX;
7859 break;
dea31012005-04-17 16:05:31 -05007860 default:
James Smart858c9f62007-06-17 19:56:39 -05007861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7862 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7863 cmd, did, vport->port_state);
7864
dea31012005-04-17 16:05:31 -05007865 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05007866 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05007867 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007868
7869 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007870 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7871 "0115 Unknown ELS command x%x "
7872 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04007873 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007874 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007875 break;
7876 }
7877
James Smarteec3d312015-08-31 16:48:18 -04007878lsrjt:
dea31012005-04-17 16:05:31 -05007879 /* check if need to LS_RJT received ELS cmd */
7880 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05007881 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05007882 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05007883 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05007884 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
7885 NULL);
dea31012005-04-17 16:05:31 -05007886 }
7887
James Smartd7c255b2008-08-24 21:50:00 -04007888 lpfc_nlp_put(elsiocb->context1);
7889 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05007890 return;
7891
7892dropit:
James Smart98c9ea52007-10-27 13:37:33 -04007893 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04007894 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7895 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05007896 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04007897 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05007898 phba->fc_stat.elsRcvDrop++;
7899}
7900
James Smarte59058c2008-08-24 21:49:00 -04007901/**
James Smart3621a712009-04-06 18:47:14 -04007902 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04007903 * @phba: pointer to lpfc hba data structure.
7904 * @pring: pointer to a SLI ring.
7905 * @elsiocb: pointer to lpfc els iocb data structure.
7906 *
7907 * This routine is used to process an unsolicited event received from a SLI
7908 * (Service Level Interface) ring. The actual processing of the data buffer
7909 * associated with the unsolicited event is done by invoking the routine
7910 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7911 * SLI ring on which the unsolicited event was received.
7912 **/
James Smarted957682007-06-17 19:56:37 -05007913void
7914lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7915 struct lpfc_iocbq *elsiocb)
7916{
7917 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05007918 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05007919 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05007920 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
7921 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05007922
James Smartd7c255b2008-08-24 21:50:00 -04007923 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007924 elsiocb->context2 = NULL;
7925 elsiocb->context3 = NULL;
7926
7927 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
7928 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
7929 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04007930 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
7931 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05007932 phba->fc_stat.NoRcvBuf++;
7933 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05007934 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04007935 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05007936 return;
7937 }
7938
James Smart92d7f7b2007-06-17 19:56:38 -05007939 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7940 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
7941 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7942 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7943 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04007944 else
7945 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04007946 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05007947 }
James Smart6d368e52011-05-24 11:44:12 -04007948
James Smart7f5f3d02008-02-08 18:50:14 -05007949 /* If there are no BDEs associated
7950 * with this IOCB, there is nothing to do.
7951 */
James Smarted957682007-06-17 19:56:37 -05007952 if (icmd->ulpBdeCount == 0)
7953 return;
7954
James Smart7f5f3d02008-02-08 18:50:14 -05007955 /* type of ELS cmd is first 32bit word
7956 * in packet
7957 */
James Smarted957682007-06-17 19:56:37 -05007958 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05007959 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05007960 } else {
7961 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7962 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05007963 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7964 paddr);
James Smarted957682007-06-17 19:56:37 -05007965 }
7966
James Smart92d7f7b2007-06-17 19:56:38 -05007967 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7968 /*
7969 * The different unsolicited event handlers would tell us
7970 * if they are done with "mp" by setting context2 to NULL.
7971 */
dea31012005-04-17 16:05:31 -05007972 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007973 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7974 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05007975 }
James Smarted957682007-06-17 19:56:37 -05007976
7977 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05007978 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05007979 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007980 elsiocb->context2 = bdeBuf2;
7981 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05007982 /* free mp if we are done with it */
7983 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007984 lpfc_in_buf_free(phba, elsiocb->context2);
7985 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05007986 }
dea31012005-04-17 16:05:31 -05007987 }
dea31012005-04-17 16:05:31 -05007988}
James Smart92d7f7b2007-06-17 19:56:38 -05007989
James Smart4258e982015-12-16 18:11:58 -05007990void
7991lpfc_start_fdmi(struct lpfc_vport *vport)
7992{
7993 struct lpfc_hba *phba = vport->phba;
7994 struct lpfc_nodelist *ndlp;
7995
7996 /* If this is the first time, allocate an ndlp and initialize
7997 * it. Otherwise, make sure the node is enabled and then do the
7998 * login.
7999 */
8000 ndlp = lpfc_findnode_did(vport, FDMI_DID);
8001 if (!ndlp) {
8002 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
8003 if (ndlp) {
8004 lpfc_nlp_init(vport, ndlp, FDMI_DID);
8005 ndlp->nlp_type |= NLP_FABRIC;
8006 } else {
8007 return;
8008 }
8009 }
8010 if (!NLP_CHK_NODE_ACT(ndlp))
8011 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
8012
8013 if (ndlp) {
8014 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8015 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
8016 }
8017}
8018
James Smarte59058c2008-08-24 21:49:00 -04008019/**
James Smart3621a712009-04-06 18:47:14 -04008020 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04008021 * @phba: pointer to lpfc hba data structure.
8022 * @vport: pointer to a virtual N_Port data structure.
8023 *
8024 * This routine issues a Port Login (PLOGI) to the Name Server with
8025 * State Change Request (SCR) for a @vport. This routine will create an
8026 * ndlp for the Name Server associated to the @vport if such node does
8027 * not already exist. The PLOGI to Name Server is issued by invoking the
8028 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8029 * (FDMI) is configured to the @vport, a FDMI node will be created and
8030 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8031 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008032void
8033lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
8034{
James Smart4258e982015-12-16 18:11:58 -05008035 struct lpfc_nodelist *ndlp;
James Smart92494142011-02-16 12:39:44 -05008036 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8037
8038 /*
8039 * If lpfc_delay_discovery parameter is set and the clean address
8040 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8041 * discovery.
8042 */
8043 spin_lock_irq(shost->host_lock);
8044 if (vport->fc_flag & FC_DISC_DELAYED) {
8045 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04008046 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
8047 "3334 Delay fc port discovery for %d seconds\n",
8048 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05008049 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04008050 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05008051 return;
8052 }
8053 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008054
8055 ndlp = lpfc_findnode_did(vport, NameServer_DID);
8056 if (!ndlp) {
8057 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
8058 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008059 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05008060 lpfc_disc_start(vport);
8061 return;
8062 }
8063 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008064 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8065 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008066 return;
8067 }
8068 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05008069 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
8070 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
8071 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05008072 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05008073 lpfc_disc_start(vport);
8074 return;
8075 }
8076 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8077 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8078 "0348 NameServer login: node freed\n");
8079 return;
8080 }
James Smart92d7f7b2007-06-17 19:56:38 -05008081 }
James Smart58da1ff2008-04-07 10:15:56 -04008082 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05008083
8084 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
8085
8086 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
8087 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008088 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8089 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008090 return;
8091 }
8092
James Smart8663cbb2016-03-31 14:12:33 -07008093 if ((phba->cfg_enable_SmartSAN ||
8094 (phba->cfg_fdmi_on == LPFC_FDMI_SUPPORT)) &&
8095 (vport->load_flag & FC_ALLOW_FDMI))
James Smart4258e982015-12-16 18:11:58 -05008096 lpfc_start_fdmi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008097}
8098
James Smarte59058c2008-08-24 21:49:00 -04008099/**
James Smart3621a712009-04-06 18:47:14 -04008100 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04008101 * @phba: pointer to lpfc hba data structure.
8102 * @pmb: pointer to the driver internal queue element for mailbox command.
8103 *
8104 * This routine is the completion callback function to register new vport
8105 * mailbox command. If the new vport mailbox command completes successfully,
8106 * the fabric registration login shall be performed on physical port (the
8107 * new vport created is actually a physical port, with VPI 0) or the port
8108 * login to Name Server for State Change Request (SCR) will be performed
8109 * on virtual port (real virtual port, with VPI greater than 0).
8110 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008111static void
8112lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
8113{
8114 struct lpfc_vport *vport = pmb->vport;
8115 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8116 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04008117 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05008118 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008119
James Smart09372822008-01-11 01:52:54 -05008120 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008121 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008122 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008123
8124 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04008125 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04008126 "0915 Register VPI failed : Status: x%x"
8127 " upd bit: x%x \n", mb->mbxStatus,
8128 mb->un.varRegVpi.upd);
8129 if (phba->sli_rev == LPFC_SLI_REV4 &&
8130 mb->un.varRegVpi.upd)
8131 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05008132
8133 switch (mb->mbxStatus) {
8134 case 0x11: /* unsupported feature */
8135 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05008136 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05008137 /* giving up on vport registration */
8138 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8139 spin_lock_irq(shost->host_lock);
8140 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
8141 spin_unlock_irq(shost->host_lock);
8142 lpfc_can_disctmo(vport);
8143 break;
James Smart695a8142010-01-26 23:08:03 -05008144 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8145 case 0x20:
8146 spin_lock_irq(shost->host_lock);
8147 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
8148 spin_unlock_irq(shost->host_lock);
8149 lpfc_init_vpi(phba, pmb, vport->vpi);
8150 pmb->vport = vport;
8151 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
8152 rc = lpfc_sli_issue_mbox(phba, pmb,
8153 MBX_NOWAIT);
8154 if (rc == MBX_NOT_FINISHED) {
8155 lpfc_printf_vlog(vport,
8156 KERN_ERR, LOG_MBOX,
8157 "2732 Failed to issue INIT_VPI"
8158 " mailbox command\n");
8159 } else {
8160 lpfc_nlp_put(ndlp);
8161 return;
8162 }
8163
James Smart92d7f7b2007-06-17 19:56:38 -05008164 default:
8165 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04008166 if (phba->sli_rev == LPFC_SLI_REV4)
8167 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008168 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05008169 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008170 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05008171 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04008172 if (vport->port_type == LPFC_PHYSICAL_PORT
8173 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05008174 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05008175 else
8176 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008177 break;
8178 }
James Smart92d7f7b2007-06-17 19:56:38 -05008179 } else {
James Smart695a8142010-01-26 23:08:03 -05008180 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05008181 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05008182 spin_unlock_irq(shost->host_lock);
8183 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04008184 if (phba->sli_rev < LPFC_SLI_REV4)
8185 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05008186 else {
James Smartfc2b9892010-02-26 14:15:29 -05008187 /*
8188 * If the physical port is instantiated using
8189 * FDISC, do not start vport discovery.
8190 */
8191 if (vport->port_state != LPFC_FDISC)
8192 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05008193 lpfc_do_scr_ns_plogi(phba, vport);
8194 }
8195 } else
James Smart92d7f7b2007-06-17 19:56:38 -05008196 lpfc_do_scr_ns_plogi(phba, vport);
8197 }
James Smart38b92ef2010-08-04 16:11:39 -04008198mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05008199 /* Now, we decrement the ndlp reference count held for this
8200 * callback function
8201 */
8202 lpfc_nlp_put(ndlp);
8203
James Smart92d7f7b2007-06-17 19:56:38 -05008204 mempool_free(pmb, phba->mbox_mem_pool);
8205 return;
8206}
8207
James Smarte59058c2008-08-24 21:49:00 -04008208/**
James Smart3621a712009-04-06 18:47:14 -04008209 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04008210 * @phba: pointer to lpfc hba data structure.
8211 * @vport: pointer to a host virtual N_Port data structure.
8212 * @ndlp: pointer to a node-list data structure.
8213 *
8214 * This routine registers the @vport as a new virtual port with a HBA.
8215 * It is done through a registering vpi mailbox command.
8216 **/
James Smart695a8142010-01-26 23:08:03 -05008217void
James Smart92d7f7b2007-06-17 19:56:38 -05008218lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
8219 struct lpfc_nodelist *ndlp)
8220{
James Smart09372822008-01-11 01:52:54 -05008221 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05008222 LPFC_MBOXQ_t *mbox;
8223
8224 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
8225 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04008226 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05008227 mbox->vport = vport;
8228 mbox->context2 = lpfc_nlp_get(ndlp);
8229 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04008230 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05008231 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05008232 /* mailbox command not success, decrement ndlp
8233 * reference count for this command
8234 */
8235 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008236 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05008237
James Smarte8b62012007-08-02 11:10:09 -04008238 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8239 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05008240 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008241 }
8242 } else {
James Smarte8b62012007-08-02 11:10:09 -04008243 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
8244 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05008245 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05008246 }
James Smartfa4066b2008-01-11 01:53:27 -05008247 return;
8248
8249mbox_err_exit:
8250 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
8251 spin_lock_irq(shost->host_lock);
8252 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
8253 spin_unlock_irq(shost->host_lock);
8254 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008255}
8256
James Smarte59058c2008-08-24 21:49:00 -04008257/**
James Smart0c9ab6f2010-02-26 14:15:57 -05008258 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05008259 * @phba: pointer to lpfc hba data structure.
8260 *
James Smart0c9ab6f2010-02-26 14:15:57 -05008261 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05008262 **/
8263void
James Smart0c9ab6f2010-02-26 14:15:57 -05008264lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05008265{
8266 struct lpfc_vport **vports;
8267 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05008268 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05008269 int i;
James Smart695a8142010-01-26 23:08:03 -05008270
8271 /* Treat this failure as linkdown for all vports */
8272 link_state = phba->link_state;
8273 lpfc_linkdown(phba);
8274 phba->link_state = link_state;
8275
8276 vports = lpfc_create_vport_work_array(phba);
8277
8278 if (vports) {
8279 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
8280 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
8281 if (ndlp)
8282 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
8283 lpfc_els_flush_cmd(vports[i]);
8284 }
8285 lpfc_destroy_vport_work_array(phba, vports);
8286 }
James Smart0c9ab6f2010-02-26 14:15:57 -05008287}
8288
8289/**
8290 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8291 * @phba: pointer to lpfc hba data structure.
8292 *
8293 * This routine abort all pending discovery commands and
8294 * start a timer to retry FLOGI for the physical port
8295 * discovery.
8296 **/
8297void
8298lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8299{
8300 struct lpfc_nodelist *ndlp;
8301 struct Scsi_Host *shost;
8302
8303 /* Cancel the all vports retry delay retry timers */
8304 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008305
8306 /* If fabric require FLOGI, then re-instantiate physical login */
8307 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8308 if (!ndlp)
8309 return;
8310
James Smart695a8142010-01-26 23:08:03 -05008311 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008312 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008313 spin_lock_irq(shost->host_lock);
8314 ndlp->nlp_flag |= NLP_DELAY_TMO;
8315 spin_unlock_irq(shost->host_lock);
8316 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8317 phba->pport->port_state = LPFC_FLOGI;
8318 return;
8319}
8320
8321/**
8322 * lpfc_fabric_login_reqd - Check if FLOGI required.
8323 * @phba: pointer to lpfc hba data structure.
8324 * @cmdiocb: pointer to FDISC command iocb.
8325 * @rspiocb: pointer to FDISC response iocb.
8326 *
8327 * This routine checks if a FLOGI is reguired for FDISC
8328 * to succeed.
8329 **/
8330static int
8331lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8332 struct lpfc_iocbq *cmdiocb,
8333 struct lpfc_iocbq *rspiocb)
8334{
8335
8336 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8337 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8338 return 0;
8339 else
8340 return 1;
8341}
8342
8343/**
James Smart3621a712009-04-06 18:47:14 -04008344 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008345 * @phba: pointer to lpfc hba data structure.
8346 * @cmdiocb: pointer to lpfc command iocb data structure.
8347 * @rspiocb: pointer to lpfc response iocb data structure.
8348 *
8349 * This routine is the completion callback function to a Fabric Discover
8350 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8351 * single threaded, each FDISC completion callback function will reset
8352 * the discovery timer for all vports such that the timers will not get
8353 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8354 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8355 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8356 * assigned to the vport has been changed with the completion of the FDISC
8357 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8358 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8359 * routine is invoked to register new vport with the HBA. Otherwise, the
8360 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8361 * Server for State Change Request (SCR).
8362 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008363static void
8364lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8365 struct lpfc_iocbq *rspiocb)
8366{
8367 struct lpfc_vport *vport = cmdiocb->vport;
8368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8369 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8370 struct lpfc_nodelist *np;
8371 struct lpfc_nodelist *next_np;
8372 IOCB_t *irsp = &rspiocb->iocb;
8373 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008374 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8375 struct serv_parm *sp;
8376 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008377
James Smarte8b62012007-08-02 11:10:09 -04008378 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8379 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8380 irsp->ulpStatus, irsp->un.ulpWord[4],
8381 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008382 /* Since all FDISCs are being single threaded, we
8383 * must reset the discovery timer for ALL vports
8384 * waiting to send FDISC when one completes.
8385 */
8386 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8387 lpfc_set_disctmo(piocb->vport);
8388 }
8389
James Smart858c9f62007-06-17 19:56:39 -05008390 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8391 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8392 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8393
James Smart92d7f7b2007-06-17 19:56:38 -05008394 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008395
8396 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8397 lpfc_retry_pport_discovery(phba);
8398 goto out;
8399 }
8400
James Smart92d7f7b2007-06-17 19:56:38 -05008401 /* Check for retry */
8402 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8403 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008404 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008405 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008406 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008407 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008408 goto fdisc_failed;
8409 }
James Smartd7c255b2008-08-24 21:50:00 -04008410 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008411 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008412 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008413 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008414 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008415 vport->fc_flag |= FC_PUBLIC_LOOP;
8416 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008417
James Smartd7c255b2008-08-24 21:50:00 -04008418 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8419 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008420 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008421 if (!prsp)
8422 goto out;
James Smart92494142011-02-16 12:39:44 -05008423 sp = prsp->virt + sizeof(uint32_t);
8424 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8425 memcpy(&vport->fabric_portname, &sp->portName,
8426 sizeof(struct lpfc_name));
8427 memcpy(&vport->fabric_nodename, &sp->nodeName,
8428 sizeof(struct lpfc_name));
8429 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008430 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8431 /* If our NportID changed, we need to ensure all
8432 * remaining NPORTs get unreg_login'ed so we can
8433 * issue unreg_vpi.
8434 */
8435 list_for_each_entry_safe(np, next_np,
8436 &vport->fc_nodes, nlp_listp) {
8437 if (!NLP_CHK_NODE_ACT(ndlp) ||
8438 (np->nlp_state != NLP_STE_NPR_NODE) ||
8439 !(np->nlp_flag & NLP_NPR_ADISC))
8440 continue;
James Smart09372822008-01-11 01:52:54 -05008441 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008442 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008443 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008444 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008445 }
James Smart78730cf2010-04-06 15:06:30 -04008446 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008447
8448 if (phba->sli_rev == LPFC_SLI_REV4)
8449 lpfc_sli4_unreg_all_rpis(vport);
8450
James Smartd7c255b2008-08-24 21:50:00 -04008451 lpfc_mbx_unreg_vpi(vport);
8452 spin_lock_irq(shost->host_lock);
8453 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008454 if (phba->sli_rev == LPFC_SLI_REV4)
8455 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008456 else
8457 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008458 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008459 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8460 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8461 /*
8462 * Driver needs to re-reg VPI in order for f/w
8463 * to update the MAC address.
8464 */
8465 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008466 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008467 }
8468
James Smartecfd03c2010-02-12 14:41:27 -05008469 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8470 lpfc_issue_init_vpi(vport);
8471 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008472 lpfc_register_new_vport(phba, vport, ndlp);
8473 else
8474 lpfc_do_scr_ns_plogi(phba, vport);
8475 goto out;
8476fdisc_failed:
James Smartc84163d2015-05-21 13:55:22 -04008477 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8478 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008479 /* Cancel discovery timer */
8480 lpfc_can_disctmo(vport);
8481 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008482out:
8483 lpfc_els_free_iocb(phba, cmdiocb);
8484}
8485
James Smarte59058c2008-08-24 21:49:00 -04008486/**
James Smart3621a712009-04-06 18:47:14 -04008487 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008488 * @vport: pointer to a virtual N_Port data structure.
8489 * @ndlp: pointer to a node-list data structure.
8490 * @retry: number of retries to the command IOCB.
8491 *
8492 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8493 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8494 * routine to issue the IOCB, which makes sure only one outstanding fabric
8495 * IOCB will be sent off HBA at any given time.
8496 *
8497 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8498 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8499 * will be stored into the context1 field of the IOCB for the completion
8500 * callback function to the FDISC ELS command.
8501 *
8502 * Return code
8503 * 0 - Successfully issued fdisc iocb command
8504 * 1 - Failed to issue fdisc iocb command
8505 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008506static int
James Smart92d7f7b2007-06-17 19:56:38 -05008507lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8508 uint8_t retry)
8509{
8510 struct lpfc_hba *phba = vport->phba;
8511 IOCB_t *icmd;
8512 struct lpfc_iocbq *elsiocb;
8513 struct serv_parm *sp;
8514 uint8_t *pcmd;
8515 uint16_t cmdsize;
8516 int did = ndlp->nlp_DID;
8517 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008518
James Smart5ffc2662009-11-18 15:39:44 -05008519 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008520 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008521 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8522 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8523 ELS_CMD_FDISC);
8524 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008525 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008526 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8527 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008528 return 1;
8529 }
8530
8531 icmd = &elsiocb->iocb;
8532 icmd->un.elsreq64.myID = 0;
8533 icmd->un.elsreq64.fl = 1;
8534
James Smart73d91e52011-10-10 21:32:10 -04008535 /*
8536 * SLI3 ports require a different context type value than SLI4.
8537 * Catch SLI3 ports here and override the prep.
8538 */
8539 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008540 icmd->ulpCt_h = 1;
8541 icmd->ulpCt_l = 0;
8542 }
James Smart92d7f7b2007-06-17 19:56:38 -05008543
8544 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8545 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8546 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8547 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8548 sp = (struct serv_parm *) pcmd;
8549 /* Setup CSPs accordingly for Fabric */
8550 sp->cmn.e_d_tov = 0;
8551 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008552 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008553 sp->cls1.classValid = 0;
8554 sp->cls2.seqDelivery = 1;
8555 sp->cls3.seqDelivery = 1;
8556
8557 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8558 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8559 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8560 pcmd += sizeof(uint32_t); /* Port Name */
8561 memcpy(pcmd, &vport->fc_portname, 8);
8562 pcmd += sizeof(uint32_t); /* Node Name */
8563 pcmd += sizeof(uint32_t); /* Node Name */
8564 memcpy(pcmd, &vport->fc_nodename, 8);
8565
8566 lpfc_set_disctmo(vport);
8567
8568 phba->fc_stat.elsXmitFDISC++;
8569 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8570
James Smart858c9f62007-06-17 19:56:39 -05008571 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8572 "Issue FDISC: did:x%x",
8573 did, 0, 0);
8574
James Smart92d7f7b2007-06-17 19:56:38 -05008575 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8576 if (rc == IOCB_ERROR) {
8577 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008578 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008579 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8580 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008581 return 1;
8582 }
8583 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008584 return 0;
8585}
8586
James Smarte59058c2008-08-24 21:49:00 -04008587/**
James Smart3621a712009-04-06 18:47:14 -04008588 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008589 * @phba: pointer to lpfc hba data structure.
8590 * @cmdiocb: pointer to lpfc command iocb data structure.
8591 * @rspiocb: pointer to lpfc response iocb data structure.
8592 *
8593 * This routine is the completion callback function to the issuing of a LOGO
8594 * ELS command off a vport. It frees the command IOCB and then decrement the
8595 * reference count held on ndlp for this completion function, indicating that
8596 * the reference to the ndlp is no long needed. Note that the
8597 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8598 * callback function and an additional explicit ndlp reference decrementation
8599 * will trigger the actual release of the ndlp.
8600 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008601static void
8602lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8603 struct lpfc_iocbq *rspiocb)
8604{
8605 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008606 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008607 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008608 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008609
James Smart9589b0622011-04-16 11:03:17 -04008610 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008611 irsp = &rspiocb->iocb;
8612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8613 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8614 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008615
8616 lpfc_els_free_iocb(phba, cmdiocb);
8617 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008618
8619 /* Trigger the release of the ndlp after logo */
8620 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008621
8622 /* NPIV LOGO completes to NPort <nlp_DID> */
8623 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8624 "2928 NPIV LOGO completes to NPort x%x "
8625 "Data: x%x x%x x%x x%x\n",
8626 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8627 irsp->ulpTimeout, vport->num_disc_nodes);
8628
8629 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8630 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008631 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008632 vport->fc_flag &= ~FC_FABRIC;
8633 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008634 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008635 }
James Smart92d7f7b2007-06-17 19:56:38 -05008636}
8637
James Smarte59058c2008-08-24 21:49:00 -04008638/**
James Smart3621a712009-04-06 18:47:14 -04008639 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008640 * @vport: pointer to a virtual N_Port data structure.
8641 * @ndlp: pointer to a node-list data structure.
8642 *
8643 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8644 *
8645 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8646 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8647 * will be stored into the context1 field of the IOCB for the completion
8648 * callback function to the LOGO ELS command.
8649 *
8650 * Return codes
8651 * 0 - Successfully issued logo off the @vport
8652 * 1 - Failed to issue logo off the @vport
8653 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008654int
8655lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8656{
8657 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8658 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008659 struct lpfc_iocbq *elsiocb;
8660 uint8_t *pcmd;
8661 uint16_t cmdsize;
8662
8663 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8664 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8665 ELS_CMD_LOGO);
8666 if (!elsiocb)
8667 return 1;
8668
James Smart92d7f7b2007-06-17 19:56:38 -05008669 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8670 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8671 pcmd += sizeof(uint32_t);
8672
8673 /* Fill in LOGO payload */
8674 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8675 pcmd += sizeof(uint32_t);
8676 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8677
James Smart858c9f62007-06-17 19:56:39 -05008678 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8679 "Issue LOGO npiv did:x%x flg:x%x",
8680 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8681
James Smart92d7f7b2007-06-17 19:56:38 -05008682 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8683 spin_lock_irq(shost->host_lock);
8684 ndlp->nlp_flag |= NLP_LOGO_SND;
8685 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008686 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8687 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05008688 spin_lock_irq(shost->host_lock);
8689 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8690 spin_unlock_irq(shost->host_lock);
8691 lpfc_els_free_iocb(phba, elsiocb);
8692 return 1;
8693 }
8694 return 0;
8695}
8696
James Smarte59058c2008-08-24 21:49:00 -04008697/**
James Smart3621a712009-04-06 18:47:14 -04008698 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04008699 * @ptr: holder for the timer function associated data.
8700 *
8701 * This routine is invoked by the fabric iocb block timer after
8702 * timeout. It posts the fabric iocb block timeout event by setting the
8703 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8704 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8705 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8706 * posted event WORKER_FABRIC_BLOCK_TMO.
8707 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008708void
8709lpfc_fabric_block_timeout(unsigned long ptr)
8710{
8711 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8712 unsigned long iflags;
8713 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04008714
James Smart92d7f7b2007-06-17 19:56:38 -05008715 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8716 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8717 if (!tmo_posted)
8718 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8719 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8720
James Smart5e9d9b82008-06-14 22:52:53 -04008721 if (!tmo_posted)
8722 lpfc_worker_wake_up(phba);
8723 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008724}
8725
James Smarte59058c2008-08-24 21:49:00 -04008726/**
James Smart3621a712009-04-06 18:47:14 -04008727 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04008728 * @phba: pointer to lpfc hba data structure.
8729 *
8730 * This routine issues one fabric iocb from the driver internal list to
8731 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8732 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8733 * remove one pending fabric iocb from the driver internal list and invokes
8734 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8735 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008736static void
8737lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8738{
8739 struct lpfc_iocbq *iocb;
8740 unsigned long iflags;
8741 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05008742 IOCB_t *cmd;
8743
8744repeat:
8745 iocb = NULL;
8746 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05008747 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05008748 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8749 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8750 list);
8751 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05008752 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05008753 atomic_inc(&phba->fabric_iocb_count);
8754 }
8755 spin_unlock_irqrestore(&phba->hbalock, iflags);
8756 if (iocb) {
8757 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8758 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8759 iocb->iocb_flag |= LPFC_IO_FABRIC;
8760
James Smart858c9f62007-06-17 19:56:39 -05008761 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8762 "Fabric sched1: ste:x%x",
8763 iocb->vport->port_state, 0, 0);
8764
James Smart3772a992009-05-22 14:50:54 -04008765 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008766
8767 if (ret == IOCB_ERROR) {
8768 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8769 iocb->fabric_iocb_cmpl = NULL;
8770 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8771 cmd = &iocb->iocb;
8772 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8773 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8774 iocb->iocb_cmpl(phba, iocb, iocb);
8775
8776 atomic_dec(&phba->fabric_iocb_count);
8777 goto repeat;
8778 }
8779 }
8780
8781 return;
8782}
8783
James Smarte59058c2008-08-24 21:49:00 -04008784/**
James Smart3621a712009-04-06 18:47:14 -04008785 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008786 * @phba: pointer to lpfc hba data structure.
8787 *
8788 * This routine unblocks the issuing fabric iocb command. The function
8789 * will clear the fabric iocb block bit and then invoke the routine
8790 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8791 * from the driver internal fabric iocb list.
8792 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008793void
8794lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8795{
8796 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8797
8798 lpfc_resume_fabric_iocbs(phba);
8799 return;
8800}
8801
James Smarte59058c2008-08-24 21:49:00 -04008802/**
James Smart3621a712009-04-06 18:47:14 -04008803 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008804 * @phba: pointer to lpfc hba data structure.
8805 *
8806 * This routine blocks the issuing fabric iocb for a specified amount of
8807 * time (currently 100 ms). This is done by set the fabric iocb block bit
8808 * and set up a timeout timer for 100ms. When the block bit is set, no more
8809 * fabric iocb will be issued out of the HBA.
8810 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008811static void
8812lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
8813{
8814 int blocked;
8815
8816 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05008817 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05008818 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04008819 mod_timer(&phba->fabric_block_timer,
8820 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05008821
8822 return;
8823}
8824
James Smarte59058c2008-08-24 21:49:00 -04008825/**
James Smart3621a712009-04-06 18:47:14 -04008826 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04008827 * @phba: pointer to lpfc hba data structure.
8828 * @cmdiocb: pointer to lpfc command iocb data structure.
8829 * @rspiocb: pointer to lpfc response iocb data structure.
8830 *
8831 * This routine is the callback function that is put to the fabric iocb's
8832 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8833 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8834 * function first restores and invokes the original iocb's callback function
8835 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8836 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8837 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008838static void
8839lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8840 struct lpfc_iocbq *rspiocb)
8841{
8842 struct ls_rjt stat;
8843
8844 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8845 BUG();
8846
8847 switch (rspiocb->iocb.ulpStatus) {
8848 case IOSTAT_NPORT_RJT:
8849 case IOSTAT_FABRIC_RJT:
8850 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
8851 lpfc_block_fabric_iocbs(phba);
8852 }
8853 break;
8854
8855 case IOSTAT_NPORT_BSY:
8856 case IOSTAT_FABRIC_BSY:
8857 lpfc_block_fabric_iocbs(phba);
8858 break;
8859
8860 case IOSTAT_LS_RJT:
8861 stat.un.lsRjtError =
8862 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
8863 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
8864 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
8865 lpfc_block_fabric_iocbs(phba);
8866 break;
8867 }
8868
8869 if (atomic_read(&phba->fabric_iocb_count) == 0)
8870 BUG();
8871
8872 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
8873 cmdiocb->fabric_iocb_cmpl = NULL;
8874 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
8875 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
8876
8877 atomic_dec(&phba->fabric_iocb_count);
8878 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05008879 /* Post any pending iocbs to HBA */
8880 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05008881 }
8882}
8883
James Smarte59058c2008-08-24 21:49:00 -04008884/**
James Smart3621a712009-04-06 18:47:14 -04008885 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008886 * @phba: pointer to lpfc hba data structure.
8887 * @iocb: pointer to lpfc command iocb data structure.
8888 *
8889 * This routine is used as the top-level API for issuing a fabric iocb command
8890 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8891 * function makes sure that only one fabric bound iocb will be outstanding at
8892 * any given time. As such, this function will first check to see whether there
8893 * is already an outstanding fabric iocb on the wire. If so, it will put the
8894 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8895 * issued later. Otherwise, it will issue the iocb on the wire and update the
8896 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8897 *
8898 * Note, this implementation has a potential sending out fabric IOCBs out of
8899 * order. The problem is caused by the construction of the "ready" boolen does
8900 * not include the condition that the internal fabric IOCB list is empty. As
8901 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8902 * ahead of the fabric IOCBs in the internal list.
8903 *
8904 * Return code
8905 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8906 * IOCB_ERROR - failed to issue fabric iocb
8907 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008908static int
James Smart92d7f7b2007-06-17 19:56:38 -05008909lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
8910{
8911 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05008912 int ready;
8913 int ret;
8914
8915 if (atomic_read(&phba->fabric_iocb_count) > 1)
8916 BUG();
8917
8918 spin_lock_irqsave(&phba->hbalock, iflags);
8919 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
8920 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8921
James Smart7f5f3d02008-02-08 18:50:14 -05008922 if (ready)
8923 /* Increment fabric iocb count to hold the position */
8924 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05008925 spin_unlock_irqrestore(&phba->hbalock, iflags);
8926 if (ready) {
8927 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8928 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8929 iocb->iocb_flag |= LPFC_IO_FABRIC;
8930
James Smart858c9f62007-06-17 19:56:39 -05008931 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8932 "Fabric sched2: ste:x%x",
8933 iocb->vport->port_state, 0, 0);
8934
James Smart3772a992009-05-22 14:50:54 -04008935 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008936
8937 if (ret == IOCB_ERROR) {
8938 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8939 iocb->fabric_iocb_cmpl = NULL;
8940 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8941 atomic_dec(&phba->fabric_iocb_count);
8942 }
8943 } else {
8944 spin_lock_irqsave(&phba->hbalock, iflags);
8945 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
8946 spin_unlock_irqrestore(&phba->hbalock, iflags);
8947 ret = IOCB_SUCCESS;
8948 }
8949 return ret;
8950}
8951
James Smarte59058c2008-08-24 21:49:00 -04008952/**
James Smart3621a712009-04-06 18:47:14 -04008953 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008954 * @vport: pointer to a virtual N_Port data structure.
8955 *
8956 * This routine aborts all the IOCBs associated with a @vport from the
8957 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8958 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8959 * list, removes each IOCB associated with the @vport off the list, set the
8960 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8961 * associated with the IOCB.
8962 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008963static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05008964{
8965 LIST_HEAD(completions);
8966 struct lpfc_hba *phba = vport->phba;
8967 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05008968
8969 spin_lock_irq(&phba->hbalock);
8970 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8971 list) {
8972
8973 if (piocb->vport != vport)
8974 continue;
8975
8976 list_move_tail(&piocb->list, &completions);
8977 }
8978 spin_unlock_irq(&phba->hbalock);
8979
James Smarta257bf92009-04-06 18:48:10 -04008980 /* Cancel all the IOCBs from the completions list */
8981 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8982 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008983}
8984
James Smarte59058c2008-08-24 21:49:00 -04008985/**
James Smart3621a712009-04-06 18:47:14 -04008986 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008987 * @ndlp: pointer to a node-list data structure.
8988 *
8989 * This routine aborts all the IOCBs associated with an @ndlp from the
8990 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8991 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8992 * list, removes each IOCB associated with the @ndlp off the list, set the
8993 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8994 * associated with the IOCB.
8995 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008996void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
8997{
8998 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04008999 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05009000 struct lpfc_iocbq *tmp_iocb, *piocb;
9001 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05009002
9003 spin_lock_irq(&phba->hbalock);
9004 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
9005 list) {
9006 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
9007
9008 list_move_tail(&piocb->list, &completions);
9009 }
9010 }
9011 spin_unlock_irq(&phba->hbalock);
9012
James Smarta257bf92009-04-06 18:48:10 -04009013 /* Cancel all the IOCBs from the completions list */
9014 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9015 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009016}
9017
James Smarte59058c2008-08-24 21:49:00 -04009018/**
James Smart3621a712009-04-06 18:47:14 -04009019 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04009020 * @phba: pointer to lpfc hba data structure.
9021 *
9022 * This routine aborts all the IOCBs currently on the driver internal
9023 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9024 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9025 * list, removes IOCBs off the list, set the status feild to
9026 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9027 * the IOCB.
9028 **/
James Smart92d7f7b2007-06-17 19:56:38 -05009029void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
9030{
9031 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05009032
9033 spin_lock_irq(&phba->hbalock);
9034 list_splice_init(&phba->fabric_iocb_list, &completions);
9035 spin_unlock_irq(&phba->hbalock);
9036
James Smarta257bf92009-04-06 18:48:10 -04009037 /* Cancel all the IOCBs from the completions list */
9038 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
9039 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05009040}
James Smart6fb120a2009-05-22 14:52:59 -04009041
9042/**
James Smart1151e3e2011-02-16 12:39:35 -05009043 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9044 * @vport: pointer to lpfc vport data structure.
9045 *
9046 * This routine is invoked by the vport cleanup for deletions and the cleanup
9047 * for an ndlp on removal.
9048 **/
9049void
9050lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
9051{
9052 struct lpfc_hba *phba = vport->phba;
9053 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9054 unsigned long iflag = 0;
9055
9056 spin_lock_irqsave(&phba->hbalock, iflag);
9057 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
9058 list_for_each_entry_safe(sglq_entry, sglq_next,
9059 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9060 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
9061 sglq_entry->ndlp = NULL;
9062 }
9063 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
9064 spin_unlock_irqrestore(&phba->hbalock, iflag);
9065 return;
9066}
9067
9068/**
James Smart6fb120a2009-05-22 14:52:59 -04009069 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9070 * @phba: pointer to lpfc hba data structure.
9071 * @axri: pointer to the els xri abort wcqe structure.
9072 *
9073 * This routine is invoked by the worker thread to process a SLI4 slow-path
9074 * ELS aborted xri.
9075 **/
9076void
9077lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
9078 struct sli4_wcqe_xri_aborted *axri)
9079{
9080 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05009081 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04009082 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05009083
James Smart6fb120a2009-05-22 14:52:59 -04009084 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
9085 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05009086 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04009087 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04009088
James Smart0f65ff62010-02-26 14:14:23 -05009089 spin_lock_irqsave(&phba->hbalock, iflag);
9090 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009091 list_for_each_entry_safe(sglq_entry, sglq_next,
9092 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
9093 if (sglq_entry->sli4_xritag == xri) {
9094 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05009095 ndlp = sglq_entry->ndlp;
9096 sglq_entry->ndlp = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -04009097 spin_lock(&pring->ring_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009098 list_add_tail(&sglq_entry->list,
9099 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05009100 sglq_entry->state = SGL_FREED;
James Smartdafe8ce2014-09-03 12:56:40 -04009101 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009102 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04009103 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04009104 lpfc_set_rrq_active(phba, ndlp,
9105 sglq_entry->sli4_lxritag,
9106 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04009107
9108 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05009109 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04009110 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04009111 return;
9112 }
9113 }
James Smart0f65ff62010-02-26 14:14:23 -05009114 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04009115 lxri = lpfc_sli4_xri_inrange(phba, xri);
9116 if (lxri == NO_XRI) {
9117 spin_unlock_irqrestore(&phba->hbalock, iflag);
9118 return;
9119 }
James Smartdafe8ce2014-09-03 12:56:40 -04009120 spin_lock(&pring->ring_lock);
James Smart7851fe22011-07-22 18:36:52 -04009121 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05009122 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smartdafe8ce2014-09-03 12:56:40 -04009123 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009124 spin_unlock_irqrestore(&phba->hbalock, iflag);
9125 return;
9126 }
9127 sglq_entry->state = SGL_XRI_ABORTED;
James Smartdafe8ce2014-09-03 12:56:40 -04009128 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05009129 spin_unlock_irqrestore(&phba->hbalock, iflag);
9130 return;
James Smart6fb120a2009-05-22 14:52:59 -04009131}
James Smart086a3452012-08-14 14:25:21 -04009132
9133/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9134 * @vport: pointer to virtual port object.
9135 * @ndlp: nodelist pointer for the impacted node.
9136 *
9137 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9138 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9139 * the driver is required to send a LOGO to the remote node before it
9140 * attempts to recover its login to the remote node.
9141 */
9142void
9143lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
9144 struct lpfc_nodelist *ndlp)
9145{
9146 struct Scsi_Host *shost;
9147 struct lpfc_hba *phba;
9148 unsigned long flags = 0;
9149
9150 shost = lpfc_shost_from_vport(vport);
9151 phba = vport->phba;
9152 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
9153 lpfc_printf_log(phba, KERN_INFO,
9154 LOG_SLI, "3093 No rport recovery needed. "
9155 "rport in state 0x%x\n", ndlp->nlp_state);
9156 return;
9157 }
9158 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
9159 "3094 Start rport recovery on shost id 0x%x "
9160 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9161 "flags 0x%x\n",
9162 shost->host_no, ndlp->nlp_DID,
9163 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
9164 ndlp->nlp_flag);
9165 /*
9166 * The rport is not responding. Remove the FCP-2 flag to prevent
9167 * an ADISC in the follow-up recovery code.
9168 */
9169 spin_lock_irqsave(shost->host_lock, flags);
9170 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
9171 spin_unlock_irqrestore(shost->host_lock, flags);
9172 lpfc_issue_els_logo(vport, ndlp, 0);
9173 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
9174}
9175