blob: f6dd15b22383cf86e4236275747ccb49348520fa [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 Smartf25e8e72015-04-07 15:07:28 -04004 * Copyright (C) 2004-2015 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 Wellnitzc9f8735b2006-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 Wellnitzc9f8735b2006-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);
691 memcpy(&vport->fabric_portname, &sp->portName,
692 sizeof(struct lpfc_name));
693 memcpy(&vport->fabric_nodename, &sp->nodeName,
694 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500695 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
696
James Smart92d7f7b2007-06-17 19:56:38 -0500697 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
698 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400699 lpfc_printf_vlog(vport, KERN_WARNING,
700 LOG_ELS | LOG_VPORT,
701 "1816 FLOGI NPIV supported, "
702 "response data 0x%x\n",
703 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500704 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500705 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500706 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500707 } else {
708 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400709 to call reg_vnpid atleast for the physcial host */
710 lpfc_printf_vlog(vport, KERN_WARNING,
711 LOG_ELS | LOG_VPORT,
712 "1817 Fabric does not support NPIV "
713 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500714 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500715 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500716 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500717 }
718 }
719
James Smartae05ebe2013-03-01 16:35:38 -0500720 /*
721 * For FC we need to do some special processing because of the SLI
722 * Port's default settings of the Common Service Parameters.
723 */
James Smartd6de08c2015-12-16 18:11:53 -0500724 if ((phba->sli_rev == LPFC_SLI_REV4) &&
725 (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC)) {
James Smartae05ebe2013-03-01 16:35:38 -0500726 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
James Smartd6de08c2015-12-16 18:11:53 -0500727 if (fabric_param_changed)
James Smartae05ebe2013-03-01 16:35:38 -0500728 lpfc_unregister_fcf_prep(phba);
729
730 /* This should just update the VFI CSPs*/
731 if (vport->fc_flag & FC_VFI_REGISTERED)
732 lpfc_issue_reg_vfi(vport);
733 }
734
James Smart92494142011-02-16 12:39:44 -0500735 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500736 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
737
738 /* If our NportID changed, we need to ensure all
739 * remaining NPORTs get unreg_login'ed.
740 */
741 list_for_each_entry_safe(np, next_np,
742 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400743 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500744 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500745 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
746 !(np->nlp_flag & NLP_NPR_ADISC))
747 continue;
748 spin_lock_irq(shost->host_lock);
749 np->nlp_flag &= ~NLP_NPR_ADISC;
750 spin_unlock_irq(shost->host_lock);
751 lpfc_unreg_rpi(vport, np);
752 }
James Smart78730cf2010-04-06 15:06:30 -0400753 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400754
James Smart5248a742011-07-22 18:37:06 -0400755 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400756 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500757 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500758 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500759 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
760 spin_unlock_irq(shost->host_lock);
761 }
James Smart27aa1b72012-05-09 21:18:49 -0400762
763 /*
764 * For SLI3 and SLI4, the VPI needs to be reregistered in
765 * response to this fabric parameter change event.
766 */
767 spin_lock_irq(shost->host_lock);
768 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
769 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400770 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
771 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
772 /*
773 * Driver needs to re-reg VPI in order for f/w
774 * to update the MAC address.
775 */
James Smart9589b0622011-04-16 11:03:17 -0400776 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400777 lpfc_register_new_vport(phba, vport, ndlp);
778 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500779 }
780
James Smart6fb120a2009-05-22 14:52:59 -0400781 if (phba->sli_rev < LPFC_SLI_REV4) {
782 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
783 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
784 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
785 lpfc_register_new_vport(phba, vport, ndlp);
786 else
787 lpfc_issue_fabric_reglogin(vport);
788 } else {
789 ndlp->nlp_type |= NLP_FABRIC;
790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500791 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
792 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400793 lpfc_start_fdiscs(phba);
794 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500795 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500796 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500797 else {
798 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
799 "3135 Need register VFI: (x%x/%x)\n",
800 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400801 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500802 }
James Smart92d7f7b2007-06-17 19:56:38 -0500803 }
dea31012005-04-17 16:05:31 -0500804 return 0;
dea31012005-04-17 16:05:31 -0500805}
James Smart1b511972011-12-13 13:23:09 -0500806
James Smarte59058c2008-08-24 21:49:00 -0400807/**
James Smart3621a712009-04-06 18:47:14 -0400808 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400809 * @vport: pointer to a host virtual N_Port data structure.
810 * @ndlp: pointer to a node-list data structure.
811 * @sp: pointer to service parameter data structure.
812 *
813 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
814 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
815 * in a point-to-point topology. First, the @vport's N_Port Name is compared
816 * with the received N_Port Name: if the @vport's N_Port Name is greater than
817 * the received N_Port Name lexicographically, this node shall assign local
818 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
819 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
820 * this node shall just wait for the remote node to issue PLOGI and assign
821 * N_Port IDs.
822 *
823 * Return code
824 * 0 - Success
825 * -ENXIO - Fail
826 **/
dea31012005-04-17 16:05:31 -0500827static int
James Smart2e0fef82007-06-17 19:56:36 -0500828lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
829 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500830{
James Smart2e0fef82007-06-17 19:56:36 -0500831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
832 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500833 LPFC_MBOXQ_t *mbox;
834 int rc;
835
James Smart2e0fef82007-06-17 19:56:36 -0500836 spin_lock_irq(shost->host_lock);
837 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
James Smartd6de08c2015-12-16 18:11:53 -0500838 vport->fc_flag |= FC_PT2PT;
James Smart2e0fef82007-06-17 19:56:36 -0500839 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500840
James Smartd6de08c2015-12-16 18:11:53 -0500841 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
842 if ((phba->sli_rev == LPFC_SLI_REV4) && phba->fc_topology_changed) {
843 lpfc_unregister_fcf_prep(phba);
844
845 spin_lock_irq(shost->host_lock);
846 vport->fc_flag &= ~FC_VFI_REGISTERED;
847 spin_unlock_irq(shost->host_lock);
848 phba->fc_topology_changed = 0;
849 }
850
James Smart2e0fef82007-06-17 19:56:36 -0500851 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500852 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400853
dea31012005-04-17 16:05:31 -0500854 if (rc >= 0) {
855 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500856 spin_lock_irq(shost->host_lock);
857 vport->fc_flag |= FC_PT2PT_PLOGI;
858 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500859
860 /*
James Smartd6de08c2015-12-16 18:11:53 -0500861 * N_Port ID cannot be 0, set our Id to LocalID
862 * the other side will be RemoteID.
dea31012005-04-17 16:05:31 -0500863 */
864
865 /* not equal */
866 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500867 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500868
James Smarte47c9092008-02-08 18:49:26 -0500869 /* Decrement ndlp reference count indicating that ndlp can be
870 * safely released when other references to it are done.
871 */
James Smart329f9bc2007-04-25 09:53:01 -0400872 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500873
James Smart2e0fef82007-06-17 19:56:36 -0500874 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500875 if (!ndlp) {
876 /*
877 * Cannot find existing Fabric ndlp, so allocate a
878 * new one
879 */
880 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
881 if (!ndlp)
882 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500883 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500884 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
885 ndlp = lpfc_enable_node(vport, ndlp,
886 NLP_STE_UNUSED_NODE);
887 if(!ndlp)
888 goto fail;
dea31012005-04-17 16:05:31 -0500889 }
890
891 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500892 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500893 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500894 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500895 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500896 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
897 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500898 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500899 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500900 } else
901 /* This side will wait for the PLOGI, decrement ndlp reference
902 * count indicating that ndlp can be released when other
903 * references to it are done.
904 */
James Smart329f9bc2007-04-25 09:53:01 -0400905 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500906
James Smart09372822008-01-11 01:52:54 -0500907 /* If we are pt2pt with another NPort, force NPIV off! */
908 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
909
James Smartd6de08c2015-12-16 18:11:53 -0500910 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
911 if (!mbox)
912 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400913
James Smartd6de08c2015-12-16 18:11:53 -0500914 lpfc_config_link(phba, mbox);
915
916 mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
917 mbox->vport = vport;
918 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
919 if (rc == MBX_NOT_FINISHED) {
920 mempool_free(mbox, phba->mbox_mem_pool);
921 goto fail;
James Smarte74c03c2013-04-17 20:15:19 -0400922 }
dea31012005-04-17 16:05:31 -0500923
dea31012005-04-17 16:05:31 -0500924 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500925fail:
dea31012005-04-17 16:05:31 -0500926 return -ENXIO;
927}
928
James Smarte59058c2008-08-24 21:49:00 -0400929/**
James Smart3621a712009-04-06 18:47:14 -0400930 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400931 * @phba: pointer to lpfc hba data structure.
932 * @cmdiocb: pointer to lpfc command iocb data structure.
933 * @rspiocb: pointer to lpfc response iocb data structure.
934 *
935 * This routine is the top-level completion callback function for issuing
936 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
937 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
938 * retry has been made (either immediately or delayed with lpfc_els_retry()
939 * returning 1), the command IOCB will be released and function returned.
940 * If the retry attempt has been given up (possibly reach the maximum
941 * number of retries), one additional decrement of ndlp reference shall be
942 * invoked before going out after releasing the command IOCB. This will
943 * actually release the remote node (Note, lpfc_els_free_iocb() will also
944 * invoke one decrement of ndlp reference count). If no error reported in
945 * the IOCB status, the command Port ID field is used to determine whether
946 * this is a point-to-point topology or a fabric topology: if the Port ID
947 * field is assigned, it is a fabric topology; otherwise, it is a
948 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
949 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
950 * specific topology completion conditions.
951 **/
dea31012005-04-17 16:05:31 -0500952static void
James Smart329f9bc2007-04-25 09:53:01 -0400953lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
954 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500955{
James Smart2e0fef82007-06-17 19:56:36 -0500956 struct lpfc_vport *vport = cmdiocb->vport;
957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500958 IOCB_t *irsp = &rspiocb->iocb;
959 struct lpfc_nodelist *ndlp = cmdiocb->context1;
960 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
961 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500962 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500963 int rc;
964
965 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500966 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500967 /* One additional decrement on node reference count to
968 * trigger the release of the node
969 */
James Smart329f9bc2007-04-25 09:53:01 -0400970 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500971 goto out;
972 }
973
James Smart858c9f62007-06-17 19:56:39 -0500974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
975 "FLOGI cmpl: status:x%x/x%x state:x%x",
976 irsp->ulpStatus, irsp->un.ulpWord[4],
977 vport->port_state);
978
dea31012005-04-17 16:05:31 -0500979 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500980 /*
James Smarta93ff372010-10-22 11:06:08 -0400981 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500982 * due to new FCF discovery
983 */
984 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500985 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
986 if (phba->link_state < LPFC_LINK_UP)
987 goto stop_rr_fcf_flogi;
988 if ((phba->fcoe_cvl_eventtag_attn ==
989 phba->fcoe_cvl_eventtag) &&
990 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400991 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
992 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -0500993 goto stop_rr_fcf_flogi;
994 else
995 phba->fcoe_cvl_eventtag_attn =
996 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500997 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400998 "2611 FLOGI failed on FCF (x%x), "
999 "status:x%x/x%x, tmo:x%x, perform "
1000 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -04001001 phba->fcf.current_rec.fcf_indx,
1002 irsp->ulpStatus, irsp->un.ulpWord[4],
1003 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -04001004 lpfc_sli4_set_fcf_flogi_fail(phba,
1005 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001006 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -04001007 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
1008 if (rc)
1009 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001010 }
1011
James Smart80c17842012-03-01 22:35:45 -05001012stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -04001013 /* FLOGI failure */
1014 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart8fe5c162015-08-31 16:48:19 -04001015 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1016 "Data x%x x%x\n",
James Smart38b92ef2010-08-04 16:11:39 -04001017 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart8fe5c162015-08-31 16:48:19 -04001018 irsp->ulpTimeout, phba->hba_flag,
1019 phba->fcf.fcf_flag);
James Smart38b92ef2010-08-04 16:11:39 -04001020
dea31012005-04-17 16:05:31 -05001021 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001022 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001023 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05001024
James Smart76a95d72010-11-20 23:11:48 -05001025 /* FLOGI failure */
1026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1027 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1028 irsp->ulpStatus, irsp->un.ulpWord[4],
1029 irsp->ulpTimeout);
1030
dea31012005-04-17 16:05:31 -05001031 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001032 spin_lock_irq(shost->host_lock);
1033 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1034 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001035
James Smart329f9bc2007-04-25 09:53:01 -04001036 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001037 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1038 * alpa map would take too long otherwise.
1039 */
James Smart1b511972011-12-13 13:23:09 -05001040 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001041 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001042 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1043 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
James Smarte74c03c2013-04-17 20:15:19 -04001044 (vport->fc_prevDID != vport->fc_myDID) ||
1045 phba->fc_topology_changed)) {
1046 if (vport->fc_flag & FC_VFI_REGISTERED) {
1047 if (phba->fc_topology_changed) {
1048 lpfc_unregister_fcf_prep(phba);
1049 spin_lock_irq(shost->host_lock);
1050 vport->fc_flag &= ~FC_VFI_REGISTERED;
1051 spin_unlock_irq(shost->host_lock);
1052 phba->fc_topology_changed = 0;
1053 } else {
1054 lpfc_sli4_unreg_all_rpis(vport);
1055 }
1056 }
James Smartff78d8f2011-12-13 13:21:35 -05001057 lpfc_issue_reg_vfi(vport);
1058 lpfc_nlp_put(ndlp);
1059 goto out;
dea31012005-04-17 16:05:31 -05001060 }
dea31012005-04-17 16:05:31 -05001061 goto flogifail;
1062 }
James Smart695a8142010-01-26 23:08:03 -05001063 spin_lock_irq(shost->host_lock);
1064 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001065 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001066 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001067
1068 /*
1069 * The FLogI succeeded. Sync the data for the CPU before
1070 * accessing it.
1071 */
1072 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04001073 if (!prsp)
1074 goto out;
dea31012005-04-17 16:05:31 -05001075 sp = prsp->virt + sizeof(uint32_t);
1076
1077 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smart88f43a02013-04-17 20:19:44 -04001079 "0101 FLOGI completes successfully, I/O tag:x%x, "
1080 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb->iotag,
James Smarte8b62012007-08-02 11:10:09 -04001081 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
James Smarte74c03c2013-04-17 20:15:19 -04001082 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution,
1083 vport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001084
James Smart2e0fef82007-06-17 19:56:36 -05001085 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001086 /*
1087 * If Common Service Parameters indicate Nport
1088 * we are point to point, if Fport we are Fabric.
1089 */
1090 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001091 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001092 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001093 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001094 else {
1095 lpfc_printf_vlog(vport, KERN_ERR,
1096 LOG_FIP | LOG_ELS,
1097 "2831 FLOGI response with cleared Fabric "
1098 "bit fcf_index 0x%x "
1099 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1100 "Fabric Name "
1101 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1102 phba->fcf.current_rec.fcf_indx,
1103 phba->fcf.current_rec.switch_name[0],
1104 phba->fcf.current_rec.switch_name[1],
1105 phba->fcf.current_rec.switch_name[2],
1106 phba->fcf.current_rec.switch_name[3],
1107 phba->fcf.current_rec.switch_name[4],
1108 phba->fcf.current_rec.switch_name[5],
1109 phba->fcf.current_rec.switch_name[6],
1110 phba->fcf.current_rec.switch_name[7],
1111 phba->fcf.current_rec.fabric_name[0],
1112 phba->fcf.current_rec.fabric_name[1],
1113 phba->fcf.current_rec.fabric_name[2],
1114 phba->fcf.current_rec.fabric_name[3],
1115 phba->fcf.current_rec.fabric_name[4],
1116 phba->fcf.current_rec.fabric_name[5],
1117 phba->fcf.current_rec.fabric_name[6],
1118 phba->fcf.current_rec.fabric_name[7]);
1119 lpfc_nlp_put(ndlp);
1120 spin_lock_irq(&phba->hbalock);
1121 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001122 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001123 spin_unlock_irq(&phba->hbalock);
1124 goto out;
1125 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001126 if (!rc) {
1127 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001128 if (phba->hba_flag & HBA_FIP_SUPPORT)
1129 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1130 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001131 "2769 FLOGI to FCF (x%x) "
1132 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001133 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001134 spin_lock_irq(&phba->hbalock);
1135 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001136 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001137 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001138 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001139 }
dea31012005-04-17 16:05:31 -05001140 }
1141
1142flogifail:
James Smart8fe5c162015-08-31 16:48:19 -04001143 spin_lock_irq(&phba->hbalock);
1144 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
1145 spin_unlock_irq(&phba->hbalock);
James Smartd6de08c2015-12-16 18:11:53 -05001146
James Smart329f9bc2007-04-25 09:53:01 -04001147 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001148
James Smart858c9f62007-06-17 19:56:39 -05001149 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001150 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001151 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001152
1153 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001154 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001155 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001156 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1157 IOERR_SLI_ABORTED) &&
1158 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1159 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001160 (phba->link_state != LPFC_CLEAR_LA)) {
1161 /* If FLOGI failed enable link interrupt. */
1162 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001163 }
dea31012005-04-17 16:05:31 -05001164out:
1165 lpfc_els_free_iocb(phba, cmdiocb);
1166}
1167
James Smarte59058c2008-08-24 21:49:00 -04001168/**
James Smart3621a712009-04-06 18:47:14 -04001169 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001170 * @vport: pointer to a host virtual N_Port data structure.
1171 * @ndlp: pointer to a node-list data structure.
1172 * @retry: number of retries to the command IOCB.
1173 *
1174 * This routine issues a Fabric Login (FLOGI) Request ELS command
1175 * for a @vport. The initiator service parameters are put into the payload
1176 * of the FLOGI Request IOCB and the top-level callback function pointer
1177 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1178 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1179 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1180 *
1181 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1182 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1183 * will be stored into the context1 field of the IOCB for the completion
1184 * callback function to the FLOGI ELS command.
1185 *
1186 * Return code
1187 * 0 - successfully issued flogi iocb for @vport
1188 * 1 - failed to issue flogi iocb for @vport
1189 **/
dea31012005-04-17 16:05:31 -05001190static int
James Smart2e0fef82007-06-17 19:56:36 -05001191lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001192 uint8_t retry)
1193{
James Smart2e0fef82007-06-17 19:56:36 -05001194 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001195 struct serv_parm *sp;
1196 IOCB_t *icmd;
1197 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001198 uint8_t *pcmd;
1199 uint16_t cmdsize;
1200 uint32_t tmo;
1201 int rc;
1202
James Smart92d7f7b2007-06-17 19:56:38 -05001203 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001204 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1205 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001206
James Smart488d1462006-03-07 15:02:37 -05001207 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001208 return 1;
dea31012005-04-17 16:05:31 -05001209
1210 icmd = &elsiocb->iocb;
1211 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1212
1213 /* For FLOGI request, remainder of payload is service parameters */
1214 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001215 pcmd += sizeof(uint32_t);
1216 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001217 sp = (struct serv_parm *) pcmd;
1218
1219 /* Setup CSPs accordingly for Fabric */
1220 sp->cmn.e_d_tov = 0;
1221 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001222 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001223 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001224 if (sp->cmn.fcphLow < FC_PH3)
1225 sp->cmn.fcphLow = FC_PH3;
1226 if (sp->cmn.fcphHigh < FC_PH3)
1227 sp->cmn.fcphHigh = FC_PH3;
1228
James Smartc31098c2011-04-16 11:03:33 -04001229 if (phba->sli_rev == LPFC_SLI_REV4) {
1230 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1231 LPFC_SLI_INTF_IF_TYPE_0) {
1232 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1233 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1234 /* FLOGI needs to be 3 for WQE FCFI */
1235 /* Set the fcfi to the fcfi we registered with */
1236 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1237 }
James Smart0f378872012-10-31 14:45:01 -04001238 /* Can't do SLI4 class2 without support sequence coalescing */
1239 sp->cls2.classValid = 0;
1240 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001241 } else {
James Smart0f378872012-10-31 14:45:01 -04001242 /* Historical, setting sequential-delivery bit for SLI3 */
1243 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1244 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001245 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1246 sp->cmn.request_multiple_Nport = 1;
1247 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1248 icmd->ulpCt_h = 1;
1249 icmd->ulpCt_l = 0;
1250 } else
1251 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001252 }
1253
James Smart76a95d72010-11-20 23:11:48 -05001254 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001255 icmd->un.elsreq64.myID = 0;
1256 icmd->un.elsreq64.fl = 1;
1257 }
1258
dea31012005-04-17 16:05:31 -05001259 tmo = phba->fc_ratov;
1260 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001261 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001262 phba->fc_ratov = tmo;
1263
1264 phba->fc_stat.elsXmitFLOGI++;
1265 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001266
1267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1268 "Issue FLOGI: opt:x%x",
1269 phba->sli3_options, 0, 0);
1270
James Smart92d7f7b2007-06-17 19:56:38 -05001271 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001272 if (rc == IOCB_ERROR) {
1273 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001274 return 1;
dea31012005-04-17 16:05:31 -05001275 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001276 return 0;
dea31012005-04-17 16:05:31 -05001277}
1278
James Smarte59058c2008-08-24 21:49:00 -04001279/**
James Smart3621a712009-04-06 18:47:14 -04001280 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001281 * @phba: pointer to lpfc hba data structure.
1282 *
1283 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1284 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1285 * list and issues an abort IOCB commond on each outstanding IOCB that
1286 * contains a active Fabric_DID ndlp. Note that this function is to issue
1287 * the abort IOCB command on all the outstanding IOCBs, thus when this
1288 * function returns, it does not guarantee all the IOCBs are actually aborted.
1289 *
1290 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001291 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001292 **/
dea31012005-04-17 16:05:31 -05001293int
James Smart2e0fef82007-06-17 19:56:36 -05001294lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001295{
1296 struct lpfc_sli_ring *pring;
1297 struct lpfc_iocbq *iocb, *next_iocb;
1298 struct lpfc_nodelist *ndlp;
1299 IOCB_t *icmd;
1300
1301 /* Abort outstanding I/O on NPort <nlp_DID> */
1302 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001303 "0201 Abort outstanding I/O on NPort x%x\n",
1304 Fabric_DID);
dea31012005-04-17 16:05:31 -05001305
1306 pring = &phba->sli.ring[LPFC_ELS_RING];
1307
1308 /*
1309 * Check the txcmplq for an iocb that matches the nport the driver is
1310 * searching for.
1311 */
James Smart2e0fef82007-06-17 19:56:36 -05001312 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001313 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1314 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001315 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001316 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001317 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1318 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001319 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001320 }
1321 }
James Smart2e0fef82007-06-17 19:56:36 -05001322 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001323
1324 return 0;
1325}
1326
James Smarte59058c2008-08-24 21:49:00 -04001327/**
James Smart3621a712009-04-06 18:47:14 -04001328 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001329 * @vport: pointer to a host virtual N_Port data structure.
1330 *
1331 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1332 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1333 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1334 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1335 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1336 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1337 * @vport.
1338 *
1339 * Return code
1340 * 0 - failed to issue initial flogi for @vport
1341 * 1 - successfully issued initial flogi for @vport
1342 **/
dea31012005-04-17 16:05:31 -05001343int
James Smart2e0fef82007-06-17 19:56:36 -05001344lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001345{
James Smart2e0fef82007-06-17 19:56:36 -05001346 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001347 struct lpfc_nodelist *ndlp;
1348
James Smart98c9ea52007-10-27 13:37:33 -04001349 vport->port_state = LPFC_FLOGI;
1350 lpfc_set_disctmo(vport);
1351
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001352 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001353 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001354 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001355 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001356 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1357 if (!ndlp)
1358 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001359 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001360 /* Set the node type */
1361 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001362 /* Put ndlp onto node list */
1363 lpfc_enqueue_node(vport, ndlp);
1364 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1365 /* re-setup ndlp without removing from node list */
1366 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1367 if (!ndlp)
1368 return 0;
dea31012005-04-17 16:05:31 -05001369 }
James Smart87af33f2007-10-27 13:37:43 -04001370
James Smart5ac6b302010-10-22 11:05:36 -04001371 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001372 /* This decrement of reference count to node shall kick off
1373 * the release of the node.
1374 */
James Smart329f9bc2007-04-25 09:53:01 -04001375 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001376 return 0;
1377 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001378 return 1;
dea31012005-04-17 16:05:31 -05001379}
1380
James Smarte59058c2008-08-24 21:49:00 -04001381/**
James Smart3621a712009-04-06 18:47:14 -04001382 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001383 * @vport: pointer to a host virtual N_Port data structure.
1384 *
1385 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1386 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1387 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1388 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1389 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1390 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1391 * @vport.
1392 *
1393 * Return code
1394 * 0 - failed to issue initial fdisc for @vport
1395 * 1 - successfully issued initial fdisc for @vport
1396 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001397int
1398lpfc_initial_fdisc(struct lpfc_vport *vport)
1399{
1400 struct lpfc_hba *phba = vport->phba;
1401 struct lpfc_nodelist *ndlp;
1402
1403 /* First look for the Fabric ndlp */
1404 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1405 if (!ndlp) {
1406 /* Cannot find existing Fabric ndlp, so allocate a new one */
1407 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1408 if (!ndlp)
1409 return 0;
1410 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001411 /* Put ndlp onto node list */
1412 lpfc_enqueue_node(vport, ndlp);
1413 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1414 /* re-setup ndlp without removing from node list */
1415 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1416 if (!ndlp)
1417 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001418 }
James Smarte47c9092008-02-08 18:49:26 -05001419
James Smart92d7f7b2007-06-17 19:56:38 -05001420 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001421 /* decrement node reference count to trigger the release of
1422 * the node.
1423 */
James Smart92d7f7b2007-06-17 19:56:38 -05001424 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001425 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001426 }
1427 return 1;
1428}
James Smart87af33f2007-10-27 13:37:43 -04001429
James Smarte59058c2008-08-24 21:49:00 -04001430/**
James Smart3621a712009-04-06 18:47:14 -04001431 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001432 * @vport: pointer to a host virtual N_Port data structure.
1433 *
1434 * This routine checks whether there are more remaining Port Logins
1435 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1436 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1437 * to issue ELS PLOGIs up to the configured discover threads with the
1438 * @vport (@vport->cfg_discovery_threads). The function also decrement
1439 * the @vport's num_disc_node by 1 if it is not already 0.
1440 **/
James Smart87af33f2007-10-27 13:37:43 -04001441void
James Smart2e0fef82007-06-17 19:56:36 -05001442lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001443{
James Smart2e0fef82007-06-17 19:56:36 -05001444 if (vport->num_disc_nodes)
1445 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001446
1447 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001448 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1449 "0232 Continue discovery with %d PLOGIs to go "
1450 "Data: x%x x%x x%x\n",
1451 vport->num_disc_nodes, vport->fc_plogi_cnt,
1452 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001453 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001454 if (vport->fc_flag & FC_NLP_MORE)
1455 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
Sebastian Herbsztdb6f1c22015-08-31 16:48:14 -04001456 lpfc_els_disc_plogi(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001457
dea31012005-04-17 16:05:31 -05001458 return;
1459}
1460
James Smarte59058c2008-08-24 21:49:00 -04001461/**
James Smart3621a712009-04-06 18:47:14 -04001462 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001463 * @phba: pointer to lpfc hba data structure.
1464 * @prsp: pointer to response IOCB payload.
1465 * @ndlp: pointer to a node-list data structure.
1466 *
1467 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1468 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1469 * The following cases are considered N_Port confirmed:
1470 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1471 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1472 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1473 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1474 * 1) if there is a node on vport list other than the @ndlp with the same
1475 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1476 * on that node to release the RPI associated with the node; 2) if there is
1477 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1478 * into, a new node shall be allocated (or activated). In either case, the
1479 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1480 * be released and the new_ndlp shall be put on to the vport node list and
1481 * its pointer returned as the confirmed node.
1482 *
1483 * Note that before the @ndlp got "released", the keepDID from not-matching
1484 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1485 * of the @ndlp. This is because the release of @ndlp is actually to put it
1486 * into an inactive state on the vport node list and the vport node list
1487 * management algorithm does not allow two node with a same DID.
1488 *
1489 * Return code
1490 * pointer to the PLOGI N_Port @ndlp
1491 **/
James Smart488d1462006-03-07 15:02:37 -05001492static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001493lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001494 struct lpfc_nodelist *ndlp)
1495{
James Smart2e0fef82007-06-17 19:56:36 -05001496 struct lpfc_vport *vport = ndlp->vport;
James Smart953ceed2015-05-22 10:42:37 -04001497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05001498 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001499 struct lpfc_rport_data *rdata;
1500 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001501 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001502 uint8_t name[sizeof(struct lpfc_name)];
James Smarte5abba42015-05-21 13:55:27 -04001503 uint32_t rc, keepDID = 0, keep_nlp_flag = 0;
James Smart953ceed2015-05-22 10:42:37 -04001504 uint16_t keep_nlp_state;
James Smart38b92ef2010-08-04 16:11:39 -04001505 int put_node;
1506 int put_rport;
James Smartcff261f2013-12-17 20:29:47 -05001507 unsigned long *active_rrqs_xri_bitmap = NULL;
James Smart488d1462006-03-07 15:02:37 -05001508
James Smart2fb9bd82006-12-02 13:33:57 -05001509 /* Fabric nodes can have the same WWPN so we don't bother searching
1510 * by WWPN. Just return the ndlp that was given to us.
1511 */
1512 if (ndlp->nlp_type & NLP_FABRIC)
1513 return ndlp;
1514
James Smart92d7f7b2007-06-17 19:56:38 -05001515 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001516 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001517
James Smart685f0bf2007-04-25 09:53:08 -04001518 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001519 * we have for that ndlp. If not, we have some work to do.
1520 */
James Smart2e0fef82007-06-17 19:56:36 -05001521 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001522
James Smarte47c9092008-02-08 18:49:26 -05001523 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001524 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001525 if (phba->sli_rev == LPFC_SLI_REV4) {
1526 active_rrqs_xri_bitmap = mempool_alloc(phba->active_rrq_pool,
1527 GFP_KERNEL);
1528 if (active_rrqs_xri_bitmap)
1529 memset(active_rrqs_xri_bitmap, 0,
1530 phba->cfg_rrq_xri_bitmap_sz);
1531 }
James Smart488d1462006-03-07 15:02:37 -05001532
James Smart34f5ad82012-08-03 12:35:03 -04001533 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1534 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1535 ndlp, ndlp->nlp_DID, new_ndlp);
1536
James Smart488d1462006-03-07 15:02:37 -05001537 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001538 rc = memcmp(&ndlp->nlp_portname, name,
1539 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001540 if (!rc) {
1541 if (active_rrqs_xri_bitmap)
1542 mempool_free(active_rrqs_xri_bitmap,
1543 phba->active_rrq_pool);
James Smart92795652006-07-06 15:50:02 -04001544 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001545 }
James Smart488d1462006-03-07 15:02:37 -05001546 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
James Smartcff261f2013-12-17 20:29:47 -05001547 if (!new_ndlp) {
1548 if (active_rrqs_xri_bitmap)
1549 mempool_free(active_rrqs_xri_bitmap,
1550 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001551 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001552 }
James Smart2e0fef82007-06-17 19:56:36 -05001553 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001554 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001555 rc = memcmp(&ndlp->nlp_portname, name,
1556 sizeof(struct lpfc_name));
James Smartcff261f2013-12-17 20:29:47 -05001557 if (!rc) {
1558 if (active_rrqs_xri_bitmap)
1559 mempool_free(active_rrqs_xri_bitmap,
1560 phba->active_rrq_pool);
James Smart58da1ff2008-04-07 10:15:56 -04001561 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001562 }
James Smarte47c9092008-02-08 18:49:26 -05001563 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1564 NLP_STE_UNUSED_NODE);
James Smartcff261f2013-12-17 20:29:47 -05001565 if (!new_ndlp) {
1566 if (active_rrqs_xri_bitmap)
1567 mempool_free(active_rrqs_xri_bitmap,
1568 phba->active_rrq_pool);
James Smarte47c9092008-02-08 18:49:26 -05001569 return ndlp;
James Smartcff261f2013-12-17 20:29:47 -05001570 }
James Smart58da1ff2008-04-07 10:15:56 -04001571 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001572 if ((phba->sli_rev == LPFC_SLI_REV4) && active_rrqs_xri_bitmap)
1573 memcpy(active_rrqs_xri_bitmap,
1574 new_ndlp->active_rrqs_xri_bitmap,
1575 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001576 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001577 keepDID = new_ndlp->nlp_DID;
James Smartcff261f2013-12-17 20:29:47 -05001578 if (phba->sli_rev == LPFC_SLI_REV4 &&
1579 active_rrqs_xri_bitmap)
1580 memcpy(active_rrqs_xri_bitmap,
1581 new_ndlp->active_rrqs_xri_bitmap,
1582 phba->cfg_rrq_xri_bitmap_sz);
James Smart19ca7602010-11-20 23:11:55 -05001583 }
James Smart488d1462006-03-07 15:02:37 -05001584
James Smart2e0fef82007-06-17 19:56:36 -05001585 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001586 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001587 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001588 if (phba->sli_rev == LPFC_SLI_REV4)
James Smartcff261f2013-12-17 20:29:47 -05001589 memcpy(new_ndlp->active_rrqs_xri_bitmap,
1590 ndlp->active_rrqs_xri_bitmap,
1591 phba->cfg_rrq_xri_bitmap_sz);
James Smart0ff10d42008-01-11 01:52:36 -05001592
James Smart953ceed2015-05-22 10:42:37 -04001593 spin_lock_irq(shost->host_lock);
James Smarte5abba42015-05-21 13:55:27 -04001594 keep_nlp_flag = new_ndlp->nlp_flag;
1595 new_ndlp->nlp_flag = ndlp->nlp_flag;
1596 ndlp->nlp_flag = keep_nlp_flag;
James Smart953ceed2015-05-22 10:42:37 -04001597 spin_unlock_irq(shost->host_lock);
James Smart0ff10d42008-01-11 01:52:36 -05001598
James Smart953ceed2015-05-22 10:42:37 -04001599 /* Set nlp_states accordingly */
1600 keep_nlp_state = new_ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001601 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001602
James Smart2e0fef82007-06-17 19:56:36 -05001603 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001604 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1605 /* The new_ndlp is replacing ndlp totally, so we need
1606 * to put ndlp on UNUSED list and try to free it.
1607 */
James Smart34f5ad82012-08-03 12:35:03 -04001608 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1609 "3179 PLOGI confirm NEW: %x %x\n",
1610 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001611
1612 /* Fix up the rport accordingly */
1613 rport = ndlp->rport;
1614 if (rport) {
1615 rdata = rport->dd_data;
1616 if (rdata->pnode == ndlp) {
James Smart466e8402015-05-21 13:55:28 -04001617 /* break the link before dropping the ref */
James Smart0ff10d42008-01-11 01:52:36 -05001618 ndlp->rport = NULL;
James Smart466e8402015-05-21 13:55:28 -04001619 lpfc_nlp_put(ndlp);
James Smart0ff10d42008-01-11 01:52:36 -05001620 rdata->pnode = lpfc_nlp_get(new_ndlp);
1621 new_ndlp->rport = rport;
1622 }
1623 new_ndlp->nlp_type = ndlp->nlp_type;
1624 }
James Smart58da1ff2008-04-07 10:15:56 -04001625 /* We shall actually free the ndlp with both nlp_DID and
1626 * nlp_portname fields equals 0 to avoid any ndlp on the
1627 * nodelist never to be used.
1628 */
1629 if (ndlp->nlp_DID == 0) {
1630 spin_lock_irq(&phba->ndlp_lock);
1631 NLP_SET_FREE_REQ(ndlp);
1632 spin_unlock_irq(&phba->ndlp_lock);
1633 }
James Smart0ff10d42008-01-11 01:52:36 -05001634
James Smart58da1ff2008-04-07 10:15:56 -04001635 /* Two ndlps cannot have the same did on the nodelist */
1636 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001637 if (phba->sli_rev == LPFC_SLI_REV4 &&
1638 active_rrqs_xri_bitmap)
1639 memcpy(ndlp->active_rrqs_xri_bitmap,
1640 active_rrqs_xri_bitmap,
1641 phba->cfg_rrq_xri_bitmap_sz);
James Smarte5abba42015-05-21 13:55:27 -04001642
1643 if (!NLP_CHK_NODE_ACT(ndlp))
1644 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001645 }
James Smart92795652006-07-06 15:50:02 -04001646 else {
James Smart34f5ad82012-08-03 12:35:03 -04001647 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1648 "3180 PLOGI confirm SWAP: %x %x\n",
1649 new_ndlp->nlp_DID, keepDID);
1650
James Smart2e0fef82007-06-17 19:56:36 -05001651 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001652
James Smart58da1ff2008-04-07 10:15:56 -04001653 /* Two ndlps cannot have the same did */
1654 ndlp->nlp_DID = keepDID;
James Smartcff261f2013-12-17 20:29:47 -05001655 if (phba->sli_rev == LPFC_SLI_REV4 &&
1656 active_rrqs_xri_bitmap)
1657 memcpy(ndlp->active_rrqs_xri_bitmap,
1658 active_rrqs_xri_bitmap,
1659 phba->cfg_rrq_xri_bitmap_sz);
James Smart34f5ad82012-08-03 12:35:03 -04001660
James Smart953ceed2015-05-22 10:42:37 -04001661 /* Since we are switching over to the new_ndlp,
1662 * reset the old ndlp state
James Smart34f5ad82012-08-03 12:35:03 -04001663 */
1664 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1665 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
James Smart953ceed2015-05-22 10:42:37 -04001666 keep_nlp_state = NLP_STE_NPR_NODE;
1667 lpfc_nlp_set_state(vport, ndlp, keep_nlp_state);
James Smart34f5ad82012-08-03 12:35:03 -04001668
James Smart38b92ef2010-08-04 16:11:39 -04001669 /* Fix up the rport accordingly */
1670 rport = ndlp->rport;
1671 if (rport) {
1672 rdata = rport->dd_data;
1673 put_node = rdata->pnode != NULL;
1674 put_rport = ndlp->rport != NULL;
1675 rdata->pnode = NULL;
1676 ndlp->rport = NULL;
1677 if (put_node)
1678 lpfc_nlp_put(ndlp);
1679 if (put_rport)
1680 put_device(&rport->dev);
1681 }
James Smart92795652006-07-06 15:50:02 -04001682 }
James Smartcff261f2013-12-17 20:29:47 -05001683 if (phba->sli_rev == LPFC_SLI_REV4 &&
1684 active_rrqs_xri_bitmap)
1685 mempool_free(active_rrqs_xri_bitmap,
1686 phba->active_rrq_pool);
James Smart488d1462006-03-07 15:02:37 -05001687 return new_ndlp;
1688}
1689
James Smarte59058c2008-08-24 21:49:00 -04001690/**
James Smart3621a712009-04-06 18:47:14 -04001691 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001692 * @vport: pointer to a host virtual N_Port data structure.
1693 *
1694 * This routine checks whether more Registration State Change
1695 * Notifications (RSCNs) came in while the discovery state machine was in
1696 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1697 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1698 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1699 * handling the RSCNs.
1700 **/
James Smart87af33f2007-10-27 13:37:43 -04001701void
1702lpfc_end_rscn(struct lpfc_vport *vport)
1703{
1704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1705
1706 if (vport->fc_flag & FC_RSCN_MODE) {
1707 /*
1708 * Check to see if more RSCNs came in while we were
1709 * processing this one.
1710 */
1711 if (vport->fc_rscn_id_cnt ||
1712 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1713 lpfc_els_handle_rscn(vport);
1714 else {
1715 spin_lock_irq(shost->host_lock);
1716 vport->fc_flag &= ~FC_RSCN_MODE;
1717 spin_unlock_irq(shost->host_lock);
1718 }
1719 }
1720}
1721
James Smarte59058c2008-08-24 21:49:00 -04001722/**
James Smart19ca7602010-11-20 23:11:55 -05001723 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1724 * @phba: pointer to lpfc hba data structure.
1725 * @cmdiocb: pointer to lpfc command iocb data structure.
1726 * @rspiocb: pointer to lpfc response iocb data structure.
1727 *
1728 * This routine will call the clear rrq function to free the rrq and
1729 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1730 * exist then the clear_rrq is still called because the rrq needs to
1731 * be freed.
1732 **/
1733
1734static void
1735lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1736 struct lpfc_iocbq *rspiocb)
1737{
1738 struct lpfc_vport *vport = cmdiocb->vport;
1739 IOCB_t *irsp;
1740 struct lpfc_nodelist *ndlp;
1741 struct lpfc_node_rrq *rrq;
1742
1743 /* we pass cmdiocb to state machine which needs rspiocb as well */
1744 rrq = cmdiocb->context_un.rrq;
1745 cmdiocb->context_un.rsp_iocb = rspiocb;
1746
1747 irsp = &rspiocb->iocb;
1748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1749 "RRQ cmpl: status:x%x/x%x did:x%x",
1750 irsp->ulpStatus, irsp->un.ulpWord[4],
1751 irsp->un.elsreq64.remoteID);
1752
1753 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1754 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1755 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1756 "2882 RRQ completes to NPort x%x "
1757 "with no ndlp. Data: x%x x%x x%x\n",
1758 irsp->un.elsreq64.remoteID,
1759 irsp->ulpStatus, irsp->un.ulpWord[4],
1760 irsp->ulpIoTag);
1761 goto out;
1762 }
1763
1764 /* rrq completes to NPort <nlp_DID> */
1765 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1766 "2880 RRQ completes to NPort x%x "
1767 "Data: x%x x%x x%x x%x x%x\n",
1768 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1769 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1770
1771 if (irsp->ulpStatus) {
1772 /* Check for retry */
1773 /* RRQ failed Don't print the vport to vport rjts */
1774 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1775 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1776 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1777 (phba)->pport->cfg_log_verbose & LOG_ELS)
1778 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1779 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1780 ndlp->nlp_DID, irsp->ulpStatus,
1781 irsp->un.ulpWord[4]);
1782 }
1783out:
1784 if (rrq)
1785 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1786 lpfc_els_free_iocb(phba, cmdiocb);
1787 return;
1788}
1789/**
James Smart3621a712009-04-06 18:47:14 -04001790 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001791 * @phba: pointer to lpfc hba data structure.
1792 * @cmdiocb: pointer to lpfc command iocb data structure.
1793 * @rspiocb: pointer to lpfc response iocb data structure.
1794 *
1795 * This routine is the completion callback function for issuing the Port
1796 * Login (PLOGI) command. For PLOGI completion, there must be an active
1797 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001798 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001799 * ignored and command IOCB released. The PLOGI response IOCB status is
1800 * checked for error conditons. If there is error status reported, PLOGI
1801 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1802 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1803 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1804 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1805 * there are additional N_Port nodes with the vport that need to perform
1806 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1807 * PLOGIs.
1808 **/
dea31012005-04-17 16:05:31 -05001809static void
James Smart2e0fef82007-06-17 19:56:36 -05001810lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1811 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001812{
James Smart2e0fef82007-06-17 19:56:36 -05001813 struct lpfc_vport *vport = cmdiocb->vport;
1814 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001815 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001816 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001817 struct lpfc_dmabuf *prsp;
James Smarteb016562014-09-03 12:58:06 -04001818 int disc, rc;
dea31012005-04-17 16:05:31 -05001819
dea31012005-04-17 16:05:31 -05001820 /* we pass cmdiocb to state machine which needs rspiocb as well */
1821 cmdiocb->context_un.rsp_iocb = rspiocb;
1822
1823 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1825 "PLOGI cmpl: status:x%x/x%x did:x%x",
1826 irsp->ulpStatus, irsp->un.ulpWord[4],
1827 irsp->un.elsreq64.remoteID);
1828
James Smart2e0fef82007-06-17 19:56:36 -05001829 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001830 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001831 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1832 "0136 PLOGI completes to NPort x%x "
1833 "with no ndlp. Data: x%x x%x x%x\n",
1834 irsp->un.elsreq64.remoteID,
1835 irsp->ulpStatus, irsp->un.ulpWord[4],
1836 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001837 goto out;
James Smarted957682007-06-17 19:56:37 -05001838 }
dea31012005-04-17 16:05:31 -05001839
1840 /* Since ndlp can be freed in the disc state machine, note if this node
1841 * is being used during discovery.
1842 */
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001844 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001845 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001846 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001847 rc = 0;
1848
1849 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001850 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1851 "0102 PLOGI completes to NPort x%x "
1852 "Data: x%x x%x x%x x%x x%x\n",
1853 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1854 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001855 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001856 if (lpfc_els_chk_latt(vport)) {
1857 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001858 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001859 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001860 goto out;
1861 }
1862
dea31012005-04-17 16:05:31 -05001863 if (irsp->ulpStatus) {
1864 /* Check for retry */
1865 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1866 /* ELS command is being retried */
1867 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001868 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001869 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001870 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001871 }
1872 goto out;
1873 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001874 /* PLOGI failed Don't print the vport to vport rjts */
1875 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1876 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1877 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1878 (phba)->pport->cfg_log_verbose & LOG_ELS)
1879 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001880 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1881 ndlp->nlp_DID, irsp->ulpStatus,
1882 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001883 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001884 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001885 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001886 else
James Smart2e0fef82007-06-17 19:56:36 -05001887 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001888 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001889 } else {
1890 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001891 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001892 cmdiocb->context2)->list.next,
1893 struct lpfc_dmabuf, list);
1894 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001895 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001896 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001897 }
1898
James Smart2e0fef82007-06-17 19:56:36 -05001899 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001900 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001901 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001902
James Smart2e0fef82007-06-17 19:56:36 -05001903 if (vport->num_disc_nodes == 0) {
1904 spin_lock_irq(shost->host_lock);
1905 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1906 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001907
James Smart2e0fef82007-06-17 19:56:36 -05001908 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001909 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001910 }
1911 }
1912
1913out:
1914 lpfc_els_free_iocb(phba, cmdiocb);
1915 return;
1916}
1917
James Smarte59058c2008-08-24 21:49:00 -04001918/**
James Smart3621a712009-04-06 18:47:14 -04001919 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001920 * @vport: pointer to a host virtual N_Port data structure.
1921 * @did: destination port identifier.
1922 * @retry: number of retries to the command IOCB.
1923 *
1924 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1925 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1926 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1927 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1928 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1929 *
1930 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1931 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1932 * will be stored into the context1 field of the IOCB for the completion
1933 * callback function to the PLOGI ELS command.
1934 *
1935 * Return code
1936 * 0 - Successfully issued a plogi for @vport
1937 * 1 - failed to issue a plogi for @vport
1938 **/
dea31012005-04-17 16:05:31 -05001939int
James Smart2e0fef82007-06-17 19:56:36 -05001940lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001941{
James Smart2e0fef82007-06-17 19:56:36 -05001942 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001943 struct serv_parm *sp;
James Smart98c9ea52007-10-27 13:37:33 -04001944 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001945 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001946 uint8_t *pcmd;
1947 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001948 int ret;
dea31012005-04-17 16:05:31 -05001949
James Smart98c9ea52007-10-27 13:37:33 -04001950 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001951 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1952 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001953
James Smarte47c9092008-02-08 18:49:26 -05001954 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001955 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001956 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001957 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001958 if (!elsiocb)
1959 return 1;
dea31012005-04-17 16:05:31 -05001960
dea31012005-04-17 16:05:31 -05001961 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1962
1963 /* For PLOGI request, remainder of payload is service parameters */
1964 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001965 pcmd += sizeof(uint32_t);
1966 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001967 sp = (struct serv_parm *) pcmd;
1968
James Smart5ac6b302010-10-22 11:05:36 -04001969 /*
1970 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1971 * to device on remote loops work.
1972 */
1973 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1974 sp->cmn.altBbCredit = 1;
1975
dea31012005-04-17 16:05:31 -05001976 if (sp->cmn.fcphLow < FC_PH_4_3)
1977 sp->cmn.fcphLow = FC_PH_4_3;
1978
1979 if (sp->cmn.fcphHigh < FC_PH3)
1980 sp->cmn.fcphHigh = FC_PH3;
1981
James Smart858c9f62007-06-17 19:56:39 -05001982 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1983 "Issue PLOGI: did:x%x",
1984 did, 0, 0);
1985
dea31012005-04-17 16:05:31 -05001986 phba->fc_stat.elsXmitPLOGI++;
1987 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001988 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001989
1990 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001991 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001992 return 1;
dea31012005-04-17 16:05:31 -05001993 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001994 return 0;
dea31012005-04-17 16:05:31 -05001995}
1996
James Smarte59058c2008-08-24 21:49:00 -04001997/**
James Smart3621a712009-04-06 18:47:14 -04001998 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001999 * @phba: pointer to lpfc hba data structure.
2000 * @cmdiocb: pointer to lpfc command iocb data structure.
2001 * @rspiocb: pointer to lpfc response iocb data structure.
2002 *
2003 * This routine is the completion callback function for a Process Login
2004 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2005 * status. If there is error status reported, PRLI retry shall be attempted
2006 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2007 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2008 * ndlp to mark the PRLI completion.
2009 **/
dea31012005-04-17 16:05:31 -05002010static void
James Smart2e0fef82007-06-17 19:56:36 -05002011lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2012 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002013{
James Smart2e0fef82007-06-17 19:56:36 -05002014 struct lpfc_vport *vport = cmdiocb->vport;
2015 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002016 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002017 struct lpfc_nodelist *ndlp;
2018
dea31012005-04-17 16:05:31 -05002019 /* we pass cmdiocb to state machine which needs rspiocb as well */
2020 cmdiocb->context_un.rsp_iocb = rspiocb;
2021
2022 irsp = &(rspiocb->iocb);
2023 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002024 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002025 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002026 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002027
James Smart858c9f62007-06-17 19:56:39 -05002028 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2029 "PRLI cmpl: status:x%x/x%x did:x%x",
2030 irsp->ulpStatus, irsp->un.ulpWord[4],
2031 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002032 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2034 "0103 PRLI completes to NPort x%x "
2035 "Data: x%x x%x x%x x%x\n",
2036 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2037 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002038
James Smart2e0fef82007-06-17 19:56:36 -05002039 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05002040 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002041 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002042 goto out;
2043
2044 if (irsp->ulpStatus) {
2045 /* Check for retry */
2046 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2047 /* ELS command is being retried */
2048 goto out;
2049 }
2050 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05002051 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2052 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2053 ndlp->nlp_DID, irsp->ulpStatus,
2054 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002055 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002056 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002057 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002058 else
James Smart2e0fef82007-06-17 19:56:36 -05002059 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002060 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002061 } else
dea31012005-04-17 16:05:31 -05002062 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002063 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002064 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002065out:
2066 lpfc_els_free_iocb(phba, cmdiocb);
2067 return;
2068}
2069
James Smarte59058c2008-08-24 21:49:00 -04002070/**
James Smart3621a712009-04-06 18:47:14 -04002071 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002072 * @vport: pointer to a host virtual N_Port data structure.
2073 * @ndlp: pointer to a node-list data structure.
2074 * @retry: number of retries to the command IOCB.
2075 *
2076 * This routine issues a Process Login (PRLI) ELS command for the
2077 * @vport. The PRLI service parameters are set up in the payload of the
2078 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2079 * is put to the IOCB completion callback func field before invoking the
2080 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2081 *
2082 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2083 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2084 * will be stored into the context1 field of the IOCB for the completion
2085 * callback function to the PRLI ELS command.
2086 *
2087 * Return code
2088 * 0 - successfully issued prli iocb command for @vport
2089 * 1 - failed to issue prli iocb command for @vport
2090 **/
dea31012005-04-17 16:05:31 -05002091int
James Smart2e0fef82007-06-17 19:56:36 -05002092lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002093 uint8_t retry)
2094{
James Smart2e0fef82007-06-17 19:56:36 -05002095 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2096 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002097 PRLI *npr;
dea31012005-04-17 16:05:31 -05002098 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002099 uint8_t *pcmd;
2100 uint16_t cmdsize;
2101
James Smart92d7f7b2007-06-17 19:56:38 -05002102 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002103 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2104 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002105 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002106 return 1;
dea31012005-04-17 16:05:31 -05002107
dea31012005-04-17 16:05:31 -05002108 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2109
2110 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002111 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002112 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002113 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002114
2115 /* For PRLI, remainder of payload is PRLI parameter page */
2116 npr = (PRLI *) pcmd;
2117 /*
2118 * If our firmware version is 3.20 or later,
2119 * set the following bits for FC-TAPE support.
2120 */
2121 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2122 npr->ConfmComplAllowed = 1;
2123 npr->Retry = 1;
2124 npr->TaskRetryIdReq = 1;
2125 }
2126 npr->estabImagePair = 1;
2127 npr->readXferRdyDis = 1;
James Smart3cb01c52013-07-15 18:35:04 -04002128 if (vport->cfg_first_burst_size)
2129 npr->writeXferRdyDis = 1;
dea31012005-04-17 16:05:31 -05002130
2131 /* For FCP support */
2132 npr->prliType = PRLI_FCP_TYPE;
2133 npr->initiatorFunc = 1;
2134
James Smart858c9f62007-06-17 19:56:39 -05002135 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2136 "Issue PRLI: did:x%x",
2137 ndlp->nlp_DID, 0, 0);
2138
dea31012005-04-17 16:05:31 -05002139 phba->fc_stat.elsXmitPRLI++;
2140 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002141 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002142 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002143 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002144 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2145 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002146 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002147 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002148 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002149 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002150 return 1;
dea31012005-04-17 16:05:31 -05002151 }
James Smart2e0fef82007-06-17 19:56:36 -05002152 vport->fc_prli_sent++;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002153 return 0;
dea31012005-04-17 16:05:31 -05002154}
2155
James Smarte59058c2008-08-24 21:49:00 -04002156/**
James Smart3621a712009-04-06 18:47:14 -04002157 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002158 * @vport: pointer to a host virtual N_Port data structure.
2159 *
2160 * This routine performs Registration State Change Notification (RSCN)
2161 * discovery for a @vport. If the @vport's node port recovery count is not
2162 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2163 * the nodes that need recovery. If none of the PLOGI were needed through
2164 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2165 * invoked to check and handle possible more RSCN came in during the period
2166 * of processing the current ones.
2167 **/
2168static void
2169lpfc_rscn_disc(struct lpfc_vport *vport)
2170{
2171 lpfc_can_disctmo(vport);
2172
2173 /* RSCN discovery */
2174 /* go thru NPR nodes and issue ELS PLOGIs */
2175 if (vport->fc_npr_cnt)
2176 if (lpfc_els_disc_plogi(vport))
2177 return;
2178
2179 lpfc_end_rscn(vport);
2180}
2181
2182/**
James Smart3621a712009-04-06 18:47:14 -04002183 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002184 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2185 *
2186 * This function is called when the final ADISC is completed during discovery.
2187 * This function handles clearing link attention or issuing reg_vpi depending
2188 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2189 * discovery.
2190 * This function is called with no locks held.
2191 **/
2192static void
2193lpfc_adisc_done(struct lpfc_vport *vport)
2194{
2195 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2196 struct lpfc_hba *phba = vport->phba;
2197
2198 /*
2199 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2200 * and continue discovery.
2201 */
2202 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002203 !(vport->fc_flag & FC_RSCN_MODE) &&
2204 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smartd454c912014-12-30 12:08:58 -05002205 /* The ADISCs are complete. Doesn't matter if they
2206 * succeeded or failed because the ADISC completion
2207 * routine guarantees to call the state machine and
2208 * the RPI is either unregistered (failed ADISC response)
2209 * or the RPI is still valid and the node is marked
2210 * mapped for a target. The exchanges should be in the
2211 * correct state. This code is specific to SLI3.
2212 */
2213 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002214 lpfc_issue_reg_vpi(phba, vport);
2215 return;
2216 }
2217 /*
2218 * For SLI2, we need to set port_state to READY
2219 * and continue discovery.
2220 */
2221 if (vport->port_state < LPFC_VPORT_READY) {
2222 /* If we get here, there is nothing to ADISC */
James Smart85c0f172015-04-07 15:07:12 -04002223 lpfc_issue_clear_la(phba, vport);
James Smart90160e02008-08-24 21:49:45 -04002224 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2225 vport->num_disc_nodes = 0;
2226 /* go thru NPR list, issue ELS PLOGIs */
2227 if (vport->fc_npr_cnt)
2228 lpfc_els_disc_plogi(vport);
2229 if (!vport->num_disc_nodes) {
2230 spin_lock_irq(shost->host_lock);
2231 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2232 spin_unlock_irq(shost->host_lock);
2233 lpfc_can_disctmo(vport);
2234 lpfc_end_rscn(vport);
2235 }
2236 }
2237 vport->port_state = LPFC_VPORT_READY;
2238 } else
2239 lpfc_rscn_disc(vport);
2240}
2241
2242/**
James Smart3621a712009-04-06 18:47:14 -04002243 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002244 * @vport: pointer to a host virtual N_Port data structure.
2245 *
2246 * This routine determines whether there are more ndlps on a @vport
2247 * node list need to have Address Discover (ADISC) issued. If so, it will
2248 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2249 * remaining nodes which need to have ADISC sent.
2250 **/
James Smart0ff10d42008-01-11 01:52:36 -05002251void
James Smart2e0fef82007-06-17 19:56:36 -05002252lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002253{
James Smart2e0fef82007-06-17 19:56:36 -05002254 if (vport->num_disc_nodes)
2255 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002256 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002257 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2258 "0210 Continue discovery with %d ADISCs to go "
2259 "Data: x%x x%x x%x\n",
2260 vport->num_disc_nodes, vport->fc_adisc_cnt,
2261 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002262 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002263 if (vport->fc_flag & FC_NLP_MORE) {
2264 lpfc_set_disctmo(vport);
2265 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smarteb016562014-09-03 12:58:06 -04002266 lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002267 }
James Smart90160e02008-08-24 21:49:45 -04002268 if (!vport->num_disc_nodes)
2269 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002270 return;
2271}
2272
James Smarte59058c2008-08-24 21:49:00 -04002273/**
James Smart3621a712009-04-06 18:47:14 -04002274 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002275 * @phba: pointer to lpfc hba data structure.
2276 * @cmdiocb: pointer to lpfc command iocb data structure.
2277 * @rspiocb: pointer to lpfc response iocb data structure.
2278 *
2279 * This routine is the completion function for issuing the Address Discover
2280 * (ADISC) command. It first checks to see whether link went down during
2281 * the discovery process. If so, the node will be marked as node port
2282 * recovery for issuing discover IOCB by the link attention handler and
2283 * exit. Otherwise, the response status is checked. If error was reported
2284 * in the response status, the ADISC command shall be retried by invoking
2285 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2286 * the response status, the state machine is invoked to set transition
2287 * with respect to NLP_EVT_CMPL_ADISC event.
2288 **/
dea31012005-04-17 16:05:31 -05002289static void
James Smart2e0fef82007-06-17 19:56:36 -05002290lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2291 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002292{
James Smart2e0fef82007-06-17 19:56:36 -05002293 struct lpfc_vport *vport = cmdiocb->vport;
2294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002295 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002296 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002297 int disc;
dea31012005-04-17 16:05:31 -05002298
2299 /* we pass cmdiocb to state machine which needs rspiocb as well */
2300 cmdiocb->context_un.rsp_iocb = rspiocb;
2301
2302 irsp = &(rspiocb->iocb);
2303 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002304
James Smart858c9f62007-06-17 19:56:39 -05002305 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2306 "ADISC cmpl: status:x%x/x%x did:x%x",
2307 irsp->ulpStatus, irsp->un.ulpWord[4],
2308 ndlp->nlp_DID);
2309
dea31012005-04-17 16:05:31 -05002310 /* Since ndlp can be freed in the disc state machine, note if this node
2311 * is being used during discovery.
2312 */
James Smart2e0fef82007-06-17 19:56:36 -05002313 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002314 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002315 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002316 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002317 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2319 "0104 ADISC completes to NPort x%x "
2320 "Data: x%x x%x x%x x%x x%x\n",
2321 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2322 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002323 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002324 if (lpfc_els_chk_latt(vport)) {
2325 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002326 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002327 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002328 goto out;
2329 }
2330
2331 if (irsp->ulpStatus) {
2332 /* Check for retry */
2333 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2334 /* ELS command is being retried */
2335 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002336 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002337 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002338 spin_unlock_irq(shost->host_lock);
2339 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002340 }
2341 goto out;
2342 }
2343 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002344 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2345 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2346 ndlp->nlp_DID, irsp->ulpStatus,
2347 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002348 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002349 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002350 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002351 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002352 } else
dea31012005-04-17 16:05:31 -05002353 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002354 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002355 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002356
James Smart90160e02008-08-24 21:49:45 -04002357 /* Check to see if there are more ADISCs to be sent */
2358 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002359 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002360out:
2361 lpfc_els_free_iocb(phba, cmdiocb);
2362 return;
2363}
2364
James Smarte59058c2008-08-24 21:49:00 -04002365/**
James Smart3621a712009-04-06 18:47:14 -04002366 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002367 * @vport: pointer to a virtual N_Port data structure.
2368 * @ndlp: pointer to a node-list data structure.
2369 * @retry: number of retries to the command IOCB.
2370 *
2371 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2372 * @vport. It prepares the payload of the ADISC ELS command, updates the
2373 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2374 * to issue the ADISC ELS command.
2375 *
2376 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2377 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2378 * will be stored into the context1 field of the IOCB for the completion
2379 * callback function to the ADISC ELS command.
2380 *
2381 * Return code
2382 * 0 - successfully issued adisc
2383 * 1 - failed to issue adisc
2384 **/
dea31012005-04-17 16:05:31 -05002385int
James Smart2e0fef82007-06-17 19:56:36 -05002386lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002387 uint8_t retry)
2388{
James Smart2e0fef82007-06-17 19:56:36 -05002389 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2390 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002391 ADISC *ap;
dea31012005-04-17 16:05:31 -05002392 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002393 uint8_t *pcmd;
2394 uint16_t cmdsize;
2395
James Smart92d7f7b2007-06-17 19:56:38 -05002396 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002397 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2398 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002399 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002400 return 1;
dea31012005-04-17 16:05:31 -05002401
dea31012005-04-17 16:05:31 -05002402 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2403
2404 /* For ADISC request, remainder of payload is service parameters */
2405 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002406 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002407
2408 /* Fill in ADISC payload */
2409 ap = (ADISC *) pcmd;
2410 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002411 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2412 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002413 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002414
James Smart858c9f62007-06-17 19:56:39 -05002415 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2416 "Issue ADISC: did:x%x",
2417 ndlp->nlp_DID, 0, 0);
2418
dea31012005-04-17 16:05:31 -05002419 phba->fc_stat.elsXmitADISC++;
2420 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002421 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002422 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002423 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002424 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2425 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002426 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002427 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002428 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002429 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002430 return 1;
dea31012005-04-17 16:05:31 -05002431 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002432 return 0;
dea31012005-04-17 16:05:31 -05002433}
2434
James Smarte59058c2008-08-24 21:49:00 -04002435/**
James Smart3621a712009-04-06 18:47:14 -04002436 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002437 * @phba: pointer to lpfc hba data structure.
2438 * @cmdiocb: pointer to lpfc command iocb data structure.
2439 * @rspiocb: pointer to lpfc response iocb data structure.
2440 *
2441 * This routine is the completion function for issuing the ELS Logout (LOGO)
2442 * command. If no error status was reported from the LOGO response, the
2443 * state machine of the associated ndlp shall be invoked for transition with
2444 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2445 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2446 **/
dea31012005-04-17 16:05:31 -05002447static void
James Smart2e0fef82007-06-17 19:56:36 -05002448lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2449 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002450{
James Smart2e0fef82007-06-17 19:56:36 -05002451 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2452 struct lpfc_vport *vport = ndlp->vport;
2453 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002454 IOCB_t *irsp;
James Smart92494142011-02-16 12:39:44 -05002455 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002456 unsigned long flags;
2457 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002458
dea31012005-04-17 16:05:31 -05002459 /* we pass cmdiocb to state machine which needs rspiocb as well */
2460 cmdiocb->context_un.rsp_iocb = rspiocb;
2461
2462 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002463 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002464 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002465 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002466
James Smart858c9f62007-06-17 19:56:39 -05002467 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2468 "LOGO cmpl: status:x%x/x%x did:x%x",
2469 irsp->ulpStatus, irsp->un.ulpWord[4],
2470 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002471
dea31012005-04-17 16:05:31 -05002472 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002473 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2474 "0105 LOGO completes to NPort x%x "
2475 "Data: x%x x%x x%x x%x\n",
2476 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2477 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002478
James Smart086a3452012-08-14 14:25:21 -04002479 if (lpfc_els_chk_latt(vport)) {
2480 skip_recovery = 1;
2481 goto out;
2482 }
2483
2484 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002485 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2486 /* NLP_EVT_DEVICE_RM should unregister the RPI
2487 * which should abort all outstanding IOs.
2488 */
2489 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2490 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002491 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002492 goto out;
2493 }
2494
dea31012005-04-17 16:05:31 -05002495 if (irsp->ulpStatus) {
2496 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002497 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002498 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002499 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002500 goto out;
James Smart086a3452012-08-14 14:25:21 -04002501 }
dea31012005-04-17 16:05:31 -05002502 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002503 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2504 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2505 ndlp->nlp_DID, irsp->ulpStatus,
2506 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002507 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002508 if (lpfc_error_lost_link(irsp)) {
2509 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002510 goto out;
James Smart086a3452012-08-14 14:25:21 -04002511 }
2512 }
2513
2514 /* Call state machine. This will unregister the rpi if needed. */
2515 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2516
dea31012005-04-17 16:05:31 -05002517out:
2518 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002519 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2520 if ((vport->fc_flag & FC_PT2PT) &&
2521 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2522 phba->pport->fc_myDID = 0;
2523 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2524 if (mbox) {
2525 lpfc_config_link(phba, mbox);
2526 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2527 mbox->vport = vport;
2528 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2529 MBX_NOT_FINISHED) {
2530 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002531 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002532 }
2533 }
2534 }
James Smart086a3452012-08-14 14:25:21 -04002535
2536 /*
2537 * If the node is a target, the handling attempts to recover the port.
2538 * For any other port type, the rpi is unregistered as an implicit
2539 * LOGO.
2540 */
2541 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2542 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2543 spin_lock_irqsave(shost->host_lock, flags);
2544 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2545 spin_unlock_irqrestore(shost->host_lock, flags);
2546
2547 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2548 "3187 LOGO completes to NPort x%x: Start "
2549 "Recovery Data: x%x x%x x%x x%x\n",
2550 ndlp->nlp_DID, irsp->ulpStatus,
2551 irsp->un.ulpWord[4], irsp->ulpTimeout,
2552 vport->num_disc_nodes);
2553 lpfc_disc_start(vport);
2554 }
dea31012005-04-17 16:05:31 -05002555 return;
2556}
2557
James Smarte59058c2008-08-24 21:49:00 -04002558/**
James Smart3621a712009-04-06 18:47:14 -04002559 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002560 * @vport: pointer to a virtual N_Port data structure.
2561 * @ndlp: pointer to a node-list data structure.
2562 * @retry: number of retries to the command IOCB.
2563 *
2564 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2565 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2566 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2567 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2568 *
2569 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2570 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2571 * will be stored into the context1 field of the IOCB for the completion
2572 * callback function to the LOGO ELS command.
2573 *
2574 * Return code
2575 * 0 - successfully issued logo
2576 * 1 - failed to issue logo
2577 **/
dea31012005-04-17 16:05:31 -05002578int
James Smart2e0fef82007-06-17 19:56:36 -05002579lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002580 uint8_t retry)
2581{
James Smart2e0fef82007-06-17 19:56:36 -05002582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2583 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002584 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002585 uint8_t *pcmd;
2586 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002587 int rc;
dea31012005-04-17 16:05:31 -05002588
James Smart98c9ea52007-10-27 13:37:33 -04002589 spin_lock_irq(shost->host_lock);
2590 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2591 spin_unlock_irq(shost->host_lock);
2592 return 0;
2593 }
2594 spin_unlock_irq(shost->host_lock);
2595
James Smart92d7f7b2007-06-17 19:56:38 -05002596 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002597 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2598 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002599 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002600 return 1;
dea31012005-04-17 16:05:31 -05002601
dea31012005-04-17 16:05:31 -05002602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2603 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002604 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002605
2606 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002607 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002608 pcmd += sizeof(uint32_t);
2609 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002610
James Smart858c9f62007-06-17 19:56:39 -05002611 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2612 "Issue LOGO: did:x%x",
2613 ndlp->nlp_DID, 0, 0);
2614
James Smart086a3452012-08-14 14:25:21 -04002615 /*
2616 * If we are issuing a LOGO, we may try to recover the remote NPort
2617 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2618 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2619 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2620 * for that ELS cmd. To avoid this situation, lets get rid of the
2621 * RPI right now, before any ELS cmds are sent.
2622 */
2623 spin_lock_irq(shost->host_lock);
2624 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2625 spin_unlock_irq(shost->host_lock);
2626 if (lpfc_unreg_rpi(vport, ndlp)) {
2627 lpfc_els_free_iocb(phba, elsiocb);
2628 return 0;
2629 }
2630
dea31012005-04-17 16:05:31 -05002631 phba->fc_stat.elsXmitLOGO++;
2632 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002633 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002634 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002635 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002636 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002637 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002638
2639 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002640 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002641 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002642 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002643 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002644 return 1;
dea31012005-04-17 16:05:31 -05002645 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002646 return 0;
dea31012005-04-17 16:05:31 -05002647}
2648
James Smarte59058c2008-08-24 21:49:00 -04002649/**
James Smart3621a712009-04-06 18:47:14 -04002650 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002651 * @phba: pointer to lpfc hba data structure.
2652 * @cmdiocb: pointer to lpfc command iocb data structure.
2653 * @rspiocb: pointer to lpfc response iocb data structure.
2654 *
2655 * This routine is a generic completion callback function for ELS commands.
2656 * Specifically, it is the callback function which does not need to perform
2657 * any command specific operations. It is currently used by the ELS command
2658 * issuing routines for the ELS State Change Request (SCR),
2659 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2660 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2661 * certain debug loggings, this callback function simply invokes the
2662 * lpfc_els_chk_latt() routine to check whether link went down during the
2663 * discovery process.
2664 **/
dea31012005-04-17 16:05:31 -05002665static void
James Smart2e0fef82007-06-17 19:56:36 -05002666lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2667 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002668{
James Smart2e0fef82007-06-17 19:56:36 -05002669 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002670 IOCB_t *irsp;
2671
2672 irsp = &rspiocb->iocb;
2673
James Smart858c9f62007-06-17 19:56:39 -05002674 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2675 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2676 irsp->ulpStatus, irsp->un.ulpWord[4],
2677 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002678 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002679 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2680 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2681 irsp->ulpIoTag, irsp->ulpStatus,
2682 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002683 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002684 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002685 lpfc_els_free_iocb(phba, cmdiocb);
2686 return;
2687}
2688
James Smarte59058c2008-08-24 21:49:00 -04002689/**
James Smart3621a712009-04-06 18:47:14 -04002690 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002691 * @vport: pointer to a host virtual N_Port data structure.
2692 * @nportid: N_Port identifier to the remote node.
2693 * @retry: number of retries to the command IOCB.
2694 *
2695 * This routine issues a State Change Request (SCR) to a fabric node
2696 * on a @vport. The remote node @nportid is passed into the function. It
2697 * first search the @vport node list to find the matching ndlp. If no such
2698 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2699 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2700 * routine is invoked to send the SCR IOCB.
2701 *
2702 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2703 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2704 * will be stored into the context1 field of the IOCB for the completion
2705 * callback function to the SCR ELS command.
2706 *
2707 * Return code
2708 * 0 - Successfully issued scr command
2709 * 1 - Failed to issue scr command
2710 **/
dea31012005-04-17 16:05:31 -05002711int
James Smart2e0fef82007-06-17 19:56:36 -05002712lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002713{
James Smart2e0fef82007-06-17 19:56:36 -05002714 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002715 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002716 uint8_t *pcmd;
2717 uint16_t cmdsize;
2718 struct lpfc_nodelist *ndlp;
2719
James Smart92d7f7b2007-06-17 19:56:38 -05002720 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002721
James Smarte47c9092008-02-08 18:49:26 -05002722 ndlp = lpfc_findnode_did(vport, nportid);
2723 if (!ndlp) {
2724 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2725 if (!ndlp)
2726 return 1;
2727 lpfc_nlp_init(vport, ndlp, nportid);
2728 lpfc_enqueue_node(vport, ndlp);
2729 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2730 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2731 if (!ndlp)
2732 return 1;
2733 }
dea31012005-04-17 16:05:31 -05002734
James Smart2e0fef82007-06-17 19:56:36 -05002735 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2736 ndlp->nlp_DID, ELS_CMD_SCR);
2737
James Smart488d1462006-03-07 15:02:37 -05002738 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002739 /* This will trigger the release of the node just
2740 * allocated
2741 */
James Smart329f9bc2007-04-25 09:53:01 -04002742 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002743 return 1;
dea31012005-04-17 16:05:31 -05002744 }
2745
dea31012005-04-17 16:05:31 -05002746 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2747
2748 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002749 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002750
2751 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002752 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002753 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2754
James Smart858c9f62007-06-17 19:56:39 -05002755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2756 "Issue SCR: did:x%x",
2757 ndlp->nlp_DID, 0, 0);
2758
dea31012005-04-17 16:05:31 -05002759 phba->fc_stat.elsXmitSCR++;
2760 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002761 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2762 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002763 /* The additional lpfc_nlp_put will cause the following
2764 * lpfc_els_free_iocb routine to trigger the rlease of
2765 * the node.
2766 */
James Smart329f9bc2007-04-25 09:53:01 -04002767 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002768 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002769 return 1;
dea31012005-04-17 16:05:31 -05002770 }
James Smartfa4066b2008-01-11 01:53:27 -05002771 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2772 * trigger the release of node.
2773 */
James Smartcff261f2013-12-17 20:29:47 -05002774
James Smart329f9bc2007-04-25 09:53:01 -04002775 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002776 return 0;
dea31012005-04-17 16:05:31 -05002777}
2778
James Smarte59058c2008-08-24 21:49:00 -04002779/**
James Smart3621a712009-04-06 18:47:14 -04002780 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002781 * @vport: pointer to a host virtual N_Port data structure.
2782 * @nportid: N_Port identifier to the remote node.
2783 * @retry: number of retries to the command IOCB.
2784 *
2785 * This routine issues a Fibre Channel Address Resolution Response
2786 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2787 * is passed into the function. It first search the @vport node list to find
2788 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2789 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2790 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2791 *
2792 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2793 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2794 * will be stored into the context1 field of the IOCB for the completion
2795 * callback function to the PARPR ELS command.
2796 *
2797 * Return code
2798 * 0 - Successfully issued farpr command
2799 * 1 - Failed to issue farpr command
2800 **/
dea31012005-04-17 16:05:31 -05002801static int
James Smart2e0fef82007-06-17 19:56:36 -05002802lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002803{
James Smart2e0fef82007-06-17 19:56:36 -05002804 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002805 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002806 FARP *fp;
2807 uint8_t *pcmd;
2808 uint32_t *lp;
2809 uint16_t cmdsize;
2810 struct lpfc_nodelist *ondlp;
2811 struct lpfc_nodelist *ndlp;
2812
James Smart92d7f7b2007-06-17 19:56:38 -05002813 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002814
James Smarte47c9092008-02-08 18:49:26 -05002815 ndlp = lpfc_findnode_did(vport, nportid);
2816 if (!ndlp) {
2817 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2818 if (!ndlp)
2819 return 1;
2820 lpfc_nlp_init(vport, ndlp, nportid);
2821 lpfc_enqueue_node(vport, ndlp);
2822 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2823 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2824 if (!ndlp)
2825 return 1;
2826 }
James Smart2e0fef82007-06-17 19:56:36 -05002827
2828 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2829 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002830 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002831 /* This will trigger the release of the node just
2832 * allocated
2833 */
James Smart329f9bc2007-04-25 09:53:01 -04002834 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002835 return 1;
dea31012005-04-17 16:05:31 -05002836 }
2837
dea31012005-04-17 16:05:31 -05002838 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2839
2840 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002841 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002842
2843 /* Fill in FARPR payload */
2844 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002845 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002846 lp = (uint32_t *) pcmd;
2847 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002848 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002849 fp->Rflags = 0;
2850 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2851
James Smart92d7f7b2007-06-17 19:56:38 -05002852 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2853 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002854 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002855 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002856 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002857 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002858 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002859 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002860 }
2861
James Smart858c9f62007-06-17 19:56:39 -05002862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2863 "Issue FARPR: did:x%x",
2864 ndlp->nlp_DID, 0, 0);
2865
dea31012005-04-17 16:05:31 -05002866 phba->fc_stat.elsXmitFARPR++;
2867 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002868 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2869 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002870 /* The additional lpfc_nlp_put will cause the following
2871 * lpfc_els_free_iocb routine to trigger the release of
2872 * the node.
2873 */
James Smart329f9bc2007-04-25 09:53:01 -04002874 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002875 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002876 return 1;
dea31012005-04-17 16:05:31 -05002877 }
James Smartfa4066b2008-01-11 01:53:27 -05002878 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2879 * trigger the release of the node.
2880 */
James Smart329f9bc2007-04-25 09:53:01 -04002881 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002882 return 0;
dea31012005-04-17 16:05:31 -05002883}
2884
James Smarte59058c2008-08-24 21:49:00 -04002885/**
James Smart3621a712009-04-06 18:47:14 -04002886 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002887 * @vport: pointer to a host virtual N_Port data structure.
2888 * @nlp: pointer to a node-list data structure.
2889 *
2890 * This routine cancels the timer with a delayed IOCB-command retry for
2891 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2892 * removes the ELS retry event if it presents. In addition, if the
2893 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2894 * commands are sent for the @vport's nodes that require issuing discovery
2895 * ADISC.
2896 **/
dea31012005-04-17 16:05:31 -05002897void
James Smart2e0fef82007-06-17 19:56:36 -05002898lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002899{
James Smart2e0fef82007-06-17 19:56:36 -05002900 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002901 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002902
James Smart0d2b6b82008-06-14 22:52:47 -04002903 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2904 return;
James Smart2e0fef82007-06-17 19:56:36 -05002905 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002906 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002907 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002908 del_timer_sync(&nlp->nlp_delayfunc);
2909 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002910 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002911 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002912 /* Decrement nlp reference count held for the delayed retry */
2913 evtp = &nlp->els_retry_evt;
2914 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2915 }
James Smartfdcebe22006-03-07 15:04:01 -05002916 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002917 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002918 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002919 spin_unlock_irq(shost->host_lock);
2920 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002921 if (vport->port_state < LPFC_VPORT_READY) {
2922 /* Check if there are more ADISCs to be sent */
2923 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002924 } else {
2925 /* Check if there are more PLOGIs to be sent */
2926 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002927 if (vport->num_disc_nodes == 0) {
2928 spin_lock_irq(shost->host_lock);
2929 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2930 spin_unlock_irq(shost->host_lock);
2931 lpfc_can_disctmo(vport);
2932 lpfc_end_rscn(vport);
2933 }
James Smartfdcebe22006-03-07 15:04:01 -05002934 }
2935 }
2936 }
2937 return;
2938}
2939
James Smarte59058c2008-08-24 21:49:00 -04002940/**
James Smart3621a712009-04-06 18:47:14 -04002941 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002942 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2943 *
2944 * This routine is invoked by the ndlp delayed-function timer to check
2945 * whether there is any pending ELS retry event(s) with the node. If not, it
2946 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2947 * adds the delayed events to the HBA work list and invokes the
2948 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2949 * event. Note that lpfc_nlp_get() is called before posting the event to
2950 * the work list to hold reference count of ndlp so that it guarantees the
2951 * reference to ndlp will still be available when the worker thread gets
2952 * to the event associated with the ndlp.
2953 **/
James Smartfdcebe22006-03-07 15:04:01 -05002954void
dea31012005-04-17 16:05:31 -05002955lpfc_els_retry_delay(unsigned long ptr)
2956{
James Smart2e0fef82007-06-17 19:56:36 -05002957 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2958 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002959 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002960 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002961 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002962
James Smart92d7f7b2007-06-17 19:56:38 -05002963 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002964 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002965 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002966 return;
2967 }
2968
James Smartfa4066b2008-01-11 01:53:27 -05002969 /* We need to hold the node by incrementing the reference
2970 * count until the queued work is done
2971 */
2972 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002973 if (evtp->evt_arg1) {
2974 evtp->evt = LPFC_EVT_ELS_RETRY;
2975 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002976 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002977 }
James Smart92d7f7b2007-06-17 19:56:38 -05002978 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002979 return;
2980}
2981
James Smarte59058c2008-08-24 21:49:00 -04002982/**
James Smart3621a712009-04-06 18:47:14 -04002983 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002984 * @ndlp: pointer to a node-list data structure.
2985 *
2986 * This routine is the worker-thread handler for processing the @ndlp delayed
2987 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2988 * the last ELS command from the associated ndlp and invokes the proper ELS
2989 * function according to the delayed ELS command to retry the command.
2990 **/
dea31012005-04-17 16:05:31 -05002991void
2992lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2993{
James Smart2e0fef82007-06-17 19:56:36 -05002994 struct lpfc_vport *vport = ndlp->vport;
2995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarteb016562014-09-03 12:58:06 -04002996 uint32_t cmd, retry;
dea31012005-04-17 16:05:31 -05002997
James Smart2e0fef82007-06-17 19:56:36 -05002998 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002999 cmd = ndlp->nlp_last_elscmd;
3000 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05003001
3002 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05003003 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003004 return;
3005 }
3006
3007 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003008 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05003009 /*
3010 * If a discovery event readded nlp_delayfunc after timer
3011 * firing and before processing the timer, cancel the
3012 * nlp_delayfunc.
3013 */
3014 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05003015 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04003016 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05003017
3018 switch (cmd) {
3019 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003020 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05003021 break;
3022 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003023 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003024 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003026 }
dea31012005-04-17 16:05:31 -05003027 break;
3028 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05003029 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003030 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003031 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003032 }
dea31012005-04-17 16:05:31 -05003033 break;
3034 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05003035 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003036 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003037 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003038 }
dea31012005-04-17 16:05:31 -05003039 break;
3040 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05003041 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003042 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003043 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05003044 }
dea31012005-04-17 16:05:31 -05003045 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003046 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05003047 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3048 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003049 break;
dea31012005-04-17 16:05:31 -05003050 }
3051 return;
3052}
3053
James Smarte59058c2008-08-24 21:49:00 -04003054/**
James Smart3621a712009-04-06 18:47:14 -04003055 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003056 * @phba: pointer to lpfc hba data structure.
3057 * @cmdiocb: pointer to lpfc command iocb data structure.
3058 * @rspiocb: pointer to lpfc response iocb data structure.
3059 *
3060 * This routine makes a retry decision on an ELS command IOCB, which has
3061 * failed. The following ELS IOCBs use this function for retrying the command
3062 * when previously issued command responsed with error status: FLOGI, PLOGI,
3063 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3064 * returned error status, it makes the decision whether a retry shall be
3065 * issued for the command, and whether a retry shall be made immediately or
3066 * delayed. In the former case, the corresponding ELS command issuing-function
3067 * is called to retry the command. In the later case, the ELS command shall
3068 * be posted to the ndlp delayed event and delayed function timer set to the
3069 * ndlp for the delayed command issusing.
3070 *
3071 * Return code
3072 * 0 - No retry of els command is made
3073 * 1 - Immediate or delayed retry of els command is made
3074 **/
dea31012005-04-17 16:05:31 -05003075static int
James Smart2e0fef82007-06-17 19:56:36 -05003076lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3077 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003078{
James Smart2e0fef82007-06-17 19:56:36 -05003079 struct lpfc_vport *vport = cmdiocb->vport;
3080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3081 IOCB_t *irsp = &rspiocb->iocb;
3082 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3083 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003084 uint32_t *elscmd;
3085 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003086 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003087 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003088 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003089 uint32_t did;
dea31012005-04-17 16:05:31 -05003090
James Smart488d1462006-03-07 15:02:37 -05003091
dea31012005-04-17 16:05:31 -05003092 /* Note: context2 may be 0 for internal driver abort
3093 * of delays ELS command.
3094 */
3095
3096 if (pcmd && pcmd->virt) {
3097 elscmd = (uint32_t *) (pcmd->virt);
3098 cmd = *elscmd++;
3099 }
3100
James Smarte47c9092008-02-08 18:49:26 -05003101 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003102 did = ndlp->nlp_DID;
3103 else {
3104 /* We should only hit this case for retrying PLOGI */
3105 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003106 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003107 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3108 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003109 return 1;
3110 }
3111
James Smart858c9f62007-06-17 19:56:39 -05003112 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3113 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3114 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3115
dea31012005-04-17 16:05:31 -05003116 switch (irsp->ulpStatus) {
3117 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003118 break;
James Smart1151e3e2011-02-16 12:39:35 -05003119 case IOSTAT_REMOTE_STOP:
3120 if (phba->sli_rev == LPFC_SLI_REV4) {
3121 /* This IO was aborted by the target, we don't
3122 * know the rxid and because we did not send the
3123 * ABTS we cannot generate and RRQ.
3124 */
3125 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003126 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003127 }
3128 break;
dea31012005-04-17 16:05:31 -05003129 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003130 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003131 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003132 if (cmd == ELS_CMD_FLOGI) {
3133 if (PCI_DEVICE_ID_HORNET ==
3134 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003135 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003136 phba->pport->fc_myDID = 0;
3137 phba->alpa_map[0] = 0;
3138 phba->alpa_map[1] = 0;
3139 }
3140 }
James Smart2e0fef82007-06-17 19:56:36 -05003141 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003142 delay = 1000;
dea31012005-04-17 16:05:31 -05003143 retry = 1;
3144 break;
3145
James Smart92d7f7b2007-06-17 19:56:38 -05003146 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003147 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3148 "0124 Retry illegal cmd x%x "
3149 "retry:x%x delay:x%x\n",
3150 cmd, cmdiocb->retry, delay);
3151 retry = 1;
3152 /* All command's retry policy */
3153 maxretry = 8;
3154 if (cmdiocb->retry > 2)
3155 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003156 break;
3157
dea31012005-04-17 16:05:31 -05003158 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003159 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003160 retry = 1;
3161 if (cmdiocb->retry > 100)
3162 delay = 100;
3163 maxretry = 250;
3164 break;
3165
3166 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003167 delay = 100;
dea31012005-04-17 16:05:31 -05003168 retry = 1;
3169 break;
3170
James Smart858c9f62007-06-17 19:56:39 -05003171 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003172 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003173 if (cmd == ELS_CMD_PLOGI &&
3174 did == NameServer_DID) {
3175 /* Continue forever if plogi to */
3176 /* the nameserver fails */
3177 maxretry = 0;
3178 delay = 100;
3179 }
dea31012005-04-17 16:05:31 -05003180 retry = 1;
3181 break;
3182 }
3183 break;
3184
3185 case IOSTAT_NPORT_RJT:
3186 case IOSTAT_FABRIC_RJT:
3187 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3188 retry = 1;
3189 break;
3190 }
3191 break;
3192
3193 case IOSTAT_NPORT_BSY:
3194 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003195 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003196 retry = 1;
3197 break;
3198
3199 case IOSTAT_LS_RJT:
3200 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3201 /* Added for Vendor specifc support
3202 * Just keep retrying for these Rsn / Exp codes
3203 */
3204 switch (stat.un.b.lsRjtRsnCode) {
3205 case LSRJT_UNABLE_TPC:
3206 if (stat.un.b.lsRjtRsnCodeExp ==
3207 LSEXP_CMD_IN_PROGRESS) {
3208 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003209 delay = 1000;
dea31012005-04-17 16:05:31 -05003210 maxretry = 48;
3211 }
3212 retry = 1;
3213 break;
3214 }
James Smartffc95492010-06-07 15:23:17 -04003215 if (stat.un.b.lsRjtRsnCodeExp ==
3216 LSEXP_CANT_GIVE_DATA) {
3217 if (cmd == ELS_CMD_PLOGI) {
3218 delay = 1000;
3219 maxretry = 48;
3220 }
3221 retry = 1;
3222 break;
3223 }
James Smart4c1b64b2012-09-29 11:31:11 -04003224 if ((cmd == ELS_CMD_PLOGI) ||
3225 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003226 delay = 1000;
dea31012005-04-17 16:05:31 -05003227 maxretry = lpfc_max_els_tries + 1;
3228 retry = 1;
3229 break;
3230 }
James Smart92d7f7b2007-06-17 19:56:38 -05003231 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3232 (cmd == ELS_CMD_FDISC) &&
3233 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003234 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3235 "0125 FDISC Failed (x%x). "
3236 "Fabric out of resources\n",
3237 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003238 lpfc_vport_set_state(vport,
3239 FC_VPORT_NO_FABRIC_RSCS);
3240 }
dea31012005-04-17 16:05:31 -05003241 break;
3242
3243 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003244 if ((cmd == ELS_CMD_PLOGI) ||
3245 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003246 delay = 1000;
dea31012005-04-17 16:05:31 -05003247 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003248 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003249 /* FDISC retry policy */
3250 maxretry = 48;
3251 if (cmdiocb->retry >= 32)
3252 delay = 1000;
dea31012005-04-17 16:05:31 -05003253 }
3254 retry = 1;
3255 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003256
3257 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003258 /* There are some cases where switches return this
3259 * error when they are not ready and should be returning
3260 * Logical Busy. We should delay every time.
3261 */
3262 if (cmd == ELS_CMD_FDISC &&
3263 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3264 maxretry = 3;
3265 delay = 1000;
3266 retry = 1;
3267 break;
3268 }
James Smart92d7f7b2007-06-17 19:56:38 -05003269 case LSRJT_PROTOCOL_ERR:
3270 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3271 (cmd == ELS_CMD_FDISC) &&
3272 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3273 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3274 ) {
James Smarte8b62012007-08-02 11:10:09 -04003275 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003276 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003277 "Fabric Detected Bad WWN\n",
3278 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003279 lpfc_vport_set_state(vport,
3280 FC_VPORT_FABRIC_REJ_WWN);
3281 }
3282 break;
dea31012005-04-17 16:05:31 -05003283 }
3284 break;
3285
3286 case IOSTAT_INTERMED_RSP:
3287 case IOSTAT_BA_RJT:
3288 break;
3289
3290 default:
3291 break;
3292 }
3293
James Smart488d1462006-03-07 15:02:37 -05003294 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003295 retry = 1;
dea31012005-04-17 16:05:31 -05003296
James Smartdf9e1b52011-12-13 13:22:17 -05003297 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003298 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003299 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003300 /* FLOGI retry policy */
3301 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003302 /* retry FLOGI forever */
James Smart6eae4302015-04-07 15:07:23 -04003303 if (phba->link_flag != LS_LOOPBACK_MODE)
3304 maxretry = 0;
3305 else
3306 maxretry = 2;
3307
James Smart6669f9b2009-10-02 15:16:45 -04003308 if (cmdiocb->retry >= 100)
3309 delay = 5000;
3310 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003311 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003312 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3313 /* retry FDISCs every second up to devloss */
3314 retry = 1;
3315 maxretry = vport->cfg_devloss_tmo;
3316 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003317 }
3318
James Smart6669f9b2009-10-02 15:16:45 -04003319 cmdiocb->retry++;
3320 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003321 phba->fc_stat.elsRetryExceeded++;
3322 retry = 0;
3323 }
3324
James Smarted957682007-06-17 19:56:37 -05003325 if ((vport->load_flag & FC_UNLOADING) != 0)
3326 retry = 0;
3327
dea31012005-04-17 16:05:31 -05003328 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003329 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3330 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3331 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3333 "2849 Stop retry ELS command "
3334 "x%x to remote NPORT x%x, "
3335 "Data: x%x x%x\n", cmd, did,
3336 cmdiocb->retry, delay);
3337 return 0;
3338 }
3339 }
dea31012005-04-17 16:05:31 -05003340
3341 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3343 "0107 Retry ELS command x%x to remote "
3344 "NPORT x%x Data: x%x x%x\n",
3345 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003346
James Smart858c9f62007-06-17 19:56:39 -05003347 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3348 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003349 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3350 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003351 /* Don't reset timer for no resources */
3352
dea31012005-04-17 16:05:31 -05003353 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003354 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003355 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003356 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003357 }
3358
3359 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003360 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003361 phba->fc_stat.elsDelayRetry++;
3362 ndlp->nlp_retry = cmdiocb->retry;
3363
James Smart92d7f7b2007-06-17 19:56:38 -05003364 /* delay is specified in milliseconds */
3365 mod_timer(&ndlp->nlp_delayfunc,
3366 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003367 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003368 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003369 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003370
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003371 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003372 if (cmd == ELS_CMD_PRLI)
3373 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003374 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003375 else
3376 lpfc_nlp_set_state(vport, ndlp,
3377 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003378 ndlp->nlp_last_elscmd = cmd;
3379
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003380 return 1;
dea31012005-04-17 16:05:31 -05003381 }
3382 switch (cmd) {
3383 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003384 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003385 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003386 case ELS_CMD_FDISC:
3387 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3388 return 1;
dea31012005-04-17 16:05:31 -05003389 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003390 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003391 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003392 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003393 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003394 }
James Smart2e0fef82007-06-17 19:56:36 -05003395 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003396 return 1;
dea31012005-04-17 16:05:31 -05003397 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003398 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003399 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3400 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003401 return 1;
dea31012005-04-17 16:05:31 -05003402 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003403 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003404 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3405 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003406 return 1;
dea31012005-04-17 16:05:31 -05003407 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003408 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003409 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003410 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003411 return 1;
dea31012005-04-17 16:05:31 -05003412 }
3413 }
dea31012005-04-17 16:05:31 -05003414 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003415 if (logerr) {
3416 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3417 "0137 No retry ELS command x%x to remote "
3418 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3419 cmd, did, irsp->ulpStatus,
3420 irsp->un.ulpWord[4]);
3421 }
3422 else {
3423 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003424 "0108 No retry ELS command x%x to remote "
3425 "NPORT x%x Retried:%d Error:x%x/%x\n",
3426 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3427 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003428 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003429 return 0;
dea31012005-04-17 16:05:31 -05003430}
3431
James Smarte59058c2008-08-24 21:49:00 -04003432/**
James Smart3621a712009-04-06 18:47:14 -04003433 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003434 * @phba: pointer to lpfc hba data structure.
3435 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3436 *
3437 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3438 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3439 * checks to see whether there is a lpfc DMA buffer associated with the
3440 * response of the command IOCB. If so, it will be released before releasing
3441 * the lpfc DMA buffer associated with the IOCB itself.
3442 *
3443 * Return code
3444 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3445 **/
James Smart09372822008-01-11 01:52:54 -05003446static int
James Smart87af33f2007-10-27 13:37:43 -04003447lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3448{
3449 struct lpfc_dmabuf *buf_ptr;
3450
James Smarte59058c2008-08-24 21:49:00 -04003451 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003452 if (!list_empty(&buf_ptr1->list)) {
3453 list_remove_head(&buf_ptr1->list, buf_ptr,
3454 struct lpfc_dmabuf,
3455 list);
3456 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3457 kfree(buf_ptr);
3458 }
3459 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3460 kfree(buf_ptr1);
3461 return 0;
3462}
3463
James Smarte59058c2008-08-24 21:49:00 -04003464/**
James Smart3621a712009-04-06 18:47:14 -04003465 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003466 * @phba: pointer to lpfc hba data structure.
3467 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3468 *
3469 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3470 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3471 * pool.
3472 *
3473 * Return code
3474 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3475 **/
James Smart09372822008-01-11 01:52:54 -05003476static int
James Smart87af33f2007-10-27 13:37:43 -04003477lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3478{
3479 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3480 kfree(buf_ptr);
3481 return 0;
3482}
3483
James Smarte59058c2008-08-24 21:49:00 -04003484/**
James Smart3621a712009-04-06 18:47:14 -04003485 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003486 * @phba: pointer to lpfc hba data structure.
3487 * @elsiocb: pointer to lpfc els command iocb data structure.
3488 *
3489 * This routine frees a command IOCB and its associated resources. The
3490 * command IOCB data structure contains the reference to various associated
3491 * resources, these fields must be set to NULL if the associated reference
3492 * not present:
3493 * context1 - reference to ndlp
3494 * context2 - reference to cmd
3495 * context2->next - reference to rsp
3496 * context3 - reference to bpl
3497 *
3498 * It first properly decrements the reference count held on ndlp for the
3499 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3500 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3501 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3502 * adds the DMA buffer the @phba data structure for the delayed release.
3503 * If reference to the Buffer Pointer List (BPL) is present, the
3504 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3505 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3506 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3507 *
3508 * Return code
3509 * 0 - Success (currently, always return 0)
3510 **/
James Smart87af33f2007-10-27 13:37:43 -04003511int
James Smart329f9bc2007-04-25 09:53:01 -04003512lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003513{
3514 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003515 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003516
James Smarta8adb832007-10-27 13:37:53 -04003517 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3518 if (ndlp) {
3519 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3520 lpfc_nlp_put(ndlp);
3521
3522 /* If the ndlp is not being used by another discovery
3523 * thread, free it.
3524 */
3525 if (!lpfc_nlp_not_used(ndlp)) {
3526 /* If ndlp is being used by another discovery
3527 * thread, just clear NLP_DEFER_RM
3528 */
3529 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3530 }
3531 }
3532 else
3533 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003534 elsiocb->context1 = NULL;
3535 }
dea31012005-04-17 16:05:31 -05003536 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3537 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003538 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3539 /* Firmware could still be in progress of DMAing
3540 * payload, so don't free data buffer till after
3541 * a hbeat.
3542 */
3543 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3544 buf_ptr = elsiocb->context2;
3545 elsiocb->context2 = NULL;
3546 if (buf_ptr) {
3547 buf_ptr1 = NULL;
3548 spin_lock_irq(&phba->hbalock);
3549 if (!list_empty(&buf_ptr->list)) {
3550 list_remove_head(&buf_ptr->list,
3551 buf_ptr1, struct lpfc_dmabuf,
3552 list);
3553 INIT_LIST_HEAD(&buf_ptr1->list);
3554 list_add_tail(&buf_ptr1->list,
3555 &phba->elsbuf);
3556 phba->elsbuf_cnt++;
3557 }
3558 INIT_LIST_HEAD(&buf_ptr->list);
3559 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3560 phba->elsbuf_cnt++;
3561 spin_unlock_irq(&phba->hbalock);
3562 }
3563 } else {
3564 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3565 lpfc_els_free_data(phba, buf_ptr1);
3566 }
dea31012005-04-17 16:05:31 -05003567 }
3568
3569 if (elsiocb->context3) {
3570 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003571 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003572 }
James Bottomley604a3e32005-10-29 10:28:33 -05003573 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003574 return 0;
3575}
3576
James Smarte59058c2008-08-24 21:49:00 -04003577/**
James Smart3621a712009-04-06 18:47:14 -04003578 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003579 * @phba: pointer to lpfc hba data structure.
3580 * @cmdiocb: pointer to lpfc command iocb data structure.
3581 * @rspiocb: pointer to lpfc response iocb data structure.
3582 *
3583 * This routine is the completion callback function to the Logout (LOGO)
3584 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3585 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3586 * release the ndlp if it has the last reference remaining (reference count
3587 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3588 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3589 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3590 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3591 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3592 * IOCB data structure.
3593 **/
dea31012005-04-17 16:05:31 -05003594static void
James Smart2e0fef82007-06-17 19:56:36 -05003595lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3596 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003597{
James Smart2e0fef82007-06-17 19:56:36 -05003598 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3599 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003600 IOCB_t *irsp;
3601
3602 irsp = &rspiocb->iocb;
3603 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3604 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3605 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003606 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003607 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3608 "0109 ACC to LOGO completes to NPort x%x "
3609 "Data: x%x x%x x%x\n",
3610 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3611 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003612
3613 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3614 /* NPort Recovery mode or node is just allocated */
3615 if (!lpfc_nlp_not_used(ndlp)) {
3616 /* If the ndlp is being used by another discovery
3617 * thread, just unregister the RPI.
3618 */
3619 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003620 } else {
3621 /* Indicate the node has already released, should
3622 * not reference to it from within lpfc_els_free_iocb.
3623 */
3624 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003625 }
dea31012005-04-17 16:05:31 -05003626 }
James Smart73d91e52011-10-10 21:32:10 -04003627
3628 /*
3629 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003630 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003631 */
dea31012005-04-17 16:05:31 -05003632 lpfc_els_free_iocb(phba, cmdiocb);
dea31012005-04-17 16:05:31 -05003633}
3634
James Smarte59058c2008-08-24 21:49:00 -04003635/**
James Smart3621a712009-04-06 18:47:14 -04003636 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003637 * @phba: pointer to lpfc hba data structure.
3638 * @pmb: pointer to the driver internal queue element for mailbox command.
3639 *
3640 * This routine is the completion callback function for unregister default
3641 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3642 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3643 * decrements the ndlp reference count held for this completion callback
3644 * function. After that, it invokes the lpfc_nlp_not_used() to check
3645 * whether there is only one reference left on the ndlp. If so, it will
3646 * perform one more decrement and trigger the release of the ndlp.
3647 **/
James Smart858c9f62007-06-17 19:56:39 -05003648void
3649lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3650{
3651 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3652 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3653
3654 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003655 pmb->context2 = NULL;
3656
James Smart858c9f62007-06-17 19:56:39 -05003657 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3658 kfree(mp);
3659 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003660 if (ndlp) {
James Smartbe6bb942015-04-07 15:07:22 -04003661 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
3662 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3663 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag,
3664 atomic_read(&ndlp->kref.refcount),
3665 ndlp->nlp_usg_map, ndlp);
James Smart086a3452012-08-14 14:25:21 -04003666 if (NLP_CHK_NODE_ACT(ndlp)) {
3667 lpfc_nlp_put(ndlp);
3668 /* This is the end of the default RPI cleanup logic for
3669 * this ndlp. If no other discovery threads are using
3670 * this ndlp, free all resources associated with it.
3671 */
3672 lpfc_nlp_not_used(ndlp);
3673 } else {
3674 lpfc_drop_node(ndlp->vport, ndlp);
3675 }
James Smarta8adb832007-10-27 13:37:53 -04003676 }
James Smart3772a992009-05-22 14:50:54 -04003677
James Smart858c9f62007-06-17 19:56:39 -05003678 return;
3679}
3680
James Smarte59058c2008-08-24 21:49:00 -04003681/**
James Smart3621a712009-04-06 18:47:14 -04003682 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003683 * @phba: pointer to lpfc hba data structure.
3684 * @cmdiocb: pointer to lpfc command iocb data structure.
3685 * @rspiocb: pointer to lpfc response iocb data structure.
3686 *
3687 * This routine is the completion callback function for ELS Response IOCB
3688 * command. In normal case, this callback function just properly sets the
3689 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3690 * field in the command IOCB is not NULL, the referred mailbox command will
3691 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3692 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3693 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3694 * routine shall be invoked trying to release the ndlp if no other threads
3695 * are currently referring it.
3696 **/
dea31012005-04-17 16:05:31 -05003697static void
James Smart858c9f62007-06-17 19:56:39 -05003698lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003699 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003700{
James Smart2e0fef82007-06-17 19:56:36 -05003701 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3702 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3703 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003704 IOCB_t *irsp;
3705 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003706 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003707 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003708 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003709
James Smart33ccf8d2006-08-17 11:57:58 -04003710 irsp = &rspiocb->iocb;
3711
dea31012005-04-17 16:05:31 -05003712 if (cmdiocb->context_un.mbox)
3713 mbox = cmdiocb->context_un.mbox;
3714
James Smartfa4066b2008-01-11 01:53:27 -05003715 /* First determine if this is a LS_RJT cmpl. Note, this callback
3716 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3717 */
James Smart87af33f2007-10-27 13:37:43 -04003718 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003719 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3720 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003721 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003722 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003723 */
3724 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3725 ls_rjt = 1;
3726 }
3727
dea31012005-04-17 16:05:31 -05003728 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003729 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003730 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003731 mp = (struct lpfc_dmabuf *) mbox->context1;
3732 if (mp) {
3733 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3734 kfree(mp);
3735 }
James Smart329f9bc2007-04-25 09:53:01 -04003736 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003737 }
James Smart58da1ff2008-04-07 10:15:56 -04003738 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3739 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003740 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003741 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003742 /* Indicate the node has already released,
3743 * should not reference to it from within
3744 * the routine lpfc_els_free_iocb.
3745 */
3746 cmdiocb->context1 = NULL;
3747 }
dea31012005-04-17 16:05:31 -05003748 goto out;
3749 }
3750
James Smart858c9f62007-06-17 19:56:39 -05003751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003752 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003753 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003754 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003755 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003756 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3757 "0110 ELS response tag x%x completes "
3758 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3759 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3760 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3761 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3762 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003763 if (mbox) {
3764 if ((rspiocb->iocb.ulpStatus == 0)
3765 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003766 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003767 /* Increment reference count to ndlp to hold the
3768 * reference to ndlp for the callback function.
3769 */
James Smart329f9bc2007-04-25 09:53:01 -04003770 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003771 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003772 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3773 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3774 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3775 }
3776 else {
3777 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3778 ndlp->nlp_prev_state = ndlp->nlp_state;
3779 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003780 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003781 }
James Smart0b727fe2007-10-27 13:37:25 -04003782 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003783 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003784 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003785 else
3786 /* Decrement the ndlp reference count we
3787 * set for this failed mailbox command.
3788 */
3789 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003790
3791 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3792 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3793 "0138 ELS rsp: Cannot issue reg_login for x%x "
3794 "Data: x%x x%x x%x\n",
3795 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3796 ndlp->nlp_rpi);
3797
James Smartfa4066b2008-01-11 01:53:27 -05003798 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003799 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003800 /* Indicate node has already been released,
3801 * should not reference to it from within
3802 * the routine lpfc_els_free_iocb.
3803 */
3804 cmdiocb->context1 = NULL;
3805 }
dea31012005-04-17 16:05:31 -05003806 } else {
James Smart858c9f62007-06-17 19:56:39 -05003807 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3808 if (!lpfc_error_lost_link(irsp) &&
3809 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003810 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003811 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003812 /* Indicate node has already been
3813 * released, should not reference
3814 * to it from within the routine
3815 * lpfc_els_free_iocb.
3816 */
3817 cmdiocb->context1 = NULL;
3818 }
dea31012005-04-17 16:05:31 -05003819 }
3820 }
James Smart14691152006-12-02 13:34:28 -05003821 mp = (struct lpfc_dmabuf *) mbox->context1;
3822 if (mp) {
3823 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3824 kfree(mp);
3825 }
3826 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003827 }
3828out:
James Smart58da1ff2008-04-07 10:15:56 -04003829 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003830 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003831 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003832 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003833
3834 /* If the node is not being used by another discovery thread,
3835 * and we are sending a reject, we are done with it.
3836 * Release driver reference count here and free associated
3837 * resources.
3838 */
3839 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003840 if (lpfc_nlp_not_used(ndlp))
3841 /* Indicate node has already been released,
3842 * should not reference to it from within
3843 * the routine lpfc_els_free_iocb.
3844 */
3845 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003846 }
James Smart87af33f2007-10-27 13:37:43 -04003847
dea31012005-04-17 16:05:31 -05003848 lpfc_els_free_iocb(phba, cmdiocb);
3849 return;
3850}
3851
James Smarte59058c2008-08-24 21:49:00 -04003852/**
James Smart3621a712009-04-06 18:47:14 -04003853 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003854 * @vport: pointer to a host virtual N_Port data structure.
3855 * @flag: the els command code to be accepted.
3856 * @oldiocb: pointer to the original lpfc command iocb data structure.
3857 * @ndlp: pointer to a node-list data structure.
3858 * @mbox: pointer to the driver internal queue element for mailbox command.
3859 *
3860 * This routine prepares and issues an Accept (ACC) response IOCB
3861 * command. It uses the @flag to properly set up the IOCB field for the
3862 * specific ACC response command to be issued and invokes the
3863 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3864 * @mbox pointer is passed in, it will be put into the context_un.mbox
3865 * field of the IOCB for the completion callback function to issue the
3866 * mailbox command to the HBA later when callback is invoked.
3867 *
3868 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3869 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3870 * will be stored into the context1 field of the IOCB for the completion
3871 * callback function to the corresponding response ELS IOCB command.
3872 *
3873 * Return code
3874 * 0 - Successfully issued acc response
3875 * 1 - Failed to issue acc response
3876 **/
dea31012005-04-17 16:05:31 -05003877int
James Smart2e0fef82007-06-17 19:56:36 -05003878lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3879 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003880 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003881{
James Smart2e0fef82007-06-17 19:56:36 -05003882 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3883 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003884 IOCB_t *icmd;
3885 IOCB_t *oldcmd;
3886 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003887 uint8_t *pcmd;
James Smartd6de08c2015-12-16 18:11:53 -05003888 struct serv_parm *sp;
dea31012005-04-17 16:05:31 -05003889 uint16_t cmdsize;
3890 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003891 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003892
dea31012005-04-17 16:05:31 -05003893 oldcmd = &oldiocb->iocb;
3894
3895 switch (flag) {
3896 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003897 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003898 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3899 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003900 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003901 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003902 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003903 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003904 return 1;
dea31012005-04-17 16:05:31 -05003905 }
James Smart2e0fef82007-06-17 19:56:36 -05003906
dea31012005-04-17 16:05:31 -05003907 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003908 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3909 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003910 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3911 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003912 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003913
3914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3915 "Issue ACC: did:x%x flg:x%x",
3916 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003917 break;
James Smartd6de08c2015-12-16 18:11:53 -05003918 case ELS_CMD_FLOGI:
dea31012005-04-17 16:05:31 -05003919 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003920 cmdsize = (sizeof(struct serv_parm) + 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)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003924 return 1;
James Smart488d1462006-03-07 15:02:37 -05003925
dea31012005-04-17 16:05:31 -05003926 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003927 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3928 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003929 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3930
3931 if (mbox)
3932 elsiocb->context_un.mbox = mbox;
3933
3934 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003935 pcmd += sizeof(uint32_t);
James Smartd6de08c2015-12-16 18:11:53 -05003936 sp = (struct serv_parm *)pcmd;
3937
3938 if (flag == ELS_CMD_FLOGI) {
3939 /* Copy the received service parameters back */
3940 memcpy(sp, &phba->fc_fabparam,
3941 sizeof(struct serv_parm));
3942
3943 /* Clear the F_Port bit */
3944 sp->cmn.fPort = 0;
3945
3946 /* Mark all class service parameters as invalid */
3947 sp->cls1.classValid = 0;
3948 sp->cls2.classValid = 0;
3949 sp->cls3.classValid = 0;
3950 sp->cls4.classValid = 0;
3951
3952 /* Copy our worldwide names */
3953 memcpy(&sp->portName, &vport->fc_sparam.portName,
3954 sizeof(struct lpfc_name));
3955 memcpy(&sp->nodeName, &vport->fc_sparam.nodeName,
3956 sizeof(struct lpfc_name));
3957 } else {
3958 memcpy(pcmd, &vport->fc_sparam,
3959 sizeof(struct serv_parm));
3960 }
James Smart858c9f62007-06-17 19:56:39 -05003961
3962 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smartd6de08c2015-12-16 18:11:53 -05003963 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003964 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003965 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003966 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003967 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003968 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003969 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3970 if (!elsiocb)
3971 return 1;
3972
3973 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003974 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3975 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003976 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3977
3978 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003979 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003980 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3981 els_pkt_ptr = (ELS_PKT *) pcmd;
3982 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003983
3984 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3985 "Issue ACC PRLO: did:x%x flg:x%x",
3986 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003987 break;
dea31012005-04-17 16:05:31 -05003988 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003989 return 1;
dea31012005-04-17 16:05:31 -05003990 }
dea31012005-04-17 16:05:31 -05003991 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003992 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3993 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003994 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3995 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003996 elsiocb->iotag, elsiocb->iocb.ulpContext,
3997 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003998 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003999 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05004000 spin_lock_irq(shost->host_lock);
James Smart7c5e5182015-05-22 10:42:43 -04004001 if (!(ndlp->nlp_flag & NLP_RPI_REGISTERED ||
4002 ndlp->nlp_flag & NLP_REG_LOGIN_SEND))
4003 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05004004 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004005 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
4006 } else {
James Smart858c9f62007-06-17 19:56:39 -05004007 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004008 }
4009
4010 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004011 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004012 if (rc == IOCB_ERROR) {
4013 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004014 return 1;
dea31012005-04-17 16:05:31 -05004015 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004016 return 0;
dea31012005-04-17 16:05:31 -05004017}
4018
James Smarte59058c2008-08-24 21:49:00 -04004019/**
James Smart3621a712009-04-06 18:47:14 -04004020 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004021 * @vport: pointer to a virtual N_Port data structure.
4022 * @rejectError:
4023 * @oldiocb: pointer to the original lpfc command iocb data structure.
4024 * @ndlp: pointer to a node-list data structure.
4025 * @mbox: pointer to the driver internal queue element for mailbox command.
4026 *
4027 * This routine prepares and issue an Reject (RJT) response IOCB
4028 * command. If a @mbox pointer is passed in, it will be put into the
4029 * context_un.mbox field of the IOCB for the completion callback function
4030 * to issue to the HBA later.
4031 *
4032 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4033 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4034 * will be stored into the context1 field of the IOCB for the completion
4035 * callback function to the reject response ELS IOCB command.
4036 *
4037 * Return code
4038 * 0 - Successfully issued reject response
4039 * 1 - Failed to issue reject response
4040 **/
dea31012005-04-17 16:05:31 -05004041int
James Smart2e0fef82007-06-17 19:56:36 -05004042lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05004043 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
4044 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05004045{
James Smart2e0fef82007-06-17 19:56:36 -05004046 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004047 IOCB_t *icmd;
4048 IOCB_t *oldcmd;
4049 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004050 uint8_t *pcmd;
4051 uint16_t cmdsize;
4052 int rc;
4053
James Smart92d7f7b2007-06-17 19:56:38 -05004054 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05004055 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4056 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05004057 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004058 return 1;
dea31012005-04-17 16:05:31 -05004059
4060 icmd = &elsiocb->iocb;
4061 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004062 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4063 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05004064 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4065
4066 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05004067 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004068 *((uint32_t *) (pcmd)) = rejectError;
4069
James Smart51ef4c22007-08-02 11:10:31 -04004070 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05004071 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004072
dea31012005-04-17 16:05:31 -05004073 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004074 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4075 "0129 Xmit ELS RJT x%x response tag x%x "
4076 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4077 "rpi x%x\n",
4078 rejectError, elsiocb->iotag,
4079 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4080 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004081 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4082 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4083 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4084
dea31012005-04-17 16:05:31 -05004085 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004086 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004087 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004088
dea31012005-04-17 16:05:31 -05004089 if (rc == IOCB_ERROR) {
4090 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004091 return 1;
dea31012005-04-17 16:05:31 -05004092 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004093 return 0;
dea31012005-04-17 16:05:31 -05004094}
4095
James Smarte59058c2008-08-24 21:49:00 -04004096/**
James Smart3621a712009-04-06 18:47:14 -04004097 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004098 * @vport: pointer to a virtual N_Port data structure.
4099 * @oldiocb: pointer to the original lpfc command iocb data structure.
4100 * @ndlp: pointer to a node-list data structure.
4101 *
4102 * This routine prepares and issues an Accept (ACC) response to Address
4103 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4104 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4105 *
4106 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4107 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4108 * will be stored into the context1 field of the IOCB for the completion
4109 * callback function to the ADISC Accept response ELS IOCB command.
4110 *
4111 * Return code
4112 * 0 - Successfully issued acc adisc response
4113 * 1 - Failed to issue adisc acc response
4114 **/
dea31012005-04-17 16:05:31 -05004115int
James Smart2e0fef82007-06-17 19:56:36 -05004116lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4117 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004118{
James Smart2e0fef82007-06-17 19:56:36 -05004119 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004120 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004121 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004122 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004123 uint8_t *pcmd;
4124 uint16_t cmdsize;
4125 int rc;
4126
James Smart92d7f7b2007-06-17 19:56:38 -05004127 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004128 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4129 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004130 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004131 return 1;
dea31012005-04-17 16:05:31 -05004132
dea31012005-04-17 16:05:31 -05004133 icmd = &elsiocb->iocb;
4134 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004135 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4136 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004137
4138 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004139 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4140 "0130 Xmit ADISC ACC response iotag x%x xri: "
4141 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4142 elsiocb->iotag, elsiocb->iocb.ulpContext,
4143 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4144 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004145 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4146
4147 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004148 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004149
4150 ap = (ADISC *) (pcmd);
4151 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004152 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4153 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004154 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004155
James Smart858c9f62007-06-17 19:56:39 -05004156 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4157 "Issue ACC ADISC: did:x%x flg:x%x",
4158 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4159
dea31012005-04-17 16:05:31 -05004160 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004161 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004162 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004163 if (rc == IOCB_ERROR) {
4164 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004165 return 1;
dea31012005-04-17 16:05:31 -05004166 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004167 return 0;
dea31012005-04-17 16:05:31 -05004168}
4169
James Smarte59058c2008-08-24 21:49:00 -04004170/**
James Smart3621a712009-04-06 18:47:14 -04004171 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004172 * @vport: pointer to a virtual N_Port data structure.
4173 * @oldiocb: pointer to the original lpfc command iocb data structure.
4174 * @ndlp: pointer to a node-list data structure.
4175 *
4176 * This routine prepares and issues an Accept (ACC) response to Process
4177 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4178 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4179 *
4180 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4181 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4182 * will be stored into the context1 field of the IOCB for the completion
4183 * callback function to the PRLI Accept response ELS IOCB command.
4184 *
4185 * Return code
4186 * 0 - Successfully issued acc prli response
4187 * 1 - Failed to issue acc prli response
4188 **/
dea31012005-04-17 16:05:31 -05004189int
James Smart2e0fef82007-06-17 19:56:36 -05004190lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004191 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004192{
James Smart2e0fef82007-06-17 19:56:36 -05004193 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004194 PRLI *npr;
4195 lpfc_vpd_t *vpd;
4196 IOCB_t *icmd;
4197 IOCB_t *oldcmd;
4198 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004199 uint8_t *pcmd;
4200 uint16_t cmdsize;
4201 int rc;
4202
James Smart92d7f7b2007-06-17 19:56:38 -05004203 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004204 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004205 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004206 if (!elsiocb)
4207 return 1;
dea31012005-04-17 16:05:31 -05004208
dea31012005-04-17 16:05:31 -05004209 icmd = &elsiocb->iocb;
4210 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004211 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4212 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4213
James Smart5b8bd0c2007-04-25 09:52:49 -04004214 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004215 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4216 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4217 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4218 elsiocb->iotag, elsiocb->iocb.ulpContext,
4219 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4220 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004221 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4222
4223 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004224 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004225
4226 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004227 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004228
4229 npr = (PRLI *) pcmd;
4230 vpd = &phba->vpd;
4231 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004232 * If the remote port is a target and our firmware version is 3.20 or
4233 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004234 */
James Smart0d2b6b82008-06-14 22:52:47 -04004235 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4236 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004237 npr->ConfmComplAllowed = 1;
4238 npr->Retry = 1;
4239 npr->TaskRetryIdReq = 1;
4240 }
4241
4242 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4243 npr->estabImagePair = 1;
4244 npr->readXferRdyDis = 1;
4245 npr->ConfmComplAllowed = 1;
4246
4247 npr->prliType = PRLI_FCP_TYPE;
4248 npr->initiatorFunc = 1;
4249
James Smart858c9f62007-06-17 19:56:39 -05004250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4251 "Issue ACC PRLI: did:x%x flg:x%x",
4252 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4253
dea31012005-04-17 16:05:31 -05004254 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004255 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004256
James Smart3772a992009-05-22 14:50:54 -04004257 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004258 if (rc == IOCB_ERROR) {
4259 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004260 return 1;
dea31012005-04-17 16:05:31 -05004261 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004262 return 0;
dea31012005-04-17 16:05:31 -05004263}
4264
James Smarte59058c2008-08-24 21:49:00 -04004265/**
James Smart3621a712009-04-06 18:47:14 -04004266 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004267 * @vport: pointer to a virtual N_Port data structure.
4268 * @format: rnid command format.
4269 * @oldiocb: pointer to the original lpfc command iocb data structure.
4270 * @ndlp: pointer to a node-list data structure.
4271 *
4272 * This routine issues a Request Node Identification Data (RNID) Accept
4273 * (ACC) response. It constructs the RNID ACC response command according to
4274 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4275 * issue the response. Note that this command does not need to hold the ndlp
4276 * reference count for the callback. So, the ndlp reference count taken by
4277 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4278 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4279 * there is no ndlp reference available.
4280 *
4281 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4282 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4283 * will be stored into the context1 field of the IOCB for the completion
4284 * callback function. However, for the RNID Accept Response ELS command,
4285 * this is undone later by this routine after the IOCB is allocated.
4286 *
4287 * Return code
4288 * 0 - Successfully issued acc rnid response
4289 * 1 - Failed to issue acc rnid response
4290 **/
dea31012005-04-17 16:05:31 -05004291static int
James Smart2e0fef82007-06-17 19:56:36 -05004292lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004293 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004294{
James Smart2e0fef82007-06-17 19:56:36 -05004295 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004296 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004297 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004298 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004299 uint8_t *pcmd;
4300 uint16_t cmdsize;
4301 int rc;
4302
James Smart92d7f7b2007-06-17 19:56:38 -05004303 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4304 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004305 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004306 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004307
James Smart2e0fef82007-06-17 19:56:36 -05004308 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4309 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004310 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004311 return 1;
dea31012005-04-17 16:05:31 -05004312
dea31012005-04-17 16:05:31 -05004313 icmd = &elsiocb->iocb;
4314 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004315 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4316 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4317
James Smart5b8bd0c2007-04-25 09:52:49 -04004318 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004319 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4320 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4321 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004322 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004323 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004324 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004325
James Smart92d7f7b2007-06-17 19:56:38 -05004326 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004327 rn = (RNID *) (pcmd);
4328 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004329 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4330 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4331 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004332 switch (format) {
4333 case 0:
4334 rn->SpecificLen = 0;
4335 break;
4336 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004337 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004338 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004339 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004340 rn->un.topologyDisc.unitType = RNID_HBA;
4341 rn->un.topologyDisc.physPort = 0;
4342 rn->un.topologyDisc.attachedNodes = 0;
4343 break;
4344 default:
4345 rn->CommonLen = 0;
4346 rn->SpecificLen = 0;
4347 break;
4348 }
4349
James Smart858c9f62007-06-17 19:56:39 -05004350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4351 "Issue ACC RNID: did:x%x flg:x%x",
4352 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4353
dea31012005-04-17 16:05:31 -05004354 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004355 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004356
James Smart3772a992009-05-22 14:50:54 -04004357 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004358 if (rc == IOCB_ERROR) {
4359 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004360 return 1;
dea31012005-04-17 16:05:31 -05004361 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004362 return 0;
dea31012005-04-17 16:05:31 -05004363}
4364
James Smarte59058c2008-08-24 21:49:00 -04004365/**
James Smart19ca7602010-11-20 23:11:55 -05004366 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4367 * @vport: pointer to a virtual N_Port data structure.
4368 * @iocb: pointer to the lpfc command iocb data structure.
4369 * @ndlp: pointer to a node-list data structure.
4370 *
4371 * Return
4372 **/
4373static void
4374lpfc_els_clear_rrq(struct lpfc_vport *vport,
4375 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4376{
4377 struct lpfc_hba *phba = vport->phba;
4378 uint8_t *pcmd;
4379 struct RRQ *rrq;
4380 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004381 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004382 struct lpfc_node_rrq *prrq;
4383
4384
4385 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4386 pcmd += sizeof(uint32_t);
4387 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004388 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004389 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004390
4391 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4392 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4393 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004394 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004395 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004396 rxid,
4397 iocb->iotag, iocb->iocb.ulpContext);
4398
4399 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4400 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4401 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004402 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004403 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004404 else
4405 xri = rxid;
4406 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004407 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004408 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004409 return;
4410}
4411
4412/**
James Smart12265f62010-10-22 11:05:53 -04004413 * lpfc_els_rsp_echo_acc - Issue echo acc response
4414 * @vport: pointer to a virtual N_Port data structure.
4415 * @data: pointer to echo data to return in the accept.
4416 * @oldiocb: pointer to the original lpfc command iocb data structure.
4417 * @ndlp: pointer to a node-list data structure.
4418 *
4419 * Return code
4420 * 0 - Successfully issued acc echo response
4421 * 1 - Failed to issue acc echo response
4422 **/
4423static int
4424lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4425 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4426{
4427 struct lpfc_hba *phba = vport->phba;
4428 struct lpfc_iocbq *elsiocb;
James Smart12265f62010-10-22 11:05:53 -04004429 uint8_t *pcmd;
4430 uint16_t cmdsize;
4431 int rc;
4432
James Smart12265f62010-10-22 11:05:53 -04004433 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4434
James Smartbf086112011-08-21 21:48:13 -04004435 /* The accumulated length can exceed the BPL_SIZE. For
4436 * now, use this as the limit
4437 */
4438 if (cmdsize > LPFC_BPL_SIZE)
4439 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004440 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4441 ndlp->nlp_DID, ELS_CMD_ACC);
4442 if (!elsiocb)
4443 return 1;
4444
James Smart7851fe22011-07-22 18:36:52 -04004445 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4446 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4447
James Smart12265f62010-10-22 11:05:53 -04004448 /* Xmit ECHO ACC response tag <ulpIoTag> */
4449 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4450 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4451 elsiocb->iotag, elsiocb->iocb.ulpContext);
4452 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4453 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4454 pcmd += sizeof(uint32_t);
4455 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4456
4457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4458 "Issue ACC ECHO: did:x%x flg:x%x",
4459 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4460
4461 phba->fc_stat.elsXmitACC++;
4462 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004463
4464 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4465 if (rc == IOCB_ERROR) {
4466 lpfc_els_free_iocb(phba, elsiocb);
4467 return 1;
4468 }
4469 return 0;
4470}
4471
4472/**
James Smart3621a712009-04-06 18:47:14 -04004473 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004474 * @vport: pointer to a host virtual N_Port data structure.
4475 *
4476 * This routine issues Address Discover (ADISC) ELS commands to those
4477 * N_Ports which are in node port recovery state and ADISC has not been issued
4478 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4479 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4480 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4481 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4482 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4483 * IOCBs quit for later pick up. On the other hand, after walking through
4484 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4485 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4486 * no more ADISC need to be sent.
4487 *
4488 * Return code
4489 * The number of N_Ports with adisc issued.
4490 **/
dea31012005-04-17 16:05:31 -05004491int
James Smart2e0fef82007-06-17 19:56:36 -05004492lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004493{
James Smart2e0fef82007-06-17 19:56:36 -05004494 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004495 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004496 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004497
James Smart685f0bf2007-04-25 09:53:08 -04004498 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004499 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004500 if (!NLP_CHK_NODE_ACT(ndlp))
4501 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004502 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4503 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4504 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004505 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004506 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004507 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004508 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004509 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4510 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004511 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004512 vport->num_disc_nodes++;
4513 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004514 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004515 spin_lock_irq(shost->host_lock);
4516 vport->fc_flag |= FC_NLP_MORE;
4517 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004518 break;
dea31012005-04-17 16:05:31 -05004519 }
4520 }
4521 }
4522 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004523 spin_lock_irq(shost->host_lock);
4524 vport->fc_flag &= ~FC_NLP_MORE;
4525 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004526 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004527 return sentadisc;
dea31012005-04-17 16:05:31 -05004528}
4529
James Smarte59058c2008-08-24 21:49:00 -04004530/**
James Smart3621a712009-04-06 18:47:14 -04004531 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004532 * @vport: pointer to a host virtual N_Port data structure.
4533 *
4534 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4535 * which are in node port recovery state, with a @vport. Each time an ELS
4536 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4537 * the per @vport number of discover count (num_disc_nodes) shall be
4538 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4539 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4540 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4541 * later pick up. On the other hand, after walking through all the ndlps with
4542 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4543 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4544 * PLOGI need to be sent.
4545 *
4546 * Return code
4547 * The number of N_Ports with plogi issued.
4548 **/
dea31012005-04-17 16:05:31 -05004549int
James Smart2e0fef82007-06-17 19:56:36 -05004550lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004551{
James Smart2e0fef82007-06-17 19:56:36 -05004552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004553 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004554 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004555
James Smart2e0fef82007-06-17 19:56:36 -05004556 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4557 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004558 if (!NLP_CHK_NODE_ACT(ndlp))
4559 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004560 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
James Smart8b017a32015-05-21 13:55:18 -04004561 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4562 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4563 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
James Smart685f0bf2007-04-25 09:53:08 -04004564 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004565 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4566 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004567 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004568 vport->num_disc_nodes++;
4569 if (vport->num_disc_nodes >=
James Smart8b017a32015-05-21 13:55:18 -04004570 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004571 spin_lock_irq(shost->host_lock);
4572 vport->fc_flag |= FC_NLP_MORE;
4573 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004574 break;
dea31012005-04-17 16:05:31 -05004575 }
4576 }
4577 }
James Smart87af33f2007-10-27 13:37:43 -04004578 if (sentplogi) {
4579 lpfc_set_disctmo(vport);
4580 }
4581 else {
James Smart2e0fef82007-06-17 19:56:36 -05004582 spin_lock_irq(shost->host_lock);
4583 vport->fc_flag &= ~FC_NLP_MORE;
4584 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004585 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004586 return sentplogi;
dea31012005-04-17 16:05:31 -05004587}
4588
James Smart86478872015-05-21 13:55:21 -04004589void
4590lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc *desc,
4591 uint32_t word0)
4592{
4593
4594 desc->tag = cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG);
4595 desc->payload.els_req = word0;
4596 desc->length = cpu_to_be32(sizeof(desc->payload));
4597}
4598
4599void
4600lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc *desc,
4601 uint8_t *page_a0, uint8_t *page_a2)
4602{
4603 uint16_t wavelength;
4604 uint16_t temperature;
4605 uint16_t rx_power;
4606 uint16_t tx_bias;
4607 uint16_t tx_power;
4608 uint16_t vcc;
4609 uint16_t flag = 0;
4610 struct sff_trasnceiver_codes_byte4 *trasn_code_byte4;
4611 struct sff_trasnceiver_codes_byte5 *trasn_code_byte5;
4612
4613 desc->tag = cpu_to_be32(RDP_SFP_DESC_TAG);
4614
4615 trasn_code_byte4 = (struct sff_trasnceiver_codes_byte4 *)
4616 &page_a0[SSF_TRANSCEIVER_CODE_B4];
4617 trasn_code_byte5 = (struct sff_trasnceiver_codes_byte5 *)
4618 &page_a0[SSF_TRANSCEIVER_CODE_B5];
4619
4620 if ((trasn_code_byte4->fc_sw_laser) ||
4621 (trasn_code_byte5->fc_sw_laser_sl) ||
4622 (trasn_code_byte5->fc_sw_laser_sn)) { /* check if its short WL */
4623 flag |= (SFP_FLAG_PT_SWLASER << SFP_FLAG_PT_SHIFT);
4624 } else if (trasn_code_byte4->fc_lw_laser) {
4625 wavelength = (page_a0[SSF_WAVELENGTH_B1] << 8) |
4626 page_a0[SSF_WAVELENGTH_B0];
4627 if (wavelength == SFP_WAVELENGTH_LC1310)
4628 flag |= SFP_FLAG_PT_LWLASER_LC1310 << SFP_FLAG_PT_SHIFT;
4629 if (wavelength == SFP_WAVELENGTH_LL1550)
4630 flag |= SFP_FLAG_PT_LWLASER_LL1550 << SFP_FLAG_PT_SHIFT;
4631 }
4632 /* check if its SFP+ */
4633 flag |= ((page_a0[SSF_IDENTIFIER] == SFF_PG0_IDENT_SFP) ?
4634 SFP_FLAG_CT_SFP_PLUS : SFP_FLAG_CT_UNKNOWN)
4635 << SFP_FLAG_CT_SHIFT;
4636
4637 /* check if its OPTICAL */
4638 flag |= ((page_a0[SSF_CONNECTOR] == SFF_PG0_CONNECTOR_LC) ?
4639 SFP_FLAG_IS_OPTICAL_PORT : 0)
4640 << SFP_FLAG_IS_OPTICAL_SHIFT;
4641
4642 temperature = (page_a2[SFF_TEMPERATURE_B1] << 8 |
4643 page_a2[SFF_TEMPERATURE_B0]);
4644 vcc = (page_a2[SFF_VCC_B1] << 8 |
4645 page_a2[SFF_VCC_B0]);
4646 tx_power = (page_a2[SFF_TXPOWER_B1] << 8 |
4647 page_a2[SFF_TXPOWER_B0]);
4648 tx_bias = (page_a2[SFF_TX_BIAS_CURRENT_B1] << 8 |
4649 page_a2[SFF_TX_BIAS_CURRENT_B0]);
4650 rx_power = (page_a2[SFF_RXPOWER_B1] << 8 |
4651 page_a2[SFF_RXPOWER_B0]);
4652 desc->sfp_info.temperature = cpu_to_be16(temperature);
4653 desc->sfp_info.rx_power = cpu_to_be16(rx_power);
4654 desc->sfp_info.tx_bias = cpu_to_be16(tx_bias);
4655 desc->sfp_info.tx_power = cpu_to_be16(tx_power);
4656 desc->sfp_info.vcc = cpu_to_be16(vcc);
4657
4658 desc->sfp_info.flags = cpu_to_be16(flag);
4659 desc->length = cpu_to_be32(sizeof(desc->sfp_info));
4660}
4661
4662void
4663lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc *desc,
4664 READ_LNK_VAR *stat)
4665{
4666 uint32_t type;
4667
4668 desc->tag = cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG);
4669
4670 type = VN_PT_PHY_PF_PORT << VN_PT_PHY_SHIFT;
4671
4672 desc->info.port_type = cpu_to_be32(type);
4673
4674 desc->info.link_status.link_failure_cnt =
4675 cpu_to_be32(stat->linkFailureCnt);
4676 desc->info.link_status.loss_of_synch_cnt =
4677 cpu_to_be32(stat->lossSyncCnt);
4678 desc->info.link_status.loss_of_signal_cnt =
4679 cpu_to_be32(stat->lossSignalCnt);
4680 desc->info.link_status.primitive_seq_proto_err =
4681 cpu_to_be32(stat->primSeqErrCnt);
4682 desc->info.link_status.invalid_trans_word =
4683 cpu_to_be32(stat->invalidXmitWord);
4684 desc->info.link_status.invalid_crc_cnt = cpu_to_be32(stat->crcCnt);
4685
4686 desc->length = cpu_to_be32(sizeof(desc->info));
4687}
4688
4689void
4690lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc *desc, struct lpfc_hba *phba)
4691{
4692 uint16_t rdp_cap = 0;
4693 uint16_t rdp_speed;
4694
4695 desc->tag = cpu_to_be32(RDP_PORT_SPEED_DESC_TAG);
4696
4697 switch (phba->sli4_hba.link_state.speed) {
4698 case LPFC_FC_LA_SPEED_1G:
4699 rdp_speed = RDP_PS_1GB;
4700 break;
4701 case LPFC_FC_LA_SPEED_2G:
4702 rdp_speed = RDP_PS_2GB;
4703 break;
4704 case LPFC_FC_LA_SPEED_4G:
4705 rdp_speed = RDP_PS_4GB;
4706 break;
4707 case LPFC_FC_LA_SPEED_8G:
4708 rdp_speed = RDP_PS_8GB;
4709 break;
4710 case LPFC_FC_LA_SPEED_10G:
4711 rdp_speed = RDP_PS_10GB;
4712 break;
4713 case LPFC_FC_LA_SPEED_16G:
4714 rdp_speed = RDP_PS_16GB;
4715 break;
4716 case LPFC_FC_LA_SPEED_32G:
4717 rdp_speed = RDP_PS_32GB;
4718 break;
4719 default:
4720 rdp_speed = RDP_PS_UNKNOWN;
4721 break;
4722 }
4723
4724 desc->info.port_speed.speed = cpu_to_be16(rdp_speed);
4725
James Smartd38dd522015-08-31 16:48:17 -04004726 if (phba->lmt & LMT_32Gb)
4727 rdp_cap |= RDP_PS_32GB;
James Smart86478872015-05-21 13:55:21 -04004728 if (phba->lmt & LMT_16Gb)
4729 rdp_cap |= RDP_PS_16GB;
4730 if (phba->lmt & LMT_10Gb)
4731 rdp_cap |= RDP_PS_10GB;
4732 if (phba->lmt & LMT_8Gb)
4733 rdp_cap |= RDP_PS_8GB;
4734 if (phba->lmt & LMT_4Gb)
4735 rdp_cap |= RDP_PS_4GB;
4736 if (phba->lmt & LMT_2Gb)
4737 rdp_cap |= RDP_PS_2GB;
4738 if (phba->lmt & LMT_1Gb)
4739 rdp_cap |= RDP_PS_1GB;
4740
4741 if (rdp_cap == 0)
4742 rdp_cap = RDP_CAP_UNKNOWN;
4743
4744 desc->info.port_speed.capabilities = cpu_to_be16(rdp_cap);
4745 desc->length = cpu_to_be32(sizeof(desc->info));
4746}
4747
4748void
4749lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc *desc,
4750 struct lpfc_hba *phba)
4751{
4752
4753 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4754
4755 memcpy(desc->port_names.wwnn, phba->wwnn,
4756 sizeof(desc->port_names.wwnn));
4757
4758 memcpy(desc->port_names.wwpn, &phba->wwpn,
4759 sizeof(desc->port_names.wwpn));
4760
4761 desc->length = cpu_to_be32(sizeof(desc->port_names));
4762}
4763
4764void
4765lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc *desc,
4766 struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4767{
4768
4769 desc->tag = cpu_to_be32(RDP_PORT_NAMES_DESC_TAG);
4770 if (vport->fc_flag & FC_FABRIC) {
4771 memcpy(desc->port_names.wwnn, &vport->fabric_nodename,
4772 sizeof(desc->port_names.wwnn));
4773
4774 memcpy(desc->port_names.wwpn, &vport->fabric_portname,
4775 sizeof(desc->port_names.wwpn));
4776 } else { /* Point to Point */
4777 memcpy(desc->port_names.wwnn, &ndlp->nlp_nodename,
4778 sizeof(desc->port_names.wwnn));
4779
4780 memcpy(desc->port_names.wwnn, &ndlp->nlp_portname,
4781 sizeof(desc->port_names.wwpn));
4782 }
4783
4784 desc->length = cpu_to_be32(sizeof(desc->port_names));
4785}
4786
4787void
4788lpfc_els_rdp_cmpl(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context,
4789 int status)
4790{
4791 struct lpfc_nodelist *ndlp = rdp_context->ndlp;
4792 struct lpfc_vport *vport = ndlp->vport;
4793 struct lpfc_iocbq *elsiocb;
4794 IOCB_t *icmd;
4795 uint8_t *pcmd;
4796 struct ls_rjt *stat;
4797 struct fc_rdp_res_frame *rdp_res;
4798 uint32_t cmdsize;
4799 int rc;
4800
4801 if (status != SUCCESS)
4802 goto error;
4803 cmdsize = sizeof(struct fc_rdp_res_frame);
4804
4805 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize,
4806 lpfc_max_els_tries, rdp_context->ndlp,
4807 rdp_context->ndlp->nlp_DID, ELS_CMD_ACC);
4808 lpfc_nlp_put(ndlp);
4809 if (!elsiocb)
4810 goto free_rdp_context;
4811
4812 icmd = &elsiocb->iocb;
4813 icmd->ulpContext = rdp_context->rx_id;
4814 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4815
4816 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4817 "2171 Xmit RDP response tag x%x xri x%x, "
4818 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
4819 elsiocb->iotag, elsiocb->iocb.ulpContext,
4820 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4821 ndlp->nlp_rpi);
4822 rdp_res = (struct fc_rdp_res_frame *)
4823 (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4824 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4825 memset(pcmd, 0, sizeof(struct fc_rdp_res_frame));
4826 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4827
4828 /* For RDP payload */
4829 lpfc_rdp_res_link_service(&rdp_res->link_service_desc, ELS_CMD_RDP);
4830
4831 lpfc_rdp_res_sfp_desc(&rdp_res->sfp_desc,
4832 rdp_context->page_a0, rdp_context->page_a2);
4833 lpfc_rdp_res_speed(&rdp_res->portspeed_desc, phba);
4834 lpfc_rdp_res_link_error(&rdp_res->link_error_desc,
4835 &rdp_context->link_stat);
4836 lpfc_rdp_res_diag_port_names(&rdp_res->diag_port_names_desc, phba);
4837 lpfc_rdp_res_attach_port_names(&rdp_res->attached_port_names_desc,
4838 vport, ndlp);
4839 rdp_res->length = cpu_to_be32(RDP_DESC_PAYLOAD_SIZE);
4840
4841 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4842
4843 phba->fc_stat.elsXmitACC++;
4844 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4845 if (rc == IOCB_ERROR)
4846 lpfc_els_free_iocb(phba, elsiocb);
4847
4848 kfree(rdp_context);
4849
4850 return;
4851error:
4852 cmdsize = 2 * sizeof(uint32_t);
4853 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, lpfc_max_els_tries,
4854 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
4855 lpfc_nlp_put(ndlp);
4856 if (!elsiocb)
4857 goto free_rdp_context;
4858
4859 icmd = &elsiocb->iocb;
4860 icmd->ulpContext = rdp_context->rx_id;
4861 icmd->unsli3.rcvsli3.ox_id = rdp_context->ox_id;
4862 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4863
4864 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
4865 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
4866 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4867
4868 phba->fc_stat.elsXmitLSRJT++;
4869 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4870 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4871
4872 if (rc == IOCB_ERROR)
4873 lpfc_els_free_iocb(phba, elsiocb);
4874free_rdp_context:
4875 kfree(rdp_context);
4876}
4877
4878int
4879lpfc_get_rdp_info(struct lpfc_hba *phba, struct lpfc_rdp_context *rdp_context)
4880{
4881 LPFC_MBOXQ_t *mbox = NULL;
4882 int rc;
4883
4884 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4885 if (!mbox) {
4886 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX | LOG_ELS,
4887 "7105 failed to allocate mailbox memory");
4888 return 1;
4889 }
4890
4891 if (lpfc_sli4_dump_page_a0(phba, mbox))
4892 goto prep_mbox_fail;
4893 mbox->vport = rdp_context->ndlp->vport;
4894 mbox->mbox_cmpl = lpfc_mbx_cmpl_rdp_page_a0;
4895 mbox->context2 = (struct lpfc_rdp_context *) rdp_context;
4896 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4897 if (rc == MBX_NOT_FINISHED)
4898 goto issue_mbox_fail;
4899
4900 return 0;
4901
4902prep_mbox_fail:
4903issue_mbox_fail:
4904 mempool_free(mbox, phba->mbox_mem_pool);
4905 return 1;
4906}
4907
4908/*
4909 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
4910 * @vport: pointer to a host virtual N_Port data structure.
4911 * @cmdiocb: pointer to lpfc command iocb data structure.
4912 * @ndlp: pointer to a node-list data structure.
4913 *
4914 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
4915 * IOCB. First, the payload of the unsolicited RDP is checked.
4916 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
4917 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
4918 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
4919 * gather all data and send RDP response.
4920 *
4921 * Return code
4922 * 0 - Sent the acc response
4923 * 1 - Sent the reject response.
4924 */
4925static int
4926lpfc_els_rcv_rdp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4927 struct lpfc_nodelist *ndlp)
4928{
4929 struct lpfc_hba *phba = vport->phba;
4930 struct lpfc_dmabuf *pcmd;
4931 uint8_t rjt_err, rjt_expl = LSEXP_NOTHING_MORE;
4932 struct fc_rdp_req_frame *rdp_req;
4933 struct lpfc_rdp_context *rdp_context;
4934 IOCB_t *cmd = NULL;
4935 struct ls_rjt stat;
4936
4937 if (phba->sli_rev < LPFC_SLI_REV4 ||
4938 (bf_get(lpfc_sli_intf_if_type,
4939 &phba->sli4_hba.sli_intf) !=
4940 LPFC_SLI_INTF_IF_TYPE_2)) {
4941 rjt_err = LSRJT_UNABLE_TPC;
4942 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4943 goto error;
4944 }
4945
4946 if (phba->sli_rev < LPFC_SLI_REV4 || (phba->hba_flag & HBA_FCOE_MODE)) {
4947 rjt_err = LSRJT_UNABLE_TPC;
4948 rjt_expl = LSEXP_REQ_UNSUPPORTED;
4949 goto error;
4950 }
4951
4952 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4953 rdp_req = (struct fc_rdp_req_frame *) pcmd->virt;
4954
4955
4956 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4957 "2422 ELS RDP Request "
4958 "dec len %d tag x%x port_id %d len %d\n",
4959 be32_to_cpu(rdp_req->rdp_des_length),
4960 be32_to_cpu(rdp_req->nport_id_desc.tag),
4961 be32_to_cpu(rdp_req->nport_id_desc.nport_id),
4962 be32_to_cpu(rdp_req->nport_id_desc.length));
4963
4964 if (sizeof(struct fc_rdp_nport_desc) !=
4965 be32_to_cpu(rdp_req->rdp_des_length))
4966 goto rjt_logerr;
4967 if (RDP_N_PORT_DESC_TAG != be32_to_cpu(rdp_req->nport_id_desc.tag))
4968 goto rjt_logerr;
4969 if (RDP_NPORT_ID_SIZE !=
4970 be32_to_cpu(rdp_req->nport_id_desc.length))
4971 goto rjt_logerr;
4972 rdp_context = kmalloc(sizeof(struct lpfc_rdp_context), GFP_KERNEL);
4973 if (!rdp_context) {
4974 rjt_err = LSRJT_UNABLE_TPC;
4975 goto error;
4976 }
4977
4978 memset(rdp_context, 0, sizeof(struct lpfc_rdp_context));
4979 cmd = &cmdiocb->iocb;
4980 rdp_context->ndlp = lpfc_nlp_get(ndlp);
4981 rdp_context->ox_id = cmd->unsli3.rcvsli3.ox_id;
4982 rdp_context->rx_id = cmd->ulpContext;
4983 rdp_context->cmpl = lpfc_els_rdp_cmpl;
4984 if (lpfc_get_rdp_info(phba, rdp_context)) {
4985 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_ELS,
4986 "2423 Unable to send mailbox");
4987 kfree(rdp_context);
4988 rjt_err = LSRJT_UNABLE_TPC;
4989 lpfc_nlp_put(ndlp);
4990 goto error;
4991 }
4992
4993 return 0;
4994
4995rjt_logerr:
4996 rjt_err = LSRJT_LOGICAL_ERR;
4997
4998error:
4999 memset(&stat, 0, sizeof(stat));
5000 stat.un.b.lsRjtRsnCode = rjt_err;
5001 stat.un.b.lsRjtRsnCodeExp = rjt_expl;
5002 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5003 return 1;
5004}
5005
5006
James Smart8b017a32015-05-21 13:55:18 -04005007static void
5008lpfc_els_lcb_rsp(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5009{
5010 MAILBOX_t *mb;
5011 IOCB_t *icmd;
5012 uint8_t *pcmd;
5013 struct lpfc_iocbq *elsiocb;
5014 struct lpfc_nodelist *ndlp;
5015 struct ls_rjt *stat;
James Smart481ad962015-05-22 10:42:35 -04005016 union lpfc_sli4_cfg_shdr *shdr;
James Smart8b017a32015-05-21 13:55:18 -04005017 struct lpfc_lcb_context *lcb_context;
5018 struct fc_lcb_res_frame *lcb_res;
James Smart481ad962015-05-22 10:42:35 -04005019 uint32_t cmdsize, shdr_status, shdr_add_status;
James Smart8b017a32015-05-21 13:55:18 -04005020 int rc;
5021
5022 mb = &pmb->u.mb;
James Smart8b017a32015-05-21 13:55:18 -04005023 lcb_context = (struct lpfc_lcb_context *)pmb->context1;
5024 ndlp = lcb_context->ndlp;
5025 pmb->context1 = NULL;
5026 pmb->context2 = NULL;
5027
James Smart481ad962015-05-22 10:42:35 -04005028 shdr = (union lpfc_sli4_cfg_shdr *)
5029 &pmb->u.mqe.un.beacon_config.header.cfg_shdr;
5030 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5031 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5032
5033 lpfc_printf_log(phba, KERN_INFO, LOG_MBOX,
5034 "0194 SET_BEACON_CONFIG mailbox "
5035 "completed with status x%x add_status x%x,"
5036 " mbx status x%x\n",
5037 shdr_status, shdr_add_status, mb->mbxStatus);
5038
5039 if (mb->mbxStatus && !(shdr_status &&
5040 shdr_add_status == ADD_STATUS_OPERATION_ALREADY_ACTIVE)) {
James Smart8b017a32015-05-21 13:55:18 -04005041 mempool_free(pmb, phba->mbox_mem_pool);
5042 goto error;
5043 }
5044
5045 mempool_free(pmb, phba->mbox_mem_pool);
James Smart8b017a32015-05-21 13:55:18 -04005046 cmdsize = sizeof(struct fc_lcb_res_frame);
5047 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5048 lpfc_max_els_tries, ndlp,
5049 ndlp->nlp_DID, ELS_CMD_ACC);
5050
5051 /* Decrement the ndlp reference count from previous mbox command */
5052 lpfc_nlp_put(ndlp);
5053
5054 if (!elsiocb)
5055 goto free_lcb_context;
5056
5057 lcb_res = (struct fc_lcb_res_frame *)
5058 (((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5059
5060 icmd = &elsiocb->iocb;
5061 icmd->ulpContext = lcb_context->rx_id;
5062 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5063
5064 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5065 *((uint32_t *)(pcmd)) = ELS_CMD_ACC;
5066 lcb_res->lcb_sub_command = lcb_context->sub_command;
5067 lcb_res->lcb_type = lcb_context->type;
5068 lcb_res->lcb_frequency = lcb_context->frequency;
5069 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5070 phba->fc_stat.elsXmitACC++;
5071 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5072 if (rc == IOCB_ERROR)
5073 lpfc_els_free_iocb(phba, elsiocb);
5074
5075 kfree(lcb_context);
5076 return;
5077
5078error:
5079 cmdsize = sizeof(struct fc_lcb_res_frame);
5080 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5081 lpfc_max_els_tries, ndlp,
5082 ndlp->nlp_DID, ELS_CMD_LS_RJT);
5083 lpfc_nlp_put(ndlp);
5084 if (!elsiocb)
5085 goto free_lcb_context;
5086
5087 icmd = &elsiocb->iocb;
5088 icmd->ulpContext = lcb_context->rx_id;
5089 icmd->unsli3.rcvsli3.ox_id = lcb_context->ox_id;
5090 pcmd = (uint8_t *)(((struct lpfc_dmabuf *)elsiocb->context2)->virt);
5091
5092 *((uint32_t *)(pcmd)) = ELS_CMD_LS_RJT;
5093 stat = (struct ls_rjt *)(pcmd + sizeof(uint32_t));
5094 stat->un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5095
5096 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5097 phba->fc_stat.elsXmitLSRJT++;
5098 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5099 if (rc == IOCB_ERROR)
5100 lpfc_els_free_iocb(phba, elsiocb);
5101free_lcb_context:
5102 kfree(lcb_context);
5103}
5104
5105static int
5106lpfc_sli4_set_beacon(struct lpfc_vport *vport,
5107 struct lpfc_lcb_context *lcb_context,
5108 uint32_t beacon_state)
5109{
5110 struct lpfc_hba *phba = vport->phba;
5111 LPFC_MBOXQ_t *mbox = NULL;
5112 uint32_t len;
5113 int rc;
5114
5115 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5116 if (!mbox)
5117 return 1;
5118
5119 len = sizeof(struct lpfc_mbx_set_beacon_config) -
5120 sizeof(struct lpfc_sli4_cfg_mhdr);
5121 lpfc_sli4_config(phba, mbox, LPFC_MBOX_SUBSYSTEM_COMMON,
5122 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG, len,
5123 LPFC_SLI4_MBX_EMBED);
5124 mbox->context1 = (void *)lcb_context;
5125 mbox->vport = phba->pport;
5126 mbox->mbox_cmpl = lpfc_els_lcb_rsp;
5127 bf_set(lpfc_mbx_set_beacon_port_num, &mbox->u.mqe.un.beacon_config,
5128 phba->sli4_hba.physical_port);
5129 bf_set(lpfc_mbx_set_beacon_state, &mbox->u.mqe.un.beacon_config,
5130 beacon_state);
5131 bf_set(lpfc_mbx_set_beacon_port_type, &mbox->u.mqe.un.beacon_config, 1);
5132 bf_set(lpfc_mbx_set_beacon_duration, &mbox->u.mqe.un.beacon_config, 0);
5133 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5134 if (rc == MBX_NOT_FINISHED) {
5135 mempool_free(mbox, phba->mbox_mem_pool);
5136 return 1;
5137 }
5138
5139 return 0;
5140}
5141
5142
5143/**
5144 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5145 * @vport: pointer to a host virtual N_Port data structure.
5146 * @cmdiocb: pointer to lpfc command iocb data structure.
5147 * @ndlp: pointer to a node-list data structure.
5148 *
5149 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5150 * First, the payload of the unsolicited LCB is checked.
5151 * Then based on Subcommand beacon will either turn on or off.
5152 *
5153 * Return code
5154 * 0 - Sent the acc response
5155 * 1 - Sent the reject response.
5156 **/
5157static int
5158lpfc_els_rcv_lcb(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5159 struct lpfc_nodelist *ndlp)
5160{
5161 struct lpfc_hba *phba = vport->phba;
5162 struct lpfc_dmabuf *pcmd;
James Smart8b017a32015-05-21 13:55:18 -04005163 uint8_t *lp;
5164 struct fc_lcb_request_frame *beacon;
5165 struct lpfc_lcb_context *lcb_context;
5166 uint8_t state, rjt_err;
5167 struct ls_rjt stat;
5168
James Smart8b017a32015-05-21 13:55:18 -04005169 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
5170 lp = (uint8_t *)pcmd->virt;
5171 beacon = (struct fc_lcb_request_frame *)pcmd->virt;
5172
5173 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5174 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5175 "type x%x frequency %x duration x%x\n",
5176 lp[0], lp[1], lp[2],
5177 beacon->lcb_command,
5178 beacon->lcb_sub_command,
5179 beacon->lcb_type,
5180 beacon->lcb_frequency,
5181 be16_to_cpu(beacon->lcb_duration));
5182
5183 if (phba->sli_rev < LPFC_SLI_REV4 ||
5184 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) !=
5185 LPFC_SLI_INTF_IF_TYPE_2)) {
5186 rjt_err = LSRJT_CMD_UNSUPPORTED;
5187 goto rjt;
5188 }
James Smart8b017a32015-05-21 13:55:18 -04005189
5190 if (phba->hba_flag & HBA_FCOE_MODE) {
5191 rjt_err = LSRJT_CMD_UNSUPPORTED;
5192 goto rjt;
5193 }
5194 if (beacon->lcb_frequency == 0) {
5195 rjt_err = LSRJT_CMD_UNSUPPORTED;
5196 goto rjt;
5197 }
5198 if ((beacon->lcb_type != LPFC_LCB_GREEN) &&
5199 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5200 rjt_err = LSRJT_CMD_UNSUPPORTED;
5201 goto rjt;
5202 }
5203 if ((beacon->lcb_sub_command != LPFC_LCB_ON) &&
5204 (beacon->lcb_sub_command != LPFC_LCB_OFF)) {
5205 rjt_err = LSRJT_CMD_UNSUPPORTED;
5206 goto rjt;
5207 }
5208 if ((beacon->lcb_sub_command == LPFC_LCB_ON) &&
5209 (beacon->lcb_type != LPFC_LCB_GREEN) &&
5210 (beacon->lcb_type != LPFC_LCB_AMBER)) {
5211 rjt_err = LSRJT_CMD_UNSUPPORTED;
5212 goto rjt;
5213 }
5214 if (be16_to_cpu(beacon->lcb_duration) != 0) {
5215 rjt_err = LSRJT_CMD_UNSUPPORTED;
5216 goto rjt;
5217 }
5218
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305219 lcb_context = kmalloc(sizeof(*lcb_context), GFP_KERNEL);
5220 if (!lcb_context) {
5221 rjt_err = LSRJT_UNABLE_TPC;
5222 goto rjt;
5223 }
5224
James Smart8b017a32015-05-21 13:55:18 -04005225 state = (beacon->lcb_sub_command == LPFC_LCB_ON) ? 1 : 0;
5226 lcb_context->sub_command = beacon->lcb_sub_command;
5227 lcb_context->type = beacon->lcb_type;
5228 lcb_context->frequency = beacon->lcb_frequency;
5229 lcb_context->ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
5230 lcb_context->rx_id = cmdiocb->iocb.ulpContext;
5231 lcb_context->ndlp = lpfc_nlp_get(ndlp);
5232 if (lpfc_sli4_set_beacon(vport, lcb_context, state)) {
5233 lpfc_printf_vlog(ndlp->vport, KERN_ERR,
5234 LOG_ELS, "0193 failed to send mail box");
Sudip Mukherjeee7950422015-09-23 19:02:32 +05305235 kfree(lcb_context);
James Smart8b017a32015-05-21 13:55:18 -04005236 lpfc_nlp_put(ndlp);
5237 rjt_err = LSRJT_UNABLE_TPC;
5238 goto rjt;
5239 }
5240 return 0;
5241rjt:
5242 memset(&stat, 0, sizeof(stat));
5243 stat.un.b.lsRjtRsnCode = rjt_err;
5244 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5245 return 1;
5246}
5247
5248
James Smarte59058c2008-08-24 21:49:00 -04005249/**
James Smart3621a712009-04-06 18:47:14 -04005250 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04005251 * @vport: pointer to a host virtual N_Port data structure.
5252 *
5253 * This routine cleans up any Registration State Change Notification
5254 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5255 * @vport together with the host_lock is used to prevent multiple thread
5256 * trying to access the RSCN array on a same @vport at the same time.
5257 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005258void
James Smart2e0fef82007-06-17 19:56:36 -05005259lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005260{
James Smart2e0fef82007-06-17 19:56:36 -05005261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5262 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005263 int i;
5264
James Smart7f5f3d02008-02-08 18:50:14 -05005265 spin_lock_irq(shost->host_lock);
5266 if (vport->fc_rscn_flush) {
5267 /* Another thread is walking fc_rscn_id_list on this vport */
5268 spin_unlock_irq(shost->host_lock);
5269 return;
5270 }
5271 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5272 vport->fc_rscn_flush = 1;
5273 spin_unlock_irq(shost->host_lock);
5274
James Smart2e0fef82007-06-17 19:56:36 -05005275 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005276 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05005277 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05005278 }
James Smart2e0fef82007-06-17 19:56:36 -05005279 spin_lock_irq(shost->host_lock);
5280 vport->fc_rscn_id_cnt = 0;
5281 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
5282 spin_unlock_irq(shost->host_lock);
5283 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05005284 /* Indicate we are done walking this fc_rscn_id_list */
5285 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005286}
5287
James Smarte59058c2008-08-24 21:49:00 -04005288/**
James Smart3621a712009-04-06 18:47:14 -04005289 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04005290 * @vport: pointer to a host virtual N_Port data structure.
5291 * @did: remote destination port identifier.
5292 *
5293 * This routine checks whether there is any pending Registration State
5294 * Configuration Notification (RSCN) to a @did on @vport.
5295 *
5296 * Return code
5297 * None zero - The @did matched with a pending rscn
5298 * 0 - not able to match @did with a pending rscn
5299 **/
dea31012005-04-17 16:05:31 -05005300int
James Smart2e0fef82007-06-17 19:56:36 -05005301lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05005302{
5303 D_ID ns_did;
5304 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05005305 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05005306 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05005307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05005308
5309 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05005310
5311 /* Never match fabric nodes for RSCNs */
5312 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05005313 return 0;
dea31012005-04-17 16:05:31 -05005314
5315 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05005316 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005317 return did;
dea31012005-04-17 16:05:31 -05005318
James Smart7f5f3d02008-02-08 18:50:14 -05005319 spin_lock_irq(shost->host_lock);
5320 if (vport->fc_rscn_flush) {
5321 /* Another thread is walking fc_rscn_id_list on this vport */
5322 spin_unlock_irq(shost->host_lock);
5323 return 0;
5324 }
5325 /* Indicate we are walking fc_rscn_id_list on this vport */
5326 vport->fc_rscn_flush = 1;
5327 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05005328 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05005329 lp = vport->fc_rscn_id_list[i]->virt;
5330 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5331 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005332 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05005333 rscn_did.un.word = be32_to_cpu(*lp++);
5334 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05005335 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
5336 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04005337 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5338 && (ns_did.un.b.area == rscn_did.un.b.area)
5339 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05005340 goto return_did_out;
dea31012005-04-17 16:05:31 -05005341 break;
James Smarteaf15d52008-12-04 22:39:29 -05005342 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05005343 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
5344 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05005345 goto return_did_out;
dea31012005-04-17 16:05:31 -05005346 break;
James Smarteaf15d52008-12-04 22:39:29 -05005347 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05005348 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05005349 goto return_did_out;
dea31012005-04-17 16:05:31 -05005350 break;
James Smarteaf15d52008-12-04 22:39:29 -05005351 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05005352 goto return_did_out;
dea31012005-04-17 16:05:31 -05005353 }
5354 }
James Smart92d7f7b2007-06-17 19:56:38 -05005355 }
James Smart7f5f3d02008-02-08 18:50:14 -05005356 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5357 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005358 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05005359return_did_out:
5360 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5361 vport->fc_rscn_flush = 0;
5362 return did;
dea31012005-04-17 16:05:31 -05005363}
5364
James Smarte59058c2008-08-24 21:49:00 -04005365/**
James Smart3621a712009-04-06 18:47:14 -04005366 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04005367 * @vport: pointer to a host virtual N_Port data structure.
5368 *
5369 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5370 * state machine for a @vport's nodes that are with pending RSCN (Registration
5371 * State Change Notification).
5372 *
5373 * Return code
5374 * 0 - Successful (currently alway return 0)
5375 **/
dea31012005-04-17 16:05:31 -05005376static int
James Smart2e0fef82007-06-17 19:56:36 -05005377lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005378{
James Smart685f0bf2007-04-25 09:53:08 -04005379 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05005380
James Smart0d2b6b82008-06-14 22:52:47 -04005381 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05005382 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005383 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04005384 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
5385 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05005386 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005387 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04005388 NLP_EVT_DEVICE_RECOVERY);
5389 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05005390 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005391 return 0;
dea31012005-04-17 16:05:31 -05005392}
5393
James Smarte59058c2008-08-24 21:49:00 -04005394/**
James Smart3621a712009-04-06 18:47:14 -04005395 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05005396 * @vport: pointer to a host virtual N_Port data structure.
5397 * @cmdiocb: pointer to lpfc command iocb data structure.
5398 *
5399 * lpfc_send_rscn_event sends an RSCN netlink event to management
5400 * applications.
5401 */
5402static void
5403lpfc_send_rscn_event(struct lpfc_vport *vport,
5404 struct lpfc_iocbq *cmdiocb)
5405{
5406 struct lpfc_dmabuf *pcmd;
5407 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5408 uint32_t *payload_ptr;
5409 uint32_t payload_len;
5410 struct lpfc_rscn_event_header *rscn_event_data;
5411
5412 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5413 payload_ptr = (uint32_t *) pcmd->virt;
5414 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
5415
5416 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
5417 payload_len, GFP_KERNEL);
5418 if (!rscn_event_data) {
5419 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5420 "0147 Failed to allocate memory for RSCN event\n");
5421 return;
5422 }
5423 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
5424 rscn_event_data->payload_length = payload_len;
5425 memcpy(rscn_event_data->rscn_payload, payload_ptr,
5426 payload_len);
5427
5428 fc_host_post_vendor_event(shost,
5429 fc_get_event_number(),
Ales Novak6599eaa2015-08-31 16:48:16 -04005430 sizeof(struct lpfc_rscn_event_header) + payload_len,
James Smartddcc50f2008-12-04 22:38:46 -05005431 (char *)rscn_event_data,
5432 LPFC_NL_VENDOR_ID);
5433
5434 kfree(rscn_event_data);
5435}
5436
5437/**
James Smart3621a712009-04-06 18:47:14 -04005438 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04005439 * @vport: pointer to a host virtual N_Port data structure.
5440 * @cmdiocb: pointer to lpfc command iocb data structure.
5441 * @ndlp: pointer to a node-list data structure.
5442 *
5443 * This routine processes an unsolicited RSCN (Registration State Change
5444 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5445 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5446 * discover state machine is about to begin discovery, it just accepts the
5447 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5448 * contains N_Port IDs for other vports on this HBA, it just accepts the
5449 * RSCN and ignore processing it. If the state machine is in the recovery
5450 * state, the fc_rscn_id_list of this @vport is walked and the
5451 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5452 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5453 * routine is invoked to handle the RSCN event.
5454 *
5455 * Return code
5456 * 0 - Just sent the acc response
5457 * 1 - Sent the acc response and waited for name server completion
5458 **/
dea31012005-04-17 16:05:31 -05005459static int
James Smart2e0fef82007-06-17 19:56:36 -05005460lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005461 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005462{
James Smart2e0fef82007-06-17 19:56:36 -05005463 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5464 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005465 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05005466 uint32_t *lp, *datap;
James Smart92d7f7b2007-06-17 19:56:38 -05005467 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005468 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05005469 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04005470 int i;
dea31012005-04-17 16:05:31 -05005471
dea31012005-04-17 16:05:31 -05005472 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5473 lp = (uint32_t *) pcmd->virt;
5474
James Smart92d7f7b2007-06-17 19:56:38 -05005475 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
5476 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05005477 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04005478 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5479 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05005480 vport->fc_flag, payload_len, *lp,
5481 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05005482
5483 /* Send an RSCN event to the management application */
5484 lpfc_send_rscn_event(vport, cmdiocb);
5485
James Smartd2873e42006-08-18 17:46:43 -04005486 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05005487 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04005488 FCH_EVT_RSCN, lp[i]);
5489
dea31012005-04-17 16:05:31 -05005490 /* If we are about to begin discovery, just ACC the RSCN.
5491 * Discovery processing will satisfy it.
5492 */
James Smart2e0fef82007-06-17 19:56:36 -05005493 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05005494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5495 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5496 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5497
James Smart51ef4c22007-08-02 11:10:31 -04005498 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005499 return 0;
dea31012005-04-17 16:05:31 -05005500 }
5501
James Smart92d7f7b2007-06-17 19:56:38 -05005502 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5503 * just ACC and ignore it.
5504 */
5505 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04005506 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05005507 i = payload_len;
5508 datap = lp;
5509 while (i > 0) {
5510 nportid = *datap++;
5511 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
5512 i -= sizeof(uint32_t);
5513 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04005514 if (lpfc_find_vport_by_did(phba, nportid))
5515 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05005516 }
5517 if (rscn_id == hba_id) {
5518 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04005519 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04005520 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04005521 "Data: x%x x%x x%x x%x\n",
5522 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05005523 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05005524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5525 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5526 ndlp->nlp_DID, vport->port_state,
5527 ndlp->nlp_flag);
5528
James Smart92d7f7b2007-06-17 19:56:38 -05005529 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005530 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05005531 return 0;
5532 }
5533 }
5534
James Smart7f5f3d02008-02-08 18:50:14 -05005535 spin_lock_irq(shost->host_lock);
5536 if (vport->fc_rscn_flush) {
5537 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05005538 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05005539 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04005540 /* Send back ACC */
5541 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05005542 return 0;
5543 }
5544 /* Indicate we are walking fc_rscn_id_list on this vport */
5545 vport->fc_rscn_flush = 1;
5546 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02005547 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05005548 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05005549 /* If we are already processing an RSCN, save the received
5550 * RSCN payload buffer, cmdiocb->context2 to process later.
5551 */
James Smart2e0fef82007-06-17 19:56:36 -05005552 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05005553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5554 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5555 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5556
James Smart09372822008-01-11 01:52:54 -05005557 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005558 vport->fc_flag |= FC_RSCN_DEFERRED;
5559 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05005560 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05005561 vport->fc_flag |= FC_RSCN_MODE;
5562 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005563 if (rscn_cnt) {
5564 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
5565 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
5566 }
5567 if ((rscn_cnt) &&
5568 (payload_len + length <= LPFC_BPL_SIZE)) {
5569 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05005570 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05005571 memcpy(((uint8_t *)cmd) + length, lp,
5572 payload_len);
5573 } else {
5574 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
5575 vport->fc_rscn_id_cnt++;
5576 /* If we zero, cmdiocb->context2, the calling
5577 * routine will not try to free it.
5578 */
5579 cmdiocb->context2 = NULL;
5580 }
dea31012005-04-17 16:05:31 -05005581 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005582 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5583 "0235 Deferred RSCN "
5584 "Data: x%x x%x x%x\n",
5585 vport->fc_rscn_id_cnt, vport->fc_flag,
5586 vport->port_state);
dea31012005-04-17 16:05:31 -05005587 } else {
James Smart2e0fef82007-06-17 19:56:36 -05005588 vport->fc_flag |= FC_RSCN_DISCOVERY;
5589 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05005590 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04005591 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5592 "0234 ReDiscovery RSCN "
5593 "Data: x%x x%x x%x\n",
5594 vport->fc_rscn_id_cnt, vport->fc_flag,
5595 vport->port_state);
dea31012005-04-17 16:05:31 -05005596 }
James Smart7f5f3d02008-02-08 18:50:14 -05005597 /* Indicate we are done walking fc_rscn_id_list on this vport */
5598 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005599 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005600 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005601 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005602 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05005603 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005604 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05005605 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005606 return 0;
dea31012005-04-17 16:05:31 -05005607 }
James Smart858c9f62007-06-17 19:56:39 -05005608 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5609 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5610 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
5611
James Smart2e0fef82007-06-17 19:56:36 -05005612 spin_lock_irq(shost->host_lock);
5613 vport->fc_flag |= FC_RSCN_MODE;
5614 spin_unlock_irq(shost->host_lock);
5615 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05005616 /* Indicate we are done walking fc_rscn_id_list on this vport */
5617 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05005618 /*
5619 * If we zero, cmdiocb->context2, the calling routine will
5620 * not try to free it.
5621 */
5622 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05005623 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005624 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005625 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005626 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05005627 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05005628 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05005629}
5630
James Smarte59058c2008-08-24 21:49:00 -04005631/**
James Smart3621a712009-04-06 18:47:14 -04005632 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04005633 * @vport: pointer to a host virtual N_Port data structure.
5634 *
5635 * This routine handles the Registration State Configuration Notification
5636 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5637 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5638 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5639 * NameServer shall be issued. If CT command to the NameServer fails to be
5640 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5641 * RSCN activities with the @vport.
5642 *
5643 * Return code
5644 * 0 - Cleaned up rscn on the @vport
5645 * 1 - Wait for plogi to name server before proceed
5646 **/
dea31012005-04-17 16:05:31 -05005647int
James Smart2e0fef82007-06-17 19:56:36 -05005648lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005649{
5650 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05005651 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005652
James Smart92d7f7b2007-06-17 19:56:38 -05005653 /* Ignore RSCN if the port is being torn down. */
5654 if (vport->load_flag & FC_UNLOADING) {
5655 lpfc_els_flush_rscn(vport);
5656 return 0;
5657 }
5658
dea31012005-04-17 16:05:31 -05005659 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05005660 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005661
5662 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04005663 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
5664 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5665 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
5666 vport->port_state);
dea31012005-04-17 16:05:31 -05005667
5668 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005669 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05005670 vport->num_disc_nodes = 0;
5671
James Smart2e0fef82007-06-17 19:56:36 -05005672 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005673 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
5674 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05005675 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05005676 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05005677 /* Wait for NameServer query cmpl before we can
5678 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005679 return 1;
dea31012005-04-17 16:05:31 -05005680 } else {
5681 /* If login to NameServer does not exist, issue one */
5682 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05005683 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005684 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05005685 /* Wait for NameServer login cmpl before we can
5686 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005687 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05005688
James Smarte47c9092008-02-08 18:49:26 -05005689 if (ndlp) {
5690 ndlp = lpfc_enable_node(vport, ndlp,
5691 NLP_STE_PLOGI_ISSUE);
5692 if (!ndlp) {
5693 lpfc_els_flush_rscn(vport);
5694 return 0;
5695 }
5696 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05005697 } else {
James Smarte47c9092008-02-08 18:49:26 -05005698 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5699 if (!ndlp) {
5700 lpfc_els_flush_rscn(vport);
5701 return 0;
5702 }
James Smart2e0fef82007-06-17 19:56:36 -05005703 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005704 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005705 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05005706 }
James Smarte47c9092008-02-08 18:49:26 -05005707 ndlp->nlp_type |= NLP_FABRIC;
5708 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
5709 /* Wait for NameServer login cmpl before we can
5710 * continue
5711 */
5712 return 1;
dea31012005-04-17 16:05:31 -05005713 }
5714
James Smart2e0fef82007-06-17 19:56:36 -05005715 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005716 return 0;
dea31012005-04-17 16:05:31 -05005717}
5718
James Smarte59058c2008-08-24 21:49:00 -04005719/**
James Smart3621a712009-04-06 18:47:14 -04005720 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04005721 * @vport: pointer to a host virtual N_Port data structure.
5722 * @cmdiocb: pointer to lpfc command iocb data structure.
5723 * @ndlp: pointer to a node-list data structure.
5724 *
5725 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5726 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5727 * point topology. As an unsolicited FLOGI should not be received in a loop
5728 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5729 * lpfc_check_sparm() routine is invoked to check the parameters in the
5730 * unsolicited FLOGI. If parameters validation failed, the routine
5731 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5732 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5733 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5734 * will initiate PLOGI. The higher lexicographical value party shall has
5735 * higher priority (as the winning port) and will initiate PLOGI and
5736 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5737 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5738 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5739 *
5740 * Return code
5741 * 0 - Successfully processed the unsolicited flogi
5742 * 1 - Failed to process the unsolicited flogi
5743 **/
dea31012005-04-17 16:05:31 -05005744static int
James Smart2e0fef82007-06-17 19:56:36 -05005745lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005746 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005747{
James Smart2e0fef82007-06-17 19:56:36 -05005748 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5749 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005750 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5751 uint32_t *lp = (uint32_t *) pcmd->virt;
5752 IOCB_t *icmd = &cmdiocb->iocb;
5753 struct serv_parm *sp;
5754 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05005755 uint32_t cmd, did;
5756 int rc;
James Smarte74c03c2013-04-17 20:15:19 -04005757 uint32_t fc_flag = 0;
5758 uint32_t port_state = 0;
dea31012005-04-17 16:05:31 -05005759
5760 cmd = *lp++;
5761 sp = (struct serv_parm *) lp;
5762
5763 /* FLOGI received */
5764
James Smart2e0fef82007-06-17 19:56:36 -05005765 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005766
James Smart76a95d72010-11-20 23:11:48 -05005767 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005768 /* We should never receive a FLOGI in loop mode, ignore it */
5769 did = icmd->un.elsreq64.remoteID;
5770
5771 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5772 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005773 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5774 "0113 An FLOGI ELS command x%x was "
5775 "received from DID x%x in Loop Mode\n",
5776 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005777 return 1;
dea31012005-04-17 16:05:31 -05005778 }
5779
James Smartd6de08c2015-12-16 18:11:53 -05005780 (void) lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1);
dea31012005-04-17 16:05:31 -05005781
dea31012005-04-17 16:05:31 -05005782
James Smartd6de08c2015-12-16 18:11:53 -05005783 /*
5784 * If our portname is greater than the remote portname,
5785 * then we initiate Nport login.
5786 */
5787
5788 rc = memcmp(&vport->fc_portname, &sp->portName,
5789 sizeof(struct lpfc_name));
5790
5791 if (!rc) {
5792 if (phba->sli_rev < LPFC_SLI_REV4) {
5793 mbox = mempool_alloc(phba->mbox_mem_pool,
5794 GFP_KERNEL);
5795 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005796 return 1;
James Smartd6de08c2015-12-16 18:11:53 -05005797 lpfc_linkdown(phba);
5798 lpfc_init_link(phba, mbox,
5799 phba->cfg_topology,
5800 phba->cfg_link_speed);
5801 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5802 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5803 mbox->vport = vport;
5804 rc = lpfc_sli_issue_mbox(phba, mbox,
5805 MBX_NOWAIT);
5806 lpfc_set_loopback_flag(phba);
5807 if (rc == MBX_NOT_FINISHED)
5808 mempool_free(mbox, phba->mbox_mem_pool);
5809 return 1;
5810 }
James Smart939723a2012-05-09 21:19:03 -04005811
James Smartd6de08c2015-12-16 18:11:53 -05005812 /* abort the flogi coming back to ourselves
5813 * due to external loopback on the port.
James Smart939723a2012-05-09 21:19:03 -04005814 */
James Smartd6de08c2015-12-16 18:11:53 -05005815 lpfc_els_abort_flogi(phba);
5816 return 0;
5817
5818 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005819 spin_lock_irq(shost->host_lock);
James Smartd6de08c2015-12-16 18:11:53 -05005820 vport->fc_flag |= FC_PT2PT_PLOGI;
James Smart2e0fef82007-06-17 19:56:36 -05005821 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005822
James Smartd6de08c2015-12-16 18:11:53 -05005823 /* If we have the high WWPN we can assign our own
5824 * myDID; otherwise, we have to WAIT for a PLOGI
5825 * from the remote NPort to find out what it
5826 * will be.
James Smart939723a2012-05-09 21:19:03 -04005827 */
James Smartd6de08c2015-12-16 18:11:53 -05005828 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -05005829 } else {
James Smartd6de08c2015-12-16 18:11:53 -05005830 vport->fc_myDID = PT2PT_RemoteID;
dea31012005-04-17 16:05:31 -05005831 }
5832
James Smartd6de08c2015-12-16 18:11:53 -05005833 /*
5834 * The vport state should go to LPFC_FLOGI only
5835 * AFTER we issue a FLOGI, not receive one.
5836 */
5837 spin_lock_irq(shost->host_lock);
5838 fc_flag = vport->fc_flag;
5839 port_state = vport->port_state;
5840 vport->fc_flag |= FC_PT2PT;
5841 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5842 spin_unlock_irq(shost->host_lock);
5843 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5844 "3311 Rcv Flogi PS x%x new PS x%x "
5845 "fc_flag x%x new fc_flag x%x\n",
5846 port_state, vport->port_state,
5847 fc_flag, vport->fc_flag);
5848
5849 /*
5850 * We temporarily set fc_myDID to make it look like we are
5851 * a Fabric. This is done just so we end up with the right
5852 * did / sid on the FLOGI ACC rsp.
5853 */
5854 did = vport->fc_myDID;
5855 vport->fc_myDID = Fabric_DID;
5856
5857 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
James Smarteec3d312015-08-31 16:48:18 -04005858
dea31012005-04-17 16:05:31 -05005859 /* Send back ACC */
James Smartd6de08c2015-12-16 18:11:53 -05005860 lpfc_els_rsp_acc(vport, ELS_CMD_FLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005861
James Smart939723a2012-05-09 21:19:03 -04005862 /* Now lets put fc_myDID back to what its supposed to be */
5863 vport->fc_myDID = did;
5864
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005865 return 0;
dea31012005-04-17 16:05:31 -05005866}
5867
James Smarte59058c2008-08-24 21:49:00 -04005868/**
James Smart3621a712009-04-06 18:47:14 -04005869 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005870 * @vport: pointer to a host virtual N_Port data structure.
5871 * @cmdiocb: pointer to lpfc command iocb data structure.
5872 * @ndlp: pointer to a node-list data structure.
5873 *
5874 * This routine processes Request Node Identification Data (RNID) IOCB
5875 * received as an ELS unsolicited event. Only when the RNID specified format
5876 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5877 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5878 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5879 * rejected by invoking the lpfc_els_rsp_reject() routine.
5880 *
5881 * Return code
5882 * 0 - Successfully processed rnid iocb (currently always return 0)
5883 **/
dea31012005-04-17 16:05:31 -05005884static int
James Smart2e0fef82007-06-17 19:56:36 -05005885lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5886 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005887{
5888 struct lpfc_dmabuf *pcmd;
5889 uint32_t *lp;
dea31012005-04-17 16:05:31 -05005890 RNID *rn;
5891 struct ls_rjt stat;
James Smarteb016562014-09-03 12:58:06 -04005892 uint32_t cmd;
dea31012005-04-17 16:05:31 -05005893
dea31012005-04-17 16:05:31 -05005894 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5895 lp = (uint32_t *) pcmd->virt;
5896
5897 cmd = *lp++;
5898 rn = (RNID *) lp;
5899
5900 /* RNID received */
5901
5902 switch (rn->Format) {
5903 case 0:
5904 case RNID_TOPOLOGY_DISC:
5905 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005906 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005907 break;
5908 default:
5909 /* Reject this request because format not supported */
5910 stat.un.b.lsRjtRsvd0 = 0;
5911 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5912 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5913 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005914 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5915 NULL);
dea31012005-04-17 16:05:31 -05005916 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005917 return 0;
dea31012005-04-17 16:05:31 -05005918}
5919
James Smarte59058c2008-08-24 21:49:00 -04005920/**
James Smart12265f62010-10-22 11:05:53 -04005921 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5922 * @vport: pointer to a host virtual N_Port data structure.
5923 * @cmdiocb: pointer to lpfc command iocb data structure.
5924 * @ndlp: pointer to a node-list data structure.
5925 *
5926 * Return code
5927 * 0 - Successfully processed echo iocb (currently always return 0)
5928 **/
5929static int
5930lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5931 struct lpfc_nodelist *ndlp)
5932{
5933 uint8_t *pcmd;
5934
5935 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5936
5937 /* skip over first word of echo command to find echo data */
5938 pcmd += sizeof(uint32_t);
5939
5940 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5941 return 0;
5942}
5943
5944/**
James Smart3621a712009-04-06 18:47:14 -04005945 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005946 * @vport: pointer to a host virtual N_Port data structure.
5947 * @cmdiocb: pointer to lpfc command iocb data structure.
5948 * @ndlp: pointer to a node-list data structure.
5949 *
5950 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5951 * received as an ELS unsolicited event. Currently, this function just invokes
5952 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5953 *
5954 * Return code
5955 * 0 - Successfully processed lirr iocb (currently always return 0)
5956 **/
dea31012005-04-17 16:05:31 -05005957static int
James Smart2e0fef82007-06-17 19:56:36 -05005958lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5959 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005960{
5961 struct ls_rjt stat;
5962
5963 /* For now, unconditionally reject this command */
5964 stat.un.b.lsRjtRsvd0 = 0;
5965 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5966 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5967 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005968 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005969 return 0;
5970}
5971
James Smarte59058c2008-08-24 21:49:00 -04005972/**
James Smart5ffc2662009-11-18 15:39:44 -05005973 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5974 * @vport: pointer to a host virtual N_Port data structure.
5975 * @cmdiocb: pointer to lpfc command iocb data structure.
5976 * @ndlp: pointer to a node-list data structure.
5977 *
5978 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5979 * received as an ELS unsolicited event. A request to RRQ shall only
5980 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5981 * Nx_Port N_Port_ID of the target Exchange is the same as the
5982 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5983 * not accepted, an LS_RJT with reason code "Unable to perform
5984 * command request" and reason code explanation "Invalid Originator
5985 * S_ID" shall be returned. For now, we just unconditionally accept
5986 * RRQ from the target.
5987 **/
5988static void
5989lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5990 struct lpfc_nodelist *ndlp)
5991{
5992 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005993 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5994 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005995}
5996
5997/**
James Smart12265f62010-10-22 11:05:53 -04005998 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5999 * @phba: pointer to lpfc hba data structure.
6000 * @pmb: pointer to the driver internal queue element for mailbox command.
6001 *
6002 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6003 * mailbox command. This callback function is to actually send the Accept
6004 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6005 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6006 * mailbox command, constructs the RPS response with the link statistics
6007 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6008 * response to the RPS.
6009 *
6010 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6011 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6012 * will be stored into the context1 field of the IOCB for the completion
6013 * callback function to the RPS Accept Response ELS IOCB command.
6014 *
6015 **/
6016static void
6017lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6018{
6019 MAILBOX_t *mb;
6020 IOCB_t *icmd;
6021 struct RLS_RSP *rls_rsp;
6022 uint8_t *pcmd;
6023 struct lpfc_iocbq *elsiocb;
6024 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006025 uint16_t oxid;
6026 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04006027 uint32_t cmdsize;
6028
6029 mb = &pmb->u.mb;
6030
6031 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006032 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6033 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04006034 pmb->context1 = NULL;
6035 pmb->context2 = NULL;
6036
6037 if (mb->mbxStatus) {
6038 mempool_free(pmb, phba->mbox_mem_pool);
6039 return;
6040 }
6041
6042 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04006043 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6044 lpfc_max_els_tries, ndlp,
6045 ndlp->nlp_DID, ELS_CMD_ACC);
6046
6047 /* Decrement the ndlp reference count from previous mbox command */
6048 lpfc_nlp_put(ndlp);
6049
James Smart37db57e2012-05-09 21:17:16 -04006050 if (!elsiocb) {
6051 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006052 return;
James Smart37db57e2012-05-09 21:17:16 -04006053 }
James Smart12265f62010-10-22 11:05:53 -04006054
6055 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006056 icmd->ulpContext = rxid;
6057 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04006058
6059 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6060 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6061 pcmd += sizeof(uint32_t); /* Skip past command */
6062 rls_rsp = (struct RLS_RSP *)pcmd;
6063
6064 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6065 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6066 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6067 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6068 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6069 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04006070 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04006071 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6072 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6073 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6074 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6075 elsiocb->iotag, elsiocb->iocb.ulpContext,
6076 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6077 ndlp->nlp_rpi);
6078 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6079 phba->fc_stat.elsXmitACC++;
6080 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6081 lpfc_els_free_iocb(phba, elsiocb);
6082}
6083
6084/**
James Smart3621a712009-04-06 18:47:14 -04006085 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04006086 * @phba: pointer to lpfc hba data structure.
6087 * @pmb: pointer to the driver internal queue element for mailbox command.
6088 *
6089 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6090 * mailbox command. This callback function is to actually send the Accept
6091 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6092 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6093 * mailbox command, constructs the RPS response with the link statistics
6094 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6095 * response to the RPS.
6096 *
6097 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6098 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6099 * will be stored into the context1 field of the IOCB for the completion
6100 * callback function to the RPS Accept Response ELS IOCB command.
6101 *
6102 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006103static void
James Smart329f9bc2007-04-25 09:53:01 -04006104lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006105{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006106 MAILBOX_t *mb;
6107 IOCB_t *icmd;
6108 RPS_RSP *rps_rsp;
6109 uint8_t *pcmd;
6110 struct lpfc_iocbq *elsiocb;
6111 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04006112 uint16_t status;
6113 uint16_t oxid;
6114 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006115 uint32_t cmdsize;
6116
James Smart04c68492009-05-22 14:52:52 -04006117 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006118
6119 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04006120 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
6121 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07006122 pmb->context1 = NULL;
6123 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006124
6125 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04006126 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006127 return;
6128 }
6129
6130 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04006131 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05006132 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6133 lpfc_max_els_tries, ndlp,
6134 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05006135
6136 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04006137 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05006138
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006139 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006140 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006141
6142 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006143 icmd->ulpContext = rxid;
6144 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006145
6146 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6147 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006148 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006149 rps_rsp = (RPS_RSP *)pcmd;
6150
James Smart76a95d72010-11-20 23:11:48 -05006151 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006152 status = 0x10;
6153 else
6154 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05006155 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006156 status |= 0x4;
6157
6158 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05006159 rps_rsp->portStatus = cpu_to_be16(status);
6160 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
6161 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
6162 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
6163 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
6164 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
6165 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006166 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006167 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6168 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6169 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6170 elsiocb->iotag, elsiocb->iocb.ulpContext,
6171 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6172 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006173 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006174 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006175 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006176 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006177 return;
6178}
6179
James Smarte59058c2008-08-24 21:49:00 -04006180/**
James Smart12265f62010-10-22 11:05:53 -04006181 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6182 * @vport: pointer to a host virtual N_Port data structure.
6183 * @cmdiocb: pointer to lpfc command iocb data structure.
6184 * @ndlp: pointer to a node-list data structure.
6185 *
6186 * This routine processes Read Port Status (RPL) IOCB received as an
6187 * ELS unsolicited event. It first checks the remote port state. If the
6188 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6189 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6190 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6191 * for reading the HBA link statistics. It is for the callback function,
6192 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6193 * to actually sending out RPL Accept (ACC) response.
6194 *
6195 * Return codes
6196 * 0 - Successfully processed rls iocb (currently always return 0)
6197 **/
6198static int
6199lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6200 struct lpfc_nodelist *ndlp)
6201{
6202 struct lpfc_hba *phba = vport->phba;
6203 LPFC_MBOXQ_t *mbox;
James Smart12265f62010-10-22 11:05:53 -04006204 struct ls_rjt stat;
6205
6206 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6207 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6208 /* reject the unsolicited RPS request and done with it */
6209 goto reject_out;
6210
James Smart12265f62010-10-22 11:05:53 -04006211 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6212 if (mbox) {
6213 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006214 mbox->context1 = (void *)((unsigned long)
6215 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6216 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04006217 mbox->context2 = lpfc_nlp_get(ndlp);
6218 mbox->vport = vport;
6219 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
6220 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6221 != MBX_NOT_FINISHED)
6222 /* Mbox completion will send ELS Response */
6223 return 0;
6224 /* Decrement reference count used for the failed mbox
6225 * command.
6226 */
6227 lpfc_nlp_put(ndlp);
6228 mempool_free(mbox, phba->mbox_mem_pool);
6229 }
6230reject_out:
6231 /* issue rejection response */
6232 stat.un.b.lsRjtRsvd0 = 0;
6233 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6234 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6235 stat.un.b.vendorUnique = 0;
6236 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6237 return 0;
6238}
6239
6240/**
6241 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6242 * @vport: pointer to a host virtual N_Port data structure.
6243 * @cmdiocb: pointer to lpfc command iocb data structure.
6244 * @ndlp: pointer to a node-list data structure.
6245 *
6246 * This routine processes Read Timout Value (RTV) IOCB received as an
6247 * ELS unsolicited event. It first checks the remote port state. If the
6248 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6249 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6250 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6251 * Value (RTV) unsolicited IOCB event.
6252 *
6253 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6254 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6255 * will be stored into the context1 field of the IOCB for the completion
6256 * callback function to the RPS Accept Response ELS IOCB command.
6257 *
6258 * Return codes
6259 * 0 - Successfully processed rtv iocb (currently always return 0)
6260 **/
6261static int
6262lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6263 struct lpfc_nodelist *ndlp)
6264{
6265 struct lpfc_hba *phba = vport->phba;
6266 struct ls_rjt stat;
6267 struct RTV_RSP *rtv_rsp;
6268 uint8_t *pcmd;
6269 struct lpfc_iocbq *elsiocb;
6270 uint32_t cmdsize;
6271
6272
6273 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6274 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6275 /* reject the unsolicited RPS request and done with it */
6276 goto reject_out;
6277
6278 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
6279 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
6280 lpfc_max_els_tries, ndlp,
6281 ndlp->nlp_DID, ELS_CMD_ACC);
6282
6283 if (!elsiocb)
6284 return 1;
6285
6286 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6287 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
6288 pcmd += sizeof(uint32_t); /* Skip past command */
6289
6290 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04006291 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
6292 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04006293
6294 rtv_rsp = (struct RTV_RSP *)pcmd;
6295
6296 /* populate RTV payload */
6297 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
6298 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
6299 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
6300 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
6301 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
6302
6303 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6304 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
6305 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6306 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6307 "Data: x%x x%x x%x\n",
6308 elsiocb->iotag, elsiocb->iocb.ulpContext,
6309 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6310 ndlp->nlp_rpi,
6311 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
6312 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
6313 phba->fc_stat.elsXmitACC++;
6314 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
6315 lpfc_els_free_iocb(phba, elsiocb);
6316 return 0;
6317
6318reject_out:
6319 /* issue rejection response */
6320 stat.un.b.lsRjtRsvd0 = 0;
6321 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6322 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6323 stat.un.b.vendorUnique = 0;
6324 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
6325 return 0;
6326}
6327
6328/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04006329 * @vport: pointer to a host virtual N_Port data structure.
6330 * @cmdiocb: pointer to lpfc command iocb data structure.
6331 * @ndlp: pointer to a node-list data structure.
6332 *
6333 * This routine processes Read Port Status (RPS) IOCB received as an
6334 * ELS unsolicited event. It first checks the remote port state. If the
6335 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6336 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6337 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6338 * for reading the HBA link statistics. It is for the callback function,
6339 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6340 * to actually sending out RPS Accept (ACC) response.
6341 *
6342 * Return codes
6343 * 0 - Successfully processed rps iocb (currently always return 0)
6344 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006345static int
James Smart2e0fef82007-06-17 19:56:36 -05006346lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6347 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006348{
James Smart2e0fef82007-06-17 19:56:36 -05006349 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006350 uint32_t *lp;
6351 uint8_t flag;
6352 LPFC_MBOXQ_t *mbox;
6353 struct lpfc_dmabuf *pcmd;
6354 RPS *rps;
6355 struct ls_rjt stat;
6356
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006357 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04006358 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
6359 /* reject the unsolicited RPS request and done with it */
6360 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006361
6362 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6363 lp = (uint32_t *) pcmd->virt;
6364 flag = (be32_to_cpu(*lp++) & 0xf);
6365 rps = (RPS *) lp;
6366
6367 if ((flag == 0) ||
6368 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05006369 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006370 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05006371
James Smart92d7f7b2007-06-17 19:56:38 -05006372 printk("Fix me....\n");
6373 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05006374 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
6375 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006376 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04006377 mbox->context1 = (void *)((unsigned long)
6378 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
6379 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04006380 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006381 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006382 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05006383 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04006384 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006385 /* Mbox completion will send ELS Response */
6386 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05006387 /* Decrement reference count used for the failed mbox
6388 * command.
6389 */
James Smart329f9bc2007-04-25 09:53:01 -04006390 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006391 mempool_free(mbox, phba->mbox_mem_pool);
6392 }
6393 }
James Smart90160e02008-08-24 21:49:45 -04006394
6395reject_out:
6396 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006397 stat.un.b.lsRjtRsvd0 = 0;
6398 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6399 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6400 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006401 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006402 return 0;
6403}
6404
James Smart19ca7602010-11-20 23:11:55 -05006405/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6406 * @vport: pointer to a host virtual N_Port data structure.
6407 * @ndlp: pointer to a node-list data structure.
6408 * @did: DID of the target.
6409 * @rrq: Pointer to the rrq struct.
6410 *
6411 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6412 * Successful the the completion handler will clear the RRQ.
6413 *
6414 * Return codes
6415 * 0 - Successfully sent rrq els iocb.
6416 * 1 - Failed to send rrq els iocb.
6417 **/
6418static int
6419lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6420 uint32_t did, struct lpfc_node_rrq *rrq)
6421{
6422 struct lpfc_hba *phba = vport->phba;
6423 struct RRQ *els_rrq;
James Smart19ca7602010-11-20 23:11:55 -05006424 struct lpfc_iocbq *elsiocb;
6425 uint8_t *pcmd;
6426 uint16_t cmdsize;
6427 int ret;
6428
6429
6430 if (ndlp != rrq->ndlp)
6431 ndlp = rrq->ndlp;
6432 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6433 return 1;
6434
6435 /* If ndlp is not NULL, we will bump the reference count on it */
6436 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
6437 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
6438 ELS_CMD_RRQ);
6439 if (!elsiocb)
6440 return 1;
6441
James Smart19ca7602010-11-20 23:11:55 -05006442 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6443
6444 /* For RRQ request, remainder of payload is Exchange IDs */
6445 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
6446 pcmd += sizeof(uint32_t);
6447 els_rrq = (struct RRQ *) pcmd;
6448
James Smartee0f4fe2012-05-09 21:19:14 -04006449 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05006450 bf_set(rrq_rxid, els_rrq, rrq->rxid);
6451 bf_set(rrq_did, els_rrq, vport->fc_myDID);
6452 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
6453 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
6454
6455
6456 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6457 "Issue RRQ: did:x%x",
6458 did, rrq->xritag, rrq->rxid);
6459 elsiocb->context_un.rrq = rrq;
6460 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
6461 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
6462
6463 if (ret == IOCB_ERROR) {
6464 lpfc_els_free_iocb(phba, elsiocb);
6465 return 1;
6466 }
6467 return 0;
6468}
6469
6470/**
6471 * lpfc_send_rrq - Sends ELS RRQ if needed.
6472 * @phba: pointer to lpfc hba data structure.
6473 * @rrq: pointer to the active rrq.
6474 *
6475 * This routine will call the lpfc_issue_els_rrq if the rrq is
6476 * still active for the xri. If this function returns a failure then
6477 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6478 *
6479 * Returns 0 Success.
6480 * 1 Failure.
6481 **/
6482int
6483lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
6484{
6485 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
6486 rrq->nlp_DID);
6487 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
6488 return lpfc_issue_els_rrq(rrq->vport, ndlp,
6489 rrq->nlp_DID, rrq);
6490 else
6491 return 1;
6492}
6493
James Smarte59058c2008-08-24 21:49:00 -04006494/**
James Smart3621a712009-04-06 18:47:14 -04006495 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04006496 * @vport: pointer to a host virtual N_Port data structure.
6497 * @cmdsize: size of the ELS command.
6498 * @oldiocb: pointer to the original lpfc command iocb data structure.
6499 * @ndlp: pointer to a node-list data structure.
6500 *
6501 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6502 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6503 *
6504 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6505 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6506 * will be stored into the context1 field of the IOCB for the completion
6507 * callback function to the RPL Accept Response ELS command.
6508 *
6509 * Return code
6510 * 0 - Successfully issued ACC RPL ELS command
6511 * 1 - Failed to issue ACC RPL ELS command
6512 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05006513static int
James Smart2e0fef82007-06-17 19:56:36 -05006514lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
6515 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006516{
James Smart2e0fef82007-06-17 19:56:36 -05006517 struct lpfc_hba *phba = vport->phba;
6518 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006519 RPL_RSP rpl_rsp;
6520 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006521 uint8_t *pcmd;
6522
James Smart2e0fef82007-06-17 19:56:36 -05006523 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
6524 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006525
James Smart488d1462006-03-07 15:02:37 -05006526 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006527 return 1;
James Smart488d1462006-03-07 15:02:37 -05006528
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006529 icmd = &elsiocb->iocb;
6530 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04006531 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
6532 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006533
6534 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6535 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05006536 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006537 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
6538 pcmd += sizeof(uint16_t);
6539
6540 /* Setup the RPL ACC payload */
6541 rpl_rsp.listLen = be32_to_cpu(1);
6542 rpl_rsp.index = 0;
6543 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05006544 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
6545 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006546 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006547 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006548 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04006549 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6550 "0120 Xmit ELS RPL ACC response tag x%x "
6551 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6552 "rpi x%x\n",
6553 elsiocb->iotag, elsiocb->iocb.ulpContext,
6554 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
6555 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05006556 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006557 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04006558 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6559 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006560 lpfc_els_free_iocb(phba, elsiocb);
6561 return 1;
6562 }
6563 return 0;
6564}
6565
James Smarte59058c2008-08-24 21:49:00 -04006566/**
James Smart3621a712009-04-06 18:47:14 -04006567 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04006568 * @vport: pointer to a host virtual N_Port data structure.
6569 * @cmdiocb: pointer to lpfc command iocb data structure.
6570 * @ndlp: pointer to a node-list data structure.
6571 *
6572 * This routine processes Read Port List (RPL) IOCB received as an ELS
6573 * unsolicited event. It first checks the remote port state. If the remote
6574 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6575 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6576 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6577 * to accept the RPL.
6578 *
6579 * Return code
6580 * 0 - Successfully processed rpl iocb (currently always return 0)
6581 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006582static int
James Smart2e0fef82007-06-17 19:56:36 -05006583lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6584 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006585{
6586 struct lpfc_dmabuf *pcmd;
6587 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006588 uint32_t maxsize;
6589 uint16_t cmdsize;
6590 RPL *rpl;
6591 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05006592
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006593 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
6594 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04006595 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006596 stat.un.b.lsRjtRsvd0 = 0;
6597 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
6598 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
6599 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05006600 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
6601 NULL);
James Smart90160e02008-08-24 21:49:45 -04006602 /* rejected the unsolicited RPL request and done with it */
6603 return 0;
dea31012005-04-17 16:05:31 -05006604 }
6605
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006606 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6607 lp = (uint32_t *) pcmd->virt;
6608 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006609 maxsize = be32_to_cpu(rpl->maxsize);
6610
6611 /* We support only one port */
6612 if ((rpl->index == 0) &&
6613 ((maxsize == 0) ||
6614 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
6615 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05006616 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006617 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
6618 }
James Smart2e0fef82007-06-17 19:56:36 -05006619 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05006620
6621 return 0;
6622}
6623
James Smarte59058c2008-08-24 21:49:00 -04006624/**
James Smart3621a712009-04-06 18:47:14 -04006625 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04006626 * @vport: pointer to a virtual N_Port data structure.
6627 * @cmdiocb: pointer to lpfc command iocb data structure.
6628 * @ndlp: pointer to a node-list data structure.
6629 *
6630 * This routine processes Fibre Channel Address Resolution Protocol
6631 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6632 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6633 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6634 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6635 * remote PortName is compared against the FC PortName stored in the @vport
6636 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6637 * compared against the FC NodeName stored in the @vport data structure.
6638 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6639 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6640 * invoked to send out FARP Response to the remote node. Before sending the
6641 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6642 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6643 * routine is invoked to log into the remote port first.
6644 *
6645 * Return code
6646 * 0 - Either the FARP Match Mode not supported or successfully processed
6647 **/
dea31012005-04-17 16:05:31 -05006648static int
James Smart2e0fef82007-06-17 19:56:36 -05006649lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6650 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006651{
6652 struct lpfc_dmabuf *pcmd;
6653 uint32_t *lp;
6654 IOCB_t *icmd;
6655 FARP *fp;
6656 uint32_t cmd, cnt, did;
6657
6658 icmd = &cmdiocb->iocb;
6659 did = icmd->un.elsreq64.remoteID;
6660 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6661 lp = (uint32_t *) pcmd->virt;
6662
6663 cmd = *lp++;
6664 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05006665 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006666 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6667 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006668 /* We will only support match on WWPN or WWNN */
6669 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006670 return 0;
dea31012005-04-17 16:05:31 -05006671 }
6672
6673 cnt = 0;
6674 /* If this FARP command is searching for my portname */
6675 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05006676 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05006677 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006678 cnt = 1;
6679 }
6680
6681 /* If this FARP command is searching for my nodename */
6682 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05006683 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05006684 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05006685 cnt = 1;
6686 }
6687
6688 if (cnt) {
6689 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6690 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6691 /* Log back into the node before sending the FARP. */
6692 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006693 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006694 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04006695 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05006696 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05006697 }
6698
6699 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05006700 if (fp->Rflags & FARP_REQUEST_FARPR)
6701 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006702 }
6703 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006704 return 0;
dea31012005-04-17 16:05:31 -05006705}
6706
James Smarte59058c2008-08-24 21:49:00 -04006707/**
James Smart3621a712009-04-06 18:47:14 -04006708 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006709 * @vport: pointer to a host virtual N_Port data structure.
6710 * @cmdiocb: pointer to lpfc command iocb data structure.
6711 * @ndlp: pointer to a node-list data structure.
6712 *
6713 * This routine processes Fibre Channel Address Resolution Protocol
6714 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6715 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6716 * the FARP response request.
6717 *
6718 * Return code
6719 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6720 **/
dea31012005-04-17 16:05:31 -05006721static int
James Smart2e0fef82007-06-17 19:56:36 -05006722lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6723 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006724{
6725 struct lpfc_dmabuf *pcmd;
6726 uint32_t *lp;
6727 IOCB_t *icmd;
6728 uint32_t cmd, did;
6729
6730 icmd = &cmdiocb->iocb;
6731 did = icmd->un.elsreq64.remoteID;
6732 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6733 lp = (uint32_t *) pcmd->virt;
6734
6735 cmd = *lp++;
6736 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006737 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6738 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006739 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006740 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006741
6742 return 0;
6743}
6744
James Smarte59058c2008-08-24 21:49:00 -04006745/**
James Smart3621a712009-04-06 18:47:14 -04006746 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006747 * @vport: pointer to a host virtual N_Port data structure.
6748 * @cmdiocb: pointer to lpfc command iocb data structure.
6749 * @fan_ndlp: pointer to a node-list data structure.
6750 *
6751 * This routine processes a Fabric Address Notification (FAN) IOCB
6752 * command received as an ELS unsolicited event. The FAN ELS command will
6753 * only be processed on a physical port (i.e., the @vport represents the
6754 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6755 * compared against those in the phba data structure. If any of those is
6756 * different, the lpfc_initial_flogi() routine is invoked to initialize
6757 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6758 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6759 * is invoked to register login to the fabric.
6760 *
6761 * Return code
6762 * 0 - Successfully processed fan iocb (currently always return 0).
6763 **/
dea31012005-04-17 16:05:31 -05006764static int
James Smart2e0fef82007-06-17 19:56:36 -05006765lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6766 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006767{
James Smart2e0fef82007-06-17 19:56:36 -05006768 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006769 uint32_t *lp;
6770 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006771
James Smart0d2b6b82008-06-14 22:52:47 -04006772 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6773 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6774 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006775 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006776 if ((vport == phba->pport) &&
6777 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006778 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006779 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006780 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006781 sizeof(struct lpfc_name)))) {
6782 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006783 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006784 } else {
6785 /* FAN verified - skip FLOGI */
6786 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006787 if (phba->sli_rev < LPFC_SLI_REV4)
6788 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006789 else {
6790 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6791 "3138 Need register VFI: (x%x/%x)\n",
6792 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006793 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006794 }
dea31012005-04-17 16:05:31 -05006795 }
dea31012005-04-17 16:05:31 -05006796 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006797 return 0;
dea31012005-04-17 16:05:31 -05006798}
6799
James Smarte59058c2008-08-24 21:49:00 -04006800/**
James Smart3621a712009-04-06 18:47:14 -04006801 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006802 * @ptr: holder for the timer function associated data.
6803 *
6804 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6805 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6806 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6807 * up the worker thread. It is for the worker thread to invoke the routine
6808 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6809 **/
dea31012005-04-17 16:05:31 -05006810void
6811lpfc_els_timeout(unsigned long ptr)
6812{
James Smart2e0fef82007-06-17 19:56:36 -05006813 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6814 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006815 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006816 unsigned long iflag;
6817
James Smart2e0fef82007-06-17 19:56:36 -05006818 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006819 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
James Smart06918ac2014-02-20 09:57:57 -05006820 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart2e0fef82007-06-17 19:56:36 -05006821 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006822 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006823
James Smart06918ac2014-02-20 09:57:57 -05006824 if ((!tmo_posted) && (!(vport->load_flag & FC_UNLOADING)))
James Smart5e9d9b82008-06-14 22:52:53 -04006825 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006826 return;
6827}
6828
James Smart2a9bf3d2010-06-07 15:24:45 -04006829
James Smarte59058c2008-08-24 21:49:00 -04006830/**
James Smart3621a712009-04-06 18:47:14 -04006831 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006832 * @vport: pointer to a virtual N_Port data structure.
6833 *
6834 * This routine is the actual handler function that processes an ELS timeout
6835 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6836 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6837 * invoking the lpfc_sli_issue_abort_iotag() routine.
6838 **/
dea31012005-04-17 16:05:31 -05006839void
James Smart2e0fef82007-06-17 19:56:36 -05006840lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006841{
James Smart2e0fef82007-06-17 19:56:36 -05006842 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006843 struct lpfc_sli_ring *pring;
6844 struct lpfc_iocbq *tmp_iocb, *piocb;
6845 IOCB_t *cmd = NULL;
6846 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006847 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006848 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006849 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006850 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006851
James Smart2a9bf3d2010-06-07 15:24:45 -04006852
dea31012005-04-17 16:05:31 -05006853 timeout = (uint32_t)(phba->fc_ratov << 1);
6854
6855 pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart06918ac2014-02-20 09:57:57 -05006856 if ((phba->pport->load_flag & FC_UNLOADING))
6857 return;
James Smart2a9bf3d2010-06-07 15:24:45 -04006858 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05006859 if (phba->sli_rev == LPFC_SLI_REV4)
6860 spin_lock(&pring->ring_lock);
James Smart2a9bf3d2010-06-07 15:24:45 -04006861
James Smart06918ac2014-02-20 09:57:57 -05006862 if ((phba->pport->load_flag & FC_UNLOADING)) {
6863 if (phba->sli_rev == LPFC_SLI_REV4)
6864 spin_unlock(&pring->ring_lock);
6865 spin_unlock_irq(&phba->hbalock);
6866 return;
6867 }
6868
James Smart0976e1a2013-12-17 20:29:36 -05006869 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006870 cmd = &piocb->iocb;
6871
James Smart2e0fef82007-06-17 19:56:36 -05006872 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6873 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6874 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006875 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006876
6877 if (piocb->vport != vport)
6878 continue;
6879
dea31012005-04-17 16:05:31 -05006880 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006881 if (pcmd)
6882 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006883
James Smart92d7f7b2007-06-17 19:56:38 -05006884 if (els_command == ELS_CMD_FARP ||
6885 els_command == ELS_CMD_FARPR ||
6886 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006887 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006888
dea31012005-04-17 16:05:31 -05006889 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006890 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006891 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006892 else
dea31012005-04-17 16:05:31 -05006893 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006894 continue;
6895 }
6896
James Smart2e0fef82007-06-17 19:56:36 -05006897 remote_ID = 0xffffffff;
6898 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006899 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006900 else {
6901 struct lpfc_nodelist *ndlp;
6902 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006903 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006904 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006905 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006906 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006907 }
James Smart0976e1a2013-12-17 20:29:36 -05006908 if (phba->sli_rev == LPFC_SLI_REV4)
6909 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05006910 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006911
James Smart2a9bf3d2010-06-07 15:24:45 -04006912 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
James Smart15026c92013-12-17 20:30:09 -05006913 cmd = &piocb->iocb;
James Smart2a9bf3d2010-06-07 15:24:45 -04006914 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6915 "0127 ELS timeout Data: x%x x%x x%x "
6916 "x%x\n", els_command,
6917 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6918 spin_lock_irq(&phba->hbalock);
6919 list_del_init(&piocb->dlist);
6920 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6921 spin_unlock_irq(&phba->hbalock);
6922 }
6923
James Smart0e9bb8d2013-03-01 16:35:12 -05006924 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
James Smart06918ac2014-02-20 09:57:57 -05006925 if (!(phba->pport->load_flag & FC_UNLOADING))
6926 mod_timer(&vport->els_tmofunc,
6927 jiffies + msecs_to_jiffies(1000 * timeout));
dea31012005-04-17 16:05:31 -05006928}
6929
James Smarte59058c2008-08-24 21:49:00 -04006930/**
James Smart3621a712009-04-06 18:47:14 -04006931 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006932 * @vport: pointer to a host virtual N_Port data structure.
6933 *
6934 * This routine is used to clean up all the outstanding ELS commands on a
6935 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6936 * routine. After that, it walks the ELS transmit queue to remove all the
6937 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6938 * the IOCBs with a non-NULL completion callback function, the callback
6939 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6940 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6941 * callback function, the IOCB will simply be released. Finally, it walks
6942 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6943 * completion queue IOCB that is associated with the @vport and is not
6944 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6945 * part of the discovery state machine) out to HBA by invoking the
6946 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6947 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6948 * the IOCBs are aborted when this function returns.
6949 **/
dea31012005-04-17 16:05:31 -05006950void
James Smart2e0fef82007-06-17 19:56:36 -05006951lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006952{
James Smart0976e1a2013-12-17 20:29:36 -05006953 LIST_HEAD(abort_list);
James Smart2e0fef82007-06-17 19:56:36 -05006954 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006955 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006956 struct lpfc_iocbq *tmp_iocb, *piocb;
6957 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006958
6959 lpfc_fabric_abort_vport(vport);
James Smart0976e1a2013-12-17 20:29:36 -05006960 /*
6961 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
6962 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
6963 * ultimately grabs the ring_lock, the driver must splice the list into
6964 * a working list and release the locks before calling the abort.
6965 */
6966 spin_lock_irq(&phba->hbalock);
6967 if (phba->sli_rev == LPFC_SLI_REV4)
6968 spin_lock(&pring->ring_lock);
6969
6970 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6971 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6972 continue;
6973
6974 if (piocb->vport != vport)
6975 continue;
6976 list_add_tail(&piocb->dlist, &abort_list);
6977 }
6978 if (phba->sli_rev == LPFC_SLI_REV4)
6979 spin_unlock(&pring->ring_lock);
6980 spin_unlock_irq(&phba->hbalock);
6981 /* Abort each iocb on the aborted list and remove the dlist links. */
6982 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6983 spin_lock_irq(&phba->hbalock);
6984 list_del_init(&piocb->dlist);
6985 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6986 spin_unlock_irq(&phba->hbalock);
6987 }
6988 if (!list_empty(&abort_list))
6989 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6990 "3387 abort list for txq not empty\n");
6991 INIT_LIST_HEAD(&abort_list);
dea31012005-04-17 16:05:31 -05006992
James Smart2e0fef82007-06-17 19:56:36 -05006993 spin_lock_irq(&phba->hbalock);
James Smart0976e1a2013-12-17 20:29:36 -05006994 if (phba->sli_rev == LPFC_SLI_REV4)
6995 spin_lock(&pring->ring_lock);
6996
dea31012005-04-17 16:05:31 -05006997 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6998 cmd = &piocb->iocb;
6999
7000 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
7001 continue;
7002 }
7003
7004 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04007005 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
7006 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
7007 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
7008 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05007009 continue;
dea31012005-04-17 16:05:31 -05007010
James Smart2e0fef82007-06-17 19:56:36 -05007011 if (piocb->vport != vport)
7012 continue;
7013
James Smart0976e1a2013-12-17 20:29:36 -05007014 list_del_init(&piocb->list);
7015 list_add_tail(&piocb->list, &abort_list);
dea31012005-04-17 16:05:31 -05007016 }
James Smart0976e1a2013-12-17 20:29:36 -05007017 if (phba->sli_rev == LPFC_SLI_REV4)
7018 spin_unlock(&pring->ring_lock);
James Smart2e0fef82007-06-17 19:56:36 -05007019 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04007020
James Smarta257bf92009-04-06 18:48:10 -04007021 /* Cancell all the IOCBs from the completions list */
James Smart0976e1a2013-12-17 20:29:36 -05007022 lpfc_sli_cancel_iocbs(phba, &abort_list,
7023 IOSTAT_LOCAL_REJECT, IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04007024
dea31012005-04-17 16:05:31 -05007025 return;
7026}
7027
James Smarte59058c2008-08-24 21:49:00 -04007028/**
James Smart3621a712009-04-06 18:47:14 -04007029 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04007030 * @phba: pointer to lpfc hba data structure.
7031 *
7032 * This routine is used to clean up all the outstanding ELS commands on a
7033 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7034 * routine. After that, it walks the ELS transmit queue to remove all the
7035 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7036 * the IOCBs with the completion callback function associated, the callback
7037 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7038 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7039 * callback function associated, the IOCB will simply be released. Finally,
7040 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7041 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7042 * management plane IOCBs that are not part of the discovery state machine)
7043 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7044 **/
James Smart549e55c2007-08-02 11:09:51 -04007045void
7046lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
7047{
James Smart0976e1a2013-12-17 20:29:36 -05007048 struct lpfc_vport *vport;
7049 list_for_each_entry(vport, &phba->port_list, listentry)
7050 lpfc_els_flush_cmd(vport);
James Smarta257bf92009-04-06 18:48:10 -04007051
James Smart549e55c2007-08-02 11:09:51 -04007052 return;
7053}
7054
James Smarte59058c2008-08-24 21:49:00 -04007055/**
James Smart3621a712009-04-06 18:47:14 -04007056 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04007057 * @phba: Pointer to hba context object.
7058 * @cmdiocbp: Pointer to command iocb which reported error.
7059 * @rspiocbp: Pointer to response iocb which reported error.
7060 *
7061 * This function sends an event when there is an ELS command
7062 * failure.
7063 **/
7064void
7065lpfc_send_els_failure_event(struct lpfc_hba *phba,
7066 struct lpfc_iocbq *cmdiocbp,
7067 struct lpfc_iocbq *rspiocbp)
7068{
7069 struct lpfc_vport *vport = cmdiocbp->vport;
7070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7071 struct lpfc_lsrjt_event lsrjt_event;
7072 struct lpfc_fabric_event_header fabric_event;
7073 struct ls_rjt stat;
7074 struct lpfc_nodelist *ndlp;
7075 uint32_t *pcmd;
7076
7077 ndlp = cmdiocbp->context1;
7078 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
7079 return;
7080
7081 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
7082 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
7083 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
7084 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
7085 sizeof(struct lpfc_name));
7086 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
7087 sizeof(struct lpfc_name));
7088 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
7089 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04007090 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04007091 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
7092 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
7093 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
7094 fc_host_post_vendor_event(shost,
7095 fc_get_event_number(),
7096 sizeof(lsrjt_event),
7097 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05007098 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007099 return;
7100 }
7101 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
7102 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
7103 fabric_event.event_type = FC_REG_FABRIC_EVENT;
7104 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
7105 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
7106 else
7107 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
7108 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
7109 sizeof(struct lpfc_name));
7110 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
7111 sizeof(struct lpfc_name));
7112 fc_host_post_vendor_event(shost,
7113 fc_get_event_number(),
7114 sizeof(fabric_event),
7115 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05007116 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04007117 return;
7118 }
7119
7120}
7121
7122/**
James Smart3621a712009-04-06 18:47:14 -04007123 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04007124 * @vport: Pointer to vport object.
7125 * @ndlp: Pointer FC node object.
7126 * @cmd: ELS command code.
7127 *
7128 * This function posts an event when there is an incoming
7129 * unsolicited ELS command.
7130 **/
7131static void
7132lpfc_send_els_event(struct lpfc_vport *vport,
7133 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05007134 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04007135{
James Smartddcc50f2008-12-04 22:38:46 -05007136 struct lpfc_els_event_header *els_data = NULL;
7137 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04007138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7139
James Smartddcc50f2008-12-04 22:38:46 -05007140 if (*payload == ELS_CMD_LOGO) {
7141 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
7142 if (!logo_data) {
7143 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7144 "0148 Failed to allocate memory "
7145 "for LOGO event\n");
7146 return;
7147 }
7148 els_data = &logo_data->header;
7149 } else {
7150 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
7151 GFP_KERNEL);
7152 if (!els_data) {
7153 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7154 "0149 Failed to allocate memory "
7155 "for ELS event\n");
7156 return;
7157 }
7158 }
7159 els_data->event_type = FC_REG_ELS_EVENT;
7160 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04007161 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05007162 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007163 break;
7164 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05007165 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04007166 break;
7167 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05007168 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
7169 break;
7170 case ELS_CMD_LOGO:
7171 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
7172 /* Copy the WWPN in the LOGO payload */
7173 memcpy(logo_data->logo_wwpn, &payload[2],
7174 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04007175 break;
7176 default:
Julia Lawalle9161412009-02-08 22:43:19 +01007177 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04007178 return;
7179 }
James Smartddcc50f2008-12-04 22:38:46 -05007180 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
7181 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
7182 if (*payload == ELS_CMD_LOGO) {
7183 fc_host_post_vendor_event(shost,
7184 fc_get_event_number(),
7185 sizeof(struct lpfc_logo_event),
7186 (char *)logo_data,
7187 LPFC_NL_VENDOR_ID);
7188 kfree(logo_data);
7189 } else {
7190 fc_host_post_vendor_event(shost,
7191 fc_get_event_number(),
7192 sizeof(struct lpfc_els_event_header),
7193 (char *)els_data,
7194 LPFC_NL_VENDOR_ID);
7195 kfree(els_data);
7196 }
James Smartea2151b2008-09-07 11:52:10 -04007197
7198 return;
7199}
7200
7201
7202/**
James Smart3621a712009-04-06 18:47:14 -04007203 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04007204 * @phba: pointer to lpfc hba data structure.
7205 * @pring: pointer to a SLI ring.
7206 * @vport: pointer to a host virtual N_Port data structure.
7207 * @elsiocb: pointer to lpfc els command iocb data structure.
7208 *
7209 * This routine is used for processing the IOCB associated with a unsolicited
7210 * event. It first determines whether there is an existing ndlp that matches
7211 * the DID from the unsolicited IOCB. If not, it will create a new one with
7212 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7213 * IOCB is then used to invoke the proper routine and to set up proper state
7214 * of the discovery state machine.
7215 **/
James Smarted957682007-06-17 19:56:37 -05007216static void
7217lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05007218 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05007219{
James Smart87af33f2007-10-27 13:37:43 -04007220 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05007221 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05007222 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05007223 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05007224 uint32_t cmd, did, newnode;
7225 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05007226 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05007227
James Smarte47c9092008-02-08 18:49:26 -05007228 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05007229 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05007230
dea31012005-04-17 16:05:31 -05007231 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007232 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
7233 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05007234 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04007235 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05007236
James Smart858c9f62007-06-17 19:56:39 -05007237 did = icmd->un.rcvels.remoteID;
7238 if (icmd->ulpStatus) {
7239 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7240 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7241 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05007242 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05007243 }
dea31012005-04-17 16:05:31 -05007244
7245 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05007246 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05007247 goto dropit;
dea31012005-04-17 16:05:31 -05007248
James Smartc8685952009-11-18 15:39:16 -05007249 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05007250 if (vport->load_flag & FC_UNLOADING)
7251 goto dropit;
7252
James Smart92494142011-02-16 12:39:44 -05007253 /* If NPort discovery is delayed drop incoming ELS */
7254 if ((vport->fc_flag & FC_DISC_DELAYED) &&
7255 (cmd != ELS_CMD_PLOGI))
7256 goto dropit;
7257
James Smart2e0fef82007-06-17 19:56:36 -05007258 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007259 if (!ndlp) {
dea31012005-04-17 16:05:31 -05007260 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05007261 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05007262 if (!ndlp)
dea31012005-04-17 16:05:31 -05007263 goto dropit;
dea31012005-04-17 16:05:31 -05007264
James Smart2e0fef82007-06-17 19:56:36 -05007265 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04007266 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05007267 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05007268 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05007269 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04007270 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7271 ndlp = lpfc_enable_node(vport, ndlp,
7272 NLP_STE_UNUSED_NODE);
7273 if (!ndlp)
7274 goto dropit;
7275 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7276 newnode = 1;
7277 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
7278 ndlp->nlp_type |= NLP_FABRIC;
7279 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
7280 /* This is similar to the new node path */
7281 ndlp = lpfc_nlp_get(ndlp);
7282 if (!ndlp)
7283 goto dropit;
7284 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
7285 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04007286 }
dea31012005-04-17 16:05:31 -05007287
7288 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05007289
James Smart12838e72014-09-03 12:57:19 -04007290 /*
7291 * Do not process any unsolicited ELS commands
7292 * if the ndlp is in DEV_LOSS
7293 */
James Smart466e8402015-05-21 13:55:28 -04007294 shost = lpfc_shost_from_vport(vport);
7295 spin_lock_irq(shost->host_lock);
7296 if (ndlp->nlp_flag & NLP_IN_DEV_LOSS) {
7297 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007298 goto dropit;
James Smart466e8402015-05-21 13:55:28 -04007299 }
7300 spin_unlock_irq(shost->host_lock);
James Smart12838e72014-09-03 12:57:19 -04007301
James Smart329f9bc2007-04-25 09:53:01 -04007302 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05007303 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05007304
7305 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
7306 cmd &= ELS_CMD_MASK;
7307 }
7308 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7310 "0112 ELS command x%x received from NPORT x%x "
James Smarte74c03c2013-04-17 20:15:19 -04007311 "Data: x%x x%x x%x x%x\n",
7312 cmd, did, vport->port_state, vport->fc_flag,
7313 vport->fc_myDID, vport->fc_prevDID);
James Smarteec3d312015-08-31 16:48:18 -04007314
7315 /* reject till our FLOGI completes */
7316 if ((vport->port_state < LPFC_FABRIC_CFG_LINK) &&
James Smartd6de08c2015-12-16 18:11:53 -05007317 (cmd != ELS_CMD_FLOGI)) {
James Smarteec3d312015-08-31 16:48:18 -04007318 rjt_err = LSRJT_UNABLE_TPC;
7319 rjt_exp = LSEXP_NOTHING_MORE;
7320 goto lsrjt;
7321 }
7322
dea31012005-04-17 16:05:31 -05007323 switch (cmd) {
7324 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7326 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7327 did, vport->port_state, ndlp->nlp_flag);
7328
dea31012005-04-17 16:05:31 -05007329 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05007330 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
James Smarte74c03c2013-04-17 20:15:19 -04007331 if (phba->sli_rev == LPFC_SLI_REV4 &&
7332 (phba->pport->fc_flag & FC_PT2PT)) {
7333 vport->fc_prevDID = vport->fc_myDID;
7334 /* Our DID needs to be updated before registering
7335 * the vfi. This is done in lpfc_rcv_plogi but
7336 * that is called after the reg_vfi.
7337 */
7338 vport->fc_myDID = elsiocb->iocb.un.rcvels.parmRo;
7339 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7340 "3312 Remote port assigned DID x%x "
7341 "%x\n", vport->fc_myDID,
7342 vport->fc_prevDID);
7343 }
James Smart858c9f62007-06-17 19:56:39 -05007344
James Smartddcc50f2008-12-04 22:38:46 -05007345 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05007346
7347 /* If Nport discovery is delayed, reject PLOGIs */
7348 if (vport->fc_flag & FC_DISC_DELAYED) {
7349 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007350 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05007351 break;
7352 }
James Smartd6de08c2015-12-16 18:11:53 -05007353
James Smart858c9f62007-06-17 19:56:39 -05007354 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05007355 if (!(phba->pport->fc_flag & FC_PT2PT) ||
7356 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
7357 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007358 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05007359 break;
7360 }
dea31012005-04-17 16:05:31 -05007361 }
James Smart87af33f2007-10-27 13:37:43 -04007362
James Smart87af33f2007-10-27 13:37:43 -04007363 spin_lock_irq(shost->host_lock);
7364 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
7365 spin_unlock_irq(shost->host_lock);
7366
James Smart2e0fef82007-06-17 19:56:36 -05007367 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7368 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05007369
dea31012005-04-17 16:05:31 -05007370 break;
7371 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05007372 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7373 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7374 did, vport->port_state, ndlp->nlp_flag);
7375
dea31012005-04-17 16:05:31 -05007376 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04007377 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007378 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007379 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007380 break;
7381 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05007382 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7383 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7384 did, vport->port_state, ndlp->nlp_flag);
7385
dea31012005-04-17 16:05:31 -05007386 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05007387 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007388 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007389 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007390 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007391 break;
7392 }
James Smart2e0fef82007-06-17 19:56:36 -05007393 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05007394 break;
7395 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05007396 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7397 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7398 did, vport->port_state, ndlp->nlp_flag);
7399
dea31012005-04-17 16:05:31 -05007400 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05007401 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05007402 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007403 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007404 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007405 break;
7406 }
James Smart2e0fef82007-06-17 19:56:36 -05007407 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05007408 break;
James Smart8b017a32015-05-21 13:55:18 -04007409 case ELS_CMD_LCB:
7410 phba->fc_stat.elsRcvLCB++;
7411 lpfc_els_rcv_lcb(vport, elsiocb, ndlp);
7412 break;
James Smart86478872015-05-21 13:55:21 -04007413 case ELS_CMD_RDP:
7414 phba->fc_stat.elsRcvRDP++;
7415 lpfc_els_rcv_rdp(vport, elsiocb, ndlp);
7416 break;
dea31012005-04-17 16:05:31 -05007417 case ELS_CMD_RSCN:
7418 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04007419 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007420 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007421 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007422 break;
7423 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05007424 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7425 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7426 did, vport->port_state, ndlp->nlp_flag);
7427
James Smartddcc50f2008-12-04 22:38:46 -05007428 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05007429 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007430 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007431 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007432 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007433 break;
7434 }
James Smart2e0fef82007-06-17 19:56:36 -05007435 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7436 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05007437 break;
7438 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05007439 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7440 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7441 did, vport->port_state, ndlp->nlp_flag);
7442
dea31012005-04-17 16:05:31 -05007443 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05007444 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007445 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007446 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007447 break;
7448 }
James Smart2e0fef82007-06-17 19:56:36 -05007449 lpfc_disc_state_machine(vport, ndlp, elsiocb,
7450 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05007451 break;
7452 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05007453 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7454 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7455 did, vport->port_state, ndlp->nlp_flag);
7456
dea31012005-04-17 16:05:31 -05007457 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05007458 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007459 break;
7460 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05007461 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7462 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7463 did, vport->port_state, ndlp->nlp_flag);
7464
dea31012005-04-17 16:05:31 -05007465 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05007466 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007467 break;
7468 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05007469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7470 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7471 did, vport->port_state, ndlp->nlp_flag);
7472
dea31012005-04-17 16:05:31 -05007473 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05007474 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05007475 break;
dea31012005-04-17 16:05:31 -05007476 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05007477 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7478 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7479 did, vport->port_state, ndlp->nlp_flag);
7480
dea31012005-04-17 16:05:31 -05007481 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05007482 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05007483 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05007484 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007485 break;
7486 }
James Smart2e0fef82007-06-17 19:56:36 -05007487 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05007488 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007489 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05007490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7491 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7492 did, vport->port_state, ndlp->nlp_flag);
7493
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007494 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05007495 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007496 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007497 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007498 break;
James Smart12265f62010-10-22 11:05:53 -04007499 case ELS_CMD_RLS:
7500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7501 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7502 did, vport->port_state, ndlp->nlp_flag);
7503
7504 phba->fc_stat.elsRcvRLS++;
7505 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
7506 if (newnode)
7507 lpfc_nlp_put(ndlp);
7508 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007509 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05007510 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7511 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7512 did, vport->port_state, ndlp->nlp_flag);
7513
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007514 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05007515 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007516 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007517 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007518 break;
7519 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05007520 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7521 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7522 did, vport->port_state, ndlp->nlp_flag);
7523
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007524 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05007525 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007526 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007527 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05007528 break;
dea31012005-04-17 16:05:31 -05007529 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05007530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7531 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7532 did, vport->port_state, ndlp->nlp_flag);
7533
dea31012005-04-17 16:05:31 -05007534 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05007535 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04007536 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007537 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007538 break;
James Smart12265f62010-10-22 11:05:53 -04007539 case ELS_CMD_RTV:
7540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7541 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7542 did, vport->port_state, ndlp->nlp_flag);
7543 phba->fc_stat.elsRcvRTV++;
7544 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
7545 if (newnode)
7546 lpfc_nlp_put(ndlp);
7547 break;
James Smart5ffc2662009-11-18 15:39:44 -05007548 case ELS_CMD_RRQ:
7549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7550 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7551 did, vport->port_state, ndlp->nlp_flag);
7552
7553 phba->fc_stat.elsRcvRRQ++;
7554 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
7555 if (newnode)
7556 lpfc_nlp_put(ndlp);
7557 break;
James Smart12265f62010-10-22 11:05:53 -04007558 case ELS_CMD_ECHO:
7559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7560 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7561 did, vport->port_state, ndlp->nlp_flag);
7562
7563 phba->fc_stat.elsRcvECHO++;
7564 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
7565 if (newnode)
7566 lpfc_nlp_put(ndlp);
7567 break;
James Smart303f2f92013-01-03 15:43:11 -05007568 case ELS_CMD_REC:
7569 /* receive this due to exchange closed */
7570 rjt_err = LSRJT_UNABLE_TPC;
7571 rjt_exp = LSEXP_INVALID_OX_RX;
7572 break;
dea31012005-04-17 16:05:31 -05007573 default:
James Smart858c9f62007-06-17 19:56:39 -05007574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
7575 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7576 cmd, did, vport->port_state);
7577
dea31012005-04-17 16:05:31 -05007578 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05007579 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05007580 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05007581
7582 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04007583 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7584 "0115 Unknown ELS command x%x "
7585 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04007586 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04007587 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05007588 break;
7589 }
7590
James Smarteec3d312015-08-31 16:48:18 -04007591lsrjt:
dea31012005-04-17 16:05:31 -05007592 /* check if need to LS_RJT received ELS cmd */
7593 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05007594 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05007595 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05007596 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05007597 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
7598 NULL);
dea31012005-04-17 16:05:31 -05007599 }
7600
James Smartd7c255b2008-08-24 21:50:00 -04007601 lpfc_nlp_put(elsiocb->context1);
7602 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05007603 return;
7604
7605dropit:
James Smart98c9ea52007-10-27 13:37:33 -04007606 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04007607 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7608 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05007609 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04007610 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05007611 phba->fc_stat.elsRcvDrop++;
7612}
7613
James Smarte59058c2008-08-24 21:49:00 -04007614/**
James Smart3621a712009-04-06 18:47:14 -04007615 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04007616 * @phba: pointer to lpfc hba data structure.
7617 * @pring: pointer to a SLI ring.
7618 * @elsiocb: pointer to lpfc els iocb data structure.
7619 *
7620 * This routine is used to process an unsolicited event received from a SLI
7621 * (Service Level Interface) ring. The actual processing of the data buffer
7622 * associated with the unsolicited event is done by invoking the routine
7623 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7624 * SLI ring on which the unsolicited event was received.
7625 **/
James Smarted957682007-06-17 19:56:37 -05007626void
7627lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
7628 struct lpfc_iocbq *elsiocb)
7629{
7630 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05007631 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05007632 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05007633 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
7634 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05007635
James Smartd7c255b2008-08-24 21:50:00 -04007636 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05007637 elsiocb->context2 = NULL;
7638 elsiocb->context3 = NULL;
7639
7640 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
7641 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
7642 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04007643 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
7644 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05007645 phba->fc_stat.NoRcvBuf++;
7646 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05007647 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04007648 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05007649 return;
7650 }
7651
James Smart92d7f7b2007-06-17 19:56:38 -05007652 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
7653 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
7654 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
7655 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
7656 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04007657 else
7658 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04007659 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05007660 }
James Smart6d368e52011-05-24 11:44:12 -04007661
James Smart7f5f3d02008-02-08 18:50:14 -05007662 /* If there are no BDEs associated
7663 * with this IOCB, there is nothing to do.
7664 */
James Smarted957682007-06-17 19:56:37 -05007665 if (icmd->ulpBdeCount == 0)
7666 return;
7667
James Smart7f5f3d02008-02-08 18:50:14 -05007668 /* type of ELS cmd is first 32bit word
7669 * in packet
7670 */
James Smarted957682007-06-17 19:56:37 -05007671 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05007672 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05007673 } else {
7674 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
7675 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05007676 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
7677 paddr);
James Smarted957682007-06-17 19:56:37 -05007678 }
7679
James Smart92d7f7b2007-06-17 19:56:38 -05007680 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
7681 /*
7682 * The different unsolicited event handlers would tell us
7683 * if they are done with "mp" by setting context2 to NULL.
7684 */
dea31012005-04-17 16:05:31 -05007685 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007686 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
7687 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05007688 }
James Smarted957682007-06-17 19:56:37 -05007689
7690 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05007691 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05007692 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007693 elsiocb->context2 = bdeBuf2;
7694 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05007695 /* free mp if we are done with it */
7696 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05007697 lpfc_in_buf_free(phba, elsiocb->context2);
7698 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05007699 }
dea31012005-04-17 16:05:31 -05007700 }
dea31012005-04-17 16:05:31 -05007701}
James Smart92d7f7b2007-06-17 19:56:38 -05007702
James Smarte59058c2008-08-24 21:49:00 -04007703/**
James Smart3621a712009-04-06 18:47:14 -04007704 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04007705 * @phba: pointer to lpfc hba data structure.
7706 * @vport: pointer to a virtual N_Port data structure.
7707 *
7708 * This routine issues a Port Login (PLOGI) to the Name Server with
7709 * State Change Request (SCR) for a @vport. This routine will create an
7710 * ndlp for the Name Server associated to the @vport if such node does
7711 * not already exist. The PLOGI to Name Server is issued by invoking the
7712 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7713 * (FDMI) is configured to the @vport, a FDMI node will be created and
7714 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7715 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007716void
7717lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
7718{
7719 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05007720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7721
7722 /*
7723 * If lpfc_delay_discovery parameter is set and the clean address
7724 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7725 * discovery.
7726 */
7727 spin_lock_irq(shost->host_lock);
7728 if (vport->fc_flag & FC_DISC_DELAYED) {
7729 spin_unlock_irq(shost->host_lock);
James Smart18775702013-04-17 20:19:25 -04007730 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
7731 "3334 Delay fc port discovery for %d seconds\n",
7732 phba->fc_ratov);
James Smart92494142011-02-16 12:39:44 -05007733 mod_timer(&vport->delayed_disc_tmo,
James Smart256ec0d2013-04-17 20:14:58 -04007734 jiffies + msecs_to_jiffies(1000 * phba->fc_ratov));
James Smart92494142011-02-16 12:39:44 -05007735 return;
7736 }
7737 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007738
7739 ndlp = lpfc_findnode_did(vport, NameServer_DID);
7740 if (!ndlp) {
7741 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
7742 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007743 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05007744 lpfc_disc_start(vport);
7745 return;
7746 }
7747 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007748 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7749 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007750 return;
7751 }
7752 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007753 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7754 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7755 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007756 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05007757 lpfc_disc_start(vport);
7758 return;
7759 }
7760 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7761 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7762 "0348 NameServer login: node freed\n");
7763 return;
7764 }
James Smart92d7f7b2007-06-17 19:56:38 -05007765 }
James Smart58da1ff2008-04-07 10:15:56 -04007766 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05007767
7768 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7769
7770 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7771 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007772 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7773 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007774 return;
7775 }
7776
James Smart76b2c342015-04-07 15:07:19 -04007777 if (vport->cfg_fdmi_on & LPFC_FDMI_SUPPORT) {
James Smart63e801c2010-11-20 23:14:19 -05007778 /* If this is the first time, allocate an ndlp and initialize
7779 * it. Otherwise, make sure the node is enabled and then do the
7780 * login.
7781 */
7782 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7783 if (!ndlp_fdmi) {
7784 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7785 GFP_KERNEL);
7786 if (ndlp_fdmi) {
7787 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7788 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7789 } else
7790 return;
7791 }
7792 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7793 ndlp_fdmi = lpfc_enable_node(vport,
7794 ndlp_fdmi,
7795 NLP_STE_NPR_NODE);
7796
James Smart92d7f7b2007-06-17 19:56:38 -05007797 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007798 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007799 NLP_STE_PLOGI_ISSUE);
7800 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007801 }
7802 }
James Smart92d7f7b2007-06-17 19:56:38 -05007803}
7804
James Smarte59058c2008-08-24 21:49:00 -04007805/**
James Smart3621a712009-04-06 18:47:14 -04007806 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007807 * @phba: pointer to lpfc hba data structure.
7808 * @pmb: pointer to the driver internal queue element for mailbox command.
7809 *
7810 * This routine is the completion callback function to register new vport
7811 * mailbox command. If the new vport mailbox command completes successfully,
7812 * the fabric registration login shall be performed on physical port (the
7813 * new vport created is actually a physical port, with VPI 0) or the port
7814 * login to Name Server for State Change Request (SCR) will be performed
7815 * on virtual port (real virtual port, with VPI greater than 0).
7816 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007817static void
7818lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7819{
7820 struct lpfc_vport *vport = pmb->vport;
7821 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7822 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007823 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007824 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007825
James Smart09372822008-01-11 01:52:54 -05007826 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007827 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007828 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007829
7830 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007831 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007832 "0915 Register VPI failed : Status: x%x"
7833 " upd bit: x%x \n", mb->mbxStatus,
7834 mb->un.varRegVpi.upd);
7835 if (phba->sli_rev == LPFC_SLI_REV4 &&
7836 mb->un.varRegVpi.upd)
7837 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007838
7839 switch (mb->mbxStatus) {
7840 case 0x11: /* unsupported feature */
7841 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007842 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007843 /* giving up on vport registration */
7844 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7845 spin_lock_irq(shost->host_lock);
7846 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7847 spin_unlock_irq(shost->host_lock);
7848 lpfc_can_disctmo(vport);
7849 break;
James Smart695a8142010-01-26 23:08:03 -05007850 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7851 case 0x20:
7852 spin_lock_irq(shost->host_lock);
7853 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7854 spin_unlock_irq(shost->host_lock);
7855 lpfc_init_vpi(phba, pmb, vport->vpi);
7856 pmb->vport = vport;
7857 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7858 rc = lpfc_sli_issue_mbox(phba, pmb,
7859 MBX_NOWAIT);
7860 if (rc == MBX_NOT_FINISHED) {
7861 lpfc_printf_vlog(vport,
7862 KERN_ERR, LOG_MBOX,
7863 "2732 Failed to issue INIT_VPI"
7864 " mailbox command\n");
7865 } else {
7866 lpfc_nlp_put(ndlp);
7867 return;
7868 }
7869
James Smart92d7f7b2007-06-17 19:56:38 -05007870 default:
7871 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007872 if (phba->sli_rev == LPFC_SLI_REV4)
7873 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007874 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007875 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007876 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007877 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007878 if (vport->port_type == LPFC_PHYSICAL_PORT
7879 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007880 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007881 else
7882 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007883 break;
7884 }
James Smart92d7f7b2007-06-17 19:56:38 -05007885 } else {
James Smart695a8142010-01-26 23:08:03 -05007886 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007887 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007888 spin_unlock_irq(shost->host_lock);
7889 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007890 if (phba->sli_rev < LPFC_SLI_REV4)
7891 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007892 else {
James Smartfc2b9892010-02-26 14:15:29 -05007893 /*
7894 * If the physical port is instantiated using
7895 * FDISC, do not start vport discovery.
7896 */
7897 if (vport->port_state != LPFC_FDISC)
7898 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007899 lpfc_do_scr_ns_plogi(phba, vport);
7900 }
7901 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007902 lpfc_do_scr_ns_plogi(phba, vport);
7903 }
James Smart38b92ef2010-08-04 16:11:39 -04007904mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007905 /* Now, we decrement the ndlp reference count held for this
7906 * callback function
7907 */
7908 lpfc_nlp_put(ndlp);
7909
James Smart92d7f7b2007-06-17 19:56:38 -05007910 mempool_free(pmb, phba->mbox_mem_pool);
7911 return;
7912}
7913
James Smarte59058c2008-08-24 21:49:00 -04007914/**
James Smart3621a712009-04-06 18:47:14 -04007915 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007916 * @phba: pointer to lpfc hba data structure.
7917 * @vport: pointer to a host virtual N_Port data structure.
7918 * @ndlp: pointer to a node-list data structure.
7919 *
7920 * This routine registers the @vport as a new virtual port with a HBA.
7921 * It is done through a registering vpi mailbox command.
7922 **/
James Smart695a8142010-01-26 23:08:03 -05007923void
James Smart92d7f7b2007-06-17 19:56:38 -05007924lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7925 struct lpfc_nodelist *ndlp)
7926{
James Smart09372822008-01-11 01:52:54 -05007927 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007928 LPFC_MBOXQ_t *mbox;
7929
7930 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7931 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007932 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007933 mbox->vport = vport;
7934 mbox->context2 = lpfc_nlp_get(ndlp);
7935 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007936 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007937 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007938 /* mailbox command not success, decrement ndlp
7939 * reference count for this command
7940 */
7941 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007942 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007943
James Smarte8b62012007-08-02 11:10:09 -04007944 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7945 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007946 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007947 }
7948 } else {
James Smarte8b62012007-08-02 11:10:09 -04007949 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7950 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007951 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007952 }
James Smartfa4066b2008-01-11 01:53:27 -05007953 return;
7954
7955mbox_err_exit:
7956 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7957 spin_lock_irq(shost->host_lock);
7958 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7959 spin_unlock_irq(shost->host_lock);
7960 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007961}
7962
James Smarte59058c2008-08-24 21:49:00 -04007963/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007964 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007965 * @phba: pointer to lpfc hba data structure.
7966 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007967 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007968 **/
7969void
James Smart0c9ab6f2010-02-26 14:15:57 -05007970lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007971{
7972 struct lpfc_vport **vports;
7973 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007974 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007975 int i;
James Smart695a8142010-01-26 23:08:03 -05007976
7977 /* Treat this failure as linkdown for all vports */
7978 link_state = phba->link_state;
7979 lpfc_linkdown(phba);
7980 phba->link_state = link_state;
7981
7982 vports = lpfc_create_vport_work_array(phba);
7983
7984 if (vports) {
7985 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7986 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7987 if (ndlp)
7988 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7989 lpfc_els_flush_cmd(vports[i]);
7990 }
7991 lpfc_destroy_vport_work_array(phba, vports);
7992 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007993}
7994
7995/**
7996 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7997 * @phba: pointer to lpfc hba data structure.
7998 *
7999 * This routine abort all pending discovery commands and
8000 * start a timer to retry FLOGI for the physical port
8001 * discovery.
8002 **/
8003void
8004lpfc_retry_pport_discovery(struct lpfc_hba *phba)
8005{
8006 struct lpfc_nodelist *ndlp;
8007 struct Scsi_Host *shost;
8008
8009 /* Cancel the all vports retry delay retry timers */
8010 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05008011
8012 /* If fabric require FLOGI, then re-instantiate physical login */
8013 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
8014 if (!ndlp)
8015 return;
8016
James Smart695a8142010-01-26 23:08:03 -05008017 shost = lpfc_shost_from_vport(phba->pport);
James Smart256ec0d2013-04-17 20:14:58 -04008018 mod_timer(&ndlp->nlp_delayfunc, jiffies + msecs_to_jiffies(1000));
James Smart695a8142010-01-26 23:08:03 -05008019 spin_lock_irq(shost->host_lock);
8020 ndlp->nlp_flag |= NLP_DELAY_TMO;
8021 spin_unlock_irq(shost->host_lock);
8022 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
8023 phba->pport->port_state = LPFC_FLOGI;
8024 return;
8025}
8026
8027/**
8028 * lpfc_fabric_login_reqd - Check if FLOGI required.
8029 * @phba: pointer to lpfc hba data structure.
8030 * @cmdiocb: pointer to FDISC command iocb.
8031 * @rspiocb: pointer to FDISC response iocb.
8032 *
8033 * This routine checks if a FLOGI is reguired for FDISC
8034 * to succeed.
8035 **/
8036static int
8037lpfc_fabric_login_reqd(struct lpfc_hba *phba,
8038 struct lpfc_iocbq *cmdiocb,
8039 struct lpfc_iocbq *rspiocb)
8040{
8041
8042 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
8043 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
8044 return 0;
8045 else
8046 return 1;
8047}
8048
8049/**
James Smart3621a712009-04-06 18:47:14 -04008050 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008051 * @phba: pointer to lpfc hba data structure.
8052 * @cmdiocb: pointer to lpfc command iocb data structure.
8053 * @rspiocb: pointer to lpfc response iocb data structure.
8054 *
8055 * This routine is the completion callback function to a Fabric Discover
8056 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8057 * single threaded, each FDISC completion callback function will reset
8058 * the discovery timer for all vports such that the timers will not get
8059 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8060 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8061 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8062 * assigned to the vport has been changed with the completion of the FDISC
8063 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8064 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8065 * routine is invoked to register new vport with the HBA. Otherwise, the
8066 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8067 * Server for State Change Request (SCR).
8068 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008069static void
8070lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8071 struct lpfc_iocbq *rspiocb)
8072{
8073 struct lpfc_vport *vport = cmdiocb->vport;
8074 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8075 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
8076 struct lpfc_nodelist *np;
8077 struct lpfc_nodelist *next_np;
8078 IOCB_t *irsp = &rspiocb->iocb;
8079 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05008080 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
8081 struct serv_parm *sp;
8082 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05008083
James Smarte8b62012007-08-02 11:10:09 -04008084 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8085 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8086 irsp->ulpStatus, irsp->un.ulpWord[4],
8087 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05008088 /* Since all FDISCs are being single threaded, we
8089 * must reset the discovery timer for ALL vports
8090 * waiting to send FDISC when one completes.
8091 */
8092 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
8093 lpfc_set_disctmo(piocb->vport);
8094 }
8095
James Smart858c9f62007-06-17 19:56:39 -05008096 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8097 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8098 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
8099
James Smart92d7f7b2007-06-17 19:56:38 -05008100 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05008101
8102 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
8103 lpfc_retry_pport_discovery(phba);
8104 goto out;
8105 }
8106
James Smart92d7f7b2007-06-17 19:56:38 -05008107 /* Check for retry */
8108 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
8109 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008110 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04008111 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05008112 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04008113 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04008114 goto fdisc_failed;
8115 }
James Smartd7c255b2008-08-24 21:50:00 -04008116 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05008117 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04008118 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04008119 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05008120 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04008121 vport->fc_flag |= FC_PUBLIC_LOOP;
8122 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05008123
James Smartd7c255b2008-08-24 21:50:00 -04008124 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
8125 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05008126 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
James Smarta2fc4aef2014-09-03 12:57:55 -04008127 if (!prsp)
8128 goto out;
James Smart92494142011-02-16 12:39:44 -05008129 sp = prsp->virt + sizeof(uint32_t);
8130 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
8131 memcpy(&vport->fabric_portname, &sp->portName,
8132 sizeof(struct lpfc_name));
8133 memcpy(&vport->fabric_nodename, &sp->nodeName,
8134 sizeof(struct lpfc_name));
8135 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04008136 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8137 /* If our NportID changed, we need to ensure all
8138 * remaining NPORTs get unreg_login'ed so we can
8139 * issue unreg_vpi.
8140 */
8141 list_for_each_entry_safe(np, next_np,
8142 &vport->fc_nodes, nlp_listp) {
8143 if (!NLP_CHK_NODE_ACT(ndlp) ||
8144 (np->nlp_state != NLP_STE_NPR_NODE) ||
8145 !(np->nlp_flag & NLP_NPR_ADISC))
8146 continue;
James Smart09372822008-01-11 01:52:54 -05008147 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008148 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05008149 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04008150 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05008151 }
James Smart78730cf2010-04-06 15:06:30 -04008152 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04008153
8154 if (phba->sli_rev == LPFC_SLI_REV4)
8155 lpfc_sli4_unreg_all_rpis(vport);
8156
James Smartd7c255b2008-08-24 21:50:00 -04008157 lpfc_mbx_unreg_vpi(vport);
8158 spin_lock_irq(shost->host_lock);
8159 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05008160 if (phba->sli_rev == LPFC_SLI_REV4)
8161 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04008162 else
8163 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04008164 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04008165 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
8166 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
8167 /*
8168 * Driver needs to re-reg VPI in order for f/w
8169 * to update the MAC address.
8170 */
8171 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04008172 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05008173 }
8174
James Smartecfd03c2010-02-12 14:41:27 -05008175 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
8176 lpfc_issue_init_vpi(vport);
8177 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04008178 lpfc_register_new_vport(phba, vport, ndlp);
8179 else
8180 lpfc_do_scr_ns_plogi(phba, vport);
8181 goto out;
8182fdisc_failed:
James Smartc84163d2015-05-21 13:55:22 -04008183 if (vport->fc_vport->vport_state != FC_VPORT_NO_FABRIC_RSCS)
8184 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smartd7c255b2008-08-24 21:50:00 -04008185 /* Cancel discovery timer */
8186 lpfc_can_disctmo(vport);
8187 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05008188out:
8189 lpfc_els_free_iocb(phba, cmdiocb);
8190}
8191
James Smarte59058c2008-08-24 21:49:00 -04008192/**
James Smart3621a712009-04-06 18:47:14 -04008193 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04008194 * @vport: pointer to a virtual N_Port data structure.
8195 * @ndlp: pointer to a node-list data structure.
8196 * @retry: number of retries to the command IOCB.
8197 *
8198 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8199 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8200 * routine to issue the IOCB, which makes sure only one outstanding fabric
8201 * IOCB will be sent off HBA at any given time.
8202 *
8203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8205 * will be stored into the context1 field of the IOCB for the completion
8206 * callback function to the FDISC ELS command.
8207 *
8208 * Return code
8209 * 0 - Successfully issued fdisc iocb command
8210 * 1 - Failed to issue fdisc iocb command
8211 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008212static int
James Smart92d7f7b2007-06-17 19:56:38 -05008213lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
8214 uint8_t retry)
8215{
8216 struct lpfc_hba *phba = vport->phba;
8217 IOCB_t *icmd;
8218 struct lpfc_iocbq *elsiocb;
8219 struct serv_parm *sp;
8220 uint8_t *pcmd;
8221 uint16_t cmdsize;
8222 int did = ndlp->nlp_DID;
8223 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05008224
James Smart5ffc2662009-11-18 15:39:44 -05008225 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05008226 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008227 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
8228 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
8229 ELS_CMD_FDISC);
8230 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05008231 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008232 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8233 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008234 return 1;
8235 }
8236
8237 icmd = &elsiocb->iocb;
8238 icmd->un.elsreq64.myID = 0;
8239 icmd->un.elsreq64.fl = 1;
8240
James Smart73d91e52011-10-10 21:32:10 -04008241 /*
8242 * SLI3 ports require a different context type value than SLI4.
8243 * Catch SLI3 ports here and override the prep.
8244 */
8245 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04008246 icmd->ulpCt_h = 1;
8247 icmd->ulpCt_l = 0;
8248 }
James Smart92d7f7b2007-06-17 19:56:38 -05008249
8250 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8251 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
8252 pcmd += sizeof(uint32_t); /* CSP Word 1 */
8253 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
8254 sp = (struct serv_parm *) pcmd;
8255 /* Setup CSPs accordingly for Fabric */
8256 sp->cmn.e_d_tov = 0;
8257 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05008258 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05008259 sp->cls1.classValid = 0;
8260 sp->cls2.seqDelivery = 1;
8261 sp->cls3.seqDelivery = 1;
8262
8263 pcmd += sizeof(uint32_t); /* CSP Word 2 */
8264 pcmd += sizeof(uint32_t); /* CSP Word 3 */
8265 pcmd += sizeof(uint32_t); /* CSP Word 4 */
8266 pcmd += sizeof(uint32_t); /* Port Name */
8267 memcpy(pcmd, &vport->fc_portname, 8);
8268 pcmd += sizeof(uint32_t); /* Node Name */
8269 pcmd += sizeof(uint32_t); /* Node Name */
8270 memcpy(pcmd, &vport->fc_nodename, 8);
8271
8272 lpfc_set_disctmo(vport);
8273
8274 phba->fc_stat.elsXmitFDISC++;
8275 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
8276
James Smart858c9f62007-06-17 19:56:39 -05008277 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8278 "Issue FDISC: did:x%x",
8279 did, 0, 0);
8280
James Smart92d7f7b2007-06-17 19:56:38 -05008281 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
8282 if (rc == IOCB_ERROR) {
8283 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05008284 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04008285 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
8286 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05008287 return 1;
8288 }
8289 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05008290 return 0;
8291}
8292
James Smarte59058c2008-08-24 21:49:00 -04008293/**
James Smart3621a712009-04-06 18:47:14 -04008294 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04008295 * @phba: pointer to lpfc hba data structure.
8296 * @cmdiocb: pointer to lpfc command iocb data structure.
8297 * @rspiocb: pointer to lpfc response iocb data structure.
8298 *
8299 * This routine is the completion callback function to the issuing of a LOGO
8300 * ELS command off a vport. It frees the command IOCB and then decrement the
8301 * reference count held on ndlp for this completion function, indicating that
8302 * the reference to the ndlp is no long needed. Note that the
8303 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8304 * callback function and an additional explicit ndlp reference decrementation
8305 * will trigger the actual release of the ndlp.
8306 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008307static void
8308lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8309 struct lpfc_iocbq *rspiocb)
8310{
8311 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05008312 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05008313 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04008314 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05008315
James Smart9589b0622011-04-16 11:03:17 -04008316 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05008317 irsp = &rspiocb->iocb;
8318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8319 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8320 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05008321
8322 lpfc_els_free_iocb(phba, cmdiocb);
8323 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05008324
8325 /* Trigger the release of the ndlp after logo */
8326 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04008327
8328 /* NPIV LOGO completes to NPort <nlp_DID> */
8329 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
8330 "2928 NPIV LOGO completes to NPort x%x "
8331 "Data: x%x x%x x%x x%x\n",
8332 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
8333 irsp->ulpTimeout, vport->num_disc_nodes);
8334
8335 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
8336 spin_lock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008337 vport->fc_flag &= ~FC_NDISC_ACTIVE;
James Smart9589b0622011-04-16 11:03:17 -04008338 vport->fc_flag &= ~FC_FABRIC;
8339 spin_unlock_irq(shost->host_lock);
James Smart73dc0db2015-05-22 10:42:36 -04008340 lpfc_can_disctmo(vport);
James Smart9589b0622011-04-16 11:03:17 -04008341 }
James Smart92d7f7b2007-06-17 19:56:38 -05008342}
8343
James Smarte59058c2008-08-24 21:49:00 -04008344/**
James Smart3621a712009-04-06 18:47:14 -04008345 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04008346 * @vport: pointer to a virtual N_Port data structure.
8347 * @ndlp: pointer to a node-list data structure.
8348 *
8349 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8350 *
8351 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8352 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8353 * will be stored into the context1 field of the IOCB for the completion
8354 * callback function to the LOGO ELS command.
8355 *
8356 * Return codes
8357 * 0 - Successfully issued logo off the @vport
8358 * 1 - Failed to issue logo off the @vport
8359 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008360int
8361lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
8362{
8363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
8364 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008365 struct lpfc_iocbq *elsiocb;
8366 uint8_t *pcmd;
8367 uint16_t cmdsize;
8368
8369 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
8370 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
8371 ELS_CMD_LOGO);
8372 if (!elsiocb)
8373 return 1;
8374
James Smart92d7f7b2007-06-17 19:56:38 -05008375 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
8376 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
8377 pcmd += sizeof(uint32_t);
8378
8379 /* Fill in LOGO payload */
8380 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
8381 pcmd += sizeof(uint32_t);
8382 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
8383
James Smart858c9f62007-06-17 19:56:39 -05008384 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
8385 "Issue LOGO npiv did:x%x flg:x%x",
8386 ndlp->nlp_DID, ndlp->nlp_flag, 0);
8387
James Smart92d7f7b2007-06-17 19:56:38 -05008388 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
8389 spin_lock_irq(shost->host_lock);
8390 ndlp->nlp_flag |= NLP_LOGO_SND;
8391 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04008392 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
8393 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05008394 spin_lock_irq(shost->host_lock);
8395 ndlp->nlp_flag &= ~NLP_LOGO_SND;
8396 spin_unlock_irq(shost->host_lock);
8397 lpfc_els_free_iocb(phba, elsiocb);
8398 return 1;
8399 }
8400 return 0;
8401}
8402
James Smarte59058c2008-08-24 21:49:00 -04008403/**
James Smart3621a712009-04-06 18:47:14 -04008404 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04008405 * @ptr: holder for the timer function associated data.
8406 *
8407 * This routine is invoked by the fabric iocb block timer after
8408 * timeout. It posts the fabric iocb block timeout event by setting the
8409 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8410 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8411 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8412 * posted event WORKER_FABRIC_BLOCK_TMO.
8413 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008414void
8415lpfc_fabric_block_timeout(unsigned long ptr)
8416{
8417 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
8418 unsigned long iflags;
8419 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04008420
James Smart92d7f7b2007-06-17 19:56:38 -05008421 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
8422 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
8423 if (!tmo_posted)
8424 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
8425 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
8426
James Smart5e9d9b82008-06-14 22:52:53 -04008427 if (!tmo_posted)
8428 lpfc_worker_wake_up(phba);
8429 return;
James Smart92d7f7b2007-06-17 19:56:38 -05008430}
8431
James Smarte59058c2008-08-24 21:49:00 -04008432/**
James Smart3621a712009-04-06 18:47:14 -04008433 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04008434 * @phba: pointer to lpfc hba data structure.
8435 *
8436 * This routine issues one fabric iocb from the driver internal list to
8437 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8438 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8439 * remove one pending fabric iocb from the driver internal list and invokes
8440 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8441 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008442static void
8443lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
8444{
8445 struct lpfc_iocbq *iocb;
8446 unsigned long iflags;
8447 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05008448 IOCB_t *cmd;
8449
8450repeat:
8451 iocb = NULL;
8452 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05008453 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05008454 if (atomic_read(&phba->fabric_iocb_count) == 0) {
8455 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
8456 list);
8457 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05008458 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05008459 atomic_inc(&phba->fabric_iocb_count);
8460 }
8461 spin_unlock_irqrestore(&phba->hbalock, iflags);
8462 if (iocb) {
8463 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8464 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8465 iocb->iocb_flag |= LPFC_IO_FABRIC;
8466
James Smart858c9f62007-06-17 19:56:39 -05008467 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8468 "Fabric sched1: ste:x%x",
8469 iocb->vport->port_state, 0, 0);
8470
James Smart3772a992009-05-22 14:50:54 -04008471 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008472
8473 if (ret == IOCB_ERROR) {
8474 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8475 iocb->fabric_iocb_cmpl = NULL;
8476 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8477 cmd = &iocb->iocb;
8478 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
8479 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
8480 iocb->iocb_cmpl(phba, iocb, iocb);
8481
8482 atomic_dec(&phba->fabric_iocb_count);
8483 goto repeat;
8484 }
8485 }
8486
8487 return;
8488}
8489
James Smarte59058c2008-08-24 21:49:00 -04008490/**
James Smart3621a712009-04-06 18:47:14 -04008491 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008492 * @phba: pointer to lpfc hba data structure.
8493 *
8494 * This routine unblocks the issuing fabric iocb command. The function
8495 * will clear the fabric iocb block bit and then invoke the routine
8496 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8497 * from the driver internal fabric iocb list.
8498 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008499void
8500lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
8501{
8502 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8503
8504 lpfc_resume_fabric_iocbs(phba);
8505 return;
8506}
8507
James Smarte59058c2008-08-24 21:49:00 -04008508/**
James Smart3621a712009-04-06 18:47:14 -04008509 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008510 * @phba: pointer to lpfc hba data structure.
8511 *
8512 * This routine blocks the issuing fabric iocb for a specified amount of
8513 * time (currently 100 ms). This is done by set the fabric iocb block bit
8514 * and set up a timeout timer for 100ms. When the block bit is set, no more
8515 * fabric iocb will be issued out of the HBA.
8516 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008517static void
8518lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
8519{
8520 int blocked;
8521
8522 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05008523 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05008524 if (!blocked)
James Smart256ec0d2013-04-17 20:14:58 -04008525 mod_timer(&phba->fabric_block_timer,
8526 jiffies + msecs_to_jiffies(100));
James Smart92d7f7b2007-06-17 19:56:38 -05008527
8528 return;
8529}
8530
James Smarte59058c2008-08-24 21:49:00 -04008531/**
James Smart3621a712009-04-06 18:47:14 -04008532 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04008533 * @phba: pointer to lpfc hba data structure.
8534 * @cmdiocb: pointer to lpfc command iocb data structure.
8535 * @rspiocb: pointer to lpfc response iocb data structure.
8536 *
8537 * This routine is the callback function that is put to the fabric iocb's
8538 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8539 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8540 * function first restores and invokes the original iocb's callback function
8541 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8542 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8543 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008544static void
8545lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
8546 struct lpfc_iocbq *rspiocb)
8547{
8548 struct ls_rjt stat;
8549
8550 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
8551 BUG();
8552
8553 switch (rspiocb->iocb.ulpStatus) {
8554 case IOSTAT_NPORT_RJT:
8555 case IOSTAT_FABRIC_RJT:
8556 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
8557 lpfc_block_fabric_iocbs(phba);
8558 }
8559 break;
8560
8561 case IOSTAT_NPORT_BSY:
8562 case IOSTAT_FABRIC_BSY:
8563 lpfc_block_fabric_iocbs(phba);
8564 break;
8565
8566 case IOSTAT_LS_RJT:
8567 stat.un.lsRjtError =
8568 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
8569 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
8570 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
8571 lpfc_block_fabric_iocbs(phba);
8572 break;
8573 }
8574
8575 if (atomic_read(&phba->fabric_iocb_count) == 0)
8576 BUG();
8577
8578 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
8579 cmdiocb->fabric_iocb_cmpl = NULL;
8580 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
8581 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
8582
8583 atomic_dec(&phba->fabric_iocb_count);
8584 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05008585 /* Post any pending iocbs to HBA */
8586 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05008587 }
8588}
8589
James Smarte59058c2008-08-24 21:49:00 -04008590/**
James Smart3621a712009-04-06 18:47:14 -04008591 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04008592 * @phba: pointer to lpfc hba data structure.
8593 * @iocb: pointer to lpfc command iocb data structure.
8594 *
8595 * This routine is used as the top-level API for issuing a fabric iocb command
8596 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8597 * function makes sure that only one fabric bound iocb will be outstanding at
8598 * any given time. As such, this function will first check to see whether there
8599 * is already an outstanding fabric iocb on the wire. If so, it will put the
8600 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8601 * issued later. Otherwise, it will issue the iocb on the wire and update the
8602 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8603 *
8604 * Note, this implementation has a potential sending out fabric IOCBs out of
8605 * order. The problem is caused by the construction of the "ready" boolen does
8606 * not include the condition that the internal fabric IOCB list is empty. As
8607 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8608 * ahead of the fabric IOCBs in the internal list.
8609 *
8610 * Return code
8611 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8612 * IOCB_ERROR - failed to issue fabric iocb
8613 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008614static int
James Smart92d7f7b2007-06-17 19:56:38 -05008615lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
8616{
8617 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05008618 int ready;
8619 int ret;
8620
8621 if (atomic_read(&phba->fabric_iocb_count) > 1)
8622 BUG();
8623
8624 spin_lock_irqsave(&phba->hbalock, iflags);
8625 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
8626 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
8627
James Smart7f5f3d02008-02-08 18:50:14 -05008628 if (ready)
8629 /* Increment fabric iocb count to hold the position */
8630 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05008631 spin_unlock_irqrestore(&phba->hbalock, iflags);
8632 if (ready) {
8633 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
8634 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
8635 iocb->iocb_flag |= LPFC_IO_FABRIC;
8636
James Smart858c9f62007-06-17 19:56:39 -05008637 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
8638 "Fabric sched2: ste:x%x",
8639 iocb->vport->port_state, 0, 0);
8640
James Smart3772a992009-05-22 14:50:54 -04008641 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05008642
8643 if (ret == IOCB_ERROR) {
8644 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
8645 iocb->fabric_iocb_cmpl = NULL;
8646 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
8647 atomic_dec(&phba->fabric_iocb_count);
8648 }
8649 } else {
8650 spin_lock_irqsave(&phba->hbalock, iflags);
8651 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
8652 spin_unlock_irqrestore(&phba->hbalock, iflags);
8653 ret = IOCB_SUCCESS;
8654 }
8655 return ret;
8656}
8657
James Smarte59058c2008-08-24 21:49:00 -04008658/**
James Smart3621a712009-04-06 18:47:14 -04008659 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008660 * @vport: pointer to a virtual N_Port data structure.
8661 *
8662 * This routine aborts all the IOCBs associated with a @vport from the
8663 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8664 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8665 * list, removes each IOCB associated with the @vport off the list, set the
8666 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8667 * associated with the IOCB.
8668 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01008669static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05008670{
8671 LIST_HEAD(completions);
8672 struct lpfc_hba *phba = vport->phba;
8673 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05008674
8675 spin_lock_irq(&phba->hbalock);
8676 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8677 list) {
8678
8679 if (piocb->vport != vport)
8680 continue;
8681
8682 list_move_tail(&piocb->list, &completions);
8683 }
8684 spin_unlock_irq(&phba->hbalock);
8685
James Smarta257bf92009-04-06 18:48:10 -04008686 /* Cancel all the IOCBs from the completions list */
8687 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8688 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008689}
8690
James Smarte59058c2008-08-24 21:49:00 -04008691/**
James Smart3621a712009-04-06 18:47:14 -04008692 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008693 * @ndlp: pointer to a node-list data structure.
8694 *
8695 * This routine aborts all the IOCBs associated with an @ndlp from the
8696 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8697 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8698 * list, removes each IOCB associated with the @ndlp off the list, set the
8699 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8700 * associated with the IOCB.
8701 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008702void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
8703{
8704 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04008705 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05008706 struct lpfc_iocbq *tmp_iocb, *piocb;
8707 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05008708
8709 spin_lock_irq(&phba->hbalock);
8710 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
8711 list) {
8712 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
8713
8714 list_move_tail(&piocb->list, &completions);
8715 }
8716 }
8717 spin_unlock_irq(&phba->hbalock);
8718
James Smarta257bf92009-04-06 18:48:10 -04008719 /* Cancel all the IOCBs from the completions list */
8720 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8721 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008722}
8723
James Smarte59058c2008-08-24 21:49:00 -04008724/**
James Smart3621a712009-04-06 18:47:14 -04008725 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04008726 * @phba: pointer to lpfc hba data structure.
8727 *
8728 * This routine aborts all the IOCBs currently on the driver internal
8729 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8730 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8731 * list, removes IOCBs off the list, set the status feild to
8732 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8733 * the IOCB.
8734 **/
James Smart92d7f7b2007-06-17 19:56:38 -05008735void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
8736{
8737 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05008738
8739 spin_lock_irq(&phba->hbalock);
8740 list_splice_init(&phba->fabric_iocb_list, &completions);
8741 spin_unlock_irq(&phba->hbalock);
8742
James Smarta257bf92009-04-06 18:48:10 -04008743 /* Cancel all the IOCBs from the completions list */
8744 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
8745 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05008746}
James Smart6fb120a2009-05-22 14:52:59 -04008747
8748/**
James Smart1151e3e2011-02-16 12:39:35 -05008749 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8750 * @vport: pointer to lpfc vport data structure.
8751 *
8752 * This routine is invoked by the vport cleanup for deletions and the cleanup
8753 * for an ndlp on removal.
8754 **/
8755void
8756lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8757{
8758 struct lpfc_hba *phba = vport->phba;
8759 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8760 unsigned long iflag = 0;
8761
8762 spin_lock_irqsave(&phba->hbalock, iflag);
8763 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8764 list_for_each_entry_safe(sglq_entry, sglq_next,
8765 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8766 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8767 sglq_entry->ndlp = NULL;
8768 }
8769 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8770 spin_unlock_irqrestore(&phba->hbalock, iflag);
8771 return;
8772}
8773
8774/**
James Smart6fb120a2009-05-22 14:52:59 -04008775 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8776 * @phba: pointer to lpfc hba data structure.
8777 * @axri: pointer to the els xri abort wcqe structure.
8778 *
8779 * This routine is invoked by the worker thread to process a SLI4 slow-path
8780 * ELS aborted xri.
8781 **/
8782void
8783lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8784 struct sli4_wcqe_xri_aborted *axri)
8785{
8786 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008787 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008788 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008789
James Smart6fb120a2009-05-22 14:52:59 -04008790 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8791 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008792 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008793 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008794
James Smart0f65ff62010-02-26 14:14:23 -05008795 spin_lock_irqsave(&phba->hbalock, iflag);
8796 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008797 list_for_each_entry_safe(sglq_entry, sglq_next,
8798 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8799 if (sglq_entry->sli4_xritag == xri) {
8800 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008801 ndlp = sglq_entry->ndlp;
8802 sglq_entry->ndlp = NULL;
James Smartdafe8ce2014-09-03 12:56:40 -04008803 spin_lock(&pring->ring_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008804 list_add_tail(&sglq_entry->list,
8805 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008806 sglq_entry->state = SGL_FREED;
James Smartdafe8ce2014-09-03 12:56:40 -04008807 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05008808 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008809 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008810 lpfc_set_rrq_active(phba, ndlp,
8811 sglq_entry->sli4_lxritag,
8812 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008813
8814 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05008815 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04008816 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008817 return;
8818 }
8819 }
James Smart0f65ff62010-02-26 14:14:23 -05008820 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008821 lxri = lpfc_sli4_xri_inrange(phba, xri);
8822 if (lxri == NO_XRI) {
8823 spin_unlock_irqrestore(&phba->hbalock, iflag);
8824 return;
8825 }
James Smartdafe8ce2014-09-03 12:56:40 -04008826 spin_lock(&pring->ring_lock);
James Smart7851fe22011-07-22 18:36:52 -04008827 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008828 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
James Smartdafe8ce2014-09-03 12:56:40 -04008829 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05008830 spin_unlock_irqrestore(&phba->hbalock, iflag);
8831 return;
8832 }
8833 sglq_entry->state = SGL_XRI_ABORTED;
James Smartdafe8ce2014-09-03 12:56:40 -04008834 spin_unlock(&pring->ring_lock);
James Smart0f65ff62010-02-26 14:14:23 -05008835 spin_unlock_irqrestore(&phba->hbalock, iflag);
8836 return;
James Smart6fb120a2009-05-22 14:52:59 -04008837}
James Smart086a3452012-08-14 14:25:21 -04008838
8839/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8840 * @vport: pointer to virtual port object.
8841 * @ndlp: nodelist pointer for the impacted node.
8842 *
8843 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8844 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8845 * the driver is required to send a LOGO to the remote node before it
8846 * attempts to recover its login to the remote node.
8847 */
8848void
8849lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8850 struct lpfc_nodelist *ndlp)
8851{
8852 struct Scsi_Host *shost;
8853 struct lpfc_hba *phba;
8854 unsigned long flags = 0;
8855
8856 shost = lpfc_shost_from_vport(vport);
8857 phba = vport->phba;
8858 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8859 lpfc_printf_log(phba, KERN_INFO,
8860 LOG_SLI, "3093 No rport recovery needed. "
8861 "rport in state 0x%x\n", ndlp->nlp_state);
8862 return;
8863 }
8864 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8865 "3094 Start rport recovery on shost id 0x%x "
8866 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8867 "flags 0x%x\n",
8868 shost->host_no, ndlp->nlp_DID,
8869 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8870 ndlp->nlp_flag);
8871 /*
8872 * The rport is not responding. Remove the FCP-2 flag to prevent
8873 * an ADISC in the follow-up recovery code.
8874 */
8875 spin_lock_irqsave(shost->host_lock, flags);
8876 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8877 spin_unlock_irqrestore(shost->host_lock, flags);
8878 lpfc_issue_els_logo(vport, ndlp, 0);
8879 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8880}
8881