blob: b7a61ff43ca8b8d3ed5e2739f4ad21a7690969a1 [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 Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 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 Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050092 if (lpfc_readl(phba->HAregaddr, &ha_copy))
93 return 1;
dea31012005-04-17 16:05:31 -050094
95 if (!(ha_copy & HA_LATT))
96 return 0;
97
98 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040099 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500103
104 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300105 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
108 * events.
109 */
James Smart2e0fef82007-06-17 19:56:36 -0500110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500116
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500117 return 1;
dea31012005-04-17 16:05:31 -0500118}
119
James Smarte59058c2008-08-24 21:49:00 -0400120/**
James Smart3621a712009-04-06 18:47:14 -0400121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
129 *
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
143 *
144 * Return code
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
147 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400148struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
152 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500153{
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
158 IOCB_t *icmd;
159
dea31012005-04-17 16:05:31 -0500160
James Smart2e0fef82007-06-17 19:56:36 -0500161 if (!lpfc_is_link_up(phba))
162 return NULL;
dea31012005-04-17 16:05:31 -0500163
dea31012005-04-17 16:05:31 -0500164 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400165 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500166
167 if (elsiocb == NULL)
168 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500169
James Smart0c287582009-06-10 17:22:56 -0400170 /*
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 */
174 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500179 switch (elscmd) {
180 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500193 & LPFC_FIP_ELS_ID_MASK);
194 break;
195 }
James Smart0c287582009-06-10 17:22:56 -0400196 else
James Smartc8685952009-11-18 15:39:16 -0500197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400198
dea31012005-04-17 16:05:31 -0500199 icmd = &elsiocb->iocb;
200
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 if (pcmd)
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500208
209 INIT_LIST_HEAD(&pcmd->list);
210
211 /* Allocate buffer for response payload */
212 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500214 if (prsp)
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500219 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500220 } else
dea31012005-04-17 16:05:31 -0500221 prsp = NULL;
dea31012005-04-17 16:05:31 -0500222
223 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500225 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500230
231 INIT_LIST_HEAD(&pbuflist->list);
232
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400234 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
235 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
236 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400238
239 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500240 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400241 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500242 } else {
James Smart939723a2012-05-09 21:19:03 -0400243 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
244 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
245 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
246 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
247 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500248 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
249 }
dea31012005-04-17 16:05:31 -0500250 icmd->ulpBdeCount = 1;
251 icmd->ulpLe = 1;
252 icmd->ulpClass = CLASS3;
253
James Smart939723a2012-05-09 21:19:03 -0400254 /*
255 * If we have NPIV enabled, we want to send ELS traffic by VPI.
256 * For SLI4, since the driver controls VPIs we also want to include
257 * all ELS pt2pt protocol traffic as well.
258 */
259 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
260 ((phba->sli_rev == LPFC_SLI_REV4) &&
261 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500262
James Smart939723a2012-05-09 21:19:03 -0400263 if (expectRsp) {
264 icmd->un.elsreq64.myID = vport->fc_myDID;
265
266 /* For ELS_REQUEST64_CR, use the VPI by default */
267 icmd->ulpContext = phba->vpi_ids[vport->vpi];
268 }
269
James Smart92d7f7b2007-06-17 19:56:38 -0500270 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500271 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
272 if (elscmd == ELS_CMD_ECHO)
273 icmd->ulpCt_l = 0; /* context = invalid RPI */
274 else
275 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500276 }
277
dea31012005-04-17 16:05:31 -0500278 bpl = (struct ulp_bde64 *) pbuflist->virt;
279 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
280 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
281 bpl->tus.f.bdeSize = cmdSize;
282 bpl->tus.f.bdeFlags = 0;
283 bpl->tus.w = le32_to_cpu(bpl->tus.w);
284
285 if (expectRsp) {
286 bpl++;
287 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
288 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
289 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400290 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500291 bpl->tus.w = le32_to_cpu(bpl->tus.w);
292 }
293
James Smartfa4066b2008-01-11 01:53:27 -0500294 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400295 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500296 if (!elsiocb->context1)
297 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400298 elsiocb->context2 = pcmd;
299 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500300 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500301 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500302 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
303
304 if (prsp) {
305 list_add(&prsp->list, &pcmd->list);
306 }
dea31012005-04-17 16:05:31 -0500307 if (expectRsp) {
308 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
310 "0116 Xmit ELS command x%x to remote "
311 "NPORT x%x I/O tag: x%x, port state: x%x\n",
312 elscmd, did, elsiocb->iotag,
313 vport->port_state);
dea31012005-04-17 16:05:31 -0500314 } else {
315 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0117 Xmit ELS response x%x to remote "
318 "NPORT x%x I/O tag: x%x, size: x%x\n",
319 elscmd, ndlp->nlp_DID, elsiocb->iotag,
320 cmdSize);
dea31012005-04-17 16:05:31 -0500321 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500322 return elsiocb;
dea31012005-04-17 16:05:31 -0500323
James Smartfa4066b2008-01-11 01:53:27 -0500324els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500325 if (expectRsp)
326 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500327 kfree(pbuflist);
328
329els_iocb_free_prsp_exit:
330 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
331 kfree(prsp);
332
333els_iocb_free_pcmb_exit:
334 kfree(pcmd);
335 lpfc_sli_release_iocbq(phba, elsiocb);
336 return NULL;
337}
dea31012005-04-17 16:05:31 -0500338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400341 * @vport: pointer to a host virtual N_Port data structure.
342 *
343 * This routine issues a fabric registration login for a @vport. An
344 * active ndlp node with Fabric_DID must already exist for this @vport.
345 * The routine invokes two mailbox commands to carry out fabric registration
346 * login through the HBA firmware: the first mailbox command requests the
347 * HBA to perform link configuration for the @vport; and the second mailbox
348 * command requests the HBA to perform the actual fabric registration login
349 * with the @vport.
350 *
351 * Return code
352 * 0 - successfully issued fabric registration login for @vport
353 * -ENXIO -- failed to issue fabric registration login for @vport
354 **/
James Smart3772a992009-05-22 14:50:54 -0400355int
James Smart92d7f7b2007-06-17 19:56:38 -0500356lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
357{
358 struct lpfc_hba *phba = vport->phba;
359 LPFC_MBOXQ_t *mbox;
360 struct lpfc_dmabuf *mp;
361 struct lpfc_nodelist *ndlp;
362 struct serv_parm *sp;
363 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400364 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500365
366 sp = &phba->fc_fabparam;
367 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500368 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400369 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500370 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400371 }
James Smart92d7f7b2007-06-17 19:56:38 -0500372
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400374 if (!mbox) {
375 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500376 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400377 }
James Smart92d7f7b2007-06-17 19:56:38 -0500378
379 vport->port_state = LPFC_FABRIC_CFG_LINK;
380 lpfc_config_link(phba, mbox);
381 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
382 mbox->vport = vport;
383
James Smart0b727fe2007-10-27 13:37:25 -0400384 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400385 if (rc == MBX_NOT_FINISHED) {
386 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500387 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400388 }
James Smart92d7f7b2007-06-17 19:56:38 -0500389
390 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400391 if (!mbox) {
392 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500393 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400394 }
James Smart40426292010-12-15 17:58:10 -0500395 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
396 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400397 if (rc) {
398 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500399 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400400 }
James Smart92d7f7b2007-06-17 19:56:38 -0500401
402 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
403 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500404 /* increment the reference count on ndlp to hold reference
405 * for the callback routine.
406 */
James Smart92d7f7b2007-06-17 19:56:38 -0500407 mbox->context2 = lpfc_nlp_get(ndlp);
408
James Smart0b727fe2007-10-27 13:37:25 -0400409 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400410 if (rc == MBX_NOT_FINISHED) {
411 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500412 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400413 }
James Smart92d7f7b2007-06-17 19:56:38 -0500414
415 return 0;
416
417fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500418 /* decrement the reference count on ndlp just incremented
419 * for the failed mbox command.
420 */
James Smart92d7f7b2007-06-17 19:56:38 -0500421 lpfc_nlp_put(ndlp);
422 mp = (struct lpfc_dmabuf *) mbox->context1;
423 lpfc_mbuf_free(phba, mp->virt, mp->phys);
424 kfree(mp);
425fail_free_mbox:
426 mempool_free(mbox, phba->mbox_mem_pool);
427
428fail:
429 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400431 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500432 return -ENXIO;
433}
434
James Smarte59058c2008-08-24 21:49:00 -0400435/**
James Smart6fb120a2009-05-22 14:52:59 -0400436 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
437 * @vport: pointer to a host virtual N_Port data structure.
438 *
439 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500440 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400441 *
442 * Return code
443 * 0 - successfully issued REG_VFI for @vport
444 * A failure code otherwise.
445 **/
James Smart1b511972011-12-13 13:23:09 -0500446int
James Smart6fb120a2009-05-22 14:52:59 -0400447lpfc_issue_reg_vfi(struct lpfc_vport *vport)
448{
449 struct lpfc_hba *phba = vport->phba;
450 LPFC_MBOXQ_t *mboxq;
451 struct lpfc_nodelist *ndlp;
452 struct serv_parm *sp;
453 struct lpfc_dmabuf *dmabuf;
454 int rc = 0;
455
456 sp = &phba->fc_fabparam;
James Smart939723a2012-05-09 21:19:03 -0400457 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500458 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400459 !(phba->link_flag & LS_LOOPBACK_MODE) &&
460 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500461 ndlp = lpfc_findnode_did(vport, Fabric_DID);
462 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
463 rc = -ENODEV;
464 goto fail;
465 }
James Smart6fb120a2009-05-22 14:52:59 -0400466 }
467
468 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
469 if (!dmabuf) {
470 rc = -ENOMEM;
471 goto fail;
472 }
473 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
474 if (!dmabuf->virt) {
475 rc = -ENOMEM;
476 goto fail_free_dmabuf;
477 }
James Smart6d368e52011-05-24 11:44:12 -0400478
James Smart6fb120a2009-05-22 14:52:59 -0400479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
480 if (!mboxq) {
481 rc = -ENOMEM;
482 goto fail_free_coherent;
483 }
484 vport->port_state = LPFC_FABRIC_CFG_LINK;
485 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
486 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
487 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
488 mboxq->vport = vport;
489 mboxq->context1 = dmabuf;
490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
491 if (rc == MBX_NOT_FINISHED) {
492 rc = -ENXIO;
493 goto fail_free_mbox;
494 }
495 return 0;
496
497fail_free_mbox:
498 mempool_free(mboxq, phba->mbox_mem_pool);
499fail_free_coherent:
500 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
501fail_free_dmabuf:
502 kfree(dmabuf);
503fail:
504 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
505 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
506 "0289 Issue Register VFI failed: Err %d\n", rc);
507 return rc;
508}
509
510/**
James Smart1b511972011-12-13 13:23:09 -0500511 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
512 * @vport: pointer to a host virtual N_Port data structure.
513 *
514 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
515 * the @vport. This mailbox command is necessary for SLI4 port only.
516 *
517 * Return code
518 * 0 - successfully issued REG_VFI for @vport
519 * A failure code otherwise.
520 **/
521int
522lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
523{
524 struct lpfc_hba *phba = vport->phba;
525 struct Scsi_Host *shost;
526 LPFC_MBOXQ_t *mboxq;
527 int rc;
528
529 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
530 if (!mboxq) {
531 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
532 "2556 UNREG_VFI mbox allocation failed"
533 "HBA state x%x\n", phba->pport->port_state);
534 return -ENOMEM;
535 }
536
537 lpfc_unreg_vfi(mboxq, vport);
538 mboxq->vport = vport;
539 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
540
541 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
542 if (rc == MBX_NOT_FINISHED) {
543 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
544 "2557 UNREG_VFI issue mbox failed rc x%x "
545 "HBA state x%x\n",
546 rc, phba->pport->port_state);
547 mempool_free(mboxq, phba->mbox_mem_pool);
548 return -EIO;
549 }
550
551 shost = lpfc_shost_from_vport(vport);
552 spin_lock_irq(shost->host_lock);
553 vport->fc_flag &= ~FC_VFI_REGISTERED;
554 spin_unlock_irq(shost->host_lock);
555 return 0;
556}
557
558/**
James Smart92494142011-02-16 12:39:44 -0500559 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
560 * @vport: pointer to a host virtual N_Port data structure.
561 * @sp: pointer to service parameter data structure.
562 *
563 * This routine is called from FLOGI/FDISC completion handler functions.
564 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
565 * node nodename is changed in the completion service parameter else return
566 * 0. This function also set flag in the vport data structure to delay
567 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
568 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
569 * node nodename is changed in the completion service parameter.
570 *
571 * Return code
572 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
573 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
574 *
575 **/
576static uint8_t
577lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
578 struct serv_parm *sp)
579{
580 uint8_t fabric_param_changed = 0;
581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
582
583 if ((vport->fc_prevDID != vport->fc_myDID) ||
584 memcmp(&vport->fabric_portname, &sp->portName,
585 sizeof(struct lpfc_name)) ||
586 memcmp(&vport->fabric_nodename, &sp->nodeName,
587 sizeof(struct lpfc_name)))
588 fabric_param_changed = 1;
589
590 /*
591 * Word 1 Bit 31 in common service parameter is overloaded.
592 * Word 1 Bit 31 in FLOGI request is multiple NPort request
593 * Word 1 Bit 31 in FLOGI response is clean address bit
594 *
595 * If fabric parameter is changed and clean address bit is
596 * cleared delay nport discovery if
597 * - vport->fc_prevDID != 0 (not initial discovery) OR
598 * - lpfc_delay_discovery module parameter is set.
599 */
600 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
601 (vport->fc_prevDID || lpfc_delay_discovery)) {
602 spin_lock_irq(shost->host_lock);
603 vport->fc_flag |= FC_DISC_DELAYED;
604 spin_unlock_irq(shost->host_lock);
605 }
606
607 return fabric_param_changed;
608}
609
610
611/**
James Smart3621a712009-04-06 18:47:14 -0400612 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400613 * @vport: pointer to a host virtual N_Port data structure.
614 * @ndlp: pointer to a node-list data structure.
615 * @sp: pointer to service parameter data structure.
616 * @irsp: pointer to the IOCB within the lpfc response IOCB.
617 *
618 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
619 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
620 * port in a fabric topology. It properly sets up the parameters to the @ndlp
621 * from the IOCB response. It also check the newly assigned N_Port ID to the
622 * @vport against the previously assigned N_Port ID. If it is different from
623 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
624 * is invoked on all the remaining nodes with the @vport to unregister the
625 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
626 * is invoked to register login to the fabric.
627 *
628 * Return code
629 * 0 - Success (currently, always return 0)
630 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500631static int
James Smart2e0fef82007-06-17 19:56:36 -0500632lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
633 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500634{
James Smart2e0fef82007-06-17 19:56:36 -0500635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
636 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500637 struct lpfc_nodelist *np;
638 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500639 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500640
James Smart2e0fef82007-06-17 19:56:36 -0500641 spin_lock_irq(shost->host_lock);
642 vport->fc_flag |= FC_FABRIC;
643 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500644
645 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
646 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
647 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
648
James Smart12265f62010-10-22 11:05:53 -0400649 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500650 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
651
James Smart76a95d72010-11-20 23:11:48 -0500652 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500653 spin_lock_irq(shost->host_lock);
654 vport->fc_flag |= FC_PUBLIC_LOOP;
655 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500656 }
657
James Smart2e0fef82007-06-17 19:56:36 -0500658 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500659 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500660 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500661 ndlp->nlp_class_sup = 0;
662 if (sp->cls1.classValid)
663 ndlp->nlp_class_sup |= FC_COS_CLASS1;
664 if (sp->cls2.classValid)
665 ndlp->nlp_class_sup |= FC_COS_CLASS2;
666 if (sp->cls3.classValid)
667 ndlp->nlp_class_sup |= FC_COS_CLASS3;
668 if (sp->cls4.classValid)
669 ndlp->nlp_class_sup |= FC_COS_CLASS4;
670 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
671 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500672
673 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
674 memcpy(&vport->fabric_portname, &sp->portName,
675 sizeof(struct lpfc_name));
676 memcpy(&vport->fabric_nodename, &sp->nodeName,
677 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500678 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
679
James Smart92d7f7b2007-06-17 19:56:38 -0500680 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
681 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400682 lpfc_printf_vlog(vport, KERN_WARNING,
683 LOG_ELS | LOG_VPORT,
684 "1816 FLOGI NPIV supported, "
685 "response data 0x%x\n",
686 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500687 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500688 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500689 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500690 } else {
691 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400692 to call reg_vnpid atleast for the physcial host */
693 lpfc_printf_vlog(vport, KERN_WARNING,
694 LOG_ELS | LOG_VPORT,
695 "1817 Fabric does not support NPIV "
696 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500697 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500698 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500699 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500700 }
701 }
702
James Smart92494142011-02-16 12:39:44 -0500703 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500704 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
705
706 /* If our NportID changed, we need to ensure all
707 * remaining NPORTs get unreg_login'ed.
708 */
709 list_for_each_entry_safe(np, next_np,
710 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400711 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500712 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500713 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
714 !(np->nlp_flag & NLP_NPR_ADISC))
715 continue;
716 spin_lock_irq(shost->host_lock);
717 np->nlp_flag &= ~NLP_NPR_ADISC;
718 spin_unlock_irq(shost->host_lock);
719 lpfc_unreg_rpi(vport, np);
720 }
James Smart78730cf2010-04-06 15:06:30 -0400721 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400722
James Smart5248a742011-07-22 18:37:06 -0400723 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400724 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500725 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500726 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500727 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
728 spin_unlock_irq(shost->host_lock);
729 }
James Smart27aa1b72012-05-09 21:18:49 -0400730
731 /*
732 * For SLI3 and SLI4, the VPI needs to be reregistered in
733 * response to this fabric parameter change event.
734 */
735 spin_lock_irq(shost->host_lock);
736 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
737 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400738 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
739 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
740 /*
741 * Driver needs to re-reg VPI in order for f/w
742 * to update the MAC address.
743 */
James Smart9589b0622011-04-16 11:03:17 -0400744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400745 lpfc_register_new_vport(phba, vport, ndlp);
746 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500747 }
748
James Smart6fb120a2009-05-22 14:52:59 -0400749 if (phba->sli_rev < LPFC_SLI_REV4) {
750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
751 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
752 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
753 lpfc_register_new_vport(phba, vport, ndlp);
754 else
755 lpfc_issue_fabric_reglogin(vport);
756 } else {
757 ndlp->nlp_type |= NLP_FABRIC;
758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500759 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
760 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400761 lpfc_start_fdiscs(phba);
762 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500763 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500764 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500765 else {
766 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
767 "3135 Need register VFI: (x%x/%x)\n",
768 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400769 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500770 }
James Smart92d7f7b2007-06-17 19:56:38 -0500771 }
dea31012005-04-17 16:05:31 -0500772 return 0;
dea31012005-04-17 16:05:31 -0500773}
James Smart1b511972011-12-13 13:23:09 -0500774
James Smarte59058c2008-08-24 21:49:00 -0400775/**
James Smart3621a712009-04-06 18:47:14 -0400776 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400777 * @vport: pointer to a host virtual N_Port data structure.
778 * @ndlp: pointer to a node-list data structure.
779 * @sp: pointer to service parameter data structure.
780 *
781 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
782 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
783 * in a point-to-point topology. First, the @vport's N_Port Name is compared
784 * with the received N_Port Name: if the @vport's N_Port Name is greater than
785 * the received N_Port Name lexicographically, this node shall assign local
786 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
787 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
788 * this node shall just wait for the remote node to issue PLOGI and assign
789 * N_Port IDs.
790 *
791 * Return code
792 * 0 - Success
793 * -ENXIO - Fail
794 **/
dea31012005-04-17 16:05:31 -0500795static int
James Smart2e0fef82007-06-17 19:56:36 -0500796lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
797 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500798{
James Smart2e0fef82007-06-17 19:56:36 -0500799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
800 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500801 LPFC_MBOXQ_t *mbox;
802 int rc;
803
James Smart2e0fef82007-06-17 19:56:36 -0500804 spin_lock_irq(shost->host_lock);
805 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
806 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500807
808 phba->fc_edtov = FF_DEF_EDTOV;
809 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500810 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500811 sizeof(vport->fc_portname));
James Smart2eb68622012-09-29 11:32:27 -0400812 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
813
dea31012005-04-17 16:05:31 -0500814 if (rc >= 0) {
815 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500816 spin_lock_irq(shost->host_lock);
817 vport->fc_flag |= FC_PT2PT_PLOGI;
818 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500819
820 /*
821 * N_Port ID cannot be 0, set our to LocalID the other
822 * side will be RemoteID.
823 */
824
825 /* not equal */
826 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500827 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500828
829 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
830 if (!mbox)
831 goto fail;
832
833 lpfc_config_link(phba, mbox);
834
835 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500836 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400837 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500838 if (rc == MBX_NOT_FINISHED) {
839 mempool_free(mbox, phba->mbox_mem_pool);
840 goto fail;
841 }
James Smart939723a2012-05-09 21:19:03 -0400842
843 /*
844 * For SLI4, the VFI/VPI are registered AFTER the
845 * Nport with the higher WWPN sends the PLOGI with
846 * an assigned NPortId.
847 */
848
849 /* not equal */
850 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
851 lpfc_issue_reg_vfi(vport);
852
James Smarte47c9092008-02-08 18:49:26 -0500853 /* Decrement ndlp reference count indicating that ndlp can be
854 * safely released when other references to it are done.
855 */
James Smart329f9bc2007-04-25 09:53:01 -0400856 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500857
James Smart2e0fef82007-06-17 19:56:36 -0500858 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500859 if (!ndlp) {
860 /*
861 * Cannot find existing Fabric ndlp, so allocate a
862 * new one
863 */
864 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
865 if (!ndlp)
866 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500867 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500868 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
869 ndlp = lpfc_enable_node(vport, ndlp,
870 NLP_STE_UNUSED_NODE);
871 if(!ndlp)
872 goto fail;
dea31012005-04-17 16:05:31 -0500873 }
874
875 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500876 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500877 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500878 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500879 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500880 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
881 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500882 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500883 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500884 } else
885 /* This side will wait for the PLOGI, decrement ndlp reference
886 * count indicating that ndlp can be released when other
887 * references to it are done.
888 */
James Smart329f9bc2007-04-25 09:53:01 -0400889 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500890
James Smart09372822008-01-11 01:52:54 -0500891 /* If we are pt2pt with another NPort, force NPIV off! */
892 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
893
James Smart2e0fef82007-06-17 19:56:36 -0500894 spin_lock_irq(shost->host_lock);
895 vport->fc_flag |= FC_PT2PT;
896 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500897
898 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500899 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500900 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500901fail:
dea31012005-04-17 16:05:31 -0500902 return -ENXIO;
903}
904
James Smarte59058c2008-08-24 21:49:00 -0400905/**
James Smart3621a712009-04-06 18:47:14 -0400906 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400907 * @phba: pointer to lpfc hba data structure.
908 * @cmdiocb: pointer to lpfc command iocb data structure.
909 * @rspiocb: pointer to lpfc response iocb data structure.
910 *
911 * This routine is the top-level completion callback function for issuing
912 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
913 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
914 * retry has been made (either immediately or delayed with lpfc_els_retry()
915 * returning 1), the command IOCB will be released and function returned.
916 * If the retry attempt has been given up (possibly reach the maximum
917 * number of retries), one additional decrement of ndlp reference shall be
918 * invoked before going out after releasing the command IOCB. This will
919 * actually release the remote node (Note, lpfc_els_free_iocb() will also
920 * invoke one decrement of ndlp reference count). If no error reported in
921 * the IOCB status, the command Port ID field is used to determine whether
922 * this is a point-to-point topology or a fabric topology: if the Port ID
923 * field is assigned, it is a fabric topology; otherwise, it is a
924 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
925 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
926 * specific topology completion conditions.
927 **/
dea31012005-04-17 16:05:31 -0500928static void
James Smart329f9bc2007-04-25 09:53:01 -0400929lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
930 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500931{
James Smart2e0fef82007-06-17 19:56:36 -0500932 struct lpfc_vport *vport = cmdiocb->vport;
933 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500934 IOCB_t *irsp = &rspiocb->iocb;
935 struct lpfc_nodelist *ndlp = cmdiocb->context1;
936 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
937 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500938 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500939 int rc;
940
941 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500942 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500943 /* One additional decrement on node reference count to
944 * trigger the release of the node
945 */
James Smart329f9bc2007-04-25 09:53:01 -0400946 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500947 goto out;
948 }
949
James Smart858c9f62007-06-17 19:56:39 -0500950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
951 "FLOGI cmpl: status:x%x/x%x state:x%x",
952 irsp->ulpStatus, irsp->un.ulpWord[4],
953 vport->port_state);
954
dea31012005-04-17 16:05:31 -0500955 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500956 /*
James Smarta93ff372010-10-22 11:06:08 -0400957 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500958 * due to new FCF discovery
959 */
960 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500961 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
962 if (phba->link_state < LPFC_LINK_UP)
963 goto stop_rr_fcf_flogi;
964 if ((phba->fcoe_cvl_eventtag_attn ==
965 phba->fcoe_cvl_eventtag) &&
966 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400967 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
968 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -0500969 goto stop_rr_fcf_flogi;
970 else
971 phba->fcoe_cvl_eventtag_attn =
972 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500973 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400974 "2611 FLOGI failed on FCF (x%x), "
975 "status:x%x/x%x, tmo:x%x, perform "
976 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400977 phba->fcf.current_rec.fcf_indx,
978 irsp->ulpStatus, irsp->un.ulpWord[4],
979 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400980 lpfc_sli4_set_fcf_flogi_fail(phba,
981 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500982 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400983 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
984 if (rc)
985 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500986 }
987
James Smart80c17842012-03-01 22:35:45 -0500988stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400989 /* FLOGI failure */
990 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
991 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
992 irsp->ulpStatus, irsp->un.ulpWord[4],
993 irsp->ulpTimeout);
994
dea31012005-04-17 16:05:31 -0500995 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500996 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500997 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500998
James Smart76a95d72010-11-20 23:11:48 -0500999 /* FLOGI failure */
1000 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1001 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1002 irsp->ulpStatus, irsp->un.ulpWord[4],
1003 irsp->ulpTimeout);
1004
dea31012005-04-17 16:05:31 -05001005 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001006 spin_lock_irq(shost->host_lock);
1007 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1008 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001009
James Smart329f9bc2007-04-25 09:53:01 -04001010 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001011 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1012 * alpa map would take too long otherwise.
1013 */
James Smart1b511972011-12-13 13:23:09 -05001014 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001015 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001016 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1017 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1018 (vport->fc_prevDID != vport->fc_myDID))) {
1019 if (vport->fc_flag & FC_VFI_REGISTERED)
1020 lpfc_sli4_unreg_all_rpis(vport);
1021 lpfc_issue_reg_vfi(vport);
1022 lpfc_nlp_put(ndlp);
1023 goto out;
dea31012005-04-17 16:05:31 -05001024 }
dea31012005-04-17 16:05:31 -05001025 goto flogifail;
1026 }
James Smart695a8142010-01-26 23:08:03 -05001027 spin_lock_irq(shost->host_lock);
1028 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001029 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001030 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001031
1032 /*
1033 * The FLogI succeeded. Sync the data for the CPU before
1034 * accessing it.
1035 */
1036 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1037
1038 sp = prsp->virt + sizeof(uint32_t);
1039
1040 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001041 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001042 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001043 "Data: x%x x%x x%x x%x\n",
1044 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1045 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001046
James Smart2e0fef82007-06-17 19:56:36 -05001047 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001048 /*
1049 * If Common Service Parameters indicate Nport
1050 * we are point to point, if Fport we are Fabric.
1051 */
1052 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001053 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001054 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001055 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001056 else {
1057 lpfc_printf_vlog(vport, KERN_ERR,
1058 LOG_FIP | LOG_ELS,
1059 "2831 FLOGI response with cleared Fabric "
1060 "bit fcf_index 0x%x "
1061 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1062 "Fabric Name "
1063 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1064 phba->fcf.current_rec.fcf_indx,
1065 phba->fcf.current_rec.switch_name[0],
1066 phba->fcf.current_rec.switch_name[1],
1067 phba->fcf.current_rec.switch_name[2],
1068 phba->fcf.current_rec.switch_name[3],
1069 phba->fcf.current_rec.switch_name[4],
1070 phba->fcf.current_rec.switch_name[5],
1071 phba->fcf.current_rec.switch_name[6],
1072 phba->fcf.current_rec.switch_name[7],
1073 phba->fcf.current_rec.fabric_name[0],
1074 phba->fcf.current_rec.fabric_name[1],
1075 phba->fcf.current_rec.fabric_name[2],
1076 phba->fcf.current_rec.fabric_name[3],
1077 phba->fcf.current_rec.fabric_name[4],
1078 phba->fcf.current_rec.fabric_name[5],
1079 phba->fcf.current_rec.fabric_name[6],
1080 phba->fcf.current_rec.fabric_name[7]);
1081 lpfc_nlp_put(ndlp);
1082 spin_lock_irq(&phba->hbalock);
1083 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001084 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001085 spin_unlock_irq(&phba->hbalock);
1086 goto out;
1087 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001088 if (!rc) {
1089 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001090 if (phba->hba_flag & HBA_FIP_SUPPORT)
1091 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1092 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001093 "2769 FLOGI to FCF (x%x) "
1094 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001095 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001096 spin_lock_irq(&phba->hbalock);
1097 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001098 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001099 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001100 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001101 }
dea31012005-04-17 16:05:31 -05001102 }
1103
1104flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001105 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001106
James Smart858c9f62007-06-17 19:56:39 -05001107 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001108 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001110
1111 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001112 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001113 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001114 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1115 IOERR_SLI_ABORTED) &&
1116 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1117 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001118 (phba->link_state != LPFC_CLEAR_LA)) {
1119 /* If FLOGI failed enable link interrupt. */
1120 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001121 }
dea31012005-04-17 16:05:31 -05001122out:
1123 lpfc_els_free_iocb(phba, cmdiocb);
1124}
1125
James Smarte59058c2008-08-24 21:49:00 -04001126/**
James Smart3621a712009-04-06 18:47:14 -04001127 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001128 * @vport: pointer to a host virtual N_Port data structure.
1129 * @ndlp: pointer to a node-list data structure.
1130 * @retry: number of retries to the command IOCB.
1131 *
1132 * This routine issues a Fabric Login (FLOGI) Request ELS command
1133 * for a @vport. The initiator service parameters are put into the payload
1134 * of the FLOGI Request IOCB and the top-level callback function pointer
1135 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1136 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1137 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1138 *
1139 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1140 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1141 * will be stored into the context1 field of the IOCB for the completion
1142 * callback function to the FLOGI ELS command.
1143 *
1144 * Return code
1145 * 0 - successfully issued flogi iocb for @vport
1146 * 1 - failed to issue flogi iocb for @vport
1147 **/
dea31012005-04-17 16:05:31 -05001148static int
James Smart2e0fef82007-06-17 19:56:36 -05001149lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001150 uint8_t retry)
1151{
James Smart2e0fef82007-06-17 19:56:36 -05001152 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001153 struct serv_parm *sp;
1154 IOCB_t *icmd;
1155 struct lpfc_iocbq *elsiocb;
1156 struct lpfc_sli_ring *pring;
1157 uint8_t *pcmd;
1158 uint16_t cmdsize;
1159 uint32_t tmo;
1160 int rc;
1161
1162 pring = &phba->sli.ring[LPFC_ELS_RING];
1163
James Smart92d7f7b2007-06-17 19:56:38 -05001164 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001165 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1166 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001167
James Smart488d1462006-03-07 15:02:37 -05001168 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001169 return 1;
dea31012005-04-17 16:05:31 -05001170
1171 icmd = &elsiocb->iocb;
1172 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1173
1174 /* For FLOGI request, remainder of payload is service parameters */
1175 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001176 pcmd += sizeof(uint32_t);
1177 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001178 sp = (struct serv_parm *) pcmd;
1179
1180 /* Setup CSPs accordingly for Fabric */
1181 sp->cmn.e_d_tov = 0;
1182 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001183 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001184 sp->cls1.classValid = 0;
dea31012005-04-17 16:05:31 -05001185 if (sp->cmn.fcphLow < FC_PH3)
1186 sp->cmn.fcphLow = FC_PH3;
1187 if (sp->cmn.fcphHigh < FC_PH3)
1188 sp->cmn.fcphHigh = FC_PH3;
1189
James Smartc31098c2011-04-16 11:03:33 -04001190 if (phba->sli_rev == LPFC_SLI_REV4) {
1191 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1192 LPFC_SLI_INTF_IF_TYPE_0) {
1193 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1194 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1195 /* FLOGI needs to be 3 for WQE FCFI */
1196 /* Set the fcfi to the fcfi we registered with */
1197 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1198 }
James Smart0f378872012-10-31 14:45:01 -04001199 /* Can't do SLI4 class2 without support sequence coalescing */
1200 sp->cls2.classValid = 0;
1201 sp->cls2.seqDelivery = 0;
James Smart5248a742011-07-22 18:37:06 -04001202 } else {
James Smart0f378872012-10-31 14:45:01 -04001203 /* Historical, setting sequential-delivery bit for SLI3 */
1204 sp->cls2.seqDelivery = (sp->cls2.classValid) ? 1 : 0;
1205 sp->cls3.seqDelivery = (sp->cls3.classValid) ? 1 : 0;
James Smart5248a742011-07-22 18:37:06 -04001206 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1207 sp->cmn.request_multiple_Nport = 1;
1208 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1209 icmd->ulpCt_h = 1;
1210 icmd->ulpCt_l = 0;
1211 } else
1212 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001213 }
1214
James Smart76a95d72010-11-20 23:11:48 -05001215 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001216 icmd->un.elsreq64.myID = 0;
1217 icmd->un.elsreq64.fl = 1;
1218 }
1219
dea31012005-04-17 16:05:31 -05001220 tmo = phba->fc_ratov;
1221 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001222 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001223 phba->fc_ratov = tmo;
1224
1225 phba->fc_stat.elsXmitFLOGI++;
1226 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001227
1228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1229 "Issue FLOGI: opt:x%x",
1230 phba->sli3_options, 0, 0);
1231
James Smart92d7f7b2007-06-17 19:56:38 -05001232 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001233 if (rc == IOCB_ERROR) {
1234 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001235 return 1;
dea31012005-04-17 16:05:31 -05001236 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001237 return 0;
dea31012005-04-17 16:05:31 -05001238}
1239
James Smarte59058c2008-08-24 21:49:00 -04001240/**
James Smart3621a712009-04-06 18:47:14 -04001241 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001242 * @phba: pointer to lpfc hba data structure.
1243 *
1244 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1245 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1246 * list and issues an abort IOCB commond on each outstanding IOCB that
1247 * contains a active Fabric_DID ndlp. Note that this function is to issue
1248 * the abort IOCB command on all the outstanding IOCBs, thus when this
1249 * function returns, it does not guarantee all the IOCBs are actually aborted.
1250 *
1251 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001252 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001253 **/
dea31012005-04-17 16:05:31 -05001254int
James Smart2e0fef82007-06-17 19:56:36 -05001255lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001256{
1257 struct lpfc_sli_ring *pring;
1258 struct lpfc_iocbq *iocb, *next_iocb;
1259 struct lpfc_nodelist *ndlp;
1260 IOCB_t *icmd;
1261
1262 /* Abort outstanding I/O on NPort <nlp_DID> */
1263 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001264 "0201 Abort outstanding I/O on NPort x%x\n",
1265 Fabric_DID);
dea31012005-04-17 16:05:31 -05001266
1267 pring = &phba->sli.ring[LPFC_ELS_RING];
1268
1269 /*
1270 * Check the txcmplq for an iocb that matches the nport the driver is
1271 * searching for.
1272 */
James Smart2e0fef82007-06-17 19:56:36 -05001273 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001274 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1275 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001276 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001277 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001278 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1279 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001280 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001281 }
1282 }
James Smart2e0fef82007-06-17 19:56:36 -05001283 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001284
1285 return 0;
1286}
1287
James Smarte59058c2008-08-24 21:49:00 -04001288/**
James Smart3621a712009-04-06 18:47:14 -04001289 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001290 * @vport: pointer to a host virtual N_Port data structure.
1291 *
1292 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1293 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1294 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1295 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1296 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1297 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1298 * @vport.
1299 *
1300 * Return code
1301 * 0 - failed to issue initial flogi for @vport
1302 * 1 - successfully issued initial flogi for @vport
1303 **/
dea31012005-04-17 16:05:31 -05001304int
James Smart2e0fef82007-06-17 19:56:36 -05001305lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001306{
James Smart2e0fef82007-06-17 19:56:36 -05001307 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001308 struct lpfc_nodelist *ndlp;
1309
James Smart98c9ea52007-10-27 13:37:33 -04001310 vport->port_state = LPFC_FLOGI;
1311 lpfc_set_disctmo(vport);
1312
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001313 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001314 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001315 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001316 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001317 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1318 if (!ndlp)
1319 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001320 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001321 /* Set the node type */
1322 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001323 /* Put ndlp onto node list */
1324 lpfc_enqueue_node(vport, ndlp);
1325 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1326 /* re-setup ndlp without removing from node list */
1327 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1328 if (!ndlp)
1329 return 0;
dea31012005-04-17 16:05:31 -05001330 }
James Smart87af33f2007-10-27 13:37:43 -04001331
James Smart5ac6b302010-10-22 11:05:36 -04001332 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001333 /* This decrement of reference count to node shall kick off
1334 * the release of the node.
1335 */
James Smart329f9bc2007-04-25 09:53:01 -04001336 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001337 return 0;
1338 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001339 return 1;
dea31012005-04-17 16:05:31 -05001340}
1341
James Smarte59058c2008-08-24 21:49:00 -04001342/**
James Smart3621a712009-04-06 18:47:14 -04001343 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001344 * @vport: pointer to a host virtual N_Port data structure.
1345 *
1346 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1347 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1348 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1349 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1350 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1351 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1352 * @vport.
1353 *
1354 * Return code
1355 * 0 - failed to issue initial fdisc for @vport
1356 * 1 - successfully issued initial fdisc for @vport
1357 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001358int
1359lpfc_initial_fdisc(struct lpfc_vport *vport)
1360{
1361 struct lpfc_hba *phba = vport->phba;
1362 struct lpfc_nodelist *ndlp;
1363
1364 /* First look for the Fabric ndlp */
1365 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1366 if (!ndlp) {
1367 /* Cannot find existing Fabric ndlp, so allocate a new one */
1368 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1369 if (!ndlp)
1370 return 0;
1371 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001372 /* Put ndlp onto node list */
1373 lpfc_enqueue_node(vport, ndlp);
1374 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1375 /* re-setup ndlp without removing from node list */
1376 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1377 if (!ndlp)
1378 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001379 }
James Smarte47c9092008-02-08 18:49:26 -05001380
James Smart92d7f7b2007-06-17 19:56:38 -05001381 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001382 /* decrement node reference count to trigger the release of
1383 * the node.
1384 */
James Smart92d7f7b2007-06-17 19:56:38 -05001385 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001386 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001387 }
1388 return 1;
1389}
James Smart87af33f2007-10-27 13:37:43 -04001390
James Smarte59058c2008-08-24 21:49:00 -04001391/**
James Smart3621a712009-04-06 18:47:14 -04001392 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001393 * @vport: pointer to a host virtual N_Port data structure.
1394 *
1395 * This routine checks whether there are more remaining Port Logins
1396 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1397 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1398 * to issue ELS PLOGIs up to the configured discover threads with the
1399 * @vport (@vport->cfg_discovery_threads). The function also decrement
1400 * the @vport's num_disc_node by 1 if it is not already 0.
1401 **/
James Smart87af33f2007-10-27 13:37:43 -04001402void
James Smart2e0fef82007-06-17 19:56:36 -05001403lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001404{
1405 int sentplogi;
1406
James Smart2e0fef82007-06-17 19:56:36 -05001407 if (vport->num_disc_nodes)
1408 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001409
1410 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001411 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1412 "0232 Continue discovery with %d PLOGIs to go "
1413 "Data: x%x x%x x%x\n",
1414 vport->num_disc_nodes, vport->fc_plogi_cnt,
1415 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001416 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001417 if (vport->fc_flag & FC_NLP_MORE)
1418 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1419 sentplogi = lpfc_els_disc_plogi(vport);
1420
dea31012005-04-17 16:05:31 -05001421 return;
1422}
1423
James Smarte59058c2008-08-24 21:49:00 -04001424/**
James Smart3621a712009-04-06 18:47:14 -04001425 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001426 * @phba: pointer to lpfc hba data structure.
1427 * @prsp: pointer to response IOCB payload.
1428 * @ndlp: pointer to a node-list data structure.
1429 *
1430 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1431 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1432 * The following cases are considered N_Port confirmed:
1433 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1434 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1435 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1436 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1437 * 1) if there is a node on vport list other than the @ndlp with the same
1438 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1439 * on that node to release the RPI associated with the node; 2) if there is
1440 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1441 * into, a new node shall be allocated (or activated). In either case, the
1442 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1443 * be released and the new_ndlp shall be put on to the vport node list and
1444 * its pointer returned as the confirmed node.
1445 *
1446 * Note that before the @ndlp got "released", the keepDID from not-matching
1447 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1448 * of the @ndlp. This is because the release of @ndlp is actually to put it
1449 * into an inactive state on the vport node list and the vport node list
1450 * management algorithm does not allow two node with a same DID.
1451 *
1452 * Return code
1453 * pointer to the PLOGI N_Port @ndlp
1454 **/
James Smart488d1462006-03-07 15:02:37 -05001455static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001456lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001457 struct lpfc_nodelist *ndlp)
1458{
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001460 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001461 struct lpfc_rport_data *rdata;
1462 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001463 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001464 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001465 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001466 int put_node;
1467 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001468 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001469
James Smart2fb9bd82006-12-02 13:33:57 -05001470 /* Fabric nodes can have the same WWPN so we don't bother searching
1471 * by WWPN. Just return the ndlp that was given to us.
1472 */
1473 if (ndlp->nlp_type & NLP_FABRIC)
1474 return ndlp;
1475
James Smart92d7f7b2007-06-17 19:56:38 -05001476 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001477 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001478
James Smart685f0bf2007-04-25 09:53:08 -04001479 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001480 * we have for that ndlp. If not, we have some work to do.
1481 */
James Smart2e0fef82007-06-17 19:56:36 -05001482 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001483
James Smarte47c9092008-02-08 18:49:26 -05001484 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001485 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001486 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001487
James Smart34f5ad82012-08-03 12:35:03 -04001488 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1489 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1490 ndlp, ndlp->nlp_DID, new_ndlp);
1491
James Smart488d1462006-03-07 15:02:37 -05001492 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001493 rc = memcmp(&ndlp->nlp_portname, name,
1494 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001495 if (!rc)
1496 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001497 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1498 if (!new_ndlp)
1499 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001500 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001501 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001502 rc = memcmp(&ndlp->nlp_portname, name,
1503 sizeof(struct lpfc_name));
1504 if (!rc)
1505 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001506 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1507 NLP_STE_UNUSED_NODE);
1508 if (!new_ndlp)
1509 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001510 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001511 if (phba->sli_rev == LPFC_SLI_REV4)
1512 memcpy(&rrq.xri_bitmap,
1513 &new_ndlp->active_rrqs.xri_bitmap,
1514 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1515 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001516 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001517 if (phba->sli_rev == LPFC_SLI_REV4)
1518 memcpy(&rrq.xri_bitmap,
1519 &new_ndlp->active_rrqs.xri_bitmap,
1520 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1521 }
James Smart488d1462006-03-07 15:02:37 -05001522
James Smart2e0fef82007-06-17 19:56:36 -05001523 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001524 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001525 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001526 if (phba->sli_rev == LPFC_SLI_REV4)
1527 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1528 &ndlp->active_rrqs.xri_bitmap,
1529 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001530
1531 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1532 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1533 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1534
James Smarte47c9092008-02-08 18:49:26 -05001535 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001536 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001537
James Smart2e0fef82007-06-17 19:56:36 -05001538 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001539 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1540 /* The new_ndlp is replacing ndlp totally, so we need
1541 * to put ndlp on UNUSED list and try to free it.
1542 */
James Smart34f5ad82012-08-03 12:35:03 -04001543 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1544 "3179 PLOGI confirm NEW: %x %x\n",
1545 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001546
1547 /* Fix up the rport accordingly */
1548 rport = ndlp->rport;
1549 if (rport) {
1550 rdata = rport->dd_data;
1551 if (rdata->pnode == ndlp) {
1552 lpfc_nlp_put(ndlp);
1553 ndlp->rport = NULL;
1554 rdata->pnode = lpfc_nlp_get(new_ndlp);
1555 new_ndlp->rport = rport;
1556 }
1557 new_ndlp->nlp_type = ndlp->nlp_type;
1558 }
James Smart58da1ff2008-04-07 10:15:56 -04001559 /* We shall actually free the ndlp with both nlp_DID and
1560 * nlp_portname fields equals 0 to avoid any ndlp on the
1561 * nodelist never to be used.
1562 */
1563 if (ndlp->nlp_DID == 0) {
1564 spin_lock_irq(&phba->ndlp_lock);
1565 NLP_SET_FREE_REQ(ndlp);
1566 spin_unlock_irq(&phba->ndlp_lock);
1567 }
James Smart0ff10d42008-01-11 01:52:36 -05001568
James Smart58da1ff2008-04-07 10:15:56 -04001569 /* Two ndlps cannot have the same did on the nodelist */
1570 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001571 if (phba->sli_rev == LPFC_SLI_REV4)
1572 memcpy(&ndlp->active_rrqs.xri_bitmap,
1573 &rrq.xri_bitmap,
1574 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001575 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001576 }
James Smart92795652006-07-06 15:50:02 -04001577 else {
James Smart34f5ad82012-08-03 12:35:03 -04001578 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1579 "3180 PLOGI confirm SWAP: %x %x\n",
1580 new_ndlp->nlp_DID, keepDID);
1581
James Smart2e0fef82007-06-17 19:56:36 -05001582 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001583
James Smart58da1ff2008-04-07 10:15:56 -04001584 /* Two ndlps cannot have the same did */
1585 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001586 if (phba->sli_rev == LPFC_SLI_REV4)
1587 memcpy(&ndlp->active_rrqs.xri_bitmap,
1588 &rrq.xri_bitmap,
1589 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001590
James Smart38b92ef2010-08-04 16:11:39 -04001591 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001592 * and the did has already been swapped, copy over state.
1593 * The new WWNs are already in new_ndlp since thats what
1594 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001595 */
James Smart38b92ef2010-08-04 16:11:39 -04001596 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001597
1598 /* Since we are switching over to the new_ndlp, the old
1599 * ndlp should be put in the NPR state, unless we have
1600 * already started re-discovery on it.
1601 */
1602 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1603 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1605
James Smart38b92ef2010-08-04 16:11:39 -04001606 /* Fix up the rport accordingly */
1607 rport = ndlp->rport;
1608 if (rport) {
1609 rdata = rport->dd_data;
1610 put_node = rdata->pnode != NULL;
1611 put_rport = ndlp->rport != NULL;
1612 rdata->pnode = NULL;
1613 ndlp->rport = NULL;
1614 if (put_node)
1615 lpfc_nlp_put(ndlp);
1616 if (put_rport)
1617 put_device(&rport->dev);
1618 }
James Smart92795652006-07-06 15:50:02 -04001619 }
James Smart488d1462006-03-07 15:02:37 -05001620 return new_ndlp;
1621}
1622
James Smarte59058c2008-08-24 21:49:00 -04001623/**
James Smart3621a712009-04-06 18:47:14 -04001624 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001625 * @vport: pointer to a host virtual N_Port data structure.
1626 *
1627 * This routine checks whether more Registration State Change
1628 * Notifications (RSCNs) came in while the discovery state machine was in
1629 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1630 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1631 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1632 * handling the RSCNs.
1633 **/
James Smart87af33f2007-10-27 13:37:43 -04001634void
1635lpfc_end_rscn(struct lpfc_vport *vport)
1636{
1637 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1638
1639 if (vport->fc_flag & FC_RSCN_MODE) {
1640 /*
1641 * Check to see if more RSCNs came in while we were
1642 * processing this one.
1643 */
1644 if (vport->fc_rscn_id_cnt ||
1645 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1646 lpfc_els_handle_rscn(vport);
1647 else {
1648 spin_lock_irq(shost->host_lock);
1649 vport->fc_flag &= ~FC_RSCN_MODE;
1650 spin_unlock_irq(shost->host_lock);
1651 }
1652 }
1653}
1654
James Smarte59058c2008-08-24 21:49:00 -04001655/**
James Smart19ca7602010-11-20 23:11:55 -05001656 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1657 * @phba: pointer to lpfc hba data structure.
1658 * @cmdiocb: pointer to lpfc command iocb data structure.
1659 * @rspiocb: pointer to lpfc response iocb data structure.
1660 *
1661 * This routine will call the clear rrq function to free the rrq and
1662 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1663 * exist then the clear_rrq is still called because the rrq needs to
1664 * be freed.
1665 **/
1666
1667static void
1668lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1669 struct lpfc_iocbq *rspiocb)
1670{
1671 struct lpfc_vport *vport = cmdiocb->vport;
1672 IOCB_t *irsp;
1673 struct lpfc_nodelist *ndlp;
1674 struct lpfc_node_rrq *rrq;
1675
1676 /* we pass cmdiocb to state machine which needs rspiocb as well */
1677 rrq = cmdiocb->context_un.rrq;
1678 cmdiocb->context_un.rsp_iocb = rspiocb;
1679
1680 irsp = &rspiocb->iocb;
1681 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1682 "RRQ cmpl: status:x%x/x%x did:x%x",
1683 irsp->ulpStatus, irsp->un.ulpWord[4],
1684 irsp->un.elsreq64.remoteID);
1685
1686 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1687 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1688 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1689 "2882 RRQ completes to NPort x%x "
1690 "with no ndlp. Data: x%x x%x x%x\n",
1691 irsp->un.elsreq64.remoteID,
1692 irsp->ulpStatus, irsp->un.ulpWord[4],
1693 irsp->ulpIoTag);
1694 goto out;
1695 }
1696
1697 /* rrq completes to NPort <nlp_DID> */
1698 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1699 "2880 RRQ completes to NPort x%x "
1700 "Data: x%x x%x x%x x%x x%x\n",
1701 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1702 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1703
1704 if (irsp->ulpStatus) {
1705 /* Check for retry */
1706 /* RRQ failed Don't print the vport to vport rjts */
1707 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1708 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1709 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1710 (phba)->pport->cfg_log_verbose & LOG_ELS)
1711 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1712 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1713 ndlp->nlp_DID, irsp->ulpStatus,
1714 irsp->un.ulpWord[4]);
1715 }
1716out:
1717 if (rrq)
1718 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1719 lpfc_els_free_iocb(phba, cmdiocb);
1720 return;
1721}
1722/**
James Smart3621a712009-04-06 18:47:14 -04001723 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001724 * @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 is the completion callback function for issuing the Port
1729 * Login (PLOGI) command. For PLOGI completion, there must be an active
1730 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001731 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001732 * ignored and command IOCB released. The PLOGI response IOCB status is
1733 * checked for error conditons. If there is error status reported, PLOGI
1734 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1735 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1736 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1737 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1738 * there are additional N_Port nodes with the vport that need to perform
1739 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1740 * PLOGIs.
1741 **/
dea31012005-04-17 16:05:31 -05001742static void
James Smart2e0fef82007-06-17 19:56:36 -05001743lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1744 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001745{
James Smart2e0fef82007-06-17 19:56:36 -05001746 struct lpfc_vport *vport = cmdiocb->vport;
1747 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001748 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001749 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001750 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001751 int disc, rc, did, type;
1752
dea31012005-04-17 16:05:31 -05001753 /* we pass cmdiocb to state machine which needs rspiocb as well */
1754 cmdiocb->context_un.rsp_iocb = rspiocb;
1755
1756 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1758 "PLOGI cmpl: status:x%x/x%x did:x%x",
1759 irsp->ulpStatus, irsp->un.ulpWord[4],
1760 irsp->un.elsreq64.remoteID);
1761
James Smart2e0fef82007-06-17 19:56:36 -05001762 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001763 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001764 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1765 "0136 PLOGI completes to NPort x%x "
1766 "with no ndlp. Data: x%x x%x x%x\n",
1767 irsp->un.elsreq64.remoteID,
1768 irsp->ulpStatus, irsp->un.ulpWord[4],
1769 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001770 goto out;
James Smarted957682007-06-17 19:56:37 -05001771 }
dea31012005-04-17 16:05:31 -05001772
1773 /* Since ndlp can be freed in the disc state machine, note if this node
1774 * is being used during discovery.
1775 */
James Smart2e0fef82007-06-17 19:56:36 -05001776 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001777 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001778 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001779 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001780 rc = 0;
1781
1782 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001783 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1784 "0102 PLOGI completes to NPort x%x "
1785 "Data: x%x x%x x%x x%x x%x\n",
1786 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1787 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001788 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001789 if (lpfc_els_chk_latt(vport)) {
1790 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001791 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001792 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001793 goto out;
1794 }
1795
1796 /* ndlp could be freed in DSM, save these values now */
1797 type = ndlp->nlp_type;
1798 did = ndlp->nlp_DID;
1799
1800 if (irsp->ulpStatus) {
1801 /* Check for retry */
1802 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1803 /* ELS command is being retried */
1804 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001805 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001806 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001807 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001808 }
1809 goto out;
1810 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001811 /* PLOGI failed Don't print the vport to vport rjts */
1812 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1813 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1814 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1815 (phba)->pport->cfg_log_verbose & LOG_ELS)
1816 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001817 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1818 ndlp->nlp_DID, irsp->ulpStatus,
1819 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001820 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001821 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001822 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001823 else
James Smart2e0fef82007-06-17 19:56:36 -05001824 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001825 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001826 } else {
1827 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001828 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001829 cmdiocb->context2)->list.next,
1830 struct lpfc_dmabuf, list);
1831 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001832 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001833 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001834 }
1835
James Smart2e0fef82007-06-17 19:56:36 -05001836 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001837 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001838 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001839
James Smart2e0fef82007-06-17 19:56:36 -05001840 if (vport->num_disc_nodes == 0) {
1841 spin_lock_irq(shost->host_lock);
1842 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1843 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001844
James Smart2e0fef82007-06-17 19:56:36 -05001845 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001846 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001847 }
1848 }
1849
1850out:
1851 lpfc_els_free_iocb(phba, cmdiocb);
1852 return;
1853}
1854
James Smarte59058c2008-08-24 21:49:00 -04001855/**
James Smart3621a712009-04-06 18:47:14 -04001856 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001857 * @vport: pointer to a host virtual N_Port data structure.
1858 * @did: destination port identifier.
1859 * @retry: number of retries to the command IOCB.
1860 *
1861 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1862 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1863 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1864 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1865 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1866 *
1867 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1868 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1869 * will be stored into the context1 field of the IOCB for the completion
1870 * callback function to the PLOGI ELS command.
1871 *
1872 * Return code
1873 * 0 - Successfully issued a plogi for @vport
1874 * 1 - failed to issue a plogi for @vport
1875 **/
dea31012005-04-17 16:05:31 -05001876int
James Smart2e0fef82007-06-17 19:56:36 -05001877lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001878{
James Smart2e0fef82007-06-17 19:56:36 -05001879 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001880 struct serv_parm *sp;
1881 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001882 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001883 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001884 struct lpfc_sli *psli;
1885 uint8_t *pcmd;
1886 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001887 int ret;
dea31012005-04-17 16:05:31 -05001888
1889 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001890
James Smart98c9ea52007-10-27 13:37:33 -04001891 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001892 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1893 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001894
James Smarte47c9092008-02-08 18:49:26 -05001895 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001896 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001897 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001898 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001899 if (!elsiocb)
1900 return 1;
dea31012005-04-17 16:05:31 -05001901
1902 icmd = &elsiocb->iocb;
1903 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1904
1905 /* For PLOGI request, remainder of payload is service parameters */
1906 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001907 pcmd += sizeof(uint32_t);
1908 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001909 sp = (struct serv_parm *) pcmd;
1910
James Smart5ac6b302010-10-22 11:05:36 -04001911 /*
1912 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1913 * to device on remote loops work.
1914 */
1915 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1916 sp->cmn.altBbCredit = 1;
1917
dea31012005-04-17 16:05:31 -05001918 if (sp->cmn.fcphLow < FC_PH_4_3)
1919 sp->cmn.fcphLow = FC_PH_4_3;
1920
1921 if (sp->cmn.fcphHigh < FC_PH3)
1922 sp->cmn.fcphHigh = FC_PH3;
1923
James Smart858c9f62007-06-17 19:56:39 -05001924 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1925 "Issue PLOGI: did:x%x",
1926 did, 0, 0);
1927
dea31012005-04-17 16:05:31 -05001928 phba->fc_stat.elsXmitPLOGI++;
1929 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001930 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001931
1932 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001933 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001934 return 1;
dea31012005-04-17 16:05:31 -05001935 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001936 return 0;
dea31012005-04-17 16:05:31 -05001937}
1938
James Smarte59058c2008-08-24 21:49:00 -04001939/**
James Smart3621a712009-04-06 18:47:14 -04001940 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001941 * @phba: pointer to lpfc hba data structure.
1942 * @cmdiocb: pointer to lpfc command iocb data structure.
1943 * @rspiocb: pointer to lpfc response iocb data structure.
1944 *
1945 * This routine is the completion callback function for a Process Login
1946 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1947 * status. If there is error status reported, PRLI retry shall be attempted
1948 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1949 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1950 * ndlp to mark the PRLI completion.
1951 **/
dea31012005-04-17 16:05:31 -05001952static void
James Smart2e0fef82007-06-17 19:56:36 -05001953lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1954 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001955{
James Smart2e0fef82007-06-17 19:56:36 -05001956 struct lpfc_vport *vport = cmdiocb->vport;
1957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001958 IOCB_t *irsp;
1959 struct lpfc_sli *psli;
1960 struct lpfc_nodelist *ndlp;
1961
1962 psli = &phba->sli;
1963 /* we pass cmdiocb to state machine which needs rspiocb as well */
1964 cmdiocb->context_un.rsp_iocb = rspiocb;
1965
1966 irsp = &(rspiocb->iocb);
1967 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001968 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001969 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001970 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001971
James Smart858c9f62007-06-17 19:56:39 -05001972 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1973 "PRLI cmpl: status:x%x/x%x did:x%x",
1974 irsp->ulpStatus, irsp->un.ulpWord[4],
1975 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001976 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001977 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1978 "0103 PRLI completes to NPort x%x "
1979 "Data: x%x x%x x%x x%x\n",
1980 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1981 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001982
James Smart2e0fef82007-06-17 19:56:36 -05001983 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001984 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001985 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001986 goto out;
1987
1988 if (irsp->ulpStatus) {
1989 /* Check for retry */
1990 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1991 /* ELS command is being retried */
1992 goto out;
1993 }
1994 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001995 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1996 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1997 ndlp->nlp_DID, irsp->ulpStatus,
1998 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001999 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002000 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002001 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002002 else
James Smart2e0fef82007-06-17 19:56:36 -05002003 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002004 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002005 } else
dea31012005-04-17 16:05:31 -05002006 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002007 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002008 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002009out:
2010 lpfc_els_free_iocb(phba, cmdiocb);
2011 return;
2012}
2013
James Smarte59058c2008-08-24 21:49:00 -04002014/**
James Smart3621a712009-04-06 18:47:14 -04002015 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002016 * @vport: pointer to a host virtual N_Port data structure.
2017 * @ndlp: pointer to a node-list data structure.
2018 * @retry: number of retries to the command IOCB.
2019 *
2020 * This routine issues a Process Login (PRLI) ELS command for the
2021 * @vport. The PRLI service parameters are set up in the payload of the
2022 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2023 * is put to the IOCB completion callback func field before invoking the
2024 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2025 *
2026 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2027 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2028 * will be stored into the context1 field of the IOCB for the completion
2029 * callback function to the PRLI ELS command.
2030 *
2031 * Return code
2032 * 0 - successfully issued prli iocb command for @vport
2033 * 1 - failed to issue prli iocb command for @vport
2034 **/
dea31012005-04-17 16:05:31 -05002035int
James Smart2e0fef82007-06-17 19:56:36 -05002036lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002037 uint8_t retry)
2038{
James Smart2e0fef82007-06-17 19:56:36 -05002039 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2040 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002041 PRLI *npr;
2042 IOCB_t *icmd;
2043 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002044 uint8_t *pcmd;
2045 uint16_t cmdsize;
2046
James Smart92d7f7b2007-06-17 19:56:38 -05002047 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002048 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2049 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002050 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002051 return 1;
dea31012005-04-17 16:05:31 -05002052
2053 icmd = &elsiocb->iocb;
2054 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2055
2056 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002057 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002058 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002059 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002060
2061 /* For PRLI, remainder of payload is PRLI parameter page */
2062 npr = (PRLI *) pcmd;
2063 /*
2064 * If our firmware version is 3.20 or later,
2065 * set the following bits for FC-TAPE support.
2066 */
2067 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2068 npr->ConfmComplAllowed = 1;
2069 npr->Retry = 1;
2070 npr->TaskRetryIdReq = 1;
2071 }
2072 npr->estabImagePair = 1;
2073 npr->readXferRdyDis = 1;
2074
2075 /* For FCP support */
2076 npr->prliType = PRLI_FCP_TYPE;
2077 npr->initiatorFunc = 1;
2078
James Smart858c9f62007-06-17 19:56:39 -05002079 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2080 "Issue PRLI: did:x%x",
2081 ndlp->nlp_DID, 0, 0);
2082
dea31012005-04-17 16:05:31 -05002083 phba->fc_stat.elsXmitPRLI++;
2084 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002085 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002086 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002087 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002088 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2089 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002090 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002091 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002092 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002093 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002094 return 1;
dea31012005-04-17 16:05:31 -05002095 }
James Smart2e0fef82007-06-17 19:56:36 -05002096 vport->fc_prli_sent++;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002097 return 0;
dea31012005-04-17 16:05:31 -05002098}
2099
James Smarte59058c2008-08-24 21:49:00 -04002100/**
James Smart3621a712009-04-06 18:47:14 -04002101 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002102 * @vport: pointer to a host virtual N_Port data structure.
2103 *
2104 * This routine performs Registration State Change Notification (RSCN)
2105 * discovery for a @vport. If the @vport's node port recovery count is not
2106 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2107 * the nodes that need recovery. If none of the PLOGI were needed through
2108 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2109 * invoked to check and handle possible more RSCN came in during the period
2110 * of processing the current ones.
2111 **/
2112static void
2113lpfc_rscn_disc(struct lpfc_vport *vport)
2114{
2115 lpfc_can_disctmo(vport);
2116
2117 /* RSCN discovery */
2118 /* go thru NPR nodes and issue ELS PLOGIs */
2119 if (vport->fc_npr_cnt)
2120 if (lpfc_els_disc_plogi(vport))
2121 return;
2122
2123 lpfc_end_rscn(vport);
2124}
2125
2126/**
James Smart3621a712009-04-06 18:47:14 -04002127 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002128 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2129 *
2130 * This function is called when the final ADISC is completed during discovery.
2131 * This function handles clearing link attention or issuing reg_vpi depending
2132 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2133 * discovery.
2134 * This function is called with no locks held.
2135 **/
2136static void
2137lpfc_adisc_done(struct lpfc_vport *vport)
2138{
2139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2140 struct lpfc_hba *phba = vport->phba;
2141
2142 /*
2143 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2144 * and continue discovery.
2145 */
2146 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002147 !(vport->fc_flag & FC_RSCN_MODE) &&
2148 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002149 lpfc_issue_reg_vpi(phba, vport);
2150 return;
2151 }
2152 /*
2153 * For SLI2, we need to set port_state to READY
2154 * and continue discovery.
2155 */
2156 if (vport->port_state < LPFC_VPORT_READY) {
2157 /* If we get here, there is nothing to ADISC */
2158 if (vport->port_type == LPFC_PHYSICAL_PORT)
2159 lpfc_issue_clear_la(phba, vport);
2160 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2161 vport->num_disc_nodes = 0;
2162 /* go thru NPR list, issue ELS PLOGIs */
2163 if (vport->fc_npr_cnt)
2164 lpfc_els_disc_plogi(vport);
2165 if (!vport->num_disc_nodes) {
2166 spin_lock_irq(shost->host_lock);
2167 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2168 spin_unlock_irq(shost->host_lock);
2169 lpfc_can_disctmo(vport);
2170 lpfc_end_rscn(vport);
2171 }
2172 }
2173 vport->port_state = LPFC_VPORT_READY;
2174 } else
2175 lpfc_rscn_disc(vport);
2176}
2177
2178/**
James Smart3621a712009-04-06 18:47:14 -04002179 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002180 * @vport: pointer to a host virtual N_Port data structure.
2181 *
2182 * This routine determines whether there are more ndlps on a @vport
2183 * node list need to have Address Discover (ADISC) issued. If so, it will
2184 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2185 * remaining nodes which need to have ADISC sent.
2186 **/
James Smart0ff10d42008-01-11 01:52:36 -05002187void
James Smart2e0fef82007-06-17 19:56:36 -05002188lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002189{
2190 int sentadisc;
2191
James Smart2e0fef82007-06-17 19:56:36 -05002192 if (vport->num_disc_nodes)
2193 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002194 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002195 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2196 "0210 Continue discovery with %d ADISCs to go "
2197 "Data: x%x x%x x%x\n",
2198 vport->num_disc_nodes, vport->fc_adisc_cnt,
2199 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002200 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002201 if (vport->fc_flag & FC_NLP_MORE) {
2202 lpfc_set_disctmo(vport);
2203 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2204 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002205 }
James Smart90160e02008-08-24 21:49:45 -04002206 if (!vport->num_disc_nodes)
2207 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002208 return;
2209}
2210
James Smarte59058c2008-08-24 21:49:00 -04002211/**
James Smart3621a712009-04-06 18:47:14 -04002212 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002213 * @phba: pointer to lpfc hba data structure.
2214 * @cmdiocb: pointer to lpfc command iocb data structure.
2215 * @rspiocb: pointer to lpfc response iocb data structure.
2216 *
2217 * This routine is the completion function for issuing the Address Discover
2218 * (ADISC) command. It first checks to see whether link went down during
2219 * the discovery process. If so, the node will be marked as node port
2220 * recovery for issuing discover IOCB by the link attention handler and
2221 * exit. Otherwise, the response status is checked. If error was reported
2222 * in the response status, the ADISC command shall be retried by invoking
2223 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2224 * the response status, the state machine is invoked to set transition
2225 * with respect to NLP_EVT_CMPL_ADISC event.
2226 **/
dea31012005-04-17 16:05:31 -05002227static void
James Smart2e0fef82007-06-17 19:56:36 -05002228lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2229 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002230{
James Smart2e0fef82007-06-17 19:56:36 -05002231 struct lpfc_vport *vport = cmdiocb->vport;
2232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002233 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002234 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002235 int disc;
dea31012005-04-17 16:05:31 -05002236
2237 /* we pass cmdiocb to state machine which needs rspiocb as well */
2238 cmdiocb->context_un.rsp_iocb = rspiocb;
2239
2240 irsp = &(rspiocb->iocb);
2241 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002242
James Smart858c9f62007-06-17 19:56:39 -05002243 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2244 "ADISC cmpl: status:x%x/x%x did:x%x",
2245 irsp->ulpStatus, irsp->un.ulpWord[4],
2246 ndlp->nlp_DID);
2247
dea31012005-04-17 16:05:31 -05002248 /* Since ndlp can be freed in the disc state machine, note if this node
2249 * is being used during discovery.
2250 */
James Smart2e0fef82007-06-17 19:56:36 -05002251 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002252 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002253 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002254 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002255 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002256 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2257 "0104 ADISC completes to NPort x%x "
2258 "Data: x%x x%x x%x x%x x%x\n",
2259 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2260 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002261 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002262 if (lpfc_els_chk_latt(vport)) {
2263 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002264 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002265 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002266 goto out;
2267 }
2268
2269 if (irsp->ulpStatus) {
2270 /* Check for retry */
2271 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2272 /* ELS command is being retried */
2273 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002274 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002275 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002276 spin_unlock_irq(shost->host_lock);
2277 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002278 }
2279 goto out;
2280 }
2281 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002282 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2283 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2284 ndlp->nlp_DID, irsp->ulpStatus,
2285 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002286 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002287 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002288 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002289 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002290 } else
dea31012005-04-17 16:05:31 -05002291 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002292 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002293 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002294
James Smart90160e02008-08-24 21:49:45 -04002295 /* Check to see if there are more ADISCs to be sent */
2296 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002297 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002298out:
2299 lpfc_els_free_iocb(phba, cmdiocb);
2300 return;
2301}
2302
James Smarte59058c2008-08-24 21:49:00 -04002303/**
James Smart3621a712009-04-06 18:47:14 -04002304 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002305 * @vport: pointer to a virtual N_Port data structure.
2306 * @ndlp: pointer to a node-list data structure.
2307 * @retry: number of retries to the command IOCB.
2308 *
2309 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2310 * @vport. It prepares the payload of the ADISC ELS command, updates the
2311 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2312 * to issue the ADISC ELS command.
2313 *
2314 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2315 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2316 * will be stored into the context1 field of the IOCB for the completion
2317 * callback function to the ADISC ELS command.
2318 *
2319 * Return code
2320 * 0 - successfully issued adisc
2321 * 1 - failed to issue adisc
2322 **/
dea31012005-04-17 16:05:31 -05002323int
James Smart2e0fef82007-06-17 19:56:36 -05002324lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002325 uint8_t retry)
2326{
James Smart2e0fef82007-06-17 19:56:36 -05002327 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2328 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002329 ADISC *ap;
2330 IOCB_t *icmd;
2331 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002332 uint8_t *pcmd;
2333 uint16_t cmdsize;
2334
James Smart92d7f7b2007-06-17 19:56:38 -05002335 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002336 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2337 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002338 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002339 return 1;
dea31012005-04-17 16:05:31 -05002340
2341 icmd = &elsiocb->iocb;
2342 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2343
2344 /* For ADISC request, remainder of payload is service parameters */
2345 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002346 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002347
2348 /* Fill in ADISC payload */
2349 ap = (ADISC *) pcmd;
2350 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002351 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2352 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002353 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002354
James Smart858c9f62007-06-17 19:56:39 -05002355 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2356 "Issue ADISC: did:x%x",
2357 ndlp->nlp_DID, 0, 0);
2358
dea31012005-04-17 16:05:31 -05002359 phba->fc_stat.elsXmitADISC++;
2360 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002361 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002362 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002363 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002364 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2365 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002366 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002367 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002368 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002369 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002370 return 1;
dea31012005-04-17 16:05:31 -05002371 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002372 return 0;
dea31012005-04-17 16:05:31 -05002373}
2374
James Smarte59058c2008-08-24 21:49:00 -04002375/**
James Smart3621a712009-04-06 18:47:14 -04002376 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002377 * @phba: pointer to lpfc hba data structure.
2378 * @cmdiocb: pointer to lpfc command iocb data structure.
2379 * @rspiocb: pointer to lpfc response iocb data structure.
2380 *
2381 * This routine is the completion function for issuing the ELS Logout (LOGO)
2382 * command. If no error status was reported from the LOGO response, the
2383 * state machine of the associated ndlp shall be invoked for transition with
2384 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2385 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2386 **/
dea31012005-04-17 16:05:31 -05002387static void
James Smart2e0fef82007-06-17 19:56:36 -05002388lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2389 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002390{
James Smart2e0fef82007-06-17 19:56:36 -05002391 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2392 struct lpfc_vport *vport = ndlp->vport;
2393 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002394 IOCB_t *irsp;
2395 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002396 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002397 unsigned long flags;
2398 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002399
2400 psli = &phba->sli;
2401 /* we pass cmdiocb to state machine which needs rspiocb as well */
2402 cmdiocb->context_un.rsp_iocb = rspiocb;
2403
2404 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002405 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002406 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002407 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002408
James Smart858c9f62007-06-17 19:56:39 -05002409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2410 "LOGO cmpl: status:x%x/x%x did:x%x",
2411 irsp->ulpStatus, irsp->un.ulpWord[4],
2412 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002413
dea31012005-04-17 16:05:31 -05002414 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002415 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2416 "0105 LOGO completes to NPort x%x "
2417 "Data: x%x x%x x%x x%x\n",
2418 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2419 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002420
James Smart086a3452012-08-14 14:25:21 -04002421 if (lpfc_els_chk_latt(vport)) {
2422 skip_recovery = 1;
2423 goto out;
2424 }
2425
2426 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002427 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2428 /* NLP_EVT_DEVICE_RM should unregister the RPI
2429 * which should abort all outstanding IOs.
2430 */
2431 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2432 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002433 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002434 goto out;
2435 }
2436
dea31012005-04-17 16:05:31 -05002437 if (irsp->ulpStatus) {
2438 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002439 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002440 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002441 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002442 goto out;
James Smart086a3452012-08-14 14:25:21 -04002443 }
dea31012005-04-17 16:05:31 -05002444 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002445 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2446 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2447 ndlp->nlp_DID, irsp->ulpStatus,
2448 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002449 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002450 if (lpfc_error_lost_link(irsp)) {
2451 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002452 goto out;
James Smart086a3452012-08-14 14:25:21 -04002453 }
2454 }
2455
2456 /* Call state machine. This will unregister the rpi if needed. */
2457 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2458
dea31012005-04-17 16:05:31 -05002459out:
2460 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002461 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2462 if ((vport->fc_flag & FC_PT2PT) &&
2463 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2464 phba->pport->fc_myDID = 0;
2465 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2466 if (mbox) {
2467 lpfc_config_link(phba, mbox);
2468 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2469 mbox->vport = vport;
2470 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2471 MBX_NOT_FINISHED) {
2472 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002473 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002474 }
2475 }
2476 }
James Smart086a3452012-08-14 14:25:21 -04002477
2478 /*
2479 * If the node is a target, the handling attempts to recover the port.
2480 * For any other port type, the rpi is unregistered as an implicit
2481 * LOGO.
2482 */
2483 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2484 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2485 spin_lock_irqsave(shost->host_lock, flags);
2486 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2487 spin_unlock_irqrestore(shost->host_lock, flags);
2488
2489 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2490 "3187 LOGO completes to NPort x%x: Start "
2491 "Recovery Data: x%x x%x x%x x%x\n",
2492 ndlp->nlp_DID, irsp->ulpStatus,
2493 irsp->un.ulpWord[4], irsp->ulpTimeout,
2494 vport->num_disc_nodes);
2495 lpfc_disc_start(vport);
2496 }
dea31012005-04-17 16:05:31 -05002497 return;
2498}
2499
James Smarte59058c2008-08-24 21:49:00 -04002500/**
James Smart3621a712009-04-06 18:47:14 -04002501 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002502 * @vport: pointer to a virtual N_Port data structure.
2503 * @ndlp: pointer to a node-list data structure.
2504 * @retry: number of retries to the command IOCB.
2505 *
2506 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2507 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2508 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2509 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2510 *
2511 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2512 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2513 * will be stored into the context1 field of the IOCB for the completion
2514 * callback function to the LOGO ELS command.
2515 *
2516 * Return code
2517 * 0 - successfully issued logo
2518 * 1 - failed to issue logo
2519 **/
dea31012005-04-17 16:05:31 -05002520int
James Smart2e0fef82007-06-17 19:56:36 -05002521lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002522 uint8_t retry)
2523{
James Smart2e0fef82007-06-17 19:56:36 -05002524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2525 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002526 IOCB_t *icmd;
2527 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002528 uint8_t *pcmd;
2529 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002530 int rc;
dea31012005-04-17 16:05:31 -05002531
James Smart98c9ea52007-10-27 13:37:33 -04002532 spin_lock_irq(shost->host_lock);
2533 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2534 spin_unlock_irq(shost->host_lock);
2535 return 0;
2536 }
2537 spin_unlock_irq(shost->host_lock);
2538
James Smart92d7f7b2007-06-17 19:56:38 -05002539 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002540 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2541 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002542 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002543 return 1;
dea31012005-04-17 16:05:31 -05002544
2545 icmd = &elsiocb->iocb;
2546 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2547 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002548 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002549
2550 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002551 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002552 pcmd += sizeof(uint32_t);
2553 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002554
James Smart858c9f62007-06-17 19:56:39 -05002555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2556 "Issue LOGO: did:x%x",
2557 ndlp->nlp_DID, 0, 0);
2558
James Smart086a3452012-08-14 14:25:21 -04002559 /*
2560 * If we are issuing a LOGO, we may try to recover the remote NPort
2561 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2562 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2563 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2564 * for that ELS cmd. To avoid this situation, lets get rid of the
2565 * RPI right now, before any ELS cmds are sent.
2566 */
2567 spin_lock_irq(shost->host_lock);
2568 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2569 spin_unlock_irq(shost->host_lock);
2570 if (lpfc_unreg_rpi(vport, ndlp)) {
2571 lpfc_els_free_iocb(phba, elsiocb);
2572 return 0;
2573 }
2574
dea31012005-04-17 16:05:31 -05002575 phba->fc_stat.elsXmitLOGO++;
2576 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002577 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002578 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002579 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002580 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002581 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002582
2583 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002584 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002585 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002586 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002587 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002588 return 1;
dea31012005-04-17 16:05:31 -05002589 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002590 return 0;
dea31012005-04-17 16:05:31 -05002591}
2592
James Smarte59058c2008-08-24 21:49:00 -04002593/**
James Smart3621a712009-04-06 18:47:14 -04002594 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002595 * @phba: pointer to lpfc hba data structure.
2596 * @cmdiocb: pointer to lpfc command iocb data structure.
2597 * @rspiocb: pointer to lpfc response iocb data structure.
2598 *
2599 * This routine is a generic completion callback function for ELS commands.
2600 * Specifically, it is the callback function which does not need to perform
2601 * any command specific operations. It is currently used by the ELS command
2602 * issuing routines for the ELS State Change Request (SCR),
2603 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2604 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2605 * certain debug loggings, this callback function simply invokes the
2606 * lpfc_els_chk_latt() routine to check whether link went down during the
2607 * discovery process.
2608 **/
dea31012005-04-17 16:05:31 -05002609static void
James Smart2e0fef82007-06-17 19:56:36 -05002610lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2611 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002612{
James Smart2e0fef82007-06-17 19:56:36 -05002613 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002614 IOCB_t *irsp;
2615
2616 irsp = &rspiocb->iocb;
2617
James Smart858c9f62007-06-17 19:56:39 -05002618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2619 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2620 irsp->ulpStatus, irsp->un.ulpWord[4],
2621 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002622 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002623 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2624 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2625 irsp->ulpIoTag, irsp->ulpStatus,
2626 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002627 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002628 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002629 lpfc_els_free_iocb(phba, cmdiocb);
2630 return;
2631}
2632
James Smarte59058c2008-08-24 21:49:00 -04002633/**
James Smart3621a712009-04-06 18:47:14 -04002634 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002635 * @vport: pointer to a host virtual N_Port data structure.
2636 * @nportid: N_Port identifier to the remote node.
2637 * @retry: number of retries to the command IOCB.
2638 *
2639 * This routine issues a State Change Request (SCR) to a fabric node
2640 * on a @vport. The remote node @nportid is passed into the function. It
2641 * first search the @vport node list to find the matching ndlp. If no such
2642 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2643 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2644 * routine is invoked to send the SCR IOCB.
2645 *
2646 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2647 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2648 * will be stored into the context1 field of the IOCB for the completion
2649 * callback function to the SCR ELS command.
2650 *
2651 * Return code
2652 * 0 - Successfully issued scr command
2653 * 1 - Failed to issue scr command
2654 **/
dea31012005-04-17 16:05:31 -05002655int
James Smart2e0fef82007-06-17 19:56:36 -05002656lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002657{
James Smart2e0fef82007-06-17 19:56:36 -05002658 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002659 IOCB_t *icmd;
2660 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002661 struct lpfc_sli *psli;
2662 uint8_t *pcmd;
2663 uint16_t cmdsize;
2664 struct lpfc_nodelist *ndlp;
2665
2666 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002667 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002668
James Smarte47c9092008-02-08 18:49:26 -05002669 ndlp = lpfc_findnode_did(vport, nportid);
2670 if (!ndlp) {
2671 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2672 if (!ndlp)
2673 return 1;
2674 lpfc_nlp_init(vport, ndlp, nportid);
2675 lpfc_enqueue_node(vport, ndlp);
2676 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2677 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2678 if (!ndlp)
2679 return 1;
2680 }
dea31012005-04-17 16:05:31 -05002681
James Smart2e0fef82007-06-17 19:56:36 -05002682 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2683 ndlp->nlp_DID, ELS_CMD_SCR);
2684
James Smart488d1462006-03-07 15:02:37 -05002685 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002686 /* This will trigger the release of the node just
2687 * allocated
2688 */
James Smart329f9bc2007-04-25 09:53:01 -04002689 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002690 return 1;
dea31012005-04-17 16:05:31 -05002691 }
2692
2693 icmd = &elsiocb->iocb;
2694 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2695
2696 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002697 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002698
2699 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002700 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002701 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2702
James Smart858c9f62007-06-17 19:56:39 -05002703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2704 "Issue SCR: did:x%x",
2705 ndlp->nlp_DID, 0, 0);
2706
dea31012005-04-17 16:05:31 -05002707 phba->fc_stat.elsXmitSCR++;
2708 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002709 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2710 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002711 /* The additional lpfc_nlp_put will cause the following
2712 * lpfc_els_free_iocb routine to trigger the rlease of
2713 * the node.
2714 */
James Smart329f9bc2007-04-25 09:53:01 -04002715 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002716 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002717 return 1;
dea31012005-04-17 16:05:31 -05002718 }
James Smartfa4066b2008-01-11 01:53:27 -05002719 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2720 * trigger the release of node.
2721 */
James Smart329f9bc2007-04-25 09:53:01 -04002722 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002723 return 0;
dea31012005-04-17 16:05:31 -05002724}
2725
James Smarte59058c2008-08-24 21:49:00 -04002726/**
James Smart3621a712009-04-06 18:47:14 -04002727 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002728 * @vport: pointer to a host virtual N_Port data structure.
2729 * @nportid: N_Port identifier to the remote node.
2730 * @retry: number of retries to the command IOCB.
2731 *
2732 * This routine issues a Fibre Channel Address Resolution Response
2733 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2734 * is passed into the function. It first search the @vport node list to find
2735 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2736 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2737 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2738 *
2739 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2740 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2741 * will be stored into the context1 field of the IOCB for the completion
2742 * callback function to the PARPR ELS command.
2743 *
2744 * Return code
2745 * 0 - Successfully issued farpr command
2746 * 1 - Failed to issue farpr command
2747 **/
dea31012005-04-17 16:05:31 -05002748static int
James Smart2e0fef82007-06-17 19:56:36 -05002749lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002750{
James Smart2e0fef82007-06-17 19:56:36 -05002751 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002752 IOCB_t *icmd;
2753 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002754 struct lpfc_sli *psli;
2755 FARP *fp;
2756 uint8_t *pcmd;
2757 uint32_t *lp;
2758 uint16_t cmdsize;
2759 struct lpfc_nodelist *ondlp;
2760 struct lpfc_nodelist *ndlp;
2761
2762 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002763 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002764
James Smarte47c9092008-02-08 18:49:26 -05002765 ndlp = lpfc_findnode_did(vport, nportid);
2766 if (!ndlp) {
2767 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2768 if (!ndlp)
2769 return 1;
2770 lpfc_nlp_init(vport, ndlp, nportid);
2771 lpfc_enqueue_node(vport, ndlp);
2772 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2773 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2774 if (!ndlp)
2775 return 1;
2776 }
James Smart2e0fef82007-06-17 19:56:36 -05002777
2778 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2779 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002780 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002781 /* This will trigger the release of the node just
2782 * allocated
2783 */
James Smart329f9bc2007-04-25 09:53:01 -04002784 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002785 return 1;
dea31012005-04-17 16:05:31 -05002786 }
2787
2788 icmd = &elsiocb->iocb;
2789 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2790
2791 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002792 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002793
2794 /* Fill in FARPR payload */
2795 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002796 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002797 lp = (uint32_t *) pcmd;
2798 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002799 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002800 fp->Rflags = 0;
2801 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2802
James Smart92d7f7b2007-06-17 19:56:38 -05002803 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2804 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002805 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002806 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002807 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002808 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002809 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002810 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002811 }
2812
James Smart858c9f62007-06-17 19:56:39 -05002813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2814 "Issue FARPR: did:x%x",
2815 ndlp->nlp_DID, 0, 0);
2816
dea31012005-04-17 16:05:31 -05002817 phba->fc_stat.elsXmitFARPR++;
2818 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002819 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2820 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002821 /* The additional lpfc_nlp_put will cause the following
2822 * lpfc_els_free_iocb routine to trigger the release of
2823 * the node.
2824 */
James Smart329f9bc2007-04-25 09:53:01 -04002825 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002826 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002827 return 1;
dea31012005-04-17 16:05:31 -05002828 }
James Smartfa4066b2008-01-11 01:53:27 -05002829 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2830 * trigger the release of the node.
2831 */
James Smart329f9bc2007-04-25 09:53:01 -04002832 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002833 return 0;
dea31012005-04-17 16:05:31 -05002834}
2835
James Smarte59058c2008-08-24 21:49:00 -04002836/**
James Smart3621a712009-04-06 18:47:14 -04002837 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002838 * @vport: pointer to a host virtual N_Port data structure.
2839 * @nlp: pointer to a node-list data structure.
2840 *
2841 * This routine cancels the timer with a delayed IOCB-command retry for
2842 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2843 * removes the ELS retry event if it presents. In addition, if the
2844 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2845 * commands are sent for the @vport's nodes that require issuing discovery
2846 * ADISC.
2847 **/
dea31012005-04-17 16:05:31 -05002848void
James Smart2e0fef82007-06-17 19:56:36 -05002849lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002850{
James Smart2e0fef82007-06-17 19:56:36 -05002851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002852 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002853
James Smart0d2b6b82008-06-14 22:52:47 -04002854 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2855 return;
James Smart2e0fef82007-06-17 19:56:36 -05002856 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002857 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002858 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002859 del_timer_sync(&nlp->nlp_delayfunc);
2860 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002861 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002862 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002863 /* Decrement nlp reference count held for the delayed retry */
2864 evtp = &nlp->els_retry_evt;
2865 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2866 }
James Smartfdcebe22006-03-07 15:04:01 -05002867 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002868 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002869 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002870 spin_unlock_irq(shost->host_lock);
2871 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002872 if (vport->port_state < LPFC_VPORT_READY) {
2873 /* Check if there are more ADISCs to be sent */
2874 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002875 } else {
2876 /* Check if there are more PLOGIs to be sent */
2877 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002878 if (vport->num_disc_nodes == 0) {
2879 spin_lock_irq(shost->host_lock);
2880 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2881 spin_unlock_irq(shost->host_lock);
2882 lpfc_can_disctmo(vport);
2883 lpfc_end_rscn(vport);
2884 }
James Smartfdcebe22006-03-07 15:04:01 -05002885 }
2886 }
2887 }
2888 return;
2889}
2890
James Smarte59058c2008-08-24 21:49:00 -04002891/**
James Smart3621a712009-04-06 18:47:14 -04002892 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002893 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2894 *
2895 * This routine is invoked by the ndlp delayed-function timer to check
2896 * whether there is any pending ELS retry event(s) with the node. If not, it
2897 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2898 * adds the delayed events to the HBA work list and invokes the
2899 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2900 * event. Note that lpfc_nlp_get() is called before posting the event to
2901 * the work list to hold reference count of ndlp so that it guarantees the
2902 * reference to ndlp will still be available when the worker thread gets
2903 * to the event associated with the ndlp.
2904 **/
James Smartfdcebe22006-03-07 15:04:01 -05002905void
dea31012005-04-17 16:05:31 -05002906lpfc_els_retry_delay(unsigned long ptr)
2907{
James Smart2e0fef82007-06-17 19:56:36 -05002908 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2909 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002910 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002911 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002912 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002913
James Smart92d7f7b2007-06-17 19:56:38 -05002914 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002915 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002916 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002917 return;
2918 }
2919
James Smartfa4066b2008-01-11 01:53:27 -05002920 /* We need to hold the node by incrementing the reference
2921 * count until the queued work is done
2922 */
2923 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002924 if (evtp->evt_arg1) {
2925 evtp->evt = LPFC_EVT_ELS_RETRY;
2926 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002927 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002928 }
James Smart92d7f7b2007-06-17 19:56:38 -05002929 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002930 return;
2931}
2932
James Smarte59058c2008-08-24 21:49:00 -04002933/**
James Smart3621a712009-04-06 18:47:14 -04002934 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002935 * @ndlp: pointer to a node-list data structure.
2936 *
2937 * This routine is the worker-thread handler for processing the @ndlp delayed
2938 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2939 * the last ELS command from the associated ndlp and invokes the proper ELS
2940 * function according to the delayed ELS command to retry the command.
2941 **/
dea31012005-04-17 16:05:31 -05002942void
2943lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2944{
James Smart2e0fef82007-06-17 19:56:36 -05002945 struct lpfc_vport *vport = ndlp->vport;
2946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2947 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002948
James Smart2e0fef82007-06-17 19:56:36 -05002949 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002950 did = ndlp->nlp_DID;
2951 cmd = ndlp->nlp_last_elscmd;
2952 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002953
2954 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002955 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002956 return;
2957 }
2958
2959 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002960 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002961 /*
2962 * If a discovery event readded nlp_delayfunc after timer
2963 * firing and before processing the timer, cancel the
2964 * nlp_delayfunc.
2965 */
2966 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002967 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002968 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002969
2970 switch (cmd) {
2971 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002972 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002973 break;
2974 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002975 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002976 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002978 }
dea31012005-04-17 16:05:31 -05002979 break;
2980 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002981 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002982 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002984 }
dea31012005-04-17 16:05:31 -05002985 break;
2986 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002987 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002988 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002989 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002990 }
dea31012005-04-17 16:05:31 -05002991 break;
2992 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002993 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002994 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04002995 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002996 }
dea31012005-04-17 16:05:31 -05002997 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002998 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002999 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
3000 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05003001 break;
dea31012005-04-17 16:05:31 -05003002 }
3003 return;
3004}
3005
James Smarte59058c2008-08-24 21:49:00 -04003006/**
James Smart3621a712009-04-06 18:47:14 -04003007 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003008 * @phba: pointer to lpfc hba data structure.
3009 * @cmdiocb: pointer to lpfc command iocb data structure.
3010 * @rspiocb: pointer to lpfc response iocb data structure.
3011 *
3012 * This routine makes a retry decision on an ELS command IOCB, which has
3013 * failed. The following ELS IOCBs use this function for retrying the command
3014 * when previously issued command responsed with error status: FLOGI, PLOGI,
3015 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3016 * returned error status, it makes the decision whether a retry shall be
3017 * issued for the command, and whether a retry shall be made immediately or
3018 * delayed. In the former case, the corresponding ELS command issuing-function
3019 * is called to retry the command. In the later case, the ELS command shall
3020 * be posted to the ndlp delayed event and delayed function timer set to the
3021 * ndlp for the delayed command issusing.
3022 *
3023 * Return code
3024 * 0 - No retry of els command is made
3025 * 1 - Immediate or delayed retry of els command is made
3026 **/
dea31012005-04-17 16:05:31 -05003027static int
James Smart2e0fef82007-06-17 19:56:36 -05003028lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3029 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003030{
James Smart2e0fef82007-06-17 19:56:36 -05003031 struct lpfc_vport *vport = cmdiocb->vport;
3032 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3033 IOCB_t *irsp = &rspiocb->iocb;
3034 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3035 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003036 uint32_t *elscmd;
3037 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003038 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003039 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003040 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003041 uint32_t did;
dea31012005-04-17 16:05:31 -05003042
James Smart488d1462006-03-07 15:02:37 -05003043
dea31012005-04-17 16:05:31 -05003044 /* Note: context2 may be 0 for internal driver abort
3045 * of delays ELS command.
3046 */
3047
3048 if (pcmd && pcmd->virt) {
3049 elscmd = (uint32_t *) (pcmd->virt);
3050 cmd = *elscmd++;
3051 }
3052
James Smarte47c9092008-02-08 18:49:26 -05003053 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003054 did = ndlp->nlp_DID;
3055 else {
3056 /* We should only hit this case for retrying PLOGI */
3057 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003058 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003059 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3060 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003061 return 1;
3062 }
3063
James Smart858c9f62007-06-17 19:56:39 -05003064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3065 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3066 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3067
dea31012005-04-17 16:05:31 -05003068 switch (irsp->ulpStatus) {
3069 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003070 break;
James Smart1151e3e2011-02-16 12:39:35 -05003071 case IOSTAT_REMOTE_STOP:
3072 if (phba->sli_rev == LPFC_SLI_REV4) {
3073 /* This IO was aborted by the target, we don't
3074 * know the rxid and because we did not send the
3075 * ABTS we cannot generate and RRQ.
3076 */
3077 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003078 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003079 }
3080 break;
dea31012005-04-17 16:05:31 -05003081 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003082 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003083 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003084 if (cmd == ELS_CMD_FLOGI) {
3085 if (PCI_DEVICE_ID_HORNET ==
3086 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003087 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003088 phba->pport->fc_myDID = 0;
3089 phba->alpa_map[0] = 0;
3090 phba->alpa_map[1] = 0;
3091 }
3092 }
James Smart2e0fef82007-06-17 19:56:36 -05003093 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003094 delay = 1000;
dea31012005-04-17 16:05:31 -05003095 retry = 1;
3096 break;
3097
James Smart92d7f7b2007-06-17 19:56:38 -05003098 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003099 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3100 "0124 Retry illegal cmd x%x "
3101 "retry:x%x delay:x%x\n",
3102 cmd, cmdiocb->retry, delay);
3103 retry = 1;
3104 /* All command's retry policy */
3105 maxretry = 8;
3106 if (cmdiocb->retry > 2)
3107 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003108 break;
3109
dea31012005-04-17 16:05:31 -05003110 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003111 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003112 retry = 1;
3113 if (cmdiocb->retry > 100)
3114 delay = 100;
3115 maxretry = 250;
3116 break;
3117
3118 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003119 delay = 100;
dea31012005-04-17 16:05:31 -05003120 retry = 1;
3121 break;
3122
James Smart858c9f62007-06-17 19:56:39 -05003123 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003124 case IOERR_INVALID_RPI:
James Smart5b5b36a2013-01-03 15:43:19 -05003125 if (cmd == ELS_CMD_PLOGI &&
3126 did == NameServer_DID) {
3127 /* Continue forever if plogi to */
3128 /* the nameserver fails */
3129 maxretry = 0;
3130 delay = 100;
3131 }
dea31012005-04-17 16:05:31 -05003132 retry = 1;
3133 break;
3134 }
3135 break;
3136
3137 case IOSTAT_NPORT_RJT:
3138 case IOSTAT_FABRIC_RJT:
3139 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3140 retry = 1;
3141 break;
3142 }
3143 break;
3144
3145 case IOSTAT_NPORT_BSY:
3146 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003147 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003148 retry = 1;
3149 break;
3150
3151 case IOSTAT_LS_RJT:
3152 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3153 /* Added for Vendor specifc support
3154 * Just keep retrying for these Rsn / Exp codes
3155 */
3156 switch (stat.un.b.lsRjtRsnCode) {
3157 case LSRJT_UNABLE_TPC:
3158 if (stat.un.b.lsRjtRsnCodeExp ==
3159 LSEXP_CMD_IN_PROGRESS) {
3160 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003161 delay = 1000;
dea31012005-04-17 16:05:31 -05003162 maxretry = 48;
3163 }
3164 retry = 1;
3165 break;
3166 }
James Smartffc95492010-06-07 15:23:17 -04003167 if (stat.un.b.lsRjtRsnCodeExp ==
3168 LSEXP_CANT_GIVE_DATA) {
3169 if (cmd == ELS_CMD_PLOGI) {
3170 delay = 1000;
3171 maxretry = 48;
3172 }
3173 retry = 1;
3174 break;
3175 }
James Smart4c1b64b2012-09-29 11:31:11 -04003176 if ((cmd == ELS_CMD_PLOGI) ||
3177 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003178 delay = 1000;
dea31012005-04-17 16:05:31 -05003179 maxretry = lpfc_max_els_tries + 1;
3180 retry = 1;
3181 break;
3182 }
James Smart92d7f7b2007-06-17 19:56:38 -05003183 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3184 (cmd == ELS_CMD_FDISC) &&
3185 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003186 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3187 "0125 FDISC Failed (x%x). "
3188 "Fabric out of resources\n",
3189 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003190 lpfc_vport_set_state(vport,
3191 FC_VPORT_NO_FABRIC_RSCS);
3192 }
dea31012005-04-17 16:05:31 -05003193 break;
3194
3195 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003196 if ((cmd == ELS_CMD_PLOGI) ||
3197 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003198 delay = 1000;
dea31012005-04-17 16:05:31 -05003199 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003200 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003201 /* FDISC retry policy */
3202 maxretry = 48;
3203 if (cmdiocb->retry >= 32)
3204 delay = 1000;
dea31012005-04-17 16:05:31 -05003205 }
3206 retry = 1;
3207 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003208
3209 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003210 /* There are some cases where switches return this
3211 * error when they are not ready and should be returning
3212 * Logical Busy. We should delay every time.
3213 */
3214 if (cmd == ELS_CMD_FDISC &&
3215 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3216 maxretry = 3;
3217 delay = 1000;
3218 retry = 1;
3219 break;
3220 }
James Smart92d7f7b2007-06-17 19:56:38 -05003221 case LSRJT_PROTOCOL_ERR:
3222 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3223 (cmd == ELS_CMD_FDISC) &&
3224 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3225 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3226 ) {
James Smarte8b62012007-08-02 11:10:09 -04003227 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003228 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003229 "Fabric Detected Bad WWN\n",
3230 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003231 lpfc_vport_set_state(vport,
3232 FC_VPORT_FABRIC_REJ_WWN);
3233 }
3234 break;
dea31012005-04-17 16:05:31 -05003235 }
3236 break;
3237
3238 case IOSTAT_INTERMED_RSP:
3239 case IOSTAT_BA_RJT:
3240 break;
3241
3242 default:
3243 break;
3244 }
3245
James Smart488d1462006-03-07 15:02:37 -05003246 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003247 retry = 1;
dea31012005-04-17 16:05:31 -05003248
James Smartdf9e1b52011-12-13 13:22:17 -05003249 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003250 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003251 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003252 /* FLOGI retry policy */
3253 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003254 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003255 maxretry = 0;
3256 if (cmdiocb->retry >= 100)
3257 delay = 5000;
3258 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003259 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003260 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3261 /* retry FDISCs every second up to devloss */
3262 retry = 1;
3263 maxretry = vport->cfg_devloss_tmo;
3264 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003265 }
3266
James Smart6669f9b2009-10-02 15:16:45 -04003267 cmdiocb->retry++;
3268 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003269 phba->fc_stat.elsRetryExceeded++;
3270 retry = 0;
3271 }
3272
James Smarted957682007-06-17 19:56:37 -05003273 if ((vport->load_flag & FC_UNLOADING) != 0)
3274 retry = 0;
3275
dea31012005-04-17 16:05:31 -05003276 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003277 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3278 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3279 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3280 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3281 "2849 Stop retry ELS command "
3282 "x%x to remote NPORT x%x, "
3283 "Data: x%x x%x\n", cmd, did,
3284 cmdiocb->retry, delay);
3285 return 0;
3286 }
3287 }
dea31012005-04-17 16:05:31 -05003288
3289 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003290 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3291 "0107 Retry ELS command x%x to remote "
3292 "NPORT x%x Data: x%x x%x\n",
3293 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003294
James Smart858c9f62007-06-17 19:56:39 -05003295 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3296 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003297 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3298 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003299 /* Don't reset timer for no resources */
3300
dea31012005-04-17 16:05:31 -05003301 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003302 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003303 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003304 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003305 }
3306
3307 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003308 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003309 phba->fc_stat.elsDelayRetry++;
3310 ndlp->nlp_retry = cmdiocb->retry;
3311
James Smart92d7f7b2007-06-17 19:56:38 -05003312 /* delay is specified in milliseconds */
3313 mod_timer(&ndlp->nlp_delayfunc,
3314 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003315 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003316 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003317 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003318
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003319 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003320 if (cmd == ELS_CMD_PRLI)
3321 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003322 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003323 else
3324 lpfc_nlp_set_state(vport, ndlp,
3325 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003326 ndlp->nlp_last_elscmd = cmd;
3327
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003328 return 1;
dea31012005-04-17 16:05:31 -05003329 }
3330 switch (cmd) {
3331 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003332 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003333 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003334 case ELS_CMD_FDISC:
3335 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3336 return 1;
dea31012005-04-17 16:05:31 -05003337 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003338 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003339 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003340 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003341 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003342 }
James Smart2e0fef82007-06-17 19:56:36 -05003343 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003344 return 1;
dea31012005-04-17 16:05:31 -05003345 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003346 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003347 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3348 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003349 return 1;
dea31012005-04-17 16:05:31 -05003350 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003351 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003352 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3353 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003354 return 1;
dea31012005-04-17 16:05:31 -05003355 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003356 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003357 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003358 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003359 return 1;
dea31012005-04-17 16:05:31 -05003360 }
3361 }
dea31012005-04-17 16:05:31 -05003362 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003363 if (logerr) {
3364 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3365 "0137 No retry ELS command x%x to remote "
3366 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3367 cmd, did, irsp->ulpStatus,
3368 irsp->un.ulpWord[4]);
3369 }
3370 else {
3371 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003372 "0108 No retry ELS command x%x to remote "
3373 "NPORT x%x Retried:%d Error:x%x/%x\n",
3374 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3375 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003376 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003377 return 0;
dea31012005-04-17 16:05:31 -05003378}
3379
James Smarte59058c2008-08-24 21:49:00 -04003380/**
James Smart3621a712009-04-06 18:47:14 -04003381 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003382 * @phba: pointer to lpfc hba data structure.
3383 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3384 *
3385 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3386 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3387 * checks to see whether there is a lpfc DMA buffer associated with the
3388 * response of the command IOCB. If so, it will be released before releasing
3389 * the lpfc DMA buffer associated with the IOCB itself.
3390 *
3391 * Return code
3392 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3393 **/
James Smart09372822008-01-11 01:52:54 -05003394static int
James Smart87af33f2007-10-27 13:37:43 -04003395lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3396{
3397 struct lpfc_dmabuf *buf_ptr;
3398
James Smarte59058c2008-08-24 21:49:00 -04003399 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003400 if (!list_empty(&buf_ptr1->list)) {
3401 list_remove_head(&buf_ptr1->list, buf_ptr,
3402 struct lpfc_dmabuf,
3403 list);
3404 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3405 kfree(buf_ptr);
3406 }
3407 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3408 kfree(buf_ptr1);
3409 return 0;
3410}
3411
James Smarte59058c2008-08-24 21:49:00 -04003412/**
James Smart3621a712009-04-06 18:47:14 -04003413 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003414 * @phba: pointer to lpfc hba data structure.
3415 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3416 *
3417 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3418 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3419 * pool.
3420 *
3421 * Return code
3422 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3423 **/
James Smart09372822008-01-11 01:52:54 -05003424static int
James Smart87af33f2007-10-27 13:37:43 -04003425lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3426{
3427 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3428 kfree(buf_ptr);
3429 return 0;
3430}
3431
James Smarte59058c2008-08-24 21:49:00 -04003432/**
James Smart3621a712009-04-06 18:47:14 -04003433 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003434 * @phba: pointer to lpfc hba data structure.
3435 * @elsiocb: pointer to lpfc els command iocb data structure.
3436 *
3437 * This routine frees a command IOCB and its associated resources. The
3438 * command IOCB data structure contains the reference to various associated
3439 * resources, these fields must be set to NULL if the associated reference
3440 * not present:
3441 * context1 - reference to ndlp
3442 * context2 - reference to cmd
3443 * context2->next - reference to rsp
3444 * context3 - reference to bpl
3445 *
3446 * It first properly decrements the reference count held on ndlp for the
3447 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3448 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3449 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3450 * adds the DMA buffer the @phba data structure for the delayed release.
3451 * If reference to the Buffer Pointer List (BPL) is present, the
3452 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3453 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3454 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3455 *
3456 * Return code
3457 * 0 - Success (currently, always return 0)
3458 **/
James Smart87af33f2007-10-27 13:37:43 -04003459int
James Smart329f9bc2007-04-25 09:53:01 -04003460lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003461{
3462 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003463 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003464
James Smarta8adb832007-10-27 13:37:53 -04003465 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3466 if (ndlp) {
3467 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3468 lpfc_nlp_put(ndlp);
3469
3470 /* If the ndlp is not being used by another discovery
3471 * thread, free it.
3472 */
3473 if (!lpfc_nlp_not_used(ndlp)) {
3474 /* If ndlp is being used by another discovery
3475 * thread, just clear NLP_DEFER_RM
3476 */
3477 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3478 }
3479 }
3480 else
3481 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003482 elsiocb->context1 = NULL;
3483 }
dea31012005-04-17 16:05:31 -05003484 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3485 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003486 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3487 /* Firmware could still be in progress of DMAing
3488 * payload, so don't free data buffer till after
3489 * a hbeat.
3490 */
3491 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3492 buf_ptr = elsiocb->context2;
3493 elsiocb->context2 = NULL;
3494 if (buf_ptr) {
3495 buf_ptr1 = NULL;
3496 spin_lock_irq(&phba->hbalock);
3497 if (!list_empty(&buf_ptr->list)) {
3498 list_remove_head(&buf_ptr->list,
3499 buf_ptr1, struct lpfc_dmabuf,
3500 list);
3501 INIT_LIST_HEAD(&buf_ptr1->list);
3502 list_add_tail(&buf_ptr1->list,
3503 &phba->elsbuf);
3504 phba->elsbuf_cnt++;
3505 }
3506 INIT_LIST_HEAD(&buf_ptr->list);
3507 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3508 phba->elsbuf_cnt++;
3509 spin_unlock_irq(&phba->hbalock);
3510 }
3511 } else {
3512 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3513 lpfc_els_free_data(phba, buf_ptr1);
3514 }
dea31012005-04-17 16:05:31 -05003515 }
3516
3517 if (elsiocb->context3) {
3518 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003519 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003520 }
James Bottomley604a3e32005-10-29 10:28:33 -05003521 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003522 return 0;
3523}
3524
James Smarte59058c2008-08-24 21:49:00 -04003525/**
James Smart3621a712009-04-06 18:47:14 -04003526 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003527 * @phba: pointer to lpfc hba data structure.
3528 * @cmdiocb: pointer to lpfc command iocb data structure.
3529 * @rspiocb: pointer to lpfc response iocb data structure.
3530 *
3531 * This routine is the completion callback function to the Logout (LOGO)
3532 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3533 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3534 * release the ndlp if it has the last reference remaining (reference count
3535 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3536 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3537 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3538 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3539 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3540 * IOCB data structure.
3541 **/
dea31012005-04-17 16:05:31 -05003542static void
James Smart2e0fef82007-06-17 19:56:36 -05003543lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3544 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003545{
James Smart2e0fef82007-06-17 19:56:36 -05003546 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3547 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003548 IOCB_t *irsp;
3549
3550 irsp = &rspiocb->iocb;
3551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3552 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3553 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003554 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003555 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3556 "0109 ACC to LOGO completes to NPort x%x "
3557 "Data: x%x x%x x%x\n",
3558 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3559 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003560
3561 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3562 /* NPort Recovery mode or node is just allocated */
3563 if (!lpfc_nlp_not_used(ndlp)) {
3564 /* If the ndlp is being used by another discovery
3565 * thread, just unregister the RPI.
3566 */
3567 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003568 } else {
3569 /* Indicate the node has already released, should
3570 * not reference to it from within lpfc_els_free_iocb.
3571 */
3572 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003573 }
dea31012005-04-17 16:05:31 -05003574 }
James Smart73d91e52011-10-10 21:32:10 -04003575
3576 /*
3577 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003578 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003579 */
dea31012005-04-17 16:05:31 -05003580 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003581
3582 /*
3583 * Remove the ndlp reference if it's a fabric node that has
3584 * sent us an unsolicted LOGO.
3585 */
3586 if (ndlp->nlp_type & NLP_FABRIC)
3587 lpfc_nlp_put(ndlp);
3588
dea31012005-04-17 16:05:31 -05003589 return;
3590}
3591
James Smarte59058c2008-08-24 21:49:00 -04003592/**
James Smart3621a712009-04-06 18:47:14 -04003593 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003594 * @phba: pointer to lpfc hba data structure.
3595 * @pmb: pointer to the driver internal queue element for mailbox command.
3596 *
3597 * This routine is the completion callback function for unregister default
3598 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3599 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3600 * decrements the ndlp reference count held for this completion callback
3601 * function. After that, it invokes the lpfc_nlp_not_used() to check
3602 * whether there is only one reference left on the ndlp. If so, it will
3603 * perform one more decrement and trigger the release of the ndlp.
3604 **/
James Smart858c9f62007-06-17 19:56:39 -05003605void
3606lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3607{
3608 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3609 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3610
3611 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003612 pmb->context2 = NULL;
3613
James Smart858c9f62007-06-17 19:56:39 -05003614 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3615 kfree(mp);
3616 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003617 if (ndlp) {
3618 if (NLP_CHK_NODE_ACT(ndlp)) {
3619 lpfc_nlp_put(ndlp);
3620 /* This is the end of the default RPI cleanup logic for
3621 * this ndlp. If no other discovery threads are using
3622 * this ndlp, free all resources associated with it.
3623 */
3624 lpfc_nlp_not_used(ndlp);
3625 } else {
3626 lpfc_drop_node(ndlp->vport, ndlp);
3627 }
James Smarta8adb832007-10-27 13:37:53 -04003628 }
James Smart3772a992009-05-22 14:50:54 -04003629
James Smart858c9f62007-06-17 19:56:39 -05003630 return;
3631}
3632
James Smarte59058c2008-08-24 21:49:00 -04003633/**
James Smart3621a712009-04-06 18:47:14 -04003634 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003635 * @phba: pointer to lpfc hba data structure.
3636 * @cmdiocb: pointer to lpfc command iocb data structure.
3637 * @rspiocb: pointer to lpfc response iocb data structure.
3638 *
3639 * This routine is the completion callback function for ELS Response IOCB
3640 * command. In normal case, this callback function just properly sets the
3641 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3642 * field in the command IOCB is not NULL, the referred mailbox command will
3643 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3644 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3645 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3646 * routine shall be invoked trying to release the ndlp if no other threads
3647 * are currently referring it.
3648 **/
dea31012005-04-17 16:05:31 -05003649static void
James Smart858c9f62007-06-17 19:56:39 -05003650lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003651 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003652{
James Smart2e0fef82007-06-17 19:56:36 -05003653 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3654 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3655 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003656 IOCB_t *irsp;
3657 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003658 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003659 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003660 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003661
James Smart33ccf8d2006-08-17 11:57:58 -04003662 irsp = &rspiocb->iocb;
3663
dea31012005-04-17 16:05:31 -05003664 if (cmdiocb->context_un.mbox)
3665 mbox = cmdiocb->context_un.mbox;
3666
James Smartfa4066b2008-01-11 01:53:27 -05003667 /* First determine if this is a LS_RJT cmpl. Note, this callback
3668 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3669 */
James Smart87af33f2007-10-27 13:37:43 -04003670 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003671 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3672 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003673 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003674 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003675 */
3676 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3677 ls_rjt = 1;
3678 }
3679
dea31012005-04-17 16:05:31 -05003680 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003681 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003682 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003683 mp = (struct lpfc_dmabuf *) mbox->context1;
3684 if (mp) {
3685 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3686 kfree(mp);
3687 }
James Smart329f9bc2007-04-25 09:53:01 -04003688 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003689 }
James Smart58da1ff2008-04-07 10:15:56 -04003690 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3691 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003692 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003693 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003694 /* Indicate the node has already released,
3695 * should not reference to it from within
3696 * the routine lpfc_els_free_iocb.
3697 */
3698 cmdiocb->context1 = NULL;
3699 }
dea31012005-04-17 16:05:31 -05003700 goto out;
3701 }
3702
James Smart858c9f62007-06-17 19:56:39 -05003703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003704 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003705 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003706 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003707 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003708 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3709 "0110 ELS response tag x%x completes "
3710 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3711 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3712 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3713 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3714 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003715 if (mbox) {
3716 if ((rspiocb->iocb.ulpStatus == 0)
3717 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003718 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003719 /* Increment reference count to ndlp to hold the
3720 * reference to ndlp for the callback function.
3721 */
James Smart329f9bc2007-04-25 09:53:01 -04003722 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003723 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003724 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3725 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3726 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3727 }
3728 else {
3729 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3730 ndlp->nlp_prev_state = ndlp->nlp_state;
3731 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003732 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003733 }
James Smart0b727fe2007-10-27 13:37:25 -04003734 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003735 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003736 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003737 else
3738 /* Decrement the ndlp reference count we
3739 * set for this failed mailbox command.
3740 */
3741 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003742
3743 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3744 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3745 "0138 ELS rsp: Cannot issue reg_login for x%x "
3746 "Data: x%x x%x x%x\n",
3747 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3748 ndlp->nlp_rpi);
3749
James Smartfa4066b2008-01-11 01:53:27 -05003750 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003751 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003752 /* Indicate node has already been released,
3753 * should not reference to it from within
3754 * the routine lpfc_els_free_iocb.
3755 */
3756 cmdiocb->context1 = NULL;
3757 }
dea31012005-04-17 16:05:31 -05003758 } else {
James Smart858c9f62007-06-17 19:56:39 -05003759 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3760 if (!lpfc_error_lost_link(irsp) &&
3761 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003762 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003763 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003764 /* Indicate node has already been
3765 * released, should not reference
3766 * to it from within the routine
3767 * lpfc_els_free_iocb.
3768 */
3769 cmdiocb->context1 = NULL;
3770 }
dea31012005-04-17 16:05:31 -05003771 }
3772 }
James Smart14691152006-12-02 13:34:28 -05003773 mp = (struct lpfc_dmabuf *) mbox->context1;
3774 if (mp) {
3775 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3776 kfree(mp);
3777 }
3778 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003779 }
3780out:
James Smart58da1ff2008-04-07 10:15:56 -04003781 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003782 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003783 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003784 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003785
3786 /* If the node is not being used by another discovery thread,
3787 * and we are sending a reject, we are done with it.
3788 * Release driver reference count here and free associated
3789 * resources.
3790 */
3791 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003792 if (lpfc_nlp_not_used(ndlp))
3793 /* Indicate node has already been released,
3794 * should not reference to it from within
3795 * the routine lpfc_els_free_iocb.
3796 */
3797 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003798 }
James Smart87af33f2007-10-27 13:37:43 -04003799
dea31012005-04-17 16:05:31 -05003800 lpfc_els_free_iocb(phba, cmdiocb);
3801 return;
3802}
3803
James Smarte59058c2008-08-24 21:49:00 -04003804/**
James Smart3621a712009-04-06 18:47:14 -04003805 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003806 * @vport: pointer to a host virtual N_Port data structure.
3807 * @flag: the els command code to be accepted.
3808 * @oldiocb: pointer to the original lpfc command iocb data structure.
3809 * @ndlp: pointer to a node-list data structure.
3810 * @mbox: pointer to the driver internal queue element for mailbox command.
3811 *
3812 * This routine prepares and issues an Accept (ACC) response IOCB
3813 * command. It uses the @flag to properly set up the IOCB field for the
3814 * specific ACC response command to be issued and invokes the
3815 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3816 * @mbox pointer is passed in, it will be put into the context_un.mbox
3817 * field of the IOCB for the completion callback function to issue the
3818 * mailbox command to the HBA later when callback is invoked.
3819 *
3820 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3821 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3822 * will be stored into the context1 field of the IOCB for the completion
3823 * callback function to the corresponding response ELS IOCB command.
3824 *
3825 * Return code
3826 * 0 - Successfully issued acc response
3827 * 1 - Failed to issue acc response
3828 **/
dea31012005-04-17 16:05:31 -05003829int
James Smart2e0fef82007-06-17 19:56:36 -05003830lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3831 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003832 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003833{
James Smart2e0fef82007-06-17 19:56:36 -05003834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3835 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003836 IOCB_t *icmd;
3837 IOCB_t *oldcmd;
3838 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003839 struct lpfc_sli *psli;
3840 uint8_t *pcmd;
3841 uint16_t cmdsize;
3842 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003843 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003844
3845 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003846 oldcmd = &oldiocb->iocb;
3847
3848 switch (flag) {
3849 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003850 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003851 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3852 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003853 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003854 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003855 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003856 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003857 return 1;
dea31012005-04-17 16:05:31 -05003858 }
James Smart2e0fef82007-06-17 19:56:36 -05003859
dea31012005-04-17 16:05:31 -05003860 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003861 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3862 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003863 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3864 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003865 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003866
3867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3868 "Issue ACC: did:x%x flg:x%x",
3869 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003870 break;
3871 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003872 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003873 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3874 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003875 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003876 return 1;
James Smart488d1462006-03-07 15:02:37 -05003877
dea31012005-04-17 16:05:31 -05003878 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003879 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3880 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003881 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3882
3883 if (mbox)
3884 elsiocb->context_un.mbox = mbox;
3885
3886 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003887 pcmd += sizeof(uint32_t);
3888 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003889
3890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3891 "Issue ACC PLOGI: did:x%x flg:x%x",
3892 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003893 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003894 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003895 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003896 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003897 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3898 if (!elsiocb)
3899 return 1;
3900
3901 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003902 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3903 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003904 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3905
3906 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003907 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003908 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3909 els_pkt_ptr = (ELS_PKT *) pcmd;
3910 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003911
3912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3913 "Issue ACC PRLO: did:x%x flg:x%x",
3914 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003915 break;
dea31012005-04-17 16:05:31 -05003916 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003917 return 1;
dea31012005-04-17 16:05:31 -05003918 }
dea31012005-04-17 16:05:31 -05003919 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003920 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3921 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003922 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3923 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003924 elsiocb->iotag, elsiocb->iocb.ulpContext,
3925 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003926 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003927 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003928 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003929 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003930 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003931 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3932 } else {
James Smart858c9f62007-06-17 19:56:39 -05003933 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003934 }
3935
3936 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003937 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003938 if (rc == IOCB_ERROR) {
3939 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003940 return 1;
dea31012005-04-17 16:05:31 -05003941 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003942 return 0;
dea31012005-04-17 16:05:31 -05003943}
3944
James Smarte59058c2008-08-24 21:49:00 -04003945/**
James Smart3621a712009-04-06 18:47:14 -04003946 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003947 * @vport: pointer to a virtual N_Port data structure.
3948 * @rejectError:
3949 * @oldiocb: pointer to the original lpfc command iocb data structure.
3950 * @ndlp: pointer to a node-list data structure.
3951 * @mbox: pointer to the driver internal queue element for mailbox command.
3952 *
3953 * This routine prepares and issue an Reject (RJT) response IOCB
3954 * command. If a @mbox pointer is passed in, it will be put into the
3955 * context_un.mbox field of the IOCB for the completion callback function
3956 * to issue to the HBA later.
3957 *
3958 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3959 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3960 * will be stored into the context1 field of the IOCB for the completion
3961 * callback function to the reject response ELS IOCB command.
3962 *
3963 * Return code
3964 * 0 - Successfully issued reject response
3965 * 1 - Failed to issue reject response
3966 **/
dea31012005-04-17 16:05:31 -05003967int
James Smart2e0fef82007-06-17 19:56:36 -05003968lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003969 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3970 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003971{
James Smart2e0fef82007-06-17 19:56:36 -05003972 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003973 IOCB_t *icmd;
3974 IOCB_t *oldcmd;
3975 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003976 struct lpfc_sli *psli;
3977 uint8_t *pcmd;
3978 uint16_t cmdsize;
3979 int rc;
3980
3981 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003982 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003983 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3984 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003985 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003986 return 1;
dea31012005-04-17 16:05:31 -05003987
3988 icmd = &elsiocb->iocb;
3989 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003990 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3991 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003992 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3993
3994 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003995 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003996 *((uint32_t *) (pcmd)) = rejectError;
3997
James Smart51ef4c22007-08-02 11:10:31 -04003998 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003999 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05004000
dea31012005-04-17 16:05:31 -05004001 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004002 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4003 "0129 Xmit ELS RJT x%x response tag x%x "
4004 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4005 "rpi x%x\n",
4006 rejectError, elsiocb->iotag,
4007 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
4008 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004009 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4010 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4011 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4012
dea31012005-04-17 16:05:31 -05004013 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004014 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004015 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004016
dea31012005-04-17 16:05:31 -05004017 if (rc == IOCB_ERROR) {
4018 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004019 return 1;
dea31012005-04-17 16:05:31 -05004020 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004021 return 0;
dea31012005-04-17 16:05:31 -05004022}
4023
James Smarte59058c2008-08-24 21:49:00 -04004024/**
James Smart3621a712009-04-06 18:47:14 -04004025 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004026 * @vport: pointer to a virtual N_Port data structure.
4027 * @oldiocb: pointer to the original lpfc command iocb data structure.
4028 * @ndlp: pointer to a node-list data structure.
4029 *
4030 * This routine prepares and issues an Accept (ACC) response to Address
4031 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4032 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4033 *
4034 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4035 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4036 * will be stored into the context1 field of the IOCB for the completion
4037 * callback function to the ADISC Accept response ELS IOCB command.
4038 *
4039 * Return code
4040 * 0 - Successfully issued acc adisc response
4041 * 1 - Failed to issue adisc acc response
4042 **/
dea31012005-04-17 16:05:31 -05004043int
James Smart2e0fef82007-06-17 19:56:36 -05004044lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4045 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004046{
James Smart2e0fef82007-06-17 19:56:36 -05004047 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004048 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004049 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004050 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004051 uint8_t *pcmd;
4052 uint16_t cmdsize;
4053 int rc;
4054
James Smart92d7f7b2007-06-17 19:56:38 -05004055 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004056 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4057 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004058 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004059 return 1;
dea31012005-04-17 16:05:31 -05004060
dea31012005-04-17 16:05:31 -05004061 icmd = &elsiocb->iocb;
4062 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004063 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4064 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004065
4066 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004067 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4068 "0130 Xmit ADISC ACC response iotag x%x xri: "
4069 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4070 elsiocb->iotag, elsiocb->iocb.ulpContext,
4071 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4072 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004073 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4074
4075 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004076 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004077
4078 ap = (ADISC *) (pcmd);
4079 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004080 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4081 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004082 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004083
James Smart858c9f62007-06-17 19:56:39 -05004084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4085 "Issue ACC ADISC: did:x%x flg:x%x",
4086 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4087
dea31012005-04-17 16:05:31 -05004088 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004089 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004090 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004091 if (rc == IOCB_ERROR) {
4092 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004093 return 1;
dea31012005-04-17 16:05:31 -05004094 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004095 return 0;
dea31012005-04-17 16:05:31 -05004096}
4097
James Smarte59058c2008-08-24 21:49:00 -04004098/**
James Smart3621a712009-04-06 18:47:14 -04004099 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004100 * @vport: pointer to a virtual N_Port data structure.
4101 * @oldiocb: pointer to the original lpfc command iocb data structure.
4102 * @ndlp: pointer to a node-list data structure.
4103 *
4104 * This routine prepares and issues an Accept (ACC) response to Process
4105 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4106 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4107 *
4108 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4109 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4110 * will be stored into the context1 field of the IOCB for the completion
4111 * callback function to the PRLI Accept response ELS IOCB command.
4112 *
4113 * Return code
4114 * 0 - Successfully issued acc prli response
4115 * 1 - Failed to issue acc prli response
4116 **/
dea31012005-04-17 16:05:31 -05004117int
James Smart2e0fef82007-06-17 19:56:36 -05004118lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004119 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004120{
James Smart2e0fef82007-06-17 19:56:36 -05004121 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004122 PRLI *npr;
4123 lpfc_vpd_t *vpd;
4124 IOCB_t *icmd;
4125 IOCB_t *oldcmd;
4126 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004127 struct lpfc_sli *psli;
4128 uint8_t *pcmd;
4129 uint16_t cmdsize;
4130 int rc;
4131
4132 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004133
James Smart92d7f7b2007-06-17 19:56:38 -05004134 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004135 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004136 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004137 if (!elsiocb)
4138 return 1;
dea31012005-04-17 16:05:31 -05004139
dea31012005-04-17 16:05:31 -05004140 icmd = &elsiocb->iocb;
4141 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004142 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4143 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4144
James Smart5b8bd0c2007-04-25 09:52:49 -04004145 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004146 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4147 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4148 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4149 elsiocb->iotag, elsiocb->iocb.ulpContext,
4150 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4151 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004152 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4153
4154 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004155 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004156
4157 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004158 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004159
4160 npr = (PRLI *) pcmd;
4161 vpd = &phba->vpd;
4162 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004163 * If the remote port is a target and our firmware version is 3.20 or
4164 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004165 */
James Smart0d2b6b82008-06-14 22:52:47 -04004166 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4167 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004168 npr->ConfmComplAllowed = 1;
4169 npr->Retry = 1;
4170 npr->TaskRetryIdReq = 1;
4171 }
4172
4173 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4174 npr->estabImagePair = 1;
4175 npr->readXferRdyDis = 1;
4176 npr->ConfmComplAllowed = 1;
4177
4178 npr->prliType = PRLI_FCP_TYPE;
4179 npr->initiatorFunc = 1;
4180
James Smart858c9f62007-06-17 19:56:39 -05004181 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4182 "Issue ACC PRLI: did:x%x flg:x%x",
4183 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4184
dea31012005-04-17 16:05:31 -05004185 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004186 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004187
James Smart3772a992009-05-22 14:50:54 -04004188 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004189 if (rc == IOCB_ERROR) {
4190 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004191 return 1;
dea31012005-04-17 16:05:31 -05004192 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004193 return 0;
dea31012005-04-17 16:05:31 -05004194}
4195
James Smarte59058c2008-08-24 21:49:00 -04004196/**
James Smart3621a712009-04-06 18:47:14 -04004197 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004198 * @vport: pointer to a virtual N_Port data structure.
4199 * @format: rnid command format.
4200 * @oldiocb: pointer to the original lpfc command iocb data structure.
4201 * @ndlp: pointer to a node-list data structure.
4202 *
4203 * This routine issues a Request Node Identification Data (RNID) Accept
4204 * (ACC) response. It constructs the RNID ACC response command according to
4205 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4206 * issue the response. Note that this command does not need to hold the ndlp
4207 * reference count for the callback. So, the ndlp reference count taken by
4208 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4209 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4210 * there is no ndlp reference available.
4211 *
4212 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4213 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4214 * will be stored into the context1 field of the IOCB for the completion
4215 * callback function. However, for the RNID Accept Response ELS command,
4216 * this is undone later by this routine after the IOCB is allocated.
4217 *
4218 * Return code
4219 * 0 - Successfully issued acc rnid response
4220 * 1 - Failed to issue acc rnid response
4221 **/
dea31012005-04-17 16:05:31 -05004222static int
James Smart2e0fef82007-06-17 19:56:36 -05004223lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004224 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004225{
James Smart2e0fef82007-06-17 19:56:36 -05004226 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004227 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004228 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004229 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004230 struct lpfc_sli *psli;
4231 uint8_t *pcmd;
4232 uint16_t cmdsize;
4233 int rc;
4234
4235 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004236 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4237 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004238 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004239 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004240
James Smart2e0fef82007-06-17 19:56:36 -05004241 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4242 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004243 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004244 return 1;
dea31012005-04-17 16:05:31 -05004245
dea31012005-04-17 16:05:31 -05004246 icmd = &elsiocb->iocb;
4247 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004248 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4249 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4250
James Smart5b8bd0c2007-04-25 09:52:49 -04004251 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004252 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4253 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4254 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004255 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004256 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004257 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004258
James Smart92d7f7b2007-06-17 19:56:38 -05004259 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004260 rn = (RNID *) (pcmd);
4261 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004262 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4263 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4264 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004265 switch (format) {
4266 case 0:
4267 rn->SpecificLen = 0;
4268 break;
4269 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004270 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004271 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004272 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004273 rn->un.topologyDisc.unitType = RNID_HBA;
4274 rn->un.topologyDisc.physPort = 0;
4275 rn->un.topologyDisc.attachedNodes = 0;
4276 break;
4277 default:
4278 rn->CommonLen = 0;
4279 rn->SpecificLen = 0;
4280 break;
4281 }
4282
James Smart858c9f62007-06-17 19:56:39 -05004283 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4284 "Issue ACC RNID: did:x%x flg:x%x",
4285 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4286
dea31012005-04-17 16:05:31 -05004287 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004288 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004289
James Smart3772a992009-05-22 14:50:54 -04004290 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004291 if (rc == IOCB_ERROR) {
4292 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004293 return 1;
dea31012005-04-17 16:05:31 -05004294 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004295 return 0;
dea31012005-04-17 16:05:31 -05004296}
4297
James Smarte59058c2008-08-24 21:49:00 -04004298/**
James Smart19ca7602010-11-20 23:11:55 -05004299 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4300 * @vport: pointer to a virtual N_Port data structure.
4301 * @iocb: pointer to the lpfc command iocb data structure.
4302 * @ndlp: pointer to a node-list data structure.
4303 *
4304 * Return
4305 **/
4306static void
4307lpfc_els_clear_rrq(struct lpfc_vport *vport,
4308 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4309{
4310 struct lpfc_hba *phba = vport->phba;
4311 uint8_t *pcmd;
4312 struct RRQ *rrq;
4313 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004314 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004315 struct lpfc_node_rrq *prrq;
4316
4317
4318 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4319 pcmd += sizeof(uint32_t);
4320 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004321 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b0622011-04-16 11:03:17 -04004322 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004323
4324 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4325 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4326 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004327 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b0622011-04-16 11:03:17 -04004328 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004329 rxid,
4330 iocb->iotag, iocb->iocb.ulpContext);
4331
4332 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4333 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4334 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004335 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b0622011-04-16 11:03:17 -04004336 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004337 else
4338 xri = rxid;
4339 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004340 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004341 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004342 return;
4343}
4344
4345/**
James Smart12265f62010-10-22 11:05:53 -04004346 * lpfc_els_rsp_echo_acc - Issue echo acc response
4347 * @vport: pointer to a virtual N_Port data structure.
4348 * @data: pointer to echo data to return in the accept.
4349 * @oldiocb: pointer to the original lpfc command iocb data structure.
4350 * @ndlp: pointer to a node-list data structure.
4351 *
4352 * Return code
4353 * 0 - Successfully issued acc echo response
4354 * 1 - Failed to issue acc echo response
4355 **/
4356static int
4357lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4358 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4359{
4360 struct lpfc_hba *phba = vport->phba;
4361 struct lpfc_iocbq *elsiocb;
4362 struct lpfc_sli *psli;
4363 uint8_t *pcmd;
4364 uint16_t cmdsize;
4365 int rc;
4366
4367 psli = &phba->sli;
4368 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4369
James Smartbf086112011-08-21 21:48:13 -04004370 /* The accumulated length can exceed the BPL_SIZE. For
4371 * now, use this as the limit
4372 */
4373 if (cmdsize > LPFC_BPL_SIZE)
4374 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004375 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4376 ndlp->nlp_DID, ELS_CMD_ACC);
4377 if (!elsiocb)
4378 return 1;
4379
James Smart7851fe22011-07-22 18:36:52 -04004380 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4381 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4382
James Smart12265f62010-10-22 11:05:53 -04004383 /* Xmit ECHO ACC response tag <ulpIoTag> */
4384 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4385 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4386 elsiocb->iotag, elsiocb->iocb.ulpContext);
4387 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4388 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4389 pcmd += sizeof(uint32_t);
4390 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4391
4392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4393 "Issue ACC ECHO: did:x%x flg:x%x",
4394 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4395
4396 phba->fc_stat.elsXmitACC++;
4397 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004398
4399 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4400 if (rc == IOCB_ERROR) {
4401 lpfc_els_free_iocb(phba, elsiocb);
4402 return 1;
4403 }
4404 return 0;
4405}
4406
4407/**
James Smart3621a712009-04-06 18:47:14 -04004408 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004409 * @vport: pointer to a host virtual N_Port data structure.
4410 *
4411 * This routine issues Address Discover (ADISC) ELS commands to those
4412 * N_Ports which are in node port recovery state and ADISC has not been issued
4413 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4414 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4415 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4416 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4417 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4418 * IOCBs quit for later pick up. On the other hand, after walking through
4419 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4420 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4421 * no more ADISC need to be sent.
4422 *
4423 * Return code
4424 * The number of N_Ports with adisc issued.
4425 **/
dea31012005-04-17 16:05:31 -05004426int
James Smart2e0fef82007-06-17 19:56:36 -05004427lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004428{
James Smart2e0fef82007-06-17 19:56:36 -05004429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004430 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004431 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004432
James Smart685f0bf2007-04-25 09:53:08 -04004433 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004434 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004435 if (!NLP_CHK_NODE_ACT(ndlp))
4436 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004437 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4438 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4439 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004440 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004441 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004442 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004443 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004444 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4445 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004446 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004447 vport->num_disc_nodes++;
4448 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004449 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004450 spin_lock_irq(shost->host_lock);
4451 vport->fc_flag |= FC_NLP_MORE;
4452 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004453 break;
dea31012005-04-17 16:05:31 -05004454 }
4455 }
4456 }
4457 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004458 spin_lock_irq(shost->host_lock);
4459 vport->fc_flag &= ~FC_NLP_MORE;
4460 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004461 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004462 return sentadisc;
dea31012005-04-17 16:05:31 -05004463}
4464
James Smarte59058c2008-08-24 21:49:00 -04004465/**
James Smart3621a712009-04-06 18:47:14 -04004466 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004467 * @vport: pointer to a host virtual N_Port data structure.
4468 *
4469 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4470 * which are in node port recovery state, with a @vport. Each time an ELS
4471 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4472 * the per @vport number of discover count (num_disc_nodes) shall be
4473 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4474 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4475 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4476 * later pick up. On the other hand, after walking through all the ndlps with
4477 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4478 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4479 * PLOGI need to be sent.
4480 *
4481 * Return code
4482 * The number of N_Ports with plogi issued.
4483 **/
dea31012005-04-17 16:05:31 -05004484int
James Smart2e0fef82007-06-17 19:56:36 -05004485lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004486{
James Smart2e0fef82007-06-17 19:56:36 -05004487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004488 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004489 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004490
James Smart2e0fef82007-06-17 19:56:36 -05004491 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4492 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004493 if (!NLP_CHK_NODE_ACT(ndlp))
4494 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004495 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4496 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4497 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4498 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4499 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4501 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004502 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004503 vport->num_disc_nodes++;
4504 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004505 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004506 spin_lock_irq(shost->host_lock);
4507 vport->fc_flag |= FC_NLP_MORE;
4508 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004509 break;
dea31012005-04-17 16:05:31 -05004510 }
4511 }
4512 }
James Smart87af33f2007-10-27 13:37:43 -04004513 if (sentplogi) {
4514 lpfc_set_disctmo(vport);
4515 }
4516 else {
James Smart2e0fef82007-06-17 19:56:36 -05004517 spin_lock_irq(shost->host_lock);
4518 vport->fc_flag &= ~FC_NLP_MORE;
4519 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004520 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004521 return sentplogi;
dea31012005-04-17 16:05:31 -05004522}
4523
James Smarte59058c2008-08-24 21:49:00 -04004524/**
James Smart3621a712009-04-06 18:47:14 -04004525 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004526 * @vport: pointer to a host virtual N_Port data structure.
4527 *
4528 * This routine cleans up any Registration State Change Notification
4529 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4530 * @vport together with the host_lock is used to prevent multiple thread
4531 * trying to access the RSCN array on a same @vport at the same time.
4532 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004533void
James Smart2e0fef82007-06-17 19:56:36 -05004534lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004535{
James Smart2e0fef82007-06-17 19:56:36 -05004536 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4537 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004538 int i;
4539
James Smart7f5f3d02008-02-08 18:50:14 -05004540 spin_lock_irq(shost->host_lock);
4541 if (vport->fc_rscn_flush) {
4542 /* Another thread is walking fc_rscn_id_list on this vport */
4543 spin_unlock_irq(shost->host_lock);
4544 return;
4545 }
4546 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4547 vport->fc_rscn_flush = 1;
4548 spin_unlock_irq(shost->host_lock);
4549
James Smart2e0fef82007-06-17 19:56:36 -05004550 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004551 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004552 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004553 }
James Smart2e0fef82007-06-17 19:56:36 -05004554 spin_lock_irq(shost->host_lock);
4555 vport->fc_rscn_id_cnt = 0;
4556 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4557 spin_unlock_irq(shost->host_lock);
4558 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004559 /* Indicate we are done walking this fc_rscn_id_list */
4560 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004561}
4562
James Smarte59058c2008-08-24 21:49:00 -04004563/**
James Smart3621a712009-04-06 18:47:14 -04004564 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004565 * @vport: pointer to a host virtual N_Port data structure.
4566 * @did: remote destination port identifier.
4567 *
4568 * This routine checks whether there is any pending Registration State
4569 * Configuration Notification (RSCN) to a @did on @vport.
4570 *
4571 * Return code
4572 * None zero - The @did matched with a pending rscn
4573 * 0 - not able to match @did with a pending rscn
4574 **/
dea31012005-04-17 16:05:31 -05004575int
James Smart2e0fef82007-06-17 19:56:36 -05004576lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004577{
4578 D_ID ns_did;
4579 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004580 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004581 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004583
4584 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004585
4586 /* Never match fabric nodes for RSCNs */
4587 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004588 return 0;
dea31012005-04-17 16:05:31 -05004589
4590 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004591 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004592 return did;
dea31012005-04-17 16:05:31 -05004593
James Smart7f5f3d02008-02-08 18:50:14 -05004594 spin_lock_irq(shost->host_lock);
4595 if (vport->fc_rscn_flush) {
4596 /* Another thread is walking fc_rscn_id_list on this vport */
4597 spin_unlock_irq(shost->host_lock);
4598 return 0;
4599 }
4600 /* Indicate we are walking fc_rscn_id_list on this vport */
4601 vport->fc_rscn_flush = 1;
4602 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004603 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004604 lp = vport->fc_rscn_id_list[i]->virt;
4605 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4606 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004607 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004608 rscn_did.un.word = be32_to_cpu(*lp++);
4609 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004610 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4611 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004612 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4613 && (ns_did.un.b.area == rscn_did.un.b.area)
4614 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004615 goto return_did_out;
dea31012005-04-17 16:05:31 -05004616 break;
James Smarteaf15d52008-12-04 22:39:29 -05004617 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004618 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4619 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004620 goto return_did_out;
dea31012005-04-17 16:05:31 -05004621 break;
James Smarteaf15d52008-12-04 22:39:29 -05004622 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004623 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004624 goto return_did_out;
dea31012005-04-17 16:05:31 -05004625 break;
James Smarteaf15d52008-12-04 22:39:29 -05004626 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004627 goto return_did_out;
dea31012005-04-17 16:05:31 -05004628 }
4629 }
James Smart92d7f7b2007-06-17 19:56:38 -05004630 }
James Smart7f5f3d02008-02-08 18:50:14 -05004631 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4632 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004633 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004634return_did_out:
4635 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4636 vport->fc_rscn_flush = 0;
4637 return did;
dea31012005-04-17 16:05:31 -05004638}
4639
James Smarte59058c2008-08-24 21:49:00 -04004640/**
James Smart3621a712009-04-06 18:47:14 -04004641 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004642 * @vport: pointer to a host virtual N_Port data structure.
4643 *
4644 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4645 * state machine for a @vport's nodes that are with pending RSCN (Registration
4646 * State Change Notification).
4647 *
4648 * Return code
4649 * 0 - Successful (currently alway return 0)
4650 **/
dea31012005-04-17 16:05:31 -05004651static int
James Smart2e0fef82007-06-17 19:56:36 -05004652lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004653{
James Smart685f0bf2007-04-25 09:53:08 -04004654 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004655
James Smart0d2b6b82008-06-14 22:52:47 -04004656 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004657 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004658 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004659 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4660 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004661 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004662 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004663 NLP_EVT_DEVICE_RECOVERY);
4664 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004665 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004666 return 0;
dea31012005-04-17 16:05:31 -05004667}
4668
James Smarte59058c2008-08-24 21:49:00 -04004669/**
James Smart3621a712009-04-06 18:47:14 -04004670 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004671 * @vport: pointer to a host virtual N_Port data structure.
4672 * @cmdiocb: pointer to lpfc command iocb data structure.
4673 *
4674 * lpfc_send_rscn_event sends an RSCN netlink event to management
4675 * applications.
4676 */
4677static void
4678lpfc_send_rscn_event(struct lpfc_vport *vport,
4679 struct lpfc_iocbq *cmdiocb)
4680{
4681 struct lpfc_dmabuf *pcmd;
4682 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4683 uint32_t *payload_ptr;
4684 uint32_t payload_len;
4685 struct lpfc_rscn_event_header *rscn_event_data;
4686
4687 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4688 payload_ptr = (uint32_t *) pcmd->virt;
4689 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4690
4691 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4692 payload_len, GFP_KERNEL);
4693 if (!rscn_event_data) {
4694 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4695 "0147 Failed to allocate memory for RSCN event\n");
4696 return;
4697 }
4698 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4699 rscn_event_data->payload_length = payload_len;
4700 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4701 payload_len);
4702
4703 fc_host_post_vendor_event(shost,
4704 fc_get_event_number(),
4705 sizeof(struct lpfc_els_event_header) + payload_len,
4706 (char *)rscn_event_data,
4707 LPFC_NL_VENDOR_ID);
4708
4709 kfree(rscn_event_data);
4710}
4711
4712/**
James Smart3621a712009-04-06 18:47:14 -04004713 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004714 * @vport: pointer to a host virtual N_Port data structure.
4715 * @cmdiocb: pointer to lpfc command iocb data structure.
4716 * @ndlp: pointer to a node-list data structure.
4717 *
4718 * This routine processes an unsolicited RSCN (Registration State Change
4719 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4720 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4721 * discover state machine is about to begin discovery, it just accepts the
4722 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4723 * contains N_Port IDs for other vports on this HBA, it just accepts the
4724 * RSCN and ignore processing it. If the state machine is in the recovery
4725 * state, the fc_rscn_id_list of this @vport is walked and the
4726 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4727 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4728 * routine is invoked to handle the RSCN event.
4729 *
4730 * Return code
4731 * 0 - Just sent the acc response
4732 * 1 - Sent the acc response and waited for name server completion
4733 **/
dea31012005-04-17 16:05:31 -05004734static int
James Smart2e0fef82007-06-17 19:56:36 -05004735lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004736 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004737{
James Smart2e0fef82007-06-17 19:56:36 -05004738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4739 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004740 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004741 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004742 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004743 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004744 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004745 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004746 int i;
dea31012005-04-17 16:05:31 -05004747
4748 icmd = &cmdiocb->iocb;
4749 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4750 lp = (uint32_t *) pcmd->virt;
4751
James Smart92d7f7b2007-06-17 19:56:38 -05004752 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4753 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004754 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004755 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4756 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004757 vport->fc_flag, payload_len, *lp,
4758 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004759
4760 /* Send an RSCN event to the management application */
4761 lpfc_send_rscn_event(vport, cmdiocb);
4762
James Smartd2873e42006-08-18 17:46:43 -04004763 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004764 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004765 FCH_EVT_RSCN, lp[i]);
4766
dea31012005-04-17 16:05:31 -05004767 /* If we are about to begin discovery, just ACC the RSCN.
4768 * Discovery processing will satisfy it.
4769 */
James Smart2e0fef82007-06-17 19:56:36 -05004770 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4772 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4773 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4774
James Smart51ef4c22007-08-02 11:10:31 -04004775 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004776 return 0;
dea31012005-04-17 16:05:31 -05004777 }
4778
James Smart92d7f7b2007-06-17 19:56:38 -05004779 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4780 * just ACC and ignore it.
4781 */
4782 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004783 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004784 i = payload_len;
4785 datap = lp;
4786 while (i > 0) {
4787 nportid = *datap++;
4788 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4789 i -= sizeof(uint32_t);
4790 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004791 if (lpfc_find_vport_by_did(phba, nportid))
4792 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004793 }
4794 if (rscn_id == hba_id) {
4795 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004796 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004797 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004798 "Data: x%x x%x x%x x%x\n",
4799 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004800 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4802 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4803 ndlp->nlp_DID, vport->port_state,
4804 ndlp->nlp_flag);
4805
James Smart92d7f7b2007-06-17 19:56:38 -05004806 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004807 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004808 return 0;
4809 }
4810 }
4811
James Smart7f5f3d02008-02-08 18:50:14 -05004812 spin_lock_irq(shost->host_lock);
4813 if (vport->fc_rscn_flush) {
4814 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004815 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004816 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004817 /* Send back ACC */
4818 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004819 return 0;
4820 }
4821 /* Indicate we are walking fc_rscn_id_list on this vport */
4822 vport->fc_rscn_flush = 1;
4823 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004824 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004825 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004826 /* If we are already processing an RSCN, save the received
4827 * RSCN payload buffer, cmdiocb->context2 to process later.
4828 */
James Smart2e0fef82007-06-17 19:56:36 -05004829 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004830 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4831 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4832 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4833
James Smart09372822008-01-11 01:52:54 -05004834 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004835 vport->fc_flag |= FC_RSCN_DEFERRED;
4836 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004837 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004838 vport->fc_flag |= FC_RSCN_MODE;
4839 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004840 if (rscn_cnt) {
4841 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4842 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4843 }
4844 if ((rscn_cnt) &&
4845 (payload_len + length <= LPFC_BPL_SIZE)) {
4846 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004847 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004848 memcpy(((uint8_t *)cmd) + length, lp,
4849 payload_len);
4850 } else {
4851 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4852 vport->fc_rscn_id_cnt++;
4853 /* If we zero, cmdiocb->context2, the calling
4854 * routine will not try to free it.
4855 */
4856 cmdiocb->context2 = NULL;
4857 }
dea31012005-04-17 16:05:31 -05004858 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004859 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4860 "0235 Deferred RSCN "
4861 "Data: x%x x%x x%x\n",
4862 vport->fc_rscn_id_cnt, vport->fc_flag,
4863 vport->port_state);
dea31012005-04-17 16:05:31 -05004864 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004865 vport->fc_flag |= FC_RSCN_DISCOVERY;
4866 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004867 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004868 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4869 "0234 ReDiscovery RSCN "
4870 "Data: x%x x%x x%x\n",
4871 vport->fc_rscn_id_cnt, vport->fc_flag,
4872 vport->port_state);
dea31012005-04-17 16:05:31 -05004873 }
James Smart7f5f3d02008-02-08 18:50:14 -05004874 /* Indicate we are done walking fc_rscn_id_list on this vport */
4875 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004876 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004877 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004878 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004879 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004880 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004881 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004882 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004883 return 0;
dea31012005-04-17 16:05:31 -05004884 }
James Smart858c9f62007-06-17 19:56:39 -05004885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4886 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4887 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4888
James Smart2e0fef82007-06-17 19:56:36 -05004889 spin_lock_irq(shost->host_lock);
4890 vport->fc_flag |= FC_RSCN_MODE;
4891 spin_unlock_irq(shost->host_lock);
4892 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004893 /* Indicate we are done walking fc_rscn_id_list on this vport */
4894 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004895 /*
4896 * If we zero, cmdiocb->context2, the calling routine will
4897 * not try to free it.
4898 */
4899 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004900 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004901 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004902 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004903 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004904 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004905 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004906}
4907
James Smarte59058c2008-08-24 21:49:00 -04004908/**
James Smart3621a712009-04-06 18:47:14 -04004909 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004910 * @vport: pointer to a host virtual N_Port data structure.
4911 *
4912 * This routine handles the Registration State Configuration Notification
4913 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4914 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4915 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4916 * NameServer shall be issued. If CT command to the NameServer fails to be
4917 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4918 * RSCN activities with the @vport.
4919 *
4920 * Return code
4921 * 0 - Cleaned up rscn on the @vport
4922 * 1 - Wait for plogi to name server before proceed
4923 **/
dea31012005-04-17 16:05:31 -05004924int
James Smart2e0fef82007-06-17 19:56:36 -05004925lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004926{
4927 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004928 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004929
James Smart92d7f7b2007-06-17 19:56:38 -05004930 /* Ignore RSCN if the port is being torn down. */
4931 if (vport->load_flag & FC_UNLOADING) {
4932 lpfc_els_flush_rscn(vport);
4933 return 0;
4934 }
4935
dea31012005-04-17 16:05:31 -05004936 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004937 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004938
4939 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004940 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4941 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4942 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4943 vport->port_state);
dea31012005-04-17 16:05:31 -05004944
4945 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004946 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004947 vport->num_disc_nodes = 0;
4948
James Smart2e0fef82007-06-17 19:56:36 -05004949 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004950 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4951 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004952 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004953 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004954 /* Wait for NameServer query cmpl before we can
4955 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004956 return 1;
dea31012005-04-17 16:05:31 -05004957 } else {
4958 /* If login to NameServer does not exist, issue one */
4959 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004960 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004961 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004962 /* Wait for NameServer login cmpl before we can
4963 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004964 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004965
James Smarte47c9092008-02-08 18:49:26 -05004966 if (ndlp) {
4967 ndlp = lpfc_enable_node(vport, ndlp,
4968 NLP_STE_PLOGI_ISSUE);
4969 if (!ndlp) {
4970 lpfc_els_flush_rscn(vport);
4971 return 0;
4972 }
4973 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004974 } else {
James Smarte47c9092008-02-08 18:49:26 -05004975 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4976 if (!ndlp) {
4977 lpfc_els_flush_rscn(vport);
4978 return 0;
4979 }
James Smart2e0fef82007-06-17 19:56:36 -05004980 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004981 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004982 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004983 }
James Smarte47c9092008-02-08 18:49:26 -05004984 ndlp->nlp_type |= NLP_FABRIC;
4985 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4986 /* Wait for NameServer login cmpl before we can
4987 * continue
4988 */
4989 return 1;
dea31012005-04-17 16:05:31 -05004990 }
4991
James Smart2e0fef82007-06-17 19:56:36 -05004992 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004993 return 0;
dea31012005-04-17 16:05:31 -05004994}
4995
James Smarte59058c2008-08-24 21:49:00 -04004996/**
James Smart3621a712009-04-06 18:47:14 -04004997 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004998 * @vport: pointer to a host virtual N_Port data structure.
4999 * @cmdiocb: pointer to lpfc command iocb data structure.
5000 * @ndlp: pointer to a node-list data structure.
5001 *
5002 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5003 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5004 * point topology. As an unsolicited FLOGI should not be received in a loop
5005 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5006 * lpfc_check_sparm() routine is invoked to check the parameters in the
5007 * unsolicited FLOGI. If parameters validation failed, the routine
5008 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5009 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5010 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5011 * will initiate PLOGI. The higher lexicographical value party shall has
5012 * higher priority (as the winning port) and will initiate PLOGI and
5013 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5014 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5015 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5016 *
5017 * Return code
5018 * 0 - Successfully processed the unsolicited flogi
5019 * 1 - Failed to process the unsolicited flogi
5020 **/
dea31012005-04-17 16:05:31 -05005021static int
James Smart2e0fef82007-06-17 19:56:36 -05005022lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005023 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005024{
James Smart2e0fef82007-06-17 19:56:36 -05005025 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5026 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005027 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5028 uint32_t *lp = (uint32_t *) pcmd->virt;
5029 IOCB_t *icmd = &cmdiocb->iocb;
5030 struct serv_parm *sp;
5031 LPFC_MBOXQ_t *mbox;
5032 struct ls_rjt stat;
5033 uint32_t cmd, did;
5034 int rc;
5035
5036 cmd = *lp++;
5037 sp = (struct serv_parm *) lp;
5038
5039 /* FLOGI received */
5040
James Smart2e0fef82007-06-17 19:56:36 -05005041 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005042
James Smart76a95d72010-11-20 23:11:48 -05005043 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005044 /* We should never receive a FLOGI in loop mode, ignore it */
5045 did = icmd->un.elsreq64.remoteID;
5046
5047 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5048 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005049 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5050 "0113 An FLOGI ELS command x%x was "
5051 "received from DID x%x in Loop Mode\n",
5052 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005053 return 1;
dea31012005-04-17 16:05:31 -05005054 }
5055
James Smart341af102010-01-26 23:07:37 -05005056 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005057 /* For a FLOGI we accept, then if our portname is greater
5058 * then the remote portname we initiate Nport login.
5059 */
5060
James Smart2e0fef82007-06-17 19:56:36 -05005061 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005062 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005063
5064 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005065 if (phba->sli_rev < LPFC_SLI_REV4) {
5066 mbox = mempool_alloc(phba->mbox_mem_pool,
5067 GFP_KERNEL);
5068 if (!mbox)
5069 return 1;
5070 lpfc_linkdown(phba);
5071 lpfc_init_link(phba, mbox,
5072 phba->cfg_topology,
5073 phba->cfg_link_speed);
5074 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5075 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5076 mbox->vport = vport;
5077 rc = lpfc_sli_issue_mbox(phba, mbox,
5078 MBX_NOWAIT);
5079 lpfc_set_loopback_flag(phba);
5080 if (rc == MBX_NOT_FINISHED)
5081 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005082 return 1;
James Smart1b511972011-12-13 13:23:09 -05005083 } else {
5084 /* abort the flogi coming back to ourselves
5085 * due to external loopback on the port.
5086 */
5087 lpfc_els_abort_flogi(phba);
5088 return 0;
dea31012005-04-17 16:05:31 -05005089 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005090 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005091 spin_lock_irq(shost->host_lock);
5092 vport->fc_flag |= FC_PT2PT_PLOGI;
5093 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005094
5095 /* If we have the high WWPN we can assign our own
5096 * myDID; otherwise, we have to WAIT for a PLOGI
5097 * from the remote NPort to find out what it
5098 * will be.
5099 */
James Smarte6446432012-05-09 21:16:42 -04005100 vport->fc_myDID = PT2PT_LocalID;
James Smart939723a2012-05-09 21:19:03 -04005101 }
5102
5103 /*
5104 * The vport state should go to LPFC_FLOGI only
5105 * AFTER we issue a FLOGI, not receive one.
5106 */
James Smart2e0fef82007-06-17 19:56:36 -05005107 spin_lock_irq(shost->host_lock);
5108 vport->fc_flag |= FC_PT2PT;
5109 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5110 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005111
5112 /*
5113 * We temporarily set fc_myDID to make it look like we are
5114 * a Fabric. This is done just so we end up with the right
5115 * did / sid on the FLOGI ACC rsp.
5116 */
5117 did = vport->fc_myDID;
5118 vport->fc_myDID = Fabric_DID;
5119
dea31012005-04-17 16:05:31 -05005120 } else {
5121 /* Reject this request because invalid parameters */
5122 stat.un.b.lsRjtRsvd0 = 0;
5123 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5124 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5125 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005126
5127 /*
5128 * We temporarily set fc_myDID to make it look like we are
5129 * a Fabric. This is done just so we end up with the right
5130 * did / sid on the FLOGI LS_RJT rsp.
5131 */
5132 did = vport->fc_myDID;
5133 vport->fc_myDID = Fabric_DID;
5134
James Smart858c9f62007-06-17 19:56:39 -05005135 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5136 NULL);
James Smart939723a2012-05-09 21:19:03 -04005137
5138 /* Now lets put fc_myDID back to what its supposed to be */
5139 vport->fc_myDID = did;
5140
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005141 return 1;
dea31012005-04-17 16:05:31 -05005142 }
5143
5144 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005145 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005146
James Smart939723a2012-05-09 21:19:03 -04005147 /* Now lets put fc_myDID back to what its supposed to be */
5148 vport->fc_myDID = did;
5149
James Smarte6446432012-05-09 21:16:42 -04005150 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005151
James Smarte6446432012-05-09 21:16:42 -04005152 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5153 if (!mbox)
5154 goto fail;
5155
5156 lpfc_config_link(phba, mbox);
5157
5158 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5159 mbox->vport = vport;
5160 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5161 if (rc == MBX_NOT_FINISHED) {
5162 mempool_free(mbox, phba->mbox_mem_pool);
5163 goto fail;
5164 }
5165 }
5166
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005167 return 0;
James Smarte6446432012-05-09 21:16:42 -04005168fail:
5169 return 1;
dea31012005-04-17 16:05:31 -05005170}
5171
James Smarte59058c2008-08-24 21:49:00 -04005172/**
James Smart3621a712009-04-06 18:47:14 -04005173 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005174 * @vport: pointer to a host virtual N_Port data structure.
5175 * @cmdiocb: pointer to lpfc command iocb data structure.
5176 * @ndlp: pointer to a node-list data structure.
5177 *
5178 * This routine processes Request Node Identification Data (RNID) IOCB
5179 * received as an ELS unsolicited event. Only when the RNID specified format
5180 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5181 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5182 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5183 * rejected by invoking the lpfc_els_rsp_reject() routine.
5184 *
5185 * Return code
5186 * 0 - Successfully processed rnid iocb (currently always return 0)
5187 **/
dea31012005-04-17 16:05:31 -05005188static int
James Smart2e0fef82007-06-17 19:56:36 -05005189lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5190 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005191{
5192 struct lpfc_dmabuf *pcmd;
5193 uint32_t *lp;
5194 IOCB_t *icmd;
5195 RNID *rn;
5196 struct ls_rjt stat;
5197 uint32_t cmd, did;
5198
5199 icmd = &cmdiocb->iocb;
5200 did = icmd->un.elsreq64.remoteID;
5201 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5202 lp = (uint32_t *) pcmd->virt;
5203
5204 cmd = *lp++;
5205 rn = (RNID *) lp;
5206
5207 /* RNID received */
5208
5209 switch (rn->Format) {
5210 case 0:
5211 case RNID_TOPOLOGY_DISC:
5212 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005213 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005214 break;
5215 default:
5216 /* Reject this request because format not supported */
5217 stat.un.b.lsRjtRsvd0 = 0;
5218 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5219 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5220 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005221 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5222 NULL);
dea31012005-04-17 16:05:31 -05005223 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005224 return 0;
dea31012005-04-17 16:05:31 -05005225}
5226
James Smarte59058c2008-08-24 21:49:00 -04005227/**
James Smart12265f62010-10-22 11:05:53 -04005228 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5229 * @vport: pointer to a host virtual N_Port data structure.
5230 * @cmdiocb: pointer to lpfc command iocb data structure.
5231 * @ndlp: pointer to a node-list data structure.
5232 *
5233 * Return code
5234 * 0 - Successfully processed echo iocb (currently always return 0)
5235 **/
5236static int
5237lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5238 struct lpfc_nodelist *ndlp)
5239{
5240 uint8_t *pcmd;
5241
5242 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5243
5244 /* skip over first word of echo command to find echo data */
5245 pcmd += sizeof(uint32_t);
5246
5247 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5248 return 0;
5249}
5250
5251/**
James Smart3621a712009-04-06 18:47:14 -04005252 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005253 * @vport: pointer to a host virtual N_Port data structure.
5254 * @cmdiocb: pointer to lpfc command iocb data structure.
5255 * @ndlp: pointer to a node-list data structure.
5256 *
5257 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5258 * received as an ELS unsolicited event. Currently, this function just invokes
5259 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5260 *
5261 * Return code
5262 * 0 - Successfully processed lirr iocb (currently always return 0)
5263 **/
dea31012005-04-17 16:05:31 -05005264static int
James Smart2e0fef82007-06-17 19:56:36 -05005265lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5266 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005267{
5268 struct ls_rjt stat;
5269
5270 /* For now, unconditionally reject this command */
5271 stat.un.b.lsRjtRsvd0 = 0;
5272 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5273 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5274 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005275 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005276 return 0;
5277}
5278
James Smarte59058c2008-08-24 21:49:00 -04005279/**
James Smart5ffc2662009-11-18 15:39:44 -05005280 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5281 * @vport: pointer to a host virtual N_Port data structure.
5282 * @cmdiocb: pointer to lpfc command iocb data structure.
5283 * @ndlp: pointer to a node-list data structure.
5284 *
5285 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5286 * received as an ELS unsolicited event. A request to RRQ shall only
5287 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5288 * Nx_Port N_Port_ID of the target Exchange is the same as the
5289 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5290 * not accepted, an LS_RJT with reason code "Unable to perform
5291 * command request" and reason code explanation "Invalid Originator
5292 * S_ID" shall be returned. For now, we just unconditionally accept
5293 * RRQ from the target.
5294 **/
5295static void
5296lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5297 struct lpfc_nodelist *ndlp)
5298{
5299 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005300 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5301 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005302}
5303
5304/**
James Smart12265f62010-10-22 11:05:53 -04005305 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5306 * @phba: pointer to lpfc hba data structure.
5307 * @pmb: pointer to the driver internal queue element for mailbox command.
5308 *
5309 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5310 * mailbox command. This callback function is to actually send the Accept
5311 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5312 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5313 * mailbox command, constructs the RPS response with the link statistics
5314 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5315 * response to the RPS.
5316 *
5317 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5318 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5319 * will be stored into the context1 field of the IOCB for the completion
5320 * callback function to the RPS Accept Response ELS IOCB command.
5321 *
5322 **/
5323static void
5324lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5325{
5326 MAILBOX_t *mb;
5327 IOCB_t *icmd;
5328 struct RLS_RSP *rls_rsp;
5329 uint8_t *pcmd;
5330 struct lpfc_iocbq *elsiocb;
5331 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005332 uint16_t oxid;
5333 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005334 uint32_t cmdsize;
5335
5336 mb = &pmb->u.mb;
5337
5338 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005339 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5340 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005341 pmb->context1 = NULL;
5342 pmb->context2 = NULL;
5343
5344 if (mb->mbxStatus) {
5345 mempool_free(pmb, phba->mbox_mem_pool);
5346 return;
5347 }
5348
5349 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005350 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5351 lpfc_max_els_tries, ndlp,
5352 ndlp->nlp_DID, ELS_CMD_ACC);
5353
5354 /* Decrement the ndlp reference count from previous mbox command */
5355 lpfc_nlp_put(ndlp);
5356
James Smart37db57e2012-05-09 21:17:16 -04005357 if (!elsiocb) {
5358 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005359 return;
James Smart37db57e2012-05-09 21:17:16 -04005360 }
James Smart12265f62010-10-22 11:05:53 -04005361
5362 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005363 icmd->ulpContext = rxid;
5364 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005365
5366 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5367 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5368 pcmd += sizeof(uint32_t); /* Skip past command */
5369 rls_rsp = (struct RLS_RSP *)pcmd;
5370
5371 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5372 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5373 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5374 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5375 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5376 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005377 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005378 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5379 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5380 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5381 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5382 elsiocb->iotag, elsiocb->iocb.ulpContext,
5383 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5384 ndlp->nlp_rpi);
5385 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5386 phba->fc_stat.elsXmitACC++;
5387 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5388 lpfc_els_free_iocb(phba, elsiocb);
5389}
5390
5391/**
James Smart3621a712009-04-06 18:47:14 -04005392 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005393 * @phba: pointer to lpfc hba data structure.
5394 * @pmb: pointer to the driver internal queue element for mailbox command.
5395 *
5396 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5397 * mailbox command. This callback function is to actually send the Accept
5398 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5399 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5400 * mailbox command, constructs the RPS response with the link statistics
5401 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5402 * response to the RPS.
5403 *
5404 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5405 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5406 * will be stored into the context1 field of the IOCB for the completion
5407 * callback function to the RPS Accept Response ELS IOCB command.
5408 *
5409 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005410static void
James Smart329f9bc2007-04-25 09:53:01 -04005411lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005412{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005413 MAILBOX_t *mb;
5414 IOCB_t *icmd;
5415 RPS_RSP *rps_rsp;
5416 uint8_t *pcmd;
5417 struct lpfc_iocbq *elsiocb;
5418 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005419 uint16_t status;
5420 uint16_t oxid;
5421 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005422 uint32_t cmdsize;
5423
James Smart04c68492009-05-22 14:52:52 -04005424 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005425
5426 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005427 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5428 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005429 pmb->context1 = NULL;
5430 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005431
5432 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005433 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005434 return;
5435 }
5436
5437 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005438 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005439 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5440 lpfc_max_els_tries, ndlp,
5441 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005442
5443 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005444 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005445
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005446 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005447 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005448
5449 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005450 icmd->ulpContext = rxid;
5451 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005452
5453 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5454 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005455 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005456 rps_rsp = (RPS_RSP *)pcmd;
5457
James Smart76a95d72010-11-20 23:11:48 -05005458 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005459 status = 0x10;
5460 else
5461 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005462 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005463 status |= 0x4;
5464
5465 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005466 rps_rsp->portStatus = cpu_to_be16(status);
5467 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5468 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5469 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5470 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5471 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5472 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005473 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005474 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5475 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5476 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5477 elsiocb->iotag, elsiocb->iocb.ulpContext,
5478 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5479 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005480 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005481 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005482 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005483 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005484 return;
5485}
5486
James Smarte59058c2008-08-24 21:49:00 -04005487/**
James Smart12265f62010-10-22 11:05:53 -04005488 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5489 * @vport: pointer to a host virtual N_Port data structure.
5490 * @cmdiocb: pointer to lpfc command iocb data structure.
5491 * @ndlp: pointer to a node-list data structure.
5492 *
5493 * This routine processes Read Port Status (RPL) IOCB received as an
5494 * ELS unsolicited event. It first checks the remote port state. If the
5495 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5496 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5497 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5498 * for reading the HBA link statistics. It is for the callback function,
5499 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5500 * to actually sending out RPL Accept (ACC) response.
5501 *
5502 * Return codes
5503 * 0 - Successfully processed rls iocb (currently always return 0)
5504 **/
5505static int
5506lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5507 struct lpfc_nodelist *ndlp)
5508{
5509 struct lpfc_hba *phba = vport->phba;
5510 LPFC_MBOXQ_t *mbox;
5511 struct lpfc_dmabuf *pcmd;
5512 struct ls_rjt stat;
5513
5514 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5515 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5516 /* reject the unsolicited RPS request and done with it */
5517 goto reject_out;
5518
5519 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5520
5521 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5522 if (mbox) {
5523 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005524 mbox->context1 = (void *)((unsigned long)
5525 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5526 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005527 mbox->context2 = lpfc_nlp_get(ndlp);
5528 mbox->vport = vport;
5529 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5530 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5531 != MBX_NOT_FINISHED)
5532 /* Mbox completion will send ELS Response */
5533 return 0;
5534 /* Decrement reference count used for the failed mbox
5535 * command.
5536 */
5537 lpfc_nlp_put(ndlp);
5538 mempool_free(mbox, phba->mbox_mem_pool);
5539 }
5540reject_out:
5541 /* issue rejection response */
5542 stat.un.b.lsRjtRsvd0 = 0;
5543 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5544 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5545 stat.un.b.vendorUnique = 0;
5546 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5547 return 0;
5548}
5549
5550/**
5551 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5552 * @vport: pointer to a host virtual N_Port data structure.
5553 * @cmdiocb: pointer to lpfc command iocb data structure.
5554 * @ndlp: pointer to a node-list data structure.
5555 *
5556 * This routine processes Read Timout Value (RTV) IOCB received as an
5557 * ELS unsolicited event. It first checks the remote port state. If the
5558 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5559 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5560 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5561 * Value (RTV) unsolicited IOCB event.
5562 *
5563 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5564 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5565 * will be stored into the context1 field of the IOCB for the completion
5566 * callback function to the RPS Accept Response ELS IOCB command.
5567 *
5568 * Return codes
5569 * 0 - Successfully processed rtv iocb (currently always return 0)
5570 **/
5571static int
5572lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5573 struct lpfc_nodelist *ndlp)
5574{
5575 struct lpfc_hba *phba = vport->phba;
5576 struct ls_rjt stat;
5577 struct RTV_RSP *rtv_rsp;
5578 uint8_t *pcmd;
5579 struct lpfc_iocbq *elsiocb;
5580 uint32_t cmdsize;
5581
5582
5583 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5584 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5585 /* reject the unsolicited RPS request and done with it */
5586 goto reject_out;
5587
5588 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5589 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5590 lpfc_max_els_tries, ndlp,
5591 ndlp->nlp_DID, ELS_CMD_ACC);
5592
5593 if (!elsiocb)
5594 return 1;
5595
5596 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5597 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5598 pcmd += sizeof(uint32_t); /* Skip past command */
5599
5600 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005601 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5602 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005603
5604 rtv_rsp = (struct RTV_RSP *)pcmd;
5605
5606 /* populate RTV payload */
5607 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5608 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5609 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5610 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5611 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5612
5613 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5614 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5615 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5616 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5617 "Data: x%x x%x x%x\n",
5618 elsiocb->iotag, elsiocb->iocb.ulpContext,
5619 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5620 ndlp->nlp_rpi,
5621 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5622 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5623 phba->fc_stat.elsXmitACC++;
5624 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5625 lpfc_els_free_iocb(phba, elsiocb);
5626 return 0;
5627
5628reject_out:
5629 /* issue rejection response */
5630 stat.un.b.lsRjtRsvd0 = 0;
5631 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5632 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5633 stat.un.b.vendorUnique = 0;
5634 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5635 return 0;
5636}
5637
5638/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005639 * @vport: pointer to a host virtual N_Port data structure.
5640 * @cmdiocb: pointer to lpfc command iocb data structure.
5641 * @ndlp: pointer to a node-list data structure.
5642 *
5643 * This routine processes Read Port Status (RPS) IOCB received as an
5644 * ELS unsolicited event. It first checks the remote port state. If the
5645 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5646 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5647 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5648 * for reading the HBA link statistics. It is for the callback function,
5649 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5650 * to actually sending out RPS Accept (ACC) response.
5651 *
5652 * Return codes
5653 * 0 - Successfully processed rps iocb (currently always return 0)
5654 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005655static int
James Smart2e0fef82007-06-17 19:56:36 -05005656lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5657 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005658{
James Smart2e0fef82007-06-17 19:56:36 -05005659 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005660 uint32_t *lp;
5661 uint8_t flag;
5662 LPFC_MBOXQ_t *mbox;
5663 struct lpfc_dmabuf *pcmd;
5664 RPS *rps;
5665 struct ls_rjt stat;
5666
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005667 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005668 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5669 /* reject the unsolicited RPS request and done with it */
5670 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005671
5672 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5673 lp = (uint32_t *) pcmd->virt;
5674 flag = (be32_to_cpu(*lp++) & 0xf);
5675 rps = (RPS *) lp;
5676
5677 if ((flag == 0) ||
5678 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005679 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005680 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005681
James Smart92d7f7b2007-06-17 19:56:38 -05005682 printk("Fix me....\n");
5683 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005684 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5685 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005686 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005687 mbox->context1 = (void *)((unsigned long)
5688 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5689 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005690 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005691 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005692 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005693 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005694 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005695 /* Mbox completion will send ELS Response */
5696 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005697 /* Decrement reference count used for the failed mbox
5698 * command.
5699 */
James Smart329f9bc2007-04-25 09:53:01 -04005700 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005701 mempool_free(mbox, phba->mbox_mem_pool);
5702 }
5703 }
James Smart90160e02008-08-24 21:49:45 -04005704
5705reject_out:
5706 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005707 stat.un.b.lsRjtRsvd0 = 0;
5708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5709 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5710 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005711 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005712 return 0;
5713}
5714
James Smart19ca7602010-11-20 23:11:55 -05005715/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5716 * @vport: pointer to a host virtual N_Port data structure.
5717 * @ndlp: pointer to a node-list data structure.
5718 * @did: DID of the target.
5719 * @rrq: Pointer to the rrq struct.
5720 *
5721 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5722 * Successful the the completion handler will clear the RRQ.
5723 *
5724 * Return codes
5725 * 0 - Successfully sent rrq els iocb.
5726 * 1 - Failed to send rrq els iocb.
5727 **/
5728static int
5729lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5730 uint32_t did, struct lpfc_node_rrq *rrq)
5731{
5732 struct lpfc_hba *phba = vport->phba;
5733 struct RRQ *els_rrq;
5734 IOCB_t *icmd;
5735 struct lpfc_iocbq *elsiocb;
5736 uint8_t *pcmd;
5737 uint16_t cmdsize;
5738 int ret;
5739
5740
5741 if (ndlp != rrq->ndlp)
5742 ndlp = rrq->ndlp;
5743 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5744 return 1;
5745
5746 /* If ndlp is not NULL, we will bump the reference count on it */
5747 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5748 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5749 ELS_CMD_RRQ);
5750 if (!elsiocb)
5751 return 1;
5752
5753 icmd = &elsiocb->iocb;
5754 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5755
5756 /* For RRQ request, remainder of payload is Exchange IDs */
5757 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5758 pcmd += sizeof(uint32_t);
5759 els_rrq = (struct RRQ *) pcmd;
5760
James Smartee0f4fe2012-05-09 21:19:14 -04005761 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005762 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5763 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5764 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5765 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5766
5767
5768 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5769 "Issue RRQ: did:x%x",
5770 did, rrq->xritag, rrq->rxid);
5771 elsiocb->context_un.rrq = rrq;
5772 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5773 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5774
5775 if (ret == IOCB_ERROR) {
5776 lpfc_els_free_iocb(phba, elsiocb);
5777 return 1;
5778 }
5779 return 0;
5780}
5781
5782/**
5783 * lpfc_send_rrq - Sends ELS RRQ if needed.
5784 * @phba: pointer to lpfc hba data structure.
5785 * @rrq: pointer to the active rrq.
5786 *
5787 * This routine will call the lpfc_issue_els_rrq if the rrq is
5788 * still active for the xri. If this function returns a failure then
5789 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5790 *
5791 * Returns 0 Success.
5792 * 1 Failure.
5793 **/
5794int
5795lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5796{
5797 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5798 rrq->nlp_DID);
5799 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5800 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5801 rrq->nlp_DID, rrq);
5802 else
5803 return 1;
5804}
5805
James Smarte59058c2008-08-24 21:49:00 -04005806/**
James Smart3621a712009-04-06 18:47:14 -04005807 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005808 * @vport: pointer to a host virtual N_Port data structure.
5809 * @cmdsize: size of the ELS command.
5810 * @oldiocb: pointer to the original lpfc command iocb data structure.
5811 * @ndlp: pointer to a node-list data structure.
5812 *
5813 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5814 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5815 *
5816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5818 * will be stored into the context1 field of the IOCB for the completion
5819 * callback function to the RPL Accept Response ELS command.
5820 *
5821 * Return code
5822 * 0 - Successfully issued ACC RPL ELS command
5823 * 1 - Failed to issue ACC RPL ELS command
5824 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005825static int
James Smart2e0fef82007-06-17 19:56:36 -05005826lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5827 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005828{
James Smart2e0fef82007-06-17 19:56:36 -05005829 struct lpfc_hba *phba = vport->phba;
5830 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005831 RPL_RSP rpl_rsp;
5832 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005833 uint8_t *pcmd;
5834
James Smart2e0fef82007-06-17 19:56:36 -05005835 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5836 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005837
James Smart488d1462006-03-07 15:02:37 -05005838 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005839 return 1;
James Smart488d1462006-03-07 15:02:37 -05005840
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005841 icmd = &elsiocb->iocb;
5842 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005843 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5844 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005845
5846 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5847 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005848 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005849 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5850 pcmd += sizeof(uint16_t);
5851
5852 /* Setup the RPL ACC payload */
5853 rpl_rsp.listLen = be32_to_cpu(1);
5854 rpl_rsp.index = 0;
5855 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005856 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5857 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005858 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005859 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005860 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005861 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5862 "0120 Xmit ELS RPL ACC response tag x%x "
5863 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5864 "rpi x%x\n",
5865 elsiocb->iotag, elsiocb->iocb.ulpContext,
5866 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5867 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005868 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005869 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005870 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5871 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005872 lpfc_els_free_iocb(phba, elsiocb);
5873 return 1;
5874 }
5875 return 0;
5876}
5877
James Smarte59058c2008-08-24 21:49:00 -04005878/**
James Smart3621a712009-04-06 18:47:14 -04005879 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005880 * @vport: pointer to a host virtual N_Port data structure.
5881 * @cmdiocb: pointer to lpfc command iocb data structure.
5882 * @ndlp: pointer to a node-list data structure.
5883 *
5884 * This routine processes Read Port List (RPL) IOCB received as an ELS
5885 * unsolicited event. It first checks the remote port state. If the remote
5886 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5887 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5888 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5889 * to accept the RPL.
5890 *
5891 * Return code
5892 * 0 - Successfully processed rpl iocb (currently always return 0)
5893 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005894static int
James Smart2e0fef82007-06-17 19:56:36 -05005895lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5896 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005897{
5898 struct lpfc_dmabuf *pcmd;
5899 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005900 uint32_t maxsize;
5901 uint16_t cmdsize;
5902 RPL *rpl;
5903 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005904
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005905 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5906 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005907 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005908 stat.un.b.lsRjtRsvd0 = 0;
5909 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5910 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5911 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005912 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5913 NULL);
James Smart90160e02008-08-24 21:49:45 -04005914 /* rejected the unsolicited RPL request and done with it */
5915 return 0;
dea31012005-04-17 16:05:31 -05005916 }
5917
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005918 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5919 lp = (uint32_t *) pcmd->virt;
5920 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005921 maxsize = be32_to_cpu(rpl->maxsize);
5922
5923 /* We support only one port */
5924 if ((rpl->index == 0) &&
5925 ((maxsize == 0) ||
5926 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5927 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005928 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005929 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5930 }
James Smart2e0fef82007-06-17 19:56:36 -05005931 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005932
5933 return 0;
5934}
5935
James Smarte59058c2008-08-24 21:49:00 -04005936/**
James Smart3621a712009-04-06 18:47:14 -04005937 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005938 * @vport: pointer to a virtual N_Port data structure.
5939 * @cmdiocb: pointer to lpfc command iocb data structure.
5940 * @ndlp: pointer to a node-list data structure.
5941 *
5942 * This routine processes Fibre Channel Address Resolution Protocol
5943 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5944 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5945 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5946 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5947 * remote PortName is compared against the FC PortName stored in the @vport
5948 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5949 * compared against the FC NodeName stored in the @vport data structure.
5950 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5951 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5952 * invoked to send out FARP Response to the remote node. Before sending the
5953 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5954 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5955 * routine is invoked to log into the remote port first.
5956 *
5957 * Return code
5958 * 0 - Either the FARP Match Mode not supported or successfully processed
5959 **/
dea31012005-04-17 16:05:31 -05005960static int
James Smart2e0fef82007-06-17 19:56:36 -05005961lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5962 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005963{
5964 struct lpfc_dmabuf *pcmd;
5965 uint32_t *lp;
5966 IOCB_t *icmd;
5967 FARP *fp;
5968 uint32_t cmd, cnt, did;
5969
5970 icmd = &cmdiocb->iocb;
5971 did = icmd->un.elsreq64.remoteID;
5972 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5973 lp = (uint32_t *) pcmd->virt;
5974
5975 cmd = *lp++;
5976 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005977 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005978 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5979 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005980 /* We will only support match on WWPN or WWNN */
5981 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005982 return 0;
dea31012005-04-17 16:05:31 -05005983 }
5984
5985 cnt = 0;
5986 /* If this FARP command is searching for my portname */
5987 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005988 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005989 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005990 cnt = 1;
5991 }
5992
5993 /* If this FARP command is searching for my nodename */
5994 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005995 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005996 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005997 cnt = 1;
5998 }
5999
6000 if (cnt) {
6001 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
6002 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
6003 /* Log back into the node before sending the FARP. */
6004 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006005 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05006006 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04006007 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05006008 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05006009 }
6010
6011 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05006012 if (fp->Rflags & FARP_REQUEST_FARPR)
6013 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006014 }
6015 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006016 return 0;
dea31012005-04-17 16:05:31 -05006017}
6018
James Smarte59058c2008-08-24 21:49:00 -04006019/**
James Smart3621a712009-04-06 18:47:14 -04006020 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006021 * @vport: pointer to a host virtual N_Port data structure.
6022 * @cmdiocb: pointer to lpfc command iocb data structure.
6023 * @ndlp: pointer to a node-list data structure.
6024 *
6025 * This routine processes Fibre Channel Address Resolution Protocol
6026 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6027 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6028 * the FARP response request.
6029 *
6030 * Return code
6031 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6032 **/
dea31012005-04-17 16:05:31 -05006033static int
James Smart2e0fef82007-06-17 19:56:36 -05006034lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6035 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006036{
6037 struct lpfc_dmabuf *pcmd;
6038 uint32_t *lp;
6039 IOCB_t *icmd;
6040 uint32_t cmd, did;
6041
6042 icmd = &cmdiocb->iocb;
6043 did = icmd->un.elsreq64.remoteID;
6044 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6045 lp = (uint32_t *) pcmd->virt;
6046
6047 cmd = *lp++;
6048 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6050 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006051 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006052 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006053
6054 return 0;
6055}
6056
James Smarte59058c2008-08-24 21:49:00 -04006057/**
James Smart3621a712009-04-06 18:47:14 -04006058 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006059 * @vport: pointer to a host virtual N_Port data structure.
6060 * @cmdiocb: pointer to lpfc command iocb data structure.
6061 * @fan_ndlp: pointer to a node-list data structure.
6062 *
6063 * This routine processes a Fabric Address Notification (FAN) IOCB
6064 * command received as an ELS unsolicited event. The FAN ELS command will
6065 * only be processed on a physical port (i.e., the @vport represents the
6066 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6067 * compared against those in the phba data structure. If any of those is
6068 * different, the lpfc_initial_flogi() routine is invoked to initialize
6069 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6070 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6071 * is invoked to register login to the fabric.
6072 *
6073 * Return code
6074 * 0 - Successfully processed fan iocb (currently always return 0).
6075 **/
dea31012005-04-17 16:05:31 -05006076static int
James Smart2e0fef82007-06-17 19:56:36 -05006077lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6078 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006079{
James Smart2e0fef82007-06-17 19:56:36 -05006080 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006081 uint32_t *lp;
6082 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006083
James Smart0d2b6b82008-06-14 22:52:47 -04006084 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6085 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6086 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006087 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006088 if ((vport == phba->pport) &&
6089 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006090 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006091 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006092 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006093 sizeof(struct lpfc_name)))) {
6094 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006095 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006096 } else {
6097 /* FAN verified - skip FLOGI */
6098 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006099 if (phba->sli_rev < LPFC_SLI_REV4)
6100 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006101 else {
6102 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6103 "3138 Need register VFI: (x%x/%x)\n",
6104 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006105 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006106 }
dea31012005-04-17 16:05:31 -05006107 }
dea31012005-04-17 16:05:31 -05006108 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006109 return 0;
dea31012005-04-17 16:05:31 -05006110}
6111
James Smarte59058c2008-08-24 21:49:00 -04006112/**
James Smart3621a712009-04-06 18:47:14 -04006113 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006114 * @ptr: holder for the timer function associated data.
6115 *
6116 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6117 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6118 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6119 * up the worker thread. It is for the worker thread to invoke the routine
6120 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6121 **/
dea31012005-04-17 16:05:31 -05006122void
6123lpfc_els_timeout(unsigned long ptr)
6124{
James Smart2e0fef82007-06-17 19:56:36 -05006125 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6126 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006127 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006128 unsigned long iflag;
6129
James Smart2e0fef82007-06-17 19:56:36 -05006130 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006131 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6132 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006133 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006134 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006135
James Smart5e9d9b82008-06-14 22:52:53 -04006136 if (!tmo_posted)
6137 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006138 return;
6139}
6140
James Smart2a9bf3d2010-06-07 15:24:45 -04006141
James Smarte59058c2008-08-24 21:49:00 -04006142/**
James Smart3621a712009-04-06 18:47:14 -04006143 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006144 * @vport: pointer to a virtual N_Port data structure.
6145 *
6146 * This routine is the actual handler function that processes an ELS timeout
6147 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6148 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6149 * invoking the lpfc_sli_issue_abort_iotag() routine.
6150 **/
dea31012005-04-17 16:05:31 -05006151void
James Smart2e0fef82007-06-17 19:56:36 -05006152lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006153{
James Smart2e0fef82007-06-17 19:56:36 -05006154 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006155 struct lpfc_sli_ring *pring;
6156 struct lpfc_iocbq *tmp_iocb, *piocb;
6157 IOCB_t *cmd = NULL;
6158 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006159 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006160 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006161 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006162 LIST_HEAD(txcmplq_completions);
6163 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006164
James Smart2a9bf3d2010-06-07 15:24:45 -04006165
dea31012005-04-17 16:05:31 -05006166 timeout = (uint32_t)(phba->fc_ratov << 1);
6167
6168 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006169
James Smart2a9bf3d2010-06-07 15:24:45 -04006170 spin_lock_irq(&phba->hbalock);
6171 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6172 spin_unlock_irq(&phba->hbalock);
6173
6174 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006175 cmd = &piocb->iocb;
6176
James Smart2e0fef82007-06-17 19:56:36 -05006177 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6178 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6179 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006180 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006181
6182 if (piocb->vport != vport)
6183 continue;
6184
dea31012005-04-17 16:05:31 -05006185 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006186 if (pcmd)
6187 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006188
James Smart92d7f7b2007-06-17 19:56:38 -05006189 if (els_command == ELS_CMD_FARP ||
6190 els_command == ELS_CMD_FARPR ||
6191 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006192 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006193
dea31012005-04-17 16:05:31 -05006194 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006195 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006196 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006197 else
dea31012005-04-17 16:05:31 -05006198 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006199 continue;
6200 }
6201
James Smart2e0fef82007-06-17 19:56:36 -05006202 remote_ID = 0xffffffff;
6203 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006204 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006205 else {
6206 struct lpfc_nodelist *ndlp;
6207 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006208 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006209 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006210 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006211 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006212 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006213 spin_lock_irq(&phba->hbalock);
6214 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006215 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006216
James Smart2a9bf3d2010-06-07 15:24:45 -04006217 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6218 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6219 "0127 ELS timeout Data: x%x x%x x%x "
6220 "x%x\n", els_command,
6221 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6222 spin_lock_irq(&phba->hbalock);
6223 list_del_init(&piocb->dlist);
6224 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6225 spin_unlock_irq(&phba->hbalock);
6226 }
6227
James Smart0e9bb8d2013-03-01 16:35:12 -05006228 if (!list_empty(&phba->sli.ring[LPFC_ELS_RING].txcmplq))
James Smart2e0fef82007-06-17 19:56:36 -05006229 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006230}
6231
James Smarte59058c2008-08-24 21:49:00 -04006232/**
James Smart3621a712009-04-06 18:47:14 -04006233 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006234 * @vport: pointer to a host virtual N_Port data structure.
6235 *
6236 * This routine is used to clean up all the outstanding ELS commands on a
6237 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6238 * routine. After that, it walks the ELS transmit queue to remove all the
6239 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6240 * the IOCBs with a non-NULL completion callback function, the callback
6241 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6242 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6243 * callback function, the IOCB will simply be released. Finally, it walks
6244 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6245 * completion queue IOCB that is associated with the @vport and is not
6246 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6247 * part of the discovery state machine) out to HBA by invoking the
6248 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6249 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6250 * the IOCBs are aborted when this function returns.
6251 **/
dea31012005-04-17 16:05:31 -05006252void
James Smart2e0fef82007-06-17 19:56:36 -05006253lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006254{
James Smart2534ba72007-04-25 09:52:20 -04006255 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006256 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006257 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006258 struct lpfc_iocbq *tmp_iocb, *piocb;
6259 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006260
6261 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006262
James Smart2e0fef82007-06-17 19:56:36 -05006263 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006264 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6265 cmd = &piocb->iocb;
6266
6267 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6268 continue;
6269 }
6270
6271 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006272 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6273 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6274 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6275 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006276 continue;
dea31012005-04-17 16:05:31 -05006277
James Smart2e0fef82007-06-17 19:56:36 -05006278 if (piocb->vport != vport)
6279 continue;
6280
James Smart2534ba72007-04-25 09:52:20 -04006281 list_move_tail(&piocb->list, &completions);
dea31012005-04-17 16:05:31 -05006282 }
6283
6284 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006285 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6286 continue;
6287 }
dea31012005-04-17 16:05:31 -05006288
James Smart2e0fef82007-06-17 19:56:36 -05006289 if (piocb->vport != vport)
6290 continue;
6291
James Smart07951072007-04-25 09:51:38 -04006292 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006293 }
James Smart2e0fef82007-06-17 19:56:36 -05006294 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006295
James Smarta257bf92009-04-06 18:48:10 -04006296 /* Cancell all the IOCBs from the completions list */
6297 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6298 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006299
dea31012005-04-17 16:05:31 -05006300 return;
6301}
6302
James Smarte59058c2008-08-24 21:49:00 -04006303/**
James Smart3621a712009-04-06 18:47:14 -04006304 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006305 * @phba: pointer to lpfc hba data structure.
6306 *
6307 * This routine is used to clean up all the outstanding ELS commands on a
6308 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6309 * routine. After that, it walks the ELS transmit queue to remove all the
6310 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6311 * the IOCBs with the completion callback function associated, the callback
6312 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6313 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6314 * callback function associated, the IOCB will simply be released. Finally,
6315 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6316 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6317 * management plane IOCBs that are not part of the discovery state machine)
6318 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6319 **/
James Smart549e55c2007-08-02 11:09:51 -04006320void
6321lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6322{
6323 LIST_HEAD(completions);
6324 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6325 struct lpfc_iocbq *tmp_iocb, *piocb;
6326 IOCB_t *cmd = NULL;
6327
6328 lpfc_fabric_abort_hba(phba);
6329 spin_lock_irq(&phba->hbalock);
6330 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6331 cmd = &piocb->iocb;
6332 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6333 continue;
6334 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6335 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6336 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6337 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6338 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6339 continue;
6340 list_move_tail(&piocb->list, &completions);
James Smart549e55c2007-08-02 11:09:51 -04006341 }
6342 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6343 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6344 continue;
6345 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6346 }
6347 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006348
6349 /* Cancel all the IOCBs from the completions list */
6350 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6351 IOERR_SLI_ABORTED);
6352
James Smart549e55c2007-08-02 11:09:51 -04006353 return;
6354}
6355
James Smarte59058c2008-08-24 21:49:00 -04006356/**
James Smart3621a712009-04-06 18:47:14 -04006357 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006358 * @phba: Pointer to hba context object.
6359 * @cmdiocbp: Pointer to command iocb which reported error.
6360 * @rspiocbp: Pointer to response iocb which reported error.
6361 *
6362 * This function sends an event when there is an ELS command
6363 * failure.
6364 **/
6365void
6366lpfc_send_els_failure_event(struct lpfc_hba *phba,
6367 struct lpfc_iocbq *cmdiocbp,
6368 struct lpfc_iocbq *rspiocbp)
6369{
6370 struct lpfc_vport *vport = cmdiocbp->vport;
6371 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6372 struct lpfc_lsrjt_event lsrjt_event;
6373 struct lpfc_fabric_event_header fabric_event;
6374 struct ls_rjt stat;
6375 struct lpfc_nodelist *ndlp;
6376 uint32_t *pcmd;
6377
6378 ndlp = cmdiocbp->context1;
6379 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6380 return;
6381
6382 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6383 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6384 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6385 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6386 sizeof(struct lpfc_name));
6387 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6388 sizeof(struct lpfc_name));
6389 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6390 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006391 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006392 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6393 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6394 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6395 fc_host_post_vendor_event(shost,
6396 fc_get_event_number(),
6397 sizeof(lsrjt_event),
6398 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006399 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006400 return;
6401 }
6402 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6403 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6404 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6405 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6406 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6407 else
6408 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6409 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6410 sizeof(struct lpfc_name));
6411 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6412 sizeof(struct lpfc_name));
6413 fc_host_post_vendor_event(shost,
6414 fc_get_event_number(),
6415 sizeof(fabric_event),
6416 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006417 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006418 return;
6419 }
6420
6421}
6422
6423/**
James Smart3621a712009-04-06 18:47:14 -04006424 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006425 * @vport: Pointer to vport object.
6426 * @ndlp: Pointer FC node object.
6427 * @cmd: ELS command code.
6428 *
6429 * This function posts an event when there is an incoming
6430 * unsolicited ELS command.
6431 **/
6432static void
6433lpfc_send_els_event(struct lpfc_vport *vport,
6434 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006435 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006436{
James Smartddcc50f2008-12-04 22:38:46 -05006437 struct lpfc_els_event_header *els_data = NULL;
6438 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006439 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6440
James Smartddcc50f2008-12-04 22:38:46 -05006441 if (*payload == ELS_CMD_LOGO) {
6442 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6443 if (!logo_data) {
6444 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6445 "0148 Failed to allocate memory "
6446 "for LOGO event\n");
6447 return;
6448 }
6449 els_data = &logo_data->header;
6450 } else {
6451 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6452 GFP_KERNEL);
6453 if (!els_data) {
6454 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6455 "0149 Failed to allocate memory "
6456 "for ELS event\n");
6457 return;
6458 }
6459 }
6460 els_data->event_type = FC_REG_ELS_EVENT;
6461 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006462 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006463 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006464 break;
6465 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006466 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006467 break;
6468 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006469 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6470 break;
6471 case ELS_CMD_LOGO:
6472 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6473 /* Copy the WWPN in the LOGO payload */
6474 memcpy(logo_data->logo_wwpn, &payload[2],
6475 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006476 break;
6477 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006478 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006479 return;
6480 }
James Smartddcc50f2008-12-04 22:38:46 -05006481 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6482 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6483 if (*payload == ELS_CMD_LOGO) {
6484 fc_host_post_vendor_event(shost,
6485 fc_get_event_number(),
6486 sizeof(struct lpfc_logo_event),
6487 (char *)logo_data,
6488 LPFC_NL_VENDOR_ID);
6489 kfree(logo_data);
6490 } else {
6491 fc_host_post_vendor_event(shost,
6492 fc_get_event_number(),
6493 sizeof(struct lpfc_els_event_header),
6494 (char *)els_data,
6495 LPFC_NL_VENDOR_ID);
6496 kfree(els_data);
6497 }
James Smartea2151b2008-09-07 11:52:10 -04006498
6499 return;
6500}
6501
6502
6503/**
James Smart3621a712009-04-06 18:47:14 -04006504 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006505 * @phba: pointer to lpfc hba data structure.
6506 * @pring: pointer to a SLI ring.
6507 * @vport: pointer to a host virtual N_Port data structure.
6508 * @elsiocb: pointer to lpfc els command iocb data structure.
6509 *
6510 * This routine is used for processing the IOCB associated with a unsolicited
6511 * event. It first determines whether there is an existing ndlp that matches
6512 * the DID from the unsolicited IOCB. If not, it will create a new one with
6513 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6514 * IOCB is then used to invoke the proper routine and to set up proper state
6515 * of the discovery state machine.
6516 **/
James Smarted957682007-06-17 19:56:37 -05006517static void
6518lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006519 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006520{
James Smart87af33f2007-10-27 13:37:43 -04006521 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006522 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006523 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006524 uint32_t *payload;
James Smart303f2f92013-01-03 15:43:11 -05006525 uint32_t cmd, did, newnode;
6526 uint8_t rjt_exp, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006527 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006528
James Smarte47c9092008-02-08 18:49:26 -05006529 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006530 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006531
dea31012005-04-17 16:05:31 -05006532 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006533 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6534 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006535 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006536 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006537
James Smart858c9f62007-06-17 19:56:39 -05006538 did = icmd->un.rcvels.remoteID;
6539 if (icmd->ulpStatus) {
6540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6541 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6542 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006543 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006544 }
dea31012005-04-17 16:05:31 -05006545
6546 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006547 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006548 goto dropit;
dea31012005-04-17 16:05:31 -05006549
James Smartc8685952009-11-18 15:39:16 -05006550 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006551 if (vport->load_flag & FC_UNLOADING)
6552 goto dropit;
6553
James Smart92494142011-02-16 12:39:44 -05006554 /* If NPort discovery is delayed drop incoming ELS */
6555 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6556 (cmd != ELS_CMD_PLOGI))
6557 goto dropit;
6558
James Smart2e0fef82007-06-17 19:56:36 -05006559 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006560 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006561 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05006562 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006563 if (!ndlp)
dea31012005-04-17 16:05:31 -05006564 goto dropit;
dea31012005-04-17 16:05:31 -05006565
James Smart2e0fef82007-06-17 19:56:36 -05006566 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006567 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006568 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006569 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006570 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006571 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6572 ndlp = lpfc_enable_node(vport, ndlp,
6573 NLP_STE_UNUSED_NODE);
6574 if (!ndlp)
6575 goto dropit;
6576 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6577 newnode = 1;
6578 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6579 ndlp->nlp_type |= NLP_FABRIC;
6580 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6581 /* This is similar to the new node path */
6582 ndlp = lpfc_nlp_get(ndlp);
6583 if (!ndlp)
6584 goto dropit;
6585 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6586 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006587 }
dea31012005-04-17 16:05:31 -05006588
6589 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006590
James Smart329f9bc2007-04-25 09:53:01 -04006591 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006592 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006593
6594 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6595 cmd &= ELS_CMD_MASK;
6596 }
6597 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006598 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6599 "0112 ELS command x%x received from NPORT x%x "
6600 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006601 switch (cmd) {
6602 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006603 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6604 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6605 did, vport->port_state, ndlp->nlp_flag);
6606
dea31012005-04-17 16:05:31 -05006607 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006608 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6609
James Smartddcc50f2008-12-04 22:38:46 -05006610 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006611
6612 /* If Nport discovery is delayed, reject PLOGIs */
6613 if (vport->fc_flag & FC_DISC_DELAYED) {
6614 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006615 rjt_exp = LSEXP_NOTHING_MORE;
James Smart92494142011-02-16 12:39:44 -05006616 break;
6617 }
James Smart858c9f62007-06-17 19:56:39 -05006618 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006619 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6620 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6621 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006622 rjt_exp = LSEXP_NOTHING_MORE;
James Smart1b32f6a2008-02-08 18:49:39 -05006623 break;
6624 }
6625 /* We get here, and drop thru, if we are PT2PT with
6626 * another NPort and the other side has initiated
6627 * the PLOGI before responding to our FLOGI.
6628 */
dea31012005-04-17 16:05:31 -05006629 }
James Smart87af33f2007-10-27 13:37:43 -04006630
6631 shost = lpfc_shost_from_vport(vport);
6632 spin_lock_irq(shost->host_lock);
6633 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6634 spin_unlock_irq(shost->host_lock);
6635
James Smart2e0fef82007-06-17 19:56:36 -05006636 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6637 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006638
dea31012005-04-17 16:05:31 -05006639 break;
6640 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6642 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6643 did, vport->port_state, ndlp->nlp_flag);
6644
dea31012005-04-17 16:05:31 -05006645 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006646 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006647 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006648 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006649 break;
6650 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006651 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6652 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6653 did, vport->port_state, ndlp->nlp_flag);
6654
dea31012005-04-17 16:05:31 -05006655 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006656 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006657 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006658 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006659 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006660 break;
6661 }
James Smart2e0fef82007-06-17 19:56:36 -05006662 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006663 break;
6664 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6666 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6667 did, vport->port_state, ndlp->nlp_flag);
6668
dea31012005-04-17 16:05:31 -05006669 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006670 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006671 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006672 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006673 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006674 break;
6675 }
James Smart2e0fef82007-06-17 19:56:36 -05006676 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006677 break;
6678 case ELS_CMD_RSCN:
6679 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006680 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006681 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006682 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006683 break;
6684 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6686 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6687 did, vport->port_state, ndlp->nlp_flag);
6688
James Smartddcc50f2008-12-04 22:38:46 -05006689 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006690 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006691 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006692 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006693 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006694 break;
6695 }
James Smart2e0fef82007-06-17 19:56:36 -05006696 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6697 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006698 break;
6699 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6701 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6702 did, vport->port_state, ndlp->nlp_flag);
6703
dea31012005-04-17 16:05:31 -05006704 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006705 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006706 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006707 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006708 break;
6709 }
James Smart2e0fef82007-06-17 19:56:36 -05006710 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6711 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006712 break;
6713 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006714 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6715 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6716 did, vport->port_state, ndlp->nlp_flag);
6717
dea31012005-04-17 16:05:31 -05006718 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006719 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006720 break;
6721 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006722 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6723 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6724 did, vport->port_state, ndlp->nlp_flag);
6725
dea31012005-04-17 16:05:31 -05006726 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006727 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006728 break;
6729 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006730 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6731 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6732 did, vport->port_state, ndlp->nlp_flag);
6733
dea31012005-04-17 16:05:31 -05006734 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006735 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006736 break;
dea31012005-04-17 16:05:31 -05006737 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006738 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6739 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6740 did, vport->port_state, ndlp->nlp_flag);
6741
dea31012005-04-17 16:05:31 -05006742 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006743 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006744 rjt_err = LSRJT_UNABLE_TPC;
James Smart303f2f92013-01-03 15:43:11 -05006745 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006746 break;
6747 }
James Smart2e0fef82007-06-17 19:56:36 -05006748 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006749 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006750 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6752 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6753 did, vport->port_state, ndlp->nlp_flag);
6754
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006755 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006756 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006757 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006758 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006759 break;
James Smart12265f62010-10-22 11:05:53 -04006760 case ELS_CMD_RLS:
6761 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6762 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6763 did, vport->port_state, ndlp->nlp_flag);
6764
6765 phba->fc_stat.elsRcvRLS++;
6766 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6767 if (newnode)
6768 lpfc_nlp_put(ndlp);
6769 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006770 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6772 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6773 did, vport->port_state, ndlp->nlp_flag);
6774
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006775 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006776 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006777 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006778 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006779 break;
6780 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6782 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6783 did, vport->port_state, ndlp->nlp_flag);
6784
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006785 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006786 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006787 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006788 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006789 break;
dea31012005-04-17 16:05:31 -05006790 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6792 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6793 did, vport->port_state, ndlp->nlp_flag);
6794
dea31012005-04-17 16:05:31 -05006795 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006796 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006797 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006798 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006799 break;
James Smart12265f62010-10-22 11:05:53 -04006800 case ELS_CMD_RTV:
6801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6802 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6803 did, vport->port_state, ndlp->nlp_flag);
6804 phba->fc_stat.elsRcvRTV++;
6805 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6806 if (newnode)
6807 lpfc_nlp_put(ndlp);
6808 break;
James Smart5ffc2662009-11-18 15:39:44 -05006809 case ELS_CMD_RRQ:
6810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6811 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6812 did, vport->port_state, ndlp->nlp_flag);
6813
6814 phba->fc_stat.elsRcvRRQ++;
6815 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6816 if (newnode)
6817 lpfc_nlp_put(ndlp);
6818 break;
James Smart12265f62010-10-22 11:05:53 -04006819 case ELS_CMD_ECHO:
6820 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6821 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6822 did, vport->port_state, ndlp->nlp_flag);
6823
6824 phba->fc_stat.elsRcvECHO++;
6825 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6826 if (newnode)
6827 lpfc_nlp_put(ndlp);
6828 break;
James Smart303f2f92013-01-03 15:43:11 -05006829 case ELS_CMD_REC:
6830 /* receive this due to exchange closed */
6831 rjt_err = LSRJT_UNABLE_TPC;
6832 rjt_exp = LSEXP_INVALID_OX_RX;
6833 break;
dea31012005-04-17 16:05:31 -05006834 default:
James Smart858c9f62007-06-17 19:56:39 -05006835 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6836 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6837 cmd, did, vport->port_state);
6838
dea31012005-04-17 16:05:31 -05006839 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006840 rjt_err = LSRJT_CMD_UNSUPPORTED;
James Smart303f2f92013-01-03 15:43:11 -05006841 rjt_exp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05006842
6843 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006844 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6845 "0115 Unknown ELS command x%x "
6846 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006847 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006848 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006849 break;
6850 }
6851
6852 /* check if need to LS_RJT received ELS cmd */
6853 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006854 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006855 stat.un.b.lsRjtRsnCode = rjt_err;
James Smart303f2f92013-01-03 15:43:11 -05006856 stat.un.b.lsRjtRsnCodeExp = rjt_exp;
James Smart858c9f62007-06-17 19:56:39 -05006857 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6858 NULL);
dea31012005-04-17 16:05:31 -05006859 }
6860
James Smartd7c255b2008-08-24 21:50:00 -04006861 lpfc_nlp_put(elsiocb->context1);
6862 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006863 return;
6864
6865dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006866 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6868 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006869 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006870 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006871 phba->fc_stat.elsRcvDrop++;
6872}
6873
James Smarte59058c2008-08-24 21:49:00 -04006874/**
James Smart3621a712009-04-06 18:47:14 -04006875 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006876 * @phba: pointer to lpfc hba data structure.
6877 * @pring: pointer to a SLI ring.
6878 * @elsiocb: pointer to lpfc els iocb data structure.
6879 *
6880 * This routine is used to process an unsolicited event received from a SLI
6881 * (Service Level Interface) ring. The actual processing of the data buffer
6882 * associated with the unsolicited event is done by invoking the routine
6883 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6884 * SLI ring on which the unsolicited event was received.
6885 **/
James Smarted957682007-06-17 19:56:37 -05006886void
6887lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6888 struct lpfc_iocbq *elsiocb)
6889{
6890 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006891 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006892 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006893 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6894 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006895
James Smartd7c255b2008-08-24 21:50:00 -04006896 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006897 elsiocb->context2 = NULL;
6898 elsiocb->context3 = NULL;
6899
6900 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6901 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6902 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04006903 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6904 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006905 phba->fc_stat.NoRcvBuf++;
6906 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006907 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006908 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006909 return;
6910 }
6911
James Smart92d7f7b2007-06-17 19:56:38 -05006912 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6913 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6914 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6915 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6916 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006917 else
6918 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006919 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006920 }
James Smart6d368e52011-05-24 11:44:12 -04006921
James Smart7f5f3d02008-02-08 18:50:14 -05006922 /* If there are no BDEs associated
6923 * with this IOCB, there is nothing to do.
6924 */
James Smarted957682007-06-17 19:56:37 -05006925 if (icmd->ulpBdeCount == 0)
6926 return;
6927
James Smart7f5f3d02008-02-08 18:50:14 -05006928 /* type of ELS cmd is first 32bit word
6929 * in packet
6930 */
James Smarted957682007-06-17 19:56:37 -05006931 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006932 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006933 } else {
6934 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6935 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006936 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6937 paddr);
James Smarted957682007-06-17 19:56:37 -05006938 }
6939
James Smart92d7f7b2007-06-17 19:56:38 -05006940 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6941 /*
6942 * The different unsolicited event handlers would tell us
6943 * if they are done with "mp" by setting context2 to NULL.
6944 */
dea31012005-04-17 16:05:31 -05006945 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006946 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6947 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006948 }
James Smarted957682007-06-17 19:56:37 -05006949
6950 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006951 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006952 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006953 elsiocb->context2 = bdeBuf2;
6954 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006955 /* free mp if we are done with it */
6956 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006957 lpfc_in_buf_free(phba, elsiocb->context2);
6958 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006959 }
dea31012005-04-17 16:05:31 -05006960 }
dea31012005-04-17 16:05:31 -05006961}
James Smart92d7f7b2007-06-17 19:56:38 -05006962
James Smarte59058c2008-08-24 21:49:00 -04006963/**
James Smart3621a712009-04-06 18:47:14 -04006964 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006965 * @phba: pointer to lpfc hba data structure.
6966 * @vport: pointer to a virtual N_Port data structure.
6967 *
6968 * This routine issues a Port Login (PLOGI) to the Name Server with
6969 * State Change Request (SCR) for a @vport. This routine will create an
6970 * ndlp for the Name Server associated to the @vport if such node does
6971 * not already exist. The PLOGI to Name Server is issued by invoking the
6972 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6973 * (FDMI) is configured to the @vport, a FDMI node will be created and
6974 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6975 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006976void
6977lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6978{
6979 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006980 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6981
6982 /*
6983 * If lpfc_delay_discovery parameter is set and the clean address
6984 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6985 * discovery.
6986 */
6987 spin_lock_irq(shost->host_lock);
6988 if (vport->fc_flag & FC_DISC_DELAYED) {
6989 spin_unlock_irq(shost->host_lock);
6990 mod_timer(&vport->delayed_disc_tmo,
6991 jiffies + HZ * phba->fc_ratov);
6992 return;
6993 }
6994 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006995
6996 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6997 if (!ndlp) {
6998 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6999 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007000 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05007001 lpfc_disc_start(vport);
7002 return;
7003 }
7004 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007005 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7006 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007007 return;
7008 }
7009 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05007010 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
7011 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
7012 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05007013 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05007014 lpfc_disc_start(vport);
7015 return;
7016 }
7017 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7018 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7019 "0348 NameServer login: node freed\n");
7020 return;
7021 }
James Smart92d7f7b2007-06-17 19:56:38 -05007022 }
James Smart58da1ff2008-04-07 10:15:56 -04007023 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05007024
7025 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7026
7027 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7028 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007029 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7030 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007031 return;
7032 }
7033
James Smart3de2a652007-08-02 11:09:59 -04007034 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05007035 /* If this is the first time, allocate an ndlp and initialize
7036 * it. Otherwise, make sure the node is enabled and then do the
7037 * login.
7038 */
7039 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7040 if (!ndlp_fdmi) {
7041 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7042 GFP_KERNEL);
7043 if (ndlp_fdmi) {
7044 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7045 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7046 } else
7047 return;
7048 }
7049 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7050 ndlp_fdmi = lpfc_enable_node(vport,
7051 ndlp_fdmi,
7052 NLP_STE_NPR_NODE);
7053
James Smart92d7f7b2007-06-17 19:56:38 -05007054 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007055 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007056 NLP_STE_PLOGI_ISSUE);
7057 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007058 }
7059 }
James Smart92d7f7b2007-06-17 19:56:38 -05007060}
7061
James Smarte59058c2008-08-24 21:49:00 -04007062/**
James Smart3621a712009-04-06 18:47:14 -04007063 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007064 * @phba: pointer to lpfc hba data structure.
7065 * @pmb: pointer to the driver internal queue element for mailbox command.
7066 *
7067 * This routine is the completion callback function to register new vport
7068 * mailbox command. If the new vport mailbox command completes successfully,
7069 * the fabric registration login shall be performed on physical port (the
7070 * new vport created is actually a physical port, with VPI 0) or the port
7071 * login to Name Server for State Change Request (SCR) will be performed
7072 * on virtual port (real virtual port, with VPI greater than 0).
7073 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007074static void
7075lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7076{
7077 struct lpfc_vport *vport = pmb->vport;
7078 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7079 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007080 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007081 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007082
James Smart09372822008-01-11 01:52:54 -05007083 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007084 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007085 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007086
7087 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007088 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007089 "0915 Register VPI failed : Status: x%x"
7090 " upd bit: x%x \n", mb->mbxStatus,
7091 mb->un.varRegVpi.upd);
7092 if (phba->sli_rev == LPFC_SLI_REV4 &&
7093 mb->un.varRegVpi.upd)
7094 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007095
7096 switch (mb->mbxStatus) {
7097 case 0x11: /* unsupported feature */
7098 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007099 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007100 /* giving up on vport registration */
7101 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7102 spin_lock_irq(shost->host_lock);
7103 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7104 spin_unlock_irq(shost->host_lock);
7105 lpfc_can_disctmo(vport);
7106 break;
James Smart695a8142010-01-26 23:08:03 -05007107 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7108 case 0x20:
7109 spin_lock_irq(shost->host_lock);
7110 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7111 spin_unlock_irq(shost->host_lock);
7112 lpfc_init_vpi(phba, pmb, vport->vpi);
7113 pmb->vport = vport;
7114 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7115 rc = lpfc_sli_issue_mbox(phba, pmb,
7116 MBX_NOWAIT);
7117 if (rc == MBX_NOT_FINISHED) {
7118 lpfc_printf_vlog(vport,
7119 KERN_ERR, LOG_MBOX,
7120 "2732 Failed to issue INIT_VPI"
7121 " mailbox command\n");
7122 } else {
7123 lpfc_nlp_put(ndlp);
7124 return;
7125 }
7126
James Smart92d7f7b2007-06-17 19:56:38 -05007127 default:
7128 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007129 if (phba->sli_rev == LPFC_SLI_REV4)
7130 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007131 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007132 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007133 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007134 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007135 if (vport->port_type == LPFC_PHYSICAL_PORT
7136 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007137 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007138 else
7139 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007140 break;
7141 }
James Smart92d7f7b2007-06-17 19:56:38 -05007142 } else {
James Smart695a8142010-01-26 23:08:03 -05007143 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007144 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007145 spin_unlock_irq(shost->host_lock);
7146 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007147 if (phba->sli_rev < LPFC_SLI_REV4)
7148 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007149 else {
James Smartfc2b9892010-02-26 14:15:29 -05007150 /*
7151 * If the physical port is instantiated using
7152 * FDISC, do not start vport discovery.
7153 */
7154 if (vport->port_state != LPFC_FDISC)
7155 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007156 lpfc_do_scr_ns_plogi(phba, vport);
7157 }
7158 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007159 lpfc_do_scr_ns_plogi(phba, vport);
7160 }
James Smart38b92ef2010-08-04 16:11:39 -04007161mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007162 /* Now, we decrement the ndlp reference count held for this
7163 * callback function
7164 */
7165 lpfc_nlp_put(ndlp);
7166
James Smart92d7f7b2007-06-17 19:56:38 -05007167 mempool_free(pmb, phba->mbox_mem_pool);
7168 return;
7169}
7170
James Smarte59058c2008-08-24 21:49:00 -04007171/**
James Smart3621a712009-04-06 18:47:14 -04007172 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007173 * @phba: pointer to lpfc hba data structure.
7174 * @vport: pointer to a host virtual N_Port data structure.
7175 * @ndlp: pointer to a node-list data structure.
7176 *
7177 * This routine registers the @vport as a new virtual port with a HBA.
7178 * It is done through a registering vpi mailbox command.
7179 **/
James Smart695a8142010-01-26 23:08:03 -05007180void
James Smart92d7f7b2007-06-17 19:56:38 -05007181lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7182 struct lpfc_nodelist *ndlp)
7183{
James Smart09372822008-01-11 01:52:54 -05007184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007185 LPFC_MBOXQ_t *mbox;
7186
7187 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7188 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007189 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007190 mbox->vport = vport;
7191 mbox->context2 = lpfc_nlp_get(ndlp);
7192 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007193 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007194 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007195 /* mailbox command not success, decrement ndlp
7196 * reference count for this command
7197 */
7198 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007199 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007200
James Smarte8b62012007-08-02 11:10:09 -04007201 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7202 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007203 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007204 }
7205 } else {
James Smarte8b62012007-08-02 11:10:09 -04007206 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7207 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007208 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007209 }
James Smartfa4066b2008-01-11 01:53:27 -05007210 return;
7211
7212mbox_err_exit:
7213 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7214 spin_lock_irq(shost->host_lock);
7215 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7216 spin_unlock_irq(shost->host_lock);
7217 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007218}
7219
James Smarte59058c2008-08-24 21:49:00 -04007220/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007221 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007222 * @phba: pointer to lpfc hba data structure.
7223 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007224 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007225 **/
7226void
James Smart0c9ab6f2010-02-26 14:15:57 -05007227lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007228{
7229 struct lpfc_vport **vports;
7230 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007231 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007232 int i;
James Smart695a8142010-01-26 23:08:03 -05007233
7234 /* Treat this failure as linkdown for all vports */
7235 link_state = phba->link_state;
7236 lpfc_linkdown(phba);
7237 phba->link_state = link_state;
7238
7239 vports = lpfc_create_vport_work_array(phba);
7240
7241 if (vports) {
7242 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7243 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7244 if (ndlp)
7245 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7246 lpfc_els_flush_cmd(vports[i]);
7247 }
7248 lpfc_destroy_vport_work_array(phba, vports);
7249 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007250}
7251
7252/**
7253 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7254 * @phba: pointer to lpfc hba data structure.
7255 *
7256 * This routine abort all pending discovery commands and
7257 * start a timer to retry FLOGI for the physical port
7258 * discovery.
7259 **/
7260void
7261lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7262{
7263 struct lpfc_nodelist *ndlp;
7264 struct Scsi_Host *shost;
7265
7266 /* Cancel the all vports retry delay retry timers */
7267 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007268
7269 /* If fabric require FLOGI, then re-instantiate physical login */
7270 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7271 if (!ndlp)
7272 return;
7273
James Smart695a8142010-01-26 23:08:03 -05007274 shost = lpfc_shost_from_vport(phba->pport);
7275 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7276 spin_lock_irq(shost->host_lock);
7277 ndlp->nlp_flag |= NLP_DELAY_TMO;
7278 spin_unlock_irq(shost->host_lock);
7279 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7280 phba->pport->port_state = LPFC_FLOGI;
7281 return;
7282}
7283
7284/**
7285 * lpfc_fabric_login_reqd - Check if FLOGI required.
7286 * @phba: pointer to lpfc hba data structure.
7287 * @cmdiocb: pointer to FDISC command iocb.
7288 * @rspiocb: pointer to FDISC response iocb.
7289 *
7290 * This routine checks if a FLOGI is reguired for FDISC
7291 * to succeed.
7292 **/
7293static int
7294lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7295 struct lpfc_iocbq *cmdiocb,
7296 struct lpfc_iocbq *rspiocb)
7297{
7298
7299 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7300 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7301 return 0;
7302 else
7303 return 1;
7304}
7305
7306/**
James Smart3621a712009-04-06 18:47:14 -04007307 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007308 * @phba: pointer to lpfc hba data structure.
7309 * @cmdiocb: pointer to lpfc command iocb data structure.
7310 * @rspiocb: pointer to lpfc response iocb data structure.
7311 *
7312 * This routine is the completion callback function to a Fabric Discover
7313 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7314 * single threaded, each FDISC completion callback function will reset
7315 * the discovery timer for all vports such that the timers will not get
7316 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7317 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7318 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7319 * assigned to the vport has been changed with the completion of the FDISC
7320 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7321 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7322 * routine is invoked to register new vport with the HBA. Otherwise, the
7323 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7324 * Server for State Change Request (SCR).
7325 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007326static void
7327lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7328 struct lpfc_iocbq *rspiocb)
7329{
7330 struct lpfc_vport *vport = cmdiocb->vport;
7331 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7332 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7333 struct lpfc_nodelist *np;
7334 struct lpfc_nodelist *next_np;
7335 IOCB_t *irsp = &rspiocb->iocb;
7336 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007337 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7338 struct serv_parm *sp;
7339 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007340
James Smarte8b62012007-08-02 11:10:09 -04007341 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7342 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7343 irsp->ulpStatus, irsp->un.ulpWord[4],
7344 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007345 /* Since all FDISCs are being single threaded, we
7346 * must reset the discovery timer for ALL vports
7347 * waiting to send FDISC when one completes.
7348 */
7349 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7350 lpfc_set_disctmo(piocb->vport);
7351 }
7352
James Smart858c9f62007-06-17 19:56:39 -05007353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7354 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7355 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7356
James Smart92d7f7b2007-06-17 19:56:38 -05007357 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007358
7359 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7360 lpfc_retry_pport_discovery(phba);
7361 goto out;
7362 }
7363
James Smart92d7f7b2007-06-17 19:56:38 -05007364 /* Check for retry */
7365 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7366 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007367 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007368 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007369 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007370 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007371 goto fdisc_failed;
7372 }
James Smartd7c255b2008-08-24 21:50:00 -04007373 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007374 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007375 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007376 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007377 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007378 vport->fc_flag |= FC_PUBLIC_LOOP;
7379 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007380
James Smartd7c255b2008-08-24 21:50:00 -04007381 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7382 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007383 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7384 sp = prsp->virt + sizeof(uint32_t);
7385 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7386 memcpy(&vport->fabric_portname, &sp->portName,
7387 sizeof(struct lpfc_name));
7388 memcpy(&vport->fabric_nodename, &sp->nodeName,
7389 sizeof(struct lpfc_name));
7390 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007391 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7392 /* If our NportID changed, we need to ensure all
7393 * remaining NPORTs get unreg_login'ed so we can
7394 * issue unreg_vpi.
7395 */
7396 list_for_each_entry_safe(np, next_np,
7397 &vport->fc_nodes, nlp_listp) {
7398 if (!NLP_CHK_NODE_ACT(ndlp) ||
7399 (np->nlp_state != NLP_STE_NPR_NODE) ||
7400 !(np->nlp_flag & NLP_NPR_ADISC))
7401 continue;
James Smart09372822008-01-11 01:52:54 -05007402 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007403 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007404 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007405 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007406 }
James Smart78730cf2010-04-06 15:06:30 -04007407 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007408
7409 if (phba->sli_rev == LPFC_SLI_REV4)
7410 lpfc_sli4_unreg_all_rpis(vport);
7411
James Smartd7c255b2008-08-24 21:50:00 -04007412 lpfc_mbx_unreg_vpi(vport);
7413 spin_lock_irq(shost->host_lock);
7414 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007415 if (phba->sli_rev == LPFC_SLI_REV4)
7416 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007417 else
7418 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007419 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007420 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7421 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7422 /*
7423 * Driver needs to re-reg VPI in order for f/w
7424 * to update the MAC address.
7425 */
7426 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007427 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007428 }
7429
James Smartecfd03c2010-02-12 14:41:27 -05007430 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7431 lpfc_issue_init_vpi(vport);
7432 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007433 lpfc_register_new_vport(phba, vport, ndlp);
7434 else
7435 lpfc_do_scr_ns_plogi(phba, vport);
7436 goto out;
7437fdisc_failed:
7438 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7439 /* Cancel discovery timer */
7440 lpfc_can_disctmo(vport);
7441 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007442out:
7443 lpfc_els_free_iocb(phba, cmdiocb);
7444}
7445
James Smarte59058c2008-08-24 21:49:00 -04007446/**
James Smart3621a712009-04-06 18:47:14 -04007447 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007448 * @vport: pointer to a virtual N_Port data structure.
7449 * @ndlp: pointer to a node-list data structure.
7450 * @retry: number of retries to the command IOCB.
7451 *
7452 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7453 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7454 * routine to issue the IOCB, which makes sure only one outstanding fabric
7455 * IOCB will be sent off HBA at any given time.
7456 *
7457 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7458 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7459 * will be stored into the context1 field of the IOCB for the completion
7460 * callback function to the FDISC ELS command.
7461 *
7462 * Return code
7463 * 0 - Successfully issued fdisc iocb command
7464 * 1 - Failed to issue fdisc iocb command
7465 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007466static int
James Smart92d7f7b2007-06-17 19:56:38 -05007467lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7468 uint8_t retry)
7469{
7470 struct lpfc_hba *phba = vport->phba;
7471 IOCB_t *icmd;
7472 struct lpfc_iocbq *elsiocb;
7473 struct serv_parm *sp;
7474 uint8_t *pcmd;
7475 uint16_t cmdsize;
7476 int did = ndlp->nlp_DID;
7477 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007478
James Smart5ffc2662009-11-18 15:39:44 -05007479 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007480 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007481 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7482 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7483 ELS_CMD_FDISC);
7484 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007485 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007486 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7487 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007488 return 1;
7489 }
7490
7491 icmd = &elsiocb->iocb;
7492 icmd->un.elsreq64.myID = 0;
7493 icmd->un.elsreq64.fl = 1;
7494
James Smart73d91e52011-10-10 21:32:10 -04007495 /*
7496 * SLI3 ports require a different context type value than SLI4.
7497 * Catch SLI3 ports here and override the prep.
7498 */
7499 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007500 icmd->ulpCt_h = 1;
7501 icmd->ulpCt_l = 0;
7502 }
James Smart92d7f7b2007-06-17 19:56:38 -05007503
7504 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7505 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7506 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7507 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7508 sp = (struct serv_parm *) pcmd;
7509 /* Setup CSPs accordingly for Fabric */
7510 sp->cmn.e_d_tov = 0;
7511 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007512 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007513 sp->cls1.classValid = 0;
7514 sp->cls2.seqDelivery = 1;
7515 sp->cls3.seqDelivery = 1;
7516
7517 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7518 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7519 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7520 pcmd += sizeof(uint32_t); /* Port Name */
7521 memcpy(pcmd, &vport->fc_portname, 8);
7522 pcmd += sizeof(uint32_t); /* Node Name */
7523 pcmd += sizeof(uint32_t); /* Node Name */
7524 memcpy(pcmd, &vport->fc_nodename, 8);
7525
7526 lpfc_set_disctmo(vport);
7527
7528 phba->fc_stat.elsXmitFDISC++;
7529 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7530
James Smart858c9f62007-06-17 19:56:39 -05007531 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7532 "Issue FDISC: did:x%x",
7533 did, 0, 0);
7534
James Smart92d7f7b2007-06-17 19:56:38 -05007535 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7536 if (rc == IOCB_ERROR) {
7537 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007538 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007539 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7540 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007541 return 1;
7542 }
7543 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007544 return 0;
7545}
7546
James Smarte59058c2008-08-24 21:49:00 -04007547/**
James Smart3621a712009-04-06 18:47:14 -04007548 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007549 * @phba: pointer to lpfc hba data structure.
7550 * @cmdiocb: pointer to lpfc command iocb data structure.
7551 * @rspiocb: pointer to lpfc response iocb data structure.
7552 *
7553 * This routine is the completion callback function to the issuing of a LOGO
7554 * ELS command off a vport. It frees the command IOCB and then decrement the
7555 * reference count held on ndlp for this completion function, indicating that
7556 * the reference to the ndlp is no long needed. Note that the
7557 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7558 * callback function and an additional explicit ndlp reference decrementation
7559 * will trigger the actual release of the ndlp.
7560 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007561static void
7562lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7563 struct lpfc_iocbq *rspiocb)
7564{
7565 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007566 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007567 struct lpfc_nodelist *ndlp;
James Smart9589b0622011-04-16 11:03:17 -04007568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007569
James Smart9589b0622011-04-16 11:03:17 -04007570 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007571 irsp = &rspiocb->iocb;
7572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7573 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7574 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007575
7576 lpfc_els_free_iocb(phba, cmdiocb);
7577 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007578
7579 /* Trigger the release of the ndlp after logo */
7580 lpfc_nlp_put(ndlp);
James Smart9589b0622011-04-16 11:03:17 -04007581
7582 /* NPIV LOGO completes to NPort <nlp_DID> */
7583 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7584 "2928 NPIV LOGO completes to NPort x%x "
7585 "Data: x%x x%x x%x x%x\n",
7586 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7587 irsp->ulpTimeout, vport->num_disc_nodes);
7588
7589 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7590 spin_lock_irq(shost->host_lock);
7591 vport->fc_flag &= ~FC_FABRIC;
7592 spin_unlock_irq(shost->host_lock);
7593 }
James Smart92d7f7b2007-06-17 19:56:38 -05007594}
7595
James Smarte59058c2008-08-24 21:49:00 -04007596/**
James Smart3621a712009-04-06 18:47:14 -04007597 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007598 * @vport: pointer to a virtual N_Port data structure.
7599 * @ndlp: pointer to a node-list data structure.
7600 *
7601 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7602 *
7603 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7604 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7605 * will be stored into the context1 field of the IOCB for the completion
7606 * callback function to the LOGO ELS command.
7607 *
7608 * Return codes
7609 * 0 - Successfully issued logo off the @vport
7610 * 1 - Failed to issue logo off the @vport
7611 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007612int
7613lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7614{
7615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7616 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007617 IOCB_t *icmd;
7618 struct lpfc_iocbq *elsiocb;
7619 uint8_t *pcmd;
7620 uint16_t cmdsize;
7621
7622 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7623 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7624 ELS_CMD_LOGO);
7625 if (!elsiocb)
7626 return 1;
7627
7628 icmd = &elsiocb->iocb;
7629 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7630 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7631 pcmd += sizeof(uint32_t);
7632
7633 /* Fill in LOGO payload */
7634 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7635 pcmd += sizeof(uint32_t);
7636 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7637
James Smart858c9f62007-06-17 19:56:39 -05007638 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7639 "Issue LOGO npiv did:x%x flg:x%x",
7640 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7641
James Smart92d7f7b2007-06-17 19:56:38 -05007642 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7643 spin_lock_irq(shost->host_lock);
7644 ndlp->nlp_flag |= NLP_LOGO_SND;
7645 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007646 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7647 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007648 spin_lock_irq(shost->host_lock);
7649 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7650 spin_unlock_irq(shost->host_lock);
7651 lpfc_els_free_iocb(phba, elsiocb);
7652 return 1;
7653 }
7654 return 0;
7655}
7656
James Smarte59058c2008-08-24 21:49:00 -04007657/**
James Smart3621a712009-04-06 18:47:14 -04007658 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007659 * @ptr: holder for the timer function associated data.
7660 *
7661 * This routine is invoked by the fabric iocb block timer after
7662 * timeout. It posts the fabric iocb block timeout event by setting the
7663 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7664 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7665 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7666 * posted event WORKER_FABRIC_BLOCK_TMO.
7667 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007668void
7669lpfc_fabric_block_timeout(unsigned long ptr)
7670{
7671 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7672 unsigned long iflags;
7673 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007674
James Smart92d7f7b2007-06-17 19:56:38 -05007675 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7676 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7677 if (!tmo_posted)
7678 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7679 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7680
James Smart5e9d9b82008-06-14 22:52:53 -04007681 if (!tmo_posted)
7682 lpfc_worker_wake_up(phba);
7683 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007684}
7685
James Smarte59058c2008-08-24 21:49:00 -04007686/**
James Smart3621a712009-04-06 18:47:14 -04007687 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007688 * @phba: pointer to lpfc hba data structure.
7689 *
7690 * This routine issues one fabric iocb from the driver internal list to
7691 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7692 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7693 * remove one pending fabric iocb from the driver internal list and invokes
7694 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7695 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007696static void
7697lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7698{
7699 struct lpfc_iocbq *iocb;
7700 unsigned long iflags;
7701 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007702 IOCB_t *cmd;
7703
7704repeat:
7705 iocb = NULL;
7706 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007707 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007708 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7709 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7710 list);
7711 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007712 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007713 atomic_inc(&phba->fabric_iocb_count);
7714 }
7715 spin_unlock_irqrestore(&phba->hbalock, iflags);
7716 if (iocb) {
7717 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7718 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7719 iocb->iocb_flag |= LPFC_IO_FABRIC;
7720
James Smart858c9f62007-06-17 19:56:39 -05007721 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7722 "Fabric sched1: ste:x%x",
7723 iocb->vport->port_state, 0, 0);
7724
James Smart3772a992009-05-22 14:50:54 -04007725 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007726
7727 if (ret == IOCB_ERROR) {
7728 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7729 iocb->fabric_iocb_cmpl = NULL;
7730 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7731 cmd = &iocb->iocb;
7732 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7733 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7734 iocb->iocb_cmpl(phba, iocb, iocb);
7735
7736 atomic_dec(&phba->fabric_iocb_count);
7737 goto repeat;
7738 }
7739 }
7740
7741 return;
7742}
7743
James Smarte59058c2008-08-24 21:49:00 -04007744/**
James Smart3621a712009-04-06 18:47:14 -04007745 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007746 * @phba: pointer to lpfc hba data structure.
7747 *
7748 * This routine unblocks the issuing fabric iocb command. The function
7749 * will clear the fabric iocb block bit and then invoke the routine
7750 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7751 * from the driver internal fabric iocb list.
7752 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007753void
7754lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7755{
7756 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7757
7758 lpfc_resume_fabric_iocbs(phba);
7759 return;
7760}
7761
James Smarte59058c2008-08-24 21:49:00 -04007762/**
James Smart3621a712009-04-06 18:47:14 -04007763 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007764 * @phba: pointer to lpfc hba data structure.
7765 *
7766 * This routine blocks the issuing fabric iocb for a specified amount of
7767 * time (currently 100 ms). This is done by set the fabric iocb block bit
7768 * and set up a timeout timer for 100ms. When the block bit is set, no more
7769 * fabric iocb will be issued out of the HBA.
7770 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007771static void
7772lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7773{
7774 int blocked;
7775
7776 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007777 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007778 if (!blocked)
7779 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7780
7781 return;
7782}
7783
James Smarte59058c2008-08-24 21:49:00 -04007784/**
James Smart3621a712009-04-06 18:47:14 -04007785 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007786 * @phba: pointer to lpfc hba data structure.
7787 * @cmdiocb: pointer to lpfc command iocb data structure.
7788 * @rspiocb: pointer to lpfc response iocb data structure.
7789 *
7790 * This routine is the callback function that is put to the fabric iocb's
7791 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7792 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7793 * function first restores and invokes the original iocb's callback function
7794 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7795 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7796 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007797static void
7798lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7799 struct lpfc_iocbq *rspiocb)
7800{
7801 struct ls_rjt stat;
7802
7803 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7804 BUG();
7805
7806 switch (rspiocb->iocb.ulpStatus) {
7807 case IOSTAT_NPORT_RJT:
7808 case IOSTAT_FABRIC_RJT:
7809 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7810 lpfc_block_fabric_iocbs(phba);
7811 }
7812 break;
7813
7814 case IOSTAT_NPORT_BSY:
7815 case IOSTAT_FABRIC_BSY:
7816 lpfc_block_fabric_iocbs(phba);
7817 break;
7818
7819 case IOSTAT_LS_RJT:
7820 stat.un.lsRjtError =
7821 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7822 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7823 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7824 lpfc_block_fabric_iocbs(phba);
7825 break;
7826 }
7827
7828 if (atomic_read(&phba->fabric_iocb_count) == 0)
7829 BUG();
7830
7831 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7832 cmdiocb->fabric_iocb_cmpl = NULL;
7833 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7834 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7835
7836 atomic_dec(&phba->fabric_iocb_count);
7837 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007838 /* Post any pending iocbs to HBA */
7839 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007840 }
7841}
7842
James Smarte59058c2008-08-24 21:49:00 -04007843/**
James Smart3621a712009-04-06 18:47:14 -04007844 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007845 * @phba: pointer to lpfc hba data structure.
7846 * @iocb: pointer to lpfc command iocb data structure.
7847 *
7848 * This routine is used as the top-level API for issuing a fabric iocb command
7849 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7850 * function makes sure that only one fabric bound iocb will be outstanding at
7851 * any given time. As such, this function will first check to see whether there
7852 * is already an outstanding fabric iocb on the wire. If so, it will put the
7853 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7854 * issued later. Otherwise, it will issue the iocb on the wire and update the
7855 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7856 *
7857 * Note, this implementation has a potential sending out fabric IOCBs out of
7858 * order. The problem is caused by the construction of the "ready" boolen does
7859 * not include the condition that the internal fabric IOCB list is empty. As
7860 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7861 * ahead of the fabric IOCBs in the internal list.
7862 *
7863 * Return code
7864 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7865 * IOCB_ERROR - failed to issue fabric iocb
7866 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007867static int
James Smart92d7f7b2007-06-17 19:56:38 -05007868lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7869{
7870 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007871 int ready;
7872 int ret;
7873
7874 if (atomic_read(&phba->fabric_iocb_count) > 1)
7875 BUG();
7876
7877 spin_lock_irqsave(&phba->hbalock, iflags);
7878 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7879 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7880
James Smart7f5f3d02008-02-08 18:50:14 -05007881 if (ready)
7882 /* Increment fabric iocb count to hold the position */
7883 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007884 spin_unlock_irqrestore(&phba->hbalock, iflags);
7885 if (ready) {
7886 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7887 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7888 iocb->iocb_flag |= LPFC_IO_FABRIC;
7889
James Smart858c9f62007-06-17 19:56:39 -05007890 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7891 "Fabric sched2: ste:x%x",
7892 iocb->vport->port_state, 0, 0);
7893
James Smart3772a992009-05-22 14:50:54 -04007894 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007895
7896 if (ret == IOCB_ERROR) {
7897 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7898 iocb->fabric_iocb_cmpl = NULL;
7899 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7900 atomic_dec(&phba->fabric_iocb_count);
7901 }
7902 } else {
7903 spin_lock_irqsave(&phba->hbalock, iflags);
7904 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7905 spin_unlock_irqrestore(&phba->hbalock, iflags);
7906 ret = IOCB_SUCCESS;
7907 }
7908 return ret;
7909}
7910
James Smarte59058c2008-08-24 21:49:00 -04007911/**
James Smart3621a712009-04-06 18:47:14 -04007912 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007913 * @vport: pointer to a virtual N_Port data structure.
7914 *
7915 * This routine aborts all the IOCBs associated with a @vport from the
7916 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7917 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7918 * list, removes each IOCB associated with the @vport off the list, set the
7919 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7920 * associated with the IOCB.
7921 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007922static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007923{
7924 LIST_HEAD(completions);
7925 struct lpfc_hba *phba = vport->phba;
7926 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007927
7928 spin_lock_irq(&phba->hbalock);
7929 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7930 list) {
7931
7932 if (piocb->vport != vport)
7933 continue;
7934
7935 list_move_tail(&piocb->list, &completions);
7936 }
7937 spin_unlock_irq(&phba->hbalock);
7938
James Smarta257bf92009-04-06 18:48:10 -04007939 /* Cancel all the IOCBs from the completions list */
7940 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7941 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007942}
7943
James Smarte59058c2008-08-24 21:49:00 -04007944/**
James Smart3621a712009-04-06 18:47:14 -04007945 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007946 * @ndlp: pointer to a node-list data structure.
7947 *
7948 * This routine aborts all the IOCBs associated with an @ndlp from the
7949 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7950 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7951 * list, removes each IOCB associated with the @ndlp off the list, set the
7952 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7953 * associated with the IOCB.
7954 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007955void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7956{
7957 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007958 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007959 struct lpfc_iocbq *tmp_iocb, *piocb;
7960 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007961
7962 spin_lock_irq(&phba->hbalock);
7963 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7964 list) {
7965 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7966
7967 list_move_tail(&piocb->list, &completions);
7968 }
7969 }
7970 spin_unlock_irq(&phba->hbalock);
7971
James Smarta257bf92009-04-06 18:48:10 -04007972 /* Cancel all the IOCBs from the completions list */
7973 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7974 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007975}
7976
James Smarte59058c2008-08-24 21:49:00 -04007977/**
James Smart3621a712009-04-06 18:47:14 -04007978 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007979 * @phba: pointer to lpfc hba data structure.
7980 *
7981 * This routine aborts all the IOCBs currently on the driver internal
7982 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7983 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7984 * list, removes IOCBs off the list, set the status feild to
7985 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7986 * the IOCB.
7987 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007988void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7989{
7990 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007991
7992 spin_lock_irq(&phba->hbalock);
7993 list_splice_init(&phba->fabric_iocb_list, &completions);
7994 spin_unlock_irq(&phba->hbalock);
7995
James Smarta257bf92009-04-06 18:48:10 -04007996 /* Cancel all the IOCBs from the completions list */
7997 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7998 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007999}
James Smart6fb120a2009-05-22 14:52:59 -04008000
8001/**
James Smart1151e3e2011-02-16 12:39:35 -05008002 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8003 * @vport: pointer to lpfc vport data structure.
8004 *
8005 * This routine is invoked by the vport cleanup for deletions and the cleanup
8006 * for an ndlp on removal.
8007 **/
8008void
8009lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
8010{
8011 struct lpfc_hba *phba = vport->phba;
8012 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8013 unsigned long iflag = 0;
8014
8015 spin_lock_irqsave(&phba->hbalock, iflag);
8016 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
8017 list_for_each_entry_safe(sglq_entry, sglq_next,
8018 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8019 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
8020 sglq_entry->ndlp = NULL;
8021 }
8022 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8023 spin_unlock_irqrestore(&phba->hbalock, iflag);
8024 return;
8025}
8026
8027/**
James Smart6fb120a2009-05-22 14:52:59 -04008028 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8029 * @phba: pointer to lpfc hba data structure.
8030 * @axri: pointer to the els xri abort wcqe structure.
8031 *
8032 * This routine is invoked by the worker thread to process a SLI4 slow-path
8033 * ELS aborted xri.
8034 **/
8035void
8036lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8037 struct sli4_wcqe_xri_aborted *axri)
8038{
8039 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008040 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008041 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008042
James Smart6fb120a2009-05-22 14:52:59 -04008043 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8044 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008045 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008046 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008047
James Smart0f65ff62010-02-26 14:14:23 -05008048 spin_lock_irqsave(&phba->hbalock, iflag);
8049 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008050 list_for_each_entry_safe(sglq_entry, sglq_next,
8051 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8052 if (sglq_entry->sli4_xritag == xri) {
8053 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008054 ndlp = sglq_entry->ndlp;
8055 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04008056 list_add_tail(&sglq_entry->list,
8057 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008058 sglq_entry->state = SGL_FREED;
8059 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008060 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008061 lpfc_set_rrq_active(phba, ndlp,
8062 sglq_entry->sli4_lxritag,
8063 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008064
8065 /* Check if TXQ queue needs to be serviced */
James Smart0e9bb8d2013-03-01 16:35:12 -05008066 if (!(list_empty(&pring->txq)))
James Smart589a52d2010-07-14 15:30:54 -04008067 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008068 return;
8069 }
8070 }
James Smart0f65ff62010-02-26 14:14:23 -05008071 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008072 lxri = lpfc_sli4_xri_inrange(phba, xri);
8073 if (lxri == NO_XRI) {
8074 spin_unlock_irqrestore(&phba->hbalock, iflag);
8075 return;
8076 }
8077 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008078 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8079 spin_unlock_irqrestore(&phba->hbalock, iflag);
8080 return;
8081 }
8082 sglq_entry->state = SGL_XRI_ABORTED;
8083 spin_unlock_irqrestore(&phba->hbalock, iflag);
8084 return;
James Smart6fb120a2009-05-22 14:52:59 -04008085}
James Smart086a3452012-08-14 14:25:21 -04008086
8087/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8088 * @vport: pointer to virtual port object.
8089 * @ndlp: nodelist pointer for the impacted node.
8090 *
8091 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8092 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8093 * the driver is required to send a LOGO to the remote node before it
8094 * attempts to recover its login to the remote node.
8095 */
8096void
8097lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8098 struct lpfc_nodelist *ndlp)
8099{
8100 struct Scsi_Host *shost;
8101 struct lpfc_hba *phba;
8102 unsigned long flags = 0;
8103
8104 shost = lpfc_shost_from_vport(vport);
8105 phba = vport->phba;
8106 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8107 lpfc_printf_log(phba, KERN_INFO,
8108 LOG_SLI, "3093 No rport recovery needed. "
8109 "rport in state 0x%x\n", ndlp->nlp_state);
8110 return;
8111 }
8112 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8113 "3094 Start rport recovery on shost id 0x%x "
8114 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8115 "flags 0x%x\n",
8116 shost->host_no, ndlp->nlp_DID,
8117 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8118 ndlp->nlp_flag);
8119 /*
8120 * The rport is not responding. Remove the FCP-2 flag to prevent
8121 * an ADISC in the follow-up recovery code.
8122 */
8123 spin_lock_irqsave(shost->host_lock, flags);
8124 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8125 spin_unlock_irqrestore(shost->host_lock, flags);
8126 lpfc_issue_els_logo(vport, ndlp, 0);
8127 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8128}
8129