blob: f19e9b6f9f133de56e484bc275109377dbc58664 [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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Smart9589b062011-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 Wellnitzc9f87352006-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;
1185 sp->cls2.seqDelivery = 1;
1186 sp->cls3.seqDelivery = 1;
1187 if (sp->cmn.fcphLow < FC_PH3)
1188 sp->cmn.fcphLow = FC_PH3;
1189 if (sp->cmn.fcphHigh < FC_PH3)
1190 sp->cmn.fcphHigh = FC_PH3;
1191
James Smartc31098c2011-04-16 11:03:33 -04001192 if (phba->sli_rev == LPFC_SLI_REV4) {
1193 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1194 LPFC_SLI_INTF_IF_TYPE_0) {
1195 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1196 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1197 /* FLOGI needs to be 3 for WQE FCFI */
1198 /* Set the fcfi to the fcfi we registered with */
1199 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1200 }
James Smart5248a742011-07-22 18:37:06 -04001201 } else {
1202 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1203 sp->cmn.request_multiple_Nport = 1;
1204 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1205 icmd->ulpCt_h = 1;
1206 icmd->ulpCt_l = 0;
1207 } else
1208 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001209 }
1210
James Smart76a95d72010-11-20 23:11:48 -05001211 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001212 icmd->un.elsreq64.myID = 0;
1213 icmd->un.elsreq64.fl = 1;
1214 }
1215
dea31012005-04-17 16:05:31 -05001216 tmo = phba->fc_ratov;
1217 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001218 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001219 phba->fc_ratov = tmo;
1220
1221 phba->fc_stat.elsXmitFLOGI++;
1222 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001223
1224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1225 "Issue FLOGI: opt:x%x",
1226 phba->sli3_options, 0, 0);
1227
James Smart92d7f7b2007-06-17 19:56:38 -05001228 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001229 if (rc == IOCB_ERROR) {
1230 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return 1;
dea31012005-04-17 16:05:31 -05001232 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001233 return 0;
dea31012005-04-17 16:05:31 -05001234}
1235
James Smarte59058c2008-08-24 21:49:00 -04001236/**
James Smart3621a712009-04-06 18:47:14 -04001237 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001238 * @phba: pointer to lpfc hba data structure.
1239 *
1240 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1241 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1242 * list and issues an abort IOCB commond on each outstanding IOCB that
1243 * contains a active Fabric_DID ndlp. Note that this function is to issue
1244 * the abort IOCB command on all the outstanding IOCBs, thus when this
1245 * function returns, it does not guarantee all the IOCBs are actually aborted.
1246 *
1247 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001248 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001249 **/
dea31012005-04-17 16:05:31 -05001250int
James Smart2e0fef82007-06-17 19:56:36 -05001251lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001252{
1253 struct lpfc_sli_ring *pring;
1254 struct lpfc_iocbq *iocb, *next_iocb;
1255 struct lpfc_nodelist *ndlp;
1256 IOCB_t *icmd;
1257
1258 /* Abort outstanding I/O on NPort <nlp_DID> */
1259 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001260 "0201 Abort outstanding I/O on NPort x%x\n",
1261 Fabric_DID);
dea31012005-04-17 16:05:31 -05001262
1263 pring = &phba->sli.ring[LPFC_ELS_RING];
1264
1265 /*
1266 * Check the txcmplq for an iocb that matches the nport the driver is
1267 * searching for.
1268 */
James Smart2e0fef82007-06-17 19:56:36 -05001269 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001270 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1271 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001272 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001273 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001274 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1275 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001276 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001277 }
1278 }
James Smart2e0fef82007-06-17 19:56:36 -05001279 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001280
1281 return 0;
1282}
1283
James Smarte59058c2008-08-24 21:49:00 -04001284/**
James Smart3621a712009-04-06 18:47:14 -04001285 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001286 * @vport: pointer to a host virtual N_Port data structure.
1287 *
1288 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1289 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1290 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1291 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1292 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1293 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1294 * @vport.
1295 *
1296 * Return code
1297 * 0 - failed to issue initial flogi for @vport
1298 * 1 - successfully issued initial flogi for @vport
1299 **/
dea31012005-04-17 16:05:31 -05001300int
James Smart2e0fef82007-06-17 19:56:36 -05001301lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001302{
James Smart2e0fef82007-06-17 19:56:36 -05001303 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001304 struct lpfc_nodelist *ndlp;
1305
James Smart98c9ea52007-10-27 13:37:33 -04001306 vport->port_state = LPFC_FLOGI;
1307 lpfc_set_disctmo(vport);
1308
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001309 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001310 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001311 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001312 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001313 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1314 if (!ndlp)
1315 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001316 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001317 /* Set the node type */
1318 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001319 /* Put ndlp onto node list */
1320 lpfc_enqueue_node(vport, ndlp);
1321 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1322 /* re-setup ndlp without removing from node list */
1323 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1324 if (!ndlp)
1325 return 0;
dea31012005-04-17 16:05:31 -05001326 }
James Smart87af33f2007-10-27 13:37:43 -04001327
James Smart5ac6b302010-10-22 11:05:36 -04001328 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001329 /* This decrement of reference count to node shall kick off
1330 * the release of the node.
1331 */
James Smart329f9bc2007-04-25 09:53:01 -04001332 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001333 return 0;
1334 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001335 return 1;
dea31012005-04-17 16:05:31 -05001336}
1337
James Smarte59058c2008-08-24 21:49:00 -04001338/**
James Smart3621a712009-04-06 18:47:14 -04001339 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001340 * @vport: pointer to a host virtual N_Port data structure.
1341 *
1342 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1343 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1344 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1345 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1346 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1347 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1348 * @vport.
1349 *
1350 * Return code
1351 * 0 - failed to issue initial fdisc for @vport
1352 * 1 - successfully issued initial fdisc for @vport
1353 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001354int
1355lpfc_initial_fdisc(struct lpfc_vport *vport)
1356{
1357 struct lpfc_hba *phba = vport->phba;
1358 struct lpfc_nodelist *ndlp;
1359
1360 /* First look for the Fabric ndlp */
1361 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1362 if (!ndlp) {
1363 /* Cannot find existing Fabric ndlp, so allocate a new one */
1364 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1365 if (!ndlp)
1366 return 0;
1367 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001368 /* Put ndlp onto node list */
1369 lpfc_enqueue_node(vport, ndlp);
1370 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1371 /* re-setup ndlp without removing from node list */
1372 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1373 if (!ndlp)
1374 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001375 }
James Smarte47c9092008-02-08 18:49:26 -05001376
James Smart92d7f7b2007-06-17 19:56:38 -05001377 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001378 /* decrement node reference count to trigger the release of
1379 * the node.
1380 */
James Smart92d7f7b2007-06-17 19:56:38 -05001381 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001382 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001383 }
1384 return 1;
1385}
James Smart87af33f2007-10-27 13:37:43 -04001386
James Smarte59058c2008-08-24 21:49:00 -04001387/**
James Smart3621a712009-04-06 18:47:14 -04001388 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001389 * @vport: pointer to a host virtual N_Port data structure.
1390 *
1391 * This routine checks whether there are more remaining Port Logins
1392 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1393 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1394 * to issue ELS PLOGIs up to the configured discover threads with the
1395 * @vport (@vport->cfg_discovery_threads). The function also decrement
1396 * the @vport's num_disc_node by 1 if it is not already 0.
1397 **/
James Smart87af33f2007-10-27 13:37:43 -04001398void
James Smart2e0fef82007-06-17 19:56:36 -05001399lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001400{
1401 int sentplogi;
1402
James Smart2e0fef82007-06-17 19:56:36 -05001403 if (vport->num_disc_nodes)
1404 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001405
1406 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001407 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1408 "0232 Continue discovery with %d PLOGIs to go "
1409 "Data: x%x x%x x%x\n",
1410 vport->num_disc_nodes, vport->fc_plogi_cnt,
1411 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001412 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001413 if (vport->fc_flag & FC_NLP_MORE)
1414 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1415 sentplogi = lpfc_els_disc_plogi(vport);
1416
dea31012005-04-17 16:05:31 -05001417 return;
1418}
1419
James Smarte59058c2008-08-24 21:49:00 -04001420/**
James Smart3621a712009-04-06 18:47:14 -04001421 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001422 * @phba: pointer to lpfc hba data structure.
1423 * @prsp: pointer to response IOCB payload.
1424 * @ndlp: pointer to a node-list data structure.
1425 *
1426 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1427 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1428 * The following cases are considered N_Port confirmed:
1429 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1430 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1431 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1432 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1433 * 1) if there is a node on vport list other than the @ndlp with the same
1434 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1435 * on that node to release the RPI associated with the node; 2) if there is
1436 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1437 * into, a new node shall be allocated (or activated). In either case, the
1438 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1439 * be released and the new_ndlp shall be put on to the vport node list and
1440 * its pointer returned as the confirmed node.
1441 *
1442 * Note that before the @ndlp got "released", the keepDID from not-matching
1443 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1444 * of the @ndlp. This is because the release of @ndlp is actually to put it
1445 * into an inactive state on the vport node list and the vport node list
1446 * management algorithm does not allow two node with a same DID.
1447 *
1448 * Return code
1449 * pointer to the PLOGI N_Port @ndlp
1450 **/
James Smart488d1462006-03-07 15:02:37 -05001451static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001452lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001453 struct lpfc_nodelist *ndlp)
1454{
James Smart2e0fef82007-06-17 19:56:36 -05001455 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001456 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001457 struct lpfc_rport_data *rdata;
1458 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001459 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001460 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001461 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001462 int put_node;
1463 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001464 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001465
James Smart2fb9bd82006-12-02 13:33:57 -05001466 /* Fabric nodes can have the same WWPN so we don't bother searching
1467 * by WWPN. Just return the ndlp that was given to us.
1468 */
1469 if (ndlp->nlp_type & NLP_FABRIC)
1470 return ndlp;
1471
James Smart92d7f7b2007-06-17 19:56:38 -05001472 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001473 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001474
James Smart685f0bf2007-04-25 09:53:08 -04001475 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001476 * we have for that ndlp. If not, we have some work to do.
1477 */
James Smart2e0fef82007-06-17 19:56:36 -05001478 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001479
James Smarte47c9092008-02-08 18:49:26 -05001480 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001481 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001482 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001483
James Smart34f5ad82012-08-03 12:35:03 -04001484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1485 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1486 ndlp, ndlp->nlp_DID, new_ndlp);
1487
James Smart488d1462006-03-07 15:02:37 -05001488 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001489 rc = memcmp(&ndlp->nlp_portname, name,
1490 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001491 if (!rc)
1492 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001493 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1494 if (!new_ndlp)
1495 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001496 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001497 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001498 rc = memcmp(&ndlp->nlp_portname, name,
1499 sizeof(struct lpfc_name));
1500 if (!rc)
1501 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001502 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1503 NLP_STE_UNUSED_NODE);
1504 if (!new_ndlp)
1505 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001506 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001507 if (phba->sli_rev == LPFC_SLI_REV4)
1508 memcpy(&rrq.xri_bitmap,
1509 &new_ndlp->active_rrqs.xri_bitmap,
1510 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1511 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001512 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001513 if (phba->sli_rev == LPFC_SLI_REV4)
1514 memcpy(&rrq.xri_bitmap,
1515 &new_ndlp->active_rrqs.xri_bitmap,
1516 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1517 }
James Smart488d1462006-03-07 15:02:37 -05001518
James Smart2e0fef82007-06-17 19:56:36 -05001519 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001520 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001521 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001522 if (phba->sli_rev == LPFC_SLI_REV4)
1523 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1524 &ndlp->active_rrqs.xri_bitmap,
1525 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001526
1527 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1528 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1529 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1530
James Smarte47c9092008-02-08 18:49:26 -05001531 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001532 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001533
James Smart2e0fef82007-06-17 19:56:36 -05001534 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001535 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1536 /* The new_ndlp is replacing ndlp totally, so we need
1537 * to put ndlp on UNUSED list and try to free it.
1538 */
James Smart34f5ad82012-08-03 12:35:03 -04001539 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1540 "3179 PLOGI confirm NEW: %x %x\n",
1541 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001542
1543 /* Fix up the rport accordingly */
1544 rport = ndlp->rport;
1545 if (rport) {
1546 rdata = rport->dd_data;
1547 if (rdata->pnode == ndlp) {
1548 lpfc_nlp_put(ndlp);
1549 ndlp->rport = NULL;
1550 rdata->pnode = lpfc_nlp_get(new_ndlp);
1551 new_ndlp->rport = rport;
1552 }
1553 new_ndlp->nlp_type = ndlp->nlp_type;
1554 }
James Smart58da1ff2008-04-07 10:15:56 -04001555 /* We shall actually free the ndlp with both nlp_DID and
1556 * nlp_portname fields equals 0 to avoid any ndlp on the
1557 * nodelist never to be used.
1558 */
1559 if (ndlp->nlp_DID == 0) {
1560 spin_lock_irq(&phba->ndlp_lock);
1561 NLP_SET_FREE_REQ(ndlp);
1562 spin_unlock_irq(&phba->ndlp_lock);
1563 }
James Smart0ff10d42008-01-11 01:52:36 -05001564
James Smart58da1ff2008-04-07 10:15:56 -04001565 /* Two ndlps cannot have the same did on the nodelist */
1566 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001567 if (phba->sli_rev == LPFC_SLI_REV4)
1568 memcpy(&ndlp->active_rrqs.xri_bitmap,
1569 &rrq.xri_bitmap,
1570 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001571 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001572 }
James Smart92795652006-07-06 15:50:02 -04001573 else {
James Smart34f5ad82012-08-03 12:35:03 -04001574 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1575 "3180 PLOGI confirm SWAP: %x %x\n",
1576 new_ndlp->nlp_DID, keepDID);
1577
James Smart2e0fef82007-06-17 19:56:36 -05001578 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001579
James Smart58da1ff2008-04-07 10:15:56 -04001580 /* Two ndlps cannot have the same did */
1581 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001582 if (phba->sli_rev == LPFC_SLI_REV4)
1583 memcpy(&ndlp->active_rrqs.xri_bitmap,
1584 &rrq.xri_bitmap,
1585 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001586
James Smart38b92ef2010-08-04 16:11:39 -04001587 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001588 * and the did has already been swapped, copy over state.
1589 * The new WWNs are already in new_ndlp since thats what
1590 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001591 */
James Smart38b92ef2010-08-04 16:11:39 -04001592 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001593
1594 /* Since we are switching over to the new_ndlp, the old
1595 * ndlp should be put in the NPR state, unless we have
1596 * already started re-discovery on it.
1597 */
1598 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1599 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1600 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1601
James Smart38b92ef2010-08-04 16:11:39 -04001602 /* Fix up the rport accordingly */
1603 rport = ndlp->rport;
1604 if (rport) {
1605 rdata = rport->dd_data;
1606 put_node = rdata->pnode != NULL;
1607 put_rport = ndlp->rport != NULL;
1608 rdata->pnode = NULL;
1609 ndlp->rport = NULL;
1610 if (put_node)
1611 lpfc_nlp_put(ndlp);
1612 if (put_rport)
1613 put_device(&rport->dev);
1614 }
James Smart92795652006-07-06 15:50:02 -04001615 }
James Smart488d1462006-03-07 15:02:37 -05001616 return new_ndlp;
1617}
1618
James Smarte59058c2008-08-24 21:49:00 -04001619/**
James Smart3621a712009-04-06 18:47:14 -04001620 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001621 * @vport: pointer to a host virtual N_Port data structure.
1622 *
1623 * This routine checks whether more Registration State Change
1624 * Notifications (RSCNs) came in while the discovery state machine was in
1625 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1626 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1627 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1628 * handling the RSCNs.
1629 **/
James Smart87af33f2007-10-27 13:37:43 -04001630void
1631lpfc_end_rscn(struct lpfc_vport *vport)
1632{
1633 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1634
1635 if (vport->fc_flag & FC_RSCN_MODE) {
1636 /*
1637 * Check to see if more RSCNs came in while we were
1638 * processing this one.
1639 */
1640 if (vport->fc_rscn_id_cnt ||
1641 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1642 lpfc_els_handle_rscn(vport);
1643 else {
1644 spin_lock_irq(shost->host_lock);
1645 vport->fc_flag &= ~FC_RSCN_MODE;
1646 spin_unlock_irq(shost->host_lock);
1647 }
1648 }
1649}
1650
James Smarte59058c2008-08-24 21:49:00 -04001651/**
James Smart19ca7602010-11-20 23:11:55 -05001652 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1653 * @phba: pointer to lpfc hba data structure.
1654 * @cmdiocb: pointer to lpfc command iocb data structure.
1655 * @rspiocb: pointer to lpfc response iocb data structure.
1656 *
1657 * This routine will call the clear rrq function to free the rrq and
1658 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1659 * exist then the clear_rrq is still called because the rrq needs to
1660 * be freed.
1661 **/
1662
1663static void
1664lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1665 struct lpfc_iocbq *rspiocb)
1666{
1667 struct lpfc_vport *vport = cmdiocb->vport;
1668 IOCB_t *irsp;
1669 struct lpfc_nodelist *ndlp;
1670 struct lpfc_node_rrq *rrq;
1671
1672 /* we pass cmdiocb to state machine which needs rspiocb as well */
1673 rrq = cmdiocb->context_un.rrq;
1674 cmdiocb->context_un.rsp_iocb = rspiocb;
1675
1676 irsp = &rspiocb->iocb;
1677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1678 "RRQ cmpl: status:x%x/x%x did:x%x",
1679 irsp->ulpStatus, irsp->un.ulpWord[4],
1680 irsp->un.elsreq64.remoteID);
1681
1682 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1683 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1684 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1685 "2882 RRQ completes to NPort x%x "
1686 "with no ndlp. Data: x%x x%x x%x\n",
1687 irsp->un.elsreq64.remoteID,
1688 irsp->ulpStatus, irsp->un.ulpWord[4],
1689 irsp->ulpIoTag);
1690 goto out;
1691 }
1692
1693 /* rrq completes to NPort <nlp_DID> */
1694 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1695 "2880 RRQ completes to NPort x%x "
1696 "Data: x%x x%x x%x x%x x%x\n",
1697 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1698 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1699
1700 if (irsp->ulpStatus) {
1701 /* Check for retry */
1702 /* RRQ failed Don't print the vport to vport rjts */
1703 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1704 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1705 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1706 (phba)->pport->cfg_log_verbose & LOG_ELS)
1707 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1708 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1709 ndlp->nlp_DID, irsp->ulpStatus,
1710 irsp->un.ulpWord[4]);
1711 }
1712out:
1713 if (rrq)
1714 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1715 lpfc_els_free_iocb(phba, cmdiocb);
1716 return;
1717}
1718/**
James Smart3621a712009-04-06 18:47:14 -04001719 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001720 * @phba: pointer to lpfc hba data structure.
1721 * @cmdiocb: pointer to lpfc command iocb data structure.
1722 * @rspiocb: pointer to lpfc response iocb data structure.
1723 *
1724 * This routine is the completion callback function for issuing the Port
1725 * Login (PLOGI) command. For PLOGI completion, there must be an active
1726 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001727 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001728 * ignored and command IOCB released. The PLOGI response IOCB status is
1729 * checked for error conditons. If there is error status reported, PLOGI
1730 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1731 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1732 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1733 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1734 * there are additional N_Port nodes with the vport that need to perform
1735 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1736 * PLOGIs.
1737 **/
dea31012005-04-17 16:05:31 -05001738static void
James Smart2e0fef82007-06-17 19:56:36 -05001739lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1740 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001741{
James Smart2e0fef82007-06-17 19:56:36 -05001742 struct lpfc_vport *vport = cmdiocb->vport;
1743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001744 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001745 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001746 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001747 int disc, rc, did, type;
1748
dea31012005-04-17 16:05:31 -05001749 /* we pass cmdiocb to state machine which needs rspiocb as well */
1750 cmdiocb->context_un.rsp_iocb = rspiocb;
1751
1752 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1754 "PLOGI cmpl: status:x%x/x%x did:x%x",
1755 irsp->ulpStatus, irsp->un.ulpWord[4],
1756 irsp->un.elsreq64.remoteID);
1757
James Smart2e0fef82007-06-17 19:56:36 -05001758 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001759 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001760 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1761 "0136 PLOGI completes to NPort x%x "
1762 "with no ndlp. Data: x%x x%x x%x\n",
1763 irsp->un.elsreq64.remoteID,
1764 irsp->ulpStatus, irsp->un.ulpWord[4],
1765 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001766 goto out;
James Smarted957682007-06-17 19:56:37 -05001767 }
dea31012005-04-17 16:05:31 -05001768
1769 /* Since ndlp can be freed in the disc state machine, note if this node
1770 * is being used during discovery.
1771 */
James Smart2e0fef82007-06-17 19:56:36 -05001772 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001773 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001774 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001775 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001776 rc = 0;
1777
1778 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001779 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1780 "0102 PLOGI completes to NPort x%x "
1781 "Data: x%x x%x x%x x%x x%x\n",
1782 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1783 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001784 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001785 if (lpfc_els_chk_latt(vport)) {
1786 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001787 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001788 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001789 goto out;
1790 }
1791
1792 /* ndlp could be freed in DSM, save these values now */
1793 type = ndlp->nlp_type;
1794 did = ndlp->nlp_DID;
1795
1796 if (irsp->ulpStatus) {
1797 /* Check for retry */
1798 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1799 /* ELS command is being retried */
1800 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001801 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001802 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001803 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001804 }
1805 goto out;
1806 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001807 /* PLOGI failed Don't print the vport to vport rjts */
1808 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1809 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1810 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1811 (phba)->pport->cfg_log_verbose & LOG_ELS)
1812 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001813 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1814 ndlp->nlp_DID, irsp->ulpStatus,
1815 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001816 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001817 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001818 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001819 else
James Smart2e0fef82007-06-17 19:56:36 -05001820 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001821 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001822 } else {
1823 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001824 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001825 cmdiocb->context2)->list.next,
1826 struct lpfc_dmabuf, list);
1827 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001828 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001829 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001830 }
1831
James Smart2e0fef82007-06-17 19:56:36 -05001832 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001833 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001834 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001835
James Smart2e0fef82007-06-17 19:56:36 -05001836 if (vport->num_disc_nodes == 0) {
1837 spin_lock_irq(shost->host_lock);
1838 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1839 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001840
James Smart2e0fef82007-06-17 19:56:36 -05001841 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001842 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001843 }
1844 }
1845
1846out:
1847 lpfc_els_free_iocb(phba, cmdiocb);
1848 return;
1849}
1850
James Smarte59058c2008-08-24 21:49:00 -04001851/**
James Smart3621a712009-04-06 18:47:14 -04001852 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001853 * @vport: pointer to a host virtual N_Port data structure.
1854 * @did: destination port identifier.
1855 * @retry: number of retries to the command IOCB.
1856 *
1857 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1858 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1859 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1860 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1861 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1862 *
1863 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1864 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1865 * will be stored into the context1 field of the IOCB for the completion
1866 * callback function to the PLOGI ELS command.
1867 *
1868 * Return code
1869 * 0 - Successfully issued a plogi for @vport
1870 * 1 - failed to issue a plogi for @vport
1871 **/
dea31012005-04-17 16:05:31 -05001872int
James Smart2e0fef82007-06-17 19:56:36 -05001873lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001874{
James Smart2e0fef82007-06-17 19:56:36 -05001875 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001876 struct serv_parm *sp;
1877 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001878 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001879 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001880 struct lpfc_sli *psli;
1881 uint8_t *pcmd;
1882 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001883 int ret;
dea31012005-04-17 16:05:31 -05001884
1885 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001886
James Smart98c9ea52007-10-27 13:37:33 -04001887 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001888 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1889 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001890
James Smarte47c9092008-02-08 18:49:26 -05001891 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001892 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001893 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001894 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001895 if (!elsiocb)
1896 return 1;
dea31012005-04-17 16:05:31 -05001897
1898 icmd = &elsiocb->iocb;
1899 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1900
1901 /* For PLOGI request, remainder of payload is service parameters */
1902 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001903 pcmd += sizeof(uint32_t);
1904 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001905 sp = (struct serv_parm *) pcmd;
1906
James Smart5ac6b302010-10-22 11:05:36 -04001907 /*
1908 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1909 * to device on remote loops work.
1910 */
1911 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1912 sp->cmn.altBbCredit = 1;
1913
dea31012005-04-17 16:05:31 -05001914 if (sp->cmn.fcphLow < FC_PH_4_3)
1915 sp->cmn.fcphLow = FC_PH_4_3;
1916
1917 if (sp->cmn.fcphHigh < FC_PH3)
1918 sp->cmn.fcphHigh = FC_PH3;
1919
James Smart858c9f62007-06-17 19:56:39 -05001920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1921 "Issue PLOGI: did:x%x",
1922 did, 0, 0);
1923
dea31012005-04-17 16:05:31 -05001924 phba->fc_stat.elsXmitPLOGI++;
1925 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001926 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001927
1928 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001929 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001930 return 1;
dea31012005-04-17 16:05:31 -05001931 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001932 return 0;
dea31012005-04-17 16:05:31 -05001933}
1934
James Smarte59058c2008-08-24 21:49:00 -04001935/**
James Smart3621a712009-04-06 18:47:14 -04001936 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001937 * @phba: pointer to lpfc hba data structure.
1938 * @cmdiocb: pointer to lpfc command iocb data structure.
1939 * @rspiocb: pointer to lpfc response iocb data structure.
1940 *
1941 * This routine is the completion callback function for a Process Login
1942 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1943 * status. If there is error status reported, PRLI retry shall be attempted
1944 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1945 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1946 * ndlp to mark the PRLI completion.
1947 **/
dea31012005-04-17 16:05:31 -05001948static void
James Smart2e0fef82007-06-17 19:56:36 -05001949lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1950 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001951{
James Smart2e0fef82007-06-17 19:56:36 -05001952 struct lpfc_vport *vport = cmdiocb->vport;
1953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001954 IOCB_t *irsp;
1955 struct lpfc_sli *psli;
1956 struct lpfc_nodelist *ndlp;
1957
1958 psli = &phba->sli;
1959 /* we pass cmdiocb to state machine which needs rspiocb as well */
1960 cmdiocb->context_un.rsp_iocb = rspiocb;
1961
1962 irsp = &(rspiocb->iocb);
1963 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001964 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001966 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001967
James Smart858c9f62007-06-17 19:56:39 -05001968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1969 "PRLI cmpl: status:x%x/x%x did:x%x",
1970 irsp->ulpStatus, irsp->un.ulpWord[4],
1971 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001972 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001973 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1974 "0103 PRLI completes to NPort x%x "
1975 "Data: x%x x%x x%x x%x\n",
1976 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1977 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001978
James Smart2e0fef82007-06-17 19:56:36 -05001979 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001980 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001981 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001982 goto out;
1983
1984 if (irsp->ulpStatus) {
1985 /* Check for retry */
1986 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1987 /* ELS command is being retried */
1988 goto out;
1989 }
1990 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001991 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1992 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1993 ndlp->nlp_DID, irsp->ulpStatus,
1994 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001995 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001996 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001997 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001998 else
James Smart2e0fef82007-06-17 19:56:36 -05001999 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002000 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05002001 } else
dea31012005-04-17 16:05:31 -05002002 /* Good status, call state machine */
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);
dea31012005-04-17 16:05:31 -05002005out:
2006 lpfc_els_free_iocb(phba, cmdiocb);
2007 return;
2008}
2009
James Smarte59058c2008-08-24 21:49:00 -04002010/**
James Smart3621a712009-04-06 18:47:14 -04002011 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002012 * @vport: pointer to a host virtual N_Port data structure.
2013 * @ndlp: pointer to a node-list data structure.
2014 * @retry: number of retries to the command IOCB.
2015 *
2016 * This routine issues a Process Login (PRLI) ELS command for the
2017 * @vport. The PRLI service parameters are set up in the payload of the
2018 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2019 * is put to the IOCB completion callback func field before invoking the
2020 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2021 *
2022 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2023 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2024 * will be stored into the context1 field of the IOCB for the completion
2025 * callback function to the PRLI ELS command.
2026 *
2027 * Return code
2028 * 0 - successfully issued prli iocb command for @vport
2029 * 1 - failed to issue prli iocb command for @vport
2030 **/
dea31012005-04-17 16:05:31 -05002031int
James Smart2e0fef82007-06-17 19:56:36 -05002032lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002033 uint8_t retry)
2034{
James Smart2e0fef82007-06-17 19:56:36 -05002035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002037 PRLI *npr;
2038 IOCB_t *icmd;
2039 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002040 uint8_t *pcmd;
2041 uint16_t cmdsize;
2042
James Smart92d7f7b2007-06-17 19:56:38 -05002043 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002044 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2045 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002046 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002047 return 1;
dea31012005-04-17 16:05:31 -05002048
2049 icmd = &elsiocb->iocb;
2050 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2051
2052 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002053 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002054 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002055 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002056
2057 /* For PRLI, remainder of payload is PRLI parameter page */
2058 npr = (PRLI *) pcmd;
2059 /*
2060 * If our firmware version is 3.20 or later,
2061 * set the following bits for FC-TAPE support.
2062 */
2063 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2064 npr->ConfmComplAllowed = 1;
2065 npr->Retry = 1;
2066 npr->TaskRetryIdReq = 1;
2067 }
2068 npr->estabImagePair = 1;
2069 npr->readXferRdyDis = 1;
2070
2071 /* For FCP support */
2072 npr->prliType = PRLI_FCP_TYPE;
2073 npr->initiatorFunc = 1;
2074
James Smart858c9f62007-06-17 19:56:39 -05002075 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2076 "Issue PRLI: did:x%x",
2077 ndlp->nlp_DID, 0, 0);
2078
dea31012005-04-17 16:05:31 -05002079 phba->fc_stat.elsXmitPRLI++;
2080 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002081 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002082 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002083 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002084 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2085 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002086 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002087 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002088 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002089 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002090 return 1;
dea31012005-04-17 16:05:31 -05002091 }
James Smart2e0fef82007-06-17 19:56:36 -05002092 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002093 return 0;
dea31012005-04-17 16:05:31 -05002094}
2095
James Smarte59058c2008-08-24 21:49:00 -04002096/**
James Smart3621a712009-04-06 18:47:14 -04002097 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002098 * @vport: pointer to a host virtual N_Port data structure.
2099 *
2100 * This routine performs Registration State Change Notification (RSCN)
2101 * discovery for a @vport. If the @vport's node port recovery count is not
2102 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2103 * the nodes that need recovery. If none of the PLOGI were needed through
2104 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2105 * invoked to check and handle possible more RSCN came in during the period
2106 * of processing the current ones.
2107 **/
2108static void
2109lpfc_rscn_disc(struct lpfc_vport *vport)
2110{
2111 lpfc_can_disctmo(vport);
2112
2113 /* RSCN discovery */
2114 /* go thru NPR nodes and issue ELS PLOGIs */
2115 if (vport->fc_npr_cnt)
2116 if (lpfc_els_disc_plogi(vport))
2117 return;
2118
2119 lpfc_end_rscn(vport);
2120}
2121
2122/**
James Smart3621a712009-04-06 18:47:14 -04002123 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002124 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2125 *
2126 * This function is called when the final ADISC is completed during discovery.
2127 * This function handles clearing link attention or issuing reg_vpi depending
2128 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2129 * discovery.
2130 * This function is called with no locks held.
2131 **/
2132static void
2133lpfc_adisc_done(struct lpfc_vport *vport)
2134{
2135 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2136 struct lpfc_hba *phba = vport->phba;
2137
2138 /*
2139 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2140 * and continue discovery.
2141 */
2142 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002143 !(vport->fc_flag & FC_RSCN_MODE) &&
2144 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002145 lpfc_issue_reg_vpi(phba, vport);
2146 return;
2147 }
2148 /*
2149 * For SLI2, we need to set port_state to READY
2150 * and continue discovery.
2151 */
2152 if (vport->port_state < LPFC_VPORT_READY) {
2153 /* If we get here, there is nothing to ADISC */
2154 if (vport->port_type == LPFC_PHYSICAL_PORT)
2155 lpfc_issue_clear_la(phba, vport);
2156 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2157 vport->num_disc_nodes = 0;
2158 /* go thru NPR list, issue ELS PLOGIs */
2159 if (vport->fc_npr_cnt)
2160 lpfc_els_disc_plogi(vport);
2161 if (!vport->num_disc_nodes) {
2162 spin_lock_irq(shost->host_lock);
2163 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2164 spin_unlock_irq(shost->host_lock);
2165 lpfc_can_disctmo(vport);
2166 lpfc_end_rscn(vport);
2167 }
2168 }
2169 vport->port_state = LPFC_VPORT_READY;
2170 } else
2171 lpfc_rscn_disc(vport);
2172}
2173
2174/**
James Smart3621a712009-04-06 18:47:14 -04002175 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002176 * @vport: pointer to a host virtual N_Port data structure.
2177 *
2178 * This routine determines whether there are more ndlps on a @vport
2179 * node list need to have Address Discover (ADISC) issued. If so, it will
2180 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2181 * remaining nodes which need to have ADISC sent.
2182 **/
James Smart0ff10d42008-01-11 01:52:36 -05002183void
James Smart2e0fef82007-06-17 19:56:36 -05002184lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002185{
2186 int sentadisc;
2187
James Smart2e0fef82007-06-17 19:56:36 -05002188 if (vport->num_disc_nodes)
2189 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002190 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002191 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2192 "0210 Continue discovery with %d ADISCs to go "
2193 "Data: x%x x%x x%x\n",
2194 vport->num_disc_nodes, vport->fc_adisc_cnt,
2195 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002196 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002197 if (vport->fc_flag & FC_NLP_MORE) {
2198 lpfc_set_disctmo(vport);
2199 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2200 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002201 }
James Smart90160e02008-08-24 21:49:45 -04002202 if (!vport->num_disc_nodes)
2203 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002204 return;
2205}
2206
James Smarte59058c2008-08-24 21:49:00 -04002207/**
James Smart3621a712009-04-06 18:47:14 -04002208 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002209 * @phba: pointer to lpfc hba data structure.
2210 * @cmdiocb: pointer to lpfc command iocb data structure.
2211 * @rspiocb: pointer to lpfc response iocb data structure.
2212 *
2213 * This routine is the completion function for issuing the Address Discover
2214 * (ADISC) command. It first checks to see whether link went down during
2215 * the discovery process. If so, the node will be marked as node port
2216 * recovery for issuing discover IOCB by the link attention handler and
2217 * exit. Otherwise, the response status is checked. If error was reported
2218 * in the response status, the ADISC command shall be retried by invoking
2219 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2220 * the response status, the state machine is invoked to set transition
2221 * with respect to NLP_EVT_CMPL_ADISC event.
2222 **/
dea31012005-04-17 16:05:31 -05002223static void
James Smart2e0fef82007-06-17 19:56:36 -05002224lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2225 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002226{
James Smart2e0fef82007-06-17 19:56:36 -05002227 struct lpfc_vport *vport = cmdiocb->vport;
2228 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002229 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002230 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002231 int disc;
dea31012005-04-17 16:05:31 -05002232
2233 /* we pass cmdiocb to state machine which needs rspiocb as well */
2234 cmdiocb->context_un.rsp_iocb = rspiocb;
2235
2236 irsp = &(rspiocb->iocb);
2237 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002238
James Smart858c9f62007-06-17 19:56:39 -05002239 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2240 "ADISC cmpl: status:x%x/x%x did:x%x",
2241 irsp->ulpStatus, irsp->un.ulpWord[4],
2242 ndlp->nlp_DID);
2243
dea31012005-04-17 16:05:31 -05002244 /* Since ndlp can be freed in the disc state machine, note if this node
2245 * is being used during discovery.
2246 */
James Smart2e0fef82007-06-17 19:56:36 -05002247 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002248 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002249 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002250 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002251 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002252 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2253 "0104 ADISC completes to NPort x%x "
2254 "Data: x%x x%x x%x x%x x%x\n",
2255 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2256 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002257 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002258 if (lpfc_els_chk_latt(vport)) {
2259 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002260 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002261 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002262 goto out;
2263 }
2264
2265 if (irsp->ulpStatus) {
2266 /* Check for retry */
2267 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2268 /* ELS command is being retried */
2269 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002270 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002271 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002272 spin_unlock_irq(shost->host_lock);
2273 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002274 }
2275 goto out;
2276 }
2277 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002278 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2279 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2280 ndlp->nlp_DID, irsp->ulpStatus,
2281 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002282 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002283 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002284 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002285 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002286 } else
dea31012005-04-17 16:05:31 -05002287 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002288 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002289 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002290
James Smart90160e02008-08-24 21:49:45 -04002291 /* Check to see if there are more ADISCs to be sent */
2292 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002293 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002294out:
2295 lpfc_els_free_iocb(phba, cmdiocb);
2296 return;
2297}
2298
James Smarte59058c2008-08-24 21:49:00 -04002299/**
James Smart3621a712009-04-06 18:47:14 -04002300 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002301 * @vport: pointer to a virtual N_Port data structure.
2302 * @ndlp: pointer to a node-list data structure.
2303 * @retry: number of retries to the command IOCB.
2304 *
2305 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2306 * @vport. It prepares the payload of the ADISC ELS command, updates the
2307 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2308 * to issue the ADISC ELS command.
2309 *
2310 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2311 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2312 * will be stored into the context1 field of the IOCB for the completion
2313 * callback function to the ADISC ELS command.
2314 *
2315 * Return code
2316 * 0 - successfully issued adisc
2317 * 1 - failed to issue adisc
2318 **/
dea31012005-04-17 16:05:31 -05002319int
James Smart2e0fef82007-06-17 19:56:36 -05002320lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002321 uint8_t retry)
2322{
James Smart2e0fef82007-06-17 19:56:36 -05002323 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2324 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002325 ADISC *ap;
2326 IOCB_t *icmd;
2327 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002328 uint8_t *pcmd;
2329 uint16_t cmdsize;
2330
James Smart92d7f7b2007-06-17 19:56:38 -05002331 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002332 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2333 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002334 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002335 return 1;
dea31012005-04-17 16:05:31 -05002336
2337 icmd = &elsiocb->iocb;
2338 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2339
2340 /* For ADISC request, remainder of payload is service parameters */
2341 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002342 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002343
2344 /* Fill in ADISC payload */
2345 ap = (ADISC *) pcmd;
2346 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002347 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2348 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002349 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002350
James Smart858c9f62007-06-17 19:56:39 -05002351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2352 "Issue ADISC: did:x%x",
2353 ndlp->nlp_DID, 0, 0);
2354
dea31012005-04-17 16:05:31 -05002355 phba->fc_stat.elsXmitADISC++;
2356 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002358 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002359 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002360 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2361 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002363 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002364 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002365 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002366 return 1;
dea31012005-04-17 16:05:31 -05002367 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002368 return 0;
dea31012005-04-17 16:05:31 -05002369}
2370
James Smarte59058c2008-08-24 21:49:00 -04002371/**
James Smart3621a712009-04-06 18:47:14 -04002372 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002373 * @phba: pointer to lpfc hba data structure.
2374 * @cmdiocb: pointer to lpfc command iocb data structure.
2375 * @rspiocb: pointer to lpfc response iocb data structure.
2376 *
2377 * This routine is the completion function for issuing the ELS Logout (LOGO)
2378 * command. If no error status was reported from the LOGO response, the
2379 * state machine of the associated ndlp shall be invoked for transition with
2380 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2381 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2382 **/
dea31012005-04-17 16:05:31 -05002383static void
James Smart2e0fef82007-06-17 19:56:36 -05002384lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2385 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002386{
James Smart2e0fef82007-06-17 19:56:36 -05002387 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2388 struct lpfc_vport *vport = ndlp->vport;
2389 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002390 IOCB_t *irsp;
2391 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002392 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002393 unsigned long flags;
2394 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002395
2396 psli = &phba->sli;
2397 /* we pass cmdiocb to state machine which needs rspiocb as well */
2398 cmdiocb->context_un.rsp_iocb = rspiocb;
2399
2400 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002401 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002402 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002403 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002404
James Smart858c9f62007-06-17 19:56:39 -05002405 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2406 "LOGO cmpl: status:x%x/x%x did:x%x",
2407 irsp->ulpStatus, irsp->un.ulpWord[4],
2408 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002409
dea31012005-04-17 16:05:31 -05002410 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002411 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2412 "0105 LOGO completes to NPort x%x "
2413 "Data: x%x x%x x%x x%x\n",
2414 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2415 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002416
James Smart086a3452012-08-14 14:25:21 -04002417 if (lpfc_els_chk_latt(vport)) {
2418 skip_recovery = 1;
2419 goto out;
2420 }
2421
2422 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002423 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2424 /* NLP_EVT_DEVICE_RM should unregister the RPI
2425 * which should abort all outstanding IOs.
2426 */
2427 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2428 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002429 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002430 goto out;
2431 }
2432
dea31012005-04-17 16:05:31 -05002433 if (irsp->ulpStatus) {
2434 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002435 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002436 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002437 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002438 goto out;
James Smart086a3452012-08-14 14:25:21 -04002439 }
dea31012005-04-17 16:05:31 -05002440 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002441 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2442 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2443 ndlp->nlp_DID, irsp->ulpStatus,
2444 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002445 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002446 if (lpfc_error_lost_link(irsp)) {
2447 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002448 goto out;
James Smart086a3452012-08-14 14:25:21 -04002449 }
2450 }
2451
2452 /* Call state machine. This will unregister the rpi if needed. */
2453 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2454
dea31012005-04-17 16:05:31 -05002455out:
2456 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002457 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2458 if ((vport->fc_flag & FC_PT2PT) &&
2459 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2460 phba->pport->fc_myDID = 0;
2461 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2462 if (mbox) {
2463 lpfc_config_link(phba, mbox);
2464 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2465 mbox->vport = vport;
2466 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2467 MBX_NOT_FINISHED) {
2468 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002469 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002470 }
2471 }
2472 }
James Smart086a3452012-08-14 14:25:21 -04002473
2474 /*
2475 * If the node is a target, the handling attempts to recover the port.
2476 * For any other port type, the rpi is unregistered as an implicit
2477 * LOGO.
2478 */
2479 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2480 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2481 spin_lock_irqsave(shost->host_lock, flags);
2482 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2483 spin_unlock_irqrestore(shost->host_lock, flags);
2484
2485 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2486 "3187 LOGO completes to NPort x%x: Start "
2487 "Recovery Data: x%x x%x x%x x%x\n",
2488 ndlp->nlp_DID, irsp->ulpStatus,
2489 irsp->un.ulpWord[4], irsp->ulpTimeout,
2490 vport->num_disc_nodes);
2491 lpfc_disc_start(vport);
2492 }
dea31012005-04-17 16:05:31 -05002493 return;
2494}
2495
James Smarte59058c2008-08-24 21:49:00 -04002496/**
James Smart3621a712009-04-06 18:47:14 -04002497 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002498 * @vport: pointer to a virtual N_Port data structure.
2499 * @ndlp: pointer to a node-list data structure.
2500 * @retry: number of retries to the command IOCB.
2501 *
2502 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2503 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2504 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2505 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2506 *
2507 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2508 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2509 * will be stored into the context1 field of the IOCB for the completion
2510 * callback function to the LOGO ELS command.
2511 *
2512 * Return code
2513 * 0 - successfully issued logo
2514 * 1 - failed to issue logo
2515 **/
dea31012005-04-17 16:05:31 -05002516int
James Smart2e0fef82007-06-17 19:56:36 -05002517lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002518 uint8_t retry)
2519{
James Smart2e0fef82007-06-17 19:56:36 -05002520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2521 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002522 IOCB_t *icmd;
2523 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002524 uint8_t *pcmd;
2525 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002526 int rc;
dea31012005-04-17 16:05:31 -05002527
James Smart98c9ea52007-10-27 13:37:33 -04002528 spin_lock_irq(shost->host_lock);
2529 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2530 spin_unlock_irq(shost->host_lock);
2531 return 0;
2532 }
2533 spin_unlock_irq(shost->host_lock);
2534
James Smart92d7f7b2007-06-17 19:56:38 -05002535 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002536 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2537 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002538 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002539 return 1;
dea31012005-04-17 16:05:31 -05002540
2541 icmd = &elsiocb->iocb;
2542 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2543 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002544 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002545
2546 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002547 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002548 pcmd += sizeof(uint32_t);
2549 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002550
James Smart858c9f62007-06-17 19:56:39 -05002551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2552 "Issue LOGO: did:x%x",
2553 ndlp->nlp_DID, 0, 0);
2554
James Smart086a3452012-08-14 14:25:21 -04002555 /*
2556 * If we are issuing a LOGO, we may try to recover the remote NPort
2557 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2558 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2559 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2560 * for that ELS cmd. To avoid this situation, lets get rid of the
2561 * RPI right now, before any ELS cmds are sent.
2562 */
2563 spin_lock_irq(shost->host_lock);
2564 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2565 spin_unlock_irq(shost->host_lock);
2566 if (lpfc_unreg_rpi(vport, ndlp)) {
2567 lpfc_els_free_iocb(phba, elsiocb);
2568 return 0;
2569 }
2570
dea31012005-04-17 16:05:31 -05002571 phba->fc_stat.elsXmitLOGO++;
2572 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002573 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002574 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002575 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002576 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002577 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002578
2579 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002580 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002581 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002582 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002583 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002584 return 1;
dea31012005-04-17 16:05:31 -05002585 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002586 return 0;
dea31012005-04-17 16:05:31 -05002587}
2588
James Smarte59058c2008-08-24 21:49:00 -04002589/**
James Smart3621a712009-04-06 18:47:14 -04002590 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002591 * @phba: pointer to lpfc hba data structure.
2592 * @cmdiocb: pointer to lpfc command iocb data structure.
2593 * @rspiocb: pointer to lpfc response iocb data structure.
2594 *
2595 * This routine is a generic completion callback function for ELS commands.
2596 * Specifically, it is the callback function which does not need to perform
2597 * any command specific operations. It is currently used by the ELS command
2598 * issuing routines for the ELS State Change Request (SCR),
2599 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2600 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2601 * certain debug loggings, this callback function simply invokes the
2602 * lpfc_els_chk_latt() routine to check whether link went down during the
2603 * discovery process.
2604 **/
dea31012005-04-17 16:05:31 -05002605static void
James Smart2e0fef82007-06-17 19:56:36 -05002606lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2607 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002608{
James Smart2e0fef82007-06-17 19:56:36 -05002609 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002610 IOCB_t *irsp;
2611
2612 irsp = &rspiocb->iocb;
2613
James Smart858c9f62007-06-17 19:56:39 -05002614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2615 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2616 irsp->ulpStatus, irsp->un.ulpWord[4],
2617 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002618 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002619 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2620 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2621 irsp->ulpIoTag, irsp->ulpStatus,
2622 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002623 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002624 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002625 lpfc_els_free_iocb(phba, cmdiocb);
2626 return;
2627}
2628
James Smarte59058c2008-08-24 21:49:00 -04002629/**
James Smart3621a712009-04-06 18:47:14 -04002630 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002631 * @vport: pointer to a host virtual N_Port data structure.
2632 * @nportid: N_Port identifier to the remote node.
2633 * @retry: number of retries to the command IOCB.
2634 *
2635 * This routine issues a State Change Request (SCR) to a fabric node
2636 * on a @vport. The remote node @nportid is passed into the function. It
2637 * first search the @vport node list to find the matching ndlp. If no such
2638 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2639 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2640 * routine is invoked to send the SCR IOCB.
2641 *
2642 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2643 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2644 * will be stored into the context1 field of the IOCB for the completion
2645 * callback function to the SCR ELS command.
2646 *
2647 * Return code
2648 * 0 - Successfully issued scr command
2649 * 1 - Failed to issue scr command
2650 **/
dea31012005-04-17 16:05:31 -05002651int
James Smart2e0fef82007-06-17 19:56:36 -05002652lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002653{
James Smart2e0fef82007-06-17 19:56:36 -05002654 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002655 IOCB_t *icmd;
2656 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002657 struct lpfc_sli *psli;
2658 uint8_t *pcmd;
2659 uint16_t cmdsize;
2660 struct lpfc_nodelist *ndlp;
2661
2662 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002663 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002664
James Smarte47c9092008-02-08 18:49:26 -05002665 ndlp = lpfc_findnode_did(vport, nportid);
2666 if (!ndlp) {
2667 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2668 if (!ndlp)
2669 return 1;
2670 lpfc_nlp_init(vport, ndlp, nportid);
2671 lpfc_enqueue_node(vport, ndlp);
2672 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2673 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2674 if (!ndlp)
2675 return 1;
2676 }
dea31012005-04-17 16:05:31 -05002677
James Smart2e0fef82007-06-17 19:56:36 -05002678 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2679 ndlp->nlp_DID, ELS_CMD_SCR);
2680
James Smart488d1462006-03-07 15:02:37 -05002681 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002682 /* This will trigger the release of the node just
2683 * allocated
2684 */
James Smart329f9bc2007-04-25 09:53:01 -04002685 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002686 return 1;
dea31012005-04-17 16:05:31 -05002687 }
2688
2689 icmd = &elsiocb->iocb;
2690 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2691
2692 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002693 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002694
2695 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002696 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002697 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2698
James Smart858c9f62007-06-17 19:56:39 -05002699 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2700 "Issue SCR: did:x%x",
2701 ndlp->nlp_DID, 0, 0);
2702
dea31012005-04-17 16:05:31 -05002703 phba->fc_stat.elsXmitSCR++;
2704 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002705 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2706 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002707 /* The additional lpfc_nlp_put will cause the following
2708 * lpfc_els_free_iocb routine to trigger the rlease of
2709 * the node.
2710 */
James Smart329f9bc2007-04-25 09:53:01 -04002711 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002712 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002713 return 1;
dea31012005-04-17 16:05:31 -05002714 }
James Smartfa4066b2008-01-11 01:53:27 -05002715 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2716 * trigger the release of node.
2717 */
James Smart329f9bc2007-04-25 09:53:01 -04002718 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002719 return 0;
dea31012005-04-17 16:05:31 -05002720}
2721
James Smarte59058c2008-08-24 21:49:00 -04002722/**
James Smart3621a712009-04-06 18:47:14 -04002723 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002724 * @vport: pointer to a host virtual N_Port data structure.
2725 * @nportid: N_Port identifier to the remote node.
2726 * @retry: number of retries to the command IOCB.
2727 *
2728 * This routine issues a Fibre Channel Address Resolution Response
2729 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2730 * is passed into the function. It first search the @vport node list to find
2731 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2732 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2733 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2734 *
2735 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2736 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2737 * will be stored into the context1 field of the IOCB for the completion
2738 * callback function to the PARPR ELS command.
2739 *
2740 * Return code
2741 * 0 - Successfully issued farpr command
2742 * 1 - Failed to issue farpr command
2743 **/
dea31012005-04-17 16:05:31 -05002744static int
James Smart2e0fef82007-06-17 19:56:36 -05002745lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002746{
James Smart2e0fef82007-06-17 19:56:36 -05002747 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002748 IOCB_t *icmd;
2749 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002750 struct lpfc_sli *psli;
2751 FARP *fp;
2752 uint8_t *pcmd;
2753 uint32_t *lp;
2754 uint16_t cmdsize;
2755 struct lpfc_nodelist *ondlp;
2756 struct lpfc_nodelist *ndlp;
2757
2758 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002759 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002760
James Smarte47c9092008-02-08 18:49:26 -05002761 ndlp = lpfc_findnode_did(vport, nportid);
2762 if (!ndlp) {
2763 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2764 if (!ndlp)
2765 return 1;
2766 lpfc_nlp_init(vport, ndlp, nportid);
2767 lpfc_enqueue_node(vport, ndlp);
2768 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2769 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2770 if (!ndlp)
2771 return 1;
2772 }
James Smart2e0fef82007-06-17 19:56:36 -05002773
2774 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2775 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002776 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002777 /* This will trigger the release of the node just
2778 * allocated
2779 */
James Smart329f9bc2007-04-25 09:53:01 -04002780 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002781 return 1;
dea31012005-04-17 16:05:31 -05002782 }
2783
2784 icmd = &elsiocb->iocb;
2785 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2786
2787 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002788 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002789
2790 /* Fill in FARPR payload */
2791 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002792 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002793 lp = (uint32_t *) pcmd;
2794 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002795 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002796 fp->Rflags = 0;
2797 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2798
James Smart92d7f7b2007-06-17 19:56:38 -05002799 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2800 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002801 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002802 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002803 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002804 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002805 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002806 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002807 }
2808
James Smart858c9f62007-06-17 19:56:39 -05002809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2810 "Issue FARPR: did:x%x",
2811 ndlp->nlp_DID, 0, 0);
2812
dea31012005-04-17 16:05:31 -05002813 phba->fc_stat.elsXmitFARPR++;
2814 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002815 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2816 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002817 /* The additional lpfc_nlp_put will cause the following
2818 * lpfc_els_free_iocb routine to trigger the release of
2819 * the node.
2820 */
James Smart329f9bc2007-04-25 09:53:01 -04002821 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002822 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002823 return 1;
dea31012005-04-17 16:05:31 -05002824 }
James Smartfa4066b2008-01-11 01:53:27 -05002825 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2826 * trigger the release of the node.
2827 */
James Smart329f9bc2007-04-25 09:53:01 -04002828 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002829 return 0;
dea31012005-04-17 16:05:31 -05002830}
2831
James Smarte59058c2008-08-24 21:49:00 -04002832/**
James Smart3621a712009-04-06 18:47:14 -04002833 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002834 * @vport: pointer to a host virtual N_Port data structure.
2835 * @nlp: pointer to a node-list data structure.
2836 *
2837 * This routine cancels the timer with a delayed IOCB-command retry for
2838 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2839 * removes the ELS retry event if it presents. In addition, if the
2840 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2841 * commands are sent for the @vport's nodes that require issuing discovery
2842 * ADISC.
2843 **/
dea31012005-04-17 16:05:31 -05002844void
James Smart2e0fef82007-06-17 19:56:36 -05002845lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002846{
James Smart2e0fef82007-06-17 19:56:36 -05002847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002848 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002849
James Smart0d2b6b82008-06-14 22:52:47 -04002850 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2851 return;
James Smart2e0fef82007-06-17 19:56:36 -05002852 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002853 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002854 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002855 del_timer_sync(&nlp->nlp_delayfunc);
2856 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002857 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002858 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002859 /* Decrement nlp reference count held for the delayed retry */
2860 evtp = &nlp->els_retry_evt;
2861 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2862 }
James Smartfdcebe22006-03-07 15:04:01 -05002863 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002865 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002866 spin_unlock_irq(shost->host_lock);
2867 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002868 if (vport->port_state < LPFC_VPORT_READY) {
2869 /* Check if there are more ADISCs to be sent */
2870 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002871 } else {
2872 /* Check if there are more PLOGIs to be sent */
2873 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002874 if (vport->num_disc_nodes == 0) {
2875 spin_lock_irq(shost->host_lock);
2876 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2877 spin_unlock_irq(shost->host_lock);
2878 lpfc_can_disctmo(vport);
2879 lpfc_end_rscn(vport);
2880 }
James Smartfdcebe22006-03-07 15:04:01 -05002881 }
2882 }
2883 }
2884 return;
2885}
2886
James Smarte59058c2008-08-24 21:49:00 -04002887/**
James Smart3621a712009-04-06 18:47:14 -04002888 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002889 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2890 *
2891 * This routine is invoked by the ndlp delayed-function timer to check
2892 * whether there is any pending ELS retry event(s) with the node. If not, it
2893 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2894 * adds the delayed events to the HBA work list and invokes the
2895 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2896 * event. Note that lpfc_nlp_get() is called before posting the event to
2897 * the work list to hold reference count of ndlp so that it guarantees the
2898 * reference to ndlp will still be available when the worker thread gets
2899 * to the event associated with the ndlp.
2900 **/
James Smartfdcebe22006-03-07 15:04:01 -05002901void
dea31012005-04-17 16:05:31 -05002902lpfc_els_retry_delay(unsigned long ptr)
2903{
James Smart2e0fef82007-06-17 19:56:36 -05002904 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2905 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002906 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002907 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002908 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002909
James Smart92d7f7b2007-06-17 19:56:38 -05002910 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002911 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002912 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002913 return;
2914 }
2915
James Smartfa4066b2008-01-11 01:53:27 -05002916 /* We need to hold the node by incrementing the reference
2917 * count until the queued work is done
2918 */
2919 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002920 if (evtp->evt_arg1) {
2921 evtp->evt = LPFC_EVT_ELS_RETRY;
2922 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002923 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002924 }
James Smart92d7f7b2007-06-17 19:56:38 -05002925 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002926 return;
2927}
2928
James Smarte59058c2008-08-24 21:49:00 -04002929/**
James Smart3621a712009-04-06 18:47:14 -04002930 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002931 * @ndlp: pointer to a node-list data structure.
2932 *
2933 * This routine is the worker-thread handler for processing the @ndlp delayed
2934 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2935 * the last ELS command from the associated ndlp and invokes the proper ELS
2936 * function according to the delayed ELS command to retry the command.
2937 **/
dea31012005-04-17 16:05:31 -05002938void
2939lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2940{
James Smart2e0fef82007-06-17 19:56:36 -05002941 struct lpfc_vport *vport = ndlp->vport;
2942 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2943 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002944
James Smart2e0fef82007-06-17 19:56:36 -05002945 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002946 did = ndlp->nlp_DID;
2947 cmd = ndlp->nlp_last_elscmd;
2948 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002949
2950 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002951 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002952 return;
2953 }
2954
2955 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002956 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002957 /*
2958 * If a discovery event readded nlp_delayfunc after timer
2959 * firing and before processing the timer, cancel the
2960 * nlp_delayfunc.
2961 */
2962 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002963 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002964 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002965
2966 switch (cmd) {
2967 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002968 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002969 break;
2970 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002971 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002972 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002973 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002974 }
dea31012005-04-17 16:05:31 -05002975 break;
2976 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002977 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002978 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002980 }
dea31012005-04-17 16:05:31 -05002981 break;
2982 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002983 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002984 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002985 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002986 }
dea31012005-04-17 16:05:31 -05002987 break;
2988 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002989 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002990 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04002991 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002992 }
dea31012005-04-17 16:05:31 -05002993 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002994 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002995 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2996 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002997 break;
dea31012005-04-17 16:05:31 -05002998 }
2999 return;
3000}
3001
James Smarte59058c2008-08-24 21:49:00 -04003002/**
James Smart3621a712009-04-06 18:47:14 -04003003 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003004 * @phba: pointer to lpfc hba data structure.
3005 * @cmdiocb: pointer to lpfc command iocb data structure.
3006 * @rspiocb: pointer to lpfc response iocb data structure.
3007 *
3008 * This routine makes a retry decision on an ELS command IOCB, which has
3009 * failed. The following ELS IOCBs use this function for retrying the command
3010 * when previously issued command responsed with error status: FLOGI, PLOGI,
3011 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3012 * returned error status, it makes the decision whether a retry shall be
3013 * issued for the command, and whether a retry shall be made immediately or
3014 * delayed. In the former case, the corresponding ELS command issuing-function
3015 * is called to retry the command. In the later case, the ELS command shall
3016 * be posted to the ndlp delayed event and delayed function timer set to the
3017 * ndlp for the delayed command issusing.
3018 *
3019 * Return code
3020 * 0 - No retry of els command is made
3021 * 1 - Immediate or delayed retry of els command is made
3022 **/
dea31012005-04-17 16:05:31 -05003023static int
James Smart2e0fef82007-06-17 19:56:36 -05003024lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3025 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003026{
James Smart2e0fef82007-06-17 19:56:36 -05003027 struct lpfc_vport *vport = cmdiocb->vport;
3028 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3029 IOCB_t *irsp = &rspiocb->iocb;
3030 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3031 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003032 uint32_t *elscmd;
3033 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003034 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003035 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003036 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003037 uint32_t did;
dea31012005-04-17 16:05:31 -05003038
James Smart488d1462006-03-07 15:02:37 -05003039
dea31012005-04-17 16:05:31 -05003040 /* Note: context2 may be 0 for internal driver abort
3041 * of delays ELS command.
3042 */
3043
3044 if (pcmd && pcmd->virt) {
3045 elscmd = (uint32_t *) (pcmd->virt);
3046 cmd = *elscmd++;
3047 }
3048
James Smarte47c9092008-02-08 18:49:26 -05003049 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003050 did = ndlp->nlp_DID;
3051 else {
3052 /* We should only hit this case for retrying PLOGI */
3053 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003054 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003055 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3056 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003057 return 1;
3058 }
3059
James Smart858c9f62007-06-17 19:56:39 -05003060 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3061 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3062 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3063
dea31012005-04-17 16:05:31 -05003064 switch (irsp->ulpStatus) {
3065 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003066 break;
James Smart1151e3e2011-02-16 12:39:35 -05003067 case IOSTAT_REMOTE_STOP:
3068 if (phba->sli_rev == LPFC_SLI_REV4) {
3069 /* This IO was aborted by the target, we don't
3070 * know the rxid and because we did not send the
3071 * ABTS we cannot generate and RRQ.
3072 */
3073 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003074 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003075 }
3076 break;
dea31012005-04-17 16:05:31 -05003077 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003078 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003079 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003080 if (cmd == ELS_CMD_FLOGI) {
3081 if (PCI_DEVICE_ID_HORNET ==
3082 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003083 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003084 phba->pport->fc_myDID = 0;
3085 phba->alpa_map[0] = 0;
3086 phba->alpa_map[1] = 0;
3087 }
3088 }
James Smart2e0fef82007-06-17 19:56:36 -05003089 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003090 delay = 1000;
dea31012005-04-17 16:05:31 -05003091 retry = 1;
3092 break;
3093
James Smart92d7f7b2007-06-17 19:56:38 -05003094 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003095 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3096 "0124 Retry illegal cmd x%x "
3097 "retry:x%x delay:x%x\n",
3098 cmd, cmdiocb->retry, delay);
3099 retry = 1;
3100 /* All command's retry policy */
3101 maxretry = 8;
3102 if (cmdiocb->retry > 2)
3103 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003104 break;
3105
dea31012005-04-17 16:05:31 -05003106 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003107 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003108 retry = 1;
3109 if (cmdiocb->retry > 100)
3110 delay = 100;
3111 maxretry = 250;
3112 break;
3113
3114 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003115 delay = 100;
dea31012005-04-17 16:05:31 -05003116 retry = 1;
3117 break;
3118
James Smart858c9f62007-06-17 19:56:39 -05003119 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003120 case IOERR_INVALID_RPI:
3121 retry = 1;
3122 break;
3123 }
3124 break;
3125
3126 case IOSTAT_NPORT_RJT:
3127 case IOSTAT_FABRIC_RJT:
3128 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3129 retry = 1;
3130 break;
3131 }
3132 break;
3133
3134 case IOSTAT_NPORT_BSY:
3135 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003136 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003137 retry = 1;
3138 break;
3139
3140 case IOSTAT_LS_RJT:
3141 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3142 /* Added for Vendor specifc support
3143 * Just keep retrying for these Rsn / Exp codes
3144 */
3145 switch (stat.un.b.lsRjtRsnCode) {
3146 case LSRJT_UNABLE_TPC:
3147 if (stat.un.b.lsRjtRsnCodeExp ==
3148 LSEXP_CMD_IN_PROGRESS) {
3149 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003150 delay = 1000;
dea31012005-04-17 16:05:31 -05003151 maxretry = 48;
3152 }
3153 retry = 1;
3154 break;
3155 }
James Smartffc95492010-06-07 15:23:17 -04003156 if (stat.un.b.lsRjtRsnCodeExp ==
3157 LSEXP_CANT_GIVE_DATA) {
3158 if (cmd == ELS_CMD_PLOGI) {
3159 delay = 1000;
3160 maxretry = 48;
3161 }
3162 retry = 1;
3163 break;
3164 }
James Smart4c1b64b2012-09-29 11:31:11 -04003165 if ((cmd == ELS_CMD_PLOGI) ||
3166 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003167 delay = 1000;
dea31012005-04-17 16:05:31 -05003168 maxretry = lpfc_max_els_tries + 1;
3169 retry = 1;
3170 break;
3171 }
James Smart92d7f7b2007-06-17 19:56:38 -05003172 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3173 (cmd == ELS_CMD_FDISC) &&
3174 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003175 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3176 "0125 FDISC Failed (x%x). "
3177 "Fabric out of resources\n",
3178 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003179 lpfc_vport_set_state(vport,
3180 FC_VPORT_NO_FABRIC_RSCS);
3181 }
dea31012005-04-17 16:05:31 -05003182 break;
3183
3184 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003185 if ((cmd == ELS_CMD_PLOGI) ||
3186 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003187 delay = 1000;
dea31012005-04-17 16:05:31 -05003188 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003189 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003190 /* FDISC retry policy */
3191 maxretry = 48;
3192 if (cmdiocb->retry >= 32)
3193 delay = 1000;
dea31012005-04-17 16:05:31 -05003194 }
3195 retry = 1;
3196 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003197
3198 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003199 /* There are some cases where switches return this
3200 * error when they are not ready and should be returning
3201 * Logical Busy. We should delay every time.
3202 */
3203 if (cmd == ELS_CMD_FDISC &&
3204 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3205 maxretry = 3;
3206 delay = 1000;
3207 retry = 1;
3208 break;
3209 }
James Smart92d7f7b2007-06-17 19:56:38 -05003210 case LSRJT_PROTOCOL_ERR:
3211 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3212 (cmd == ELS_CMD_FDISC) &&
3213 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3214 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3215 ) {
James Smarte8b62012007-08-02 11:10:09 -04003216 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003217 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003218 "Fabric Detected Bad WWN\n",
3219 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003220 lpfc_vport_set_state(vport,
3221 FC_VPORT_FABRIC_REJ_WWN);
3222 }
3223 break;
dea31012005-04-17 16:05:31 -05003224 }
3225 break;
3226
3227 case IOSTAT_INTERMED_RSP:
3228 case IOSTAT_BA_RJT:
3229 break;
3230
3231 default:
3232 break;
3233 }
3234
James Smart488d1462006-03-07 15:02:37 -05003235 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003236 retry = 1;
dea31012005-04-17 16:05:31 -05003237
James Smartdf9e1b52011-12-13 13:22:17 -05003238 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003239 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003240 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003241 /* FLOGI retry policy */
3242 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003243 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003244 maxretry = 0;
3245 if (cmdiocb->retry >= 100)
3246 delay = 5000;
3247 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003248 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003249 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3250 /* retry FDISCs every second up to devloss */
3251 retry = 1;
3252 maxretry = vport->cfg_devloss_tmo;
3253 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003254 }
3255
James Smart6669f9b2009-10-02 15:16:45 -04003256 cmdiocb->retry++;
3257 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003258 phba->fc_stat.elsRetryExceeded++;
3259 retry = 0;
3260 }
3261
James Smarted957682007-06-17 19:56:37 -05003262 if ((vport->load_flag & FC_UNLOADING) != 0)
3263 retry = 0;
3264
dea31012005-04-17 16:05:31 -05003265 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003266 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3267 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3268 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3269 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3270 "2849 Stop retry ELS command "
3271 "x%x to remote NPORT x%x, "
3272 "Data: x%x x%x\n", cmd, did,
3273 cmdiocb->retry, delay);
3274 return 0;
3275 }
3276 }
dea31012005-04-17 16:05:31 -05003277
3278 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003279 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3280 "0107 Retry ELS command x%x to remote "
3281 "NPORT x%x Data: x%x x%x\n",
3282 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003283
James Smart858c9f62007-06-17 19:56:39 -05003284 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3285 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003286 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3287 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003288 /* Don't reset timer for no resources */
3289
dea31012005-04-17 16:05:31 -05003290 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003291 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003292 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003293 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003294 }
3295
3296 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003297 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003298 phba->fc_stat.elsDelayRetry++;
3299 ndlp->nlp_retry = cmdiocb->retry;
3300
James Smart92d7f7b2007-06-17 19:56:38 -05003301 /* delay is specified in milliseconds */
3302 mod_timer(&ndlp->nlp_delayfunc,
3303 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003304 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003305 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003306 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003307
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003308 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003309 if (cmd == ELS_CMD_PRLI)
3310 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003311 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003312 else
3313 lpfc_nlp_set_state(vport, ndlp,
3314 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003315 ndlp->nlp_last_elscmd = cmd;
3316
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003317 return 1;
dea31012005-04-17 16:05:31 -05003318 }
3319 switch (cmd) {
3320 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003321 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003322 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003323 case ELS_CMD_FDISC:
3324 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3325 return 1;
dea31012005-04-17 16:05:31 -05003326 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003327 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003328 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003329 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003330 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003331 }
James Smart2e0fef82007-06-17 19:56:36 -05003332 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003333 return 1;
dea31012005-04-17 16:05:31 -05003334 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003335 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003336 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3337 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003338 return 1;
dea31012005-04-17 16:05:31 -05003339 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003340 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003341 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3342 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003343 return 1;
dea31012005-04-17 16:05:31 -05003344 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003345 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003346 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003347 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003348 return 1;
dea31012005-04-17 16:05:31 -05003349 }
3350 }
dea31012005-04-17 16:05:31 -05003351 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003352 if (logerr) {
3353 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3354 "0137 No retry ELS command x%x to remote "
3355 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3356 cmd, did, irsp->ulpStatus,
3357 irsp->un.ulpWord[4]);
3358 }
3359 else {
3360 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003361 "0108 No retry ELS command x%x to remote "
3362 "NPORT x%x Retried:%d Error:x%x/%x\n",
3363 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3364 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003365 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003366 return 0;
dea31012005-04-17 16:05:31 -05003367}
3368
James Smarte59058c2008-08-24 21:49:00 -04003369/**
James Smart3621a712009-04-06 18:47:14 -04003370 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003371 * @phba: pointer to lpfc hba data structure.
3372 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3373 *
3374 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3375 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3376 * checks to see whether there is a lpfc DMA buffer associated with the
3377 * response of the command IOCB. If so, it will be released before releasing
3378 * the lpfc DMA buffer associated with the IOCB itself.
3379 *
3380 * Return code
3381 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3382 **/
James Smart09372822008-01-11 01:52:54 -05003383static int
James Smart87af33f2007-10-27 13:37:43 -04003384lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3385{
3386 struct lpfc_dmabuf *buf_ptr;
3387
James Smarte59058c2008-08-24 21:49:00 -04003388 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003389 if (!list_empty(&buf_ptr1->list)) {
3390 list_remove_head(&buf_ptr1->list, buf_ptr,
3391 struct lpfc_dmabuf,
3392 list);
3393 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3394 kfree(buf_ptr);
3395 }
3396 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3397 kfree(buf_ptr1);
3398 return 0;
3399}
3400
James Smarte59058c2008-08-24 21:49:00 -04003401/**
James Smart3621a712009-04-06 18:47:14 -04003402 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003403 * @phba: pointer to lpfc hba data structure.
3404 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3405 *
3406 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3407 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3408 * pool.
3409 *
3410 * Return code
3411 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3412 **/
James Smart09372822008-01-11 01:52:54 -05003413static int
James Smart87af33f2007-10-27 13:37:43 -04003414lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3415{
3416 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3417 kfree(buf_ptr);
3418 return 0;
3419}
3420
James Smarte59058c2008-08-24 21:49:00 -04003421/**
James Smart3621a712009-04-06 18:47:14 -04003422 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003423 * @phba: pointer to lpfc hba data structure.
3424 * @elsiocb: pointer to lpfc els command iocb data structure.
3425 *
3426 * This routine frees a command IOCB and its associated resources. The
3427 * command IOCB data structure contains the reference to various associated
3428 * resources, these fields must be set to NULL if the associated reference
3429 * not present:
3430 * context1 - reference to ndlp
3431 * context2 - reference to cmd
3432 * context2->next - reference to rsp
3433 * context3 - reference to bpl
3434 *
3435 * It first properly decrements the reference count held on ndlp for the
3436 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3437 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3438 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3439 * adds the DMA buffer the @phba data structure for the delayed release.
3440 * If reference to the Buffer Pointer List (BPL) is present, the
3441 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3442 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3443 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3444 *
3445 * Return code
3446 * 0 - Success (currently, always return 0)
3447 **/
James Smart87af33f2007-10-27 13:37:43 -04003448int
James Smart329f9bc2007-04-25 09:53:01 -04003449lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003450{
3451 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003452 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003453
James Smarta8adb832007-10-27 13:37:53 -04003454 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3455 if (ndlp) {
3456 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3457 lpfc_nlp_put(ndlp);
3458
3459 /* If the ndlp is not being used by another discovery
3460 * thread, free it.
3461 */
3462 if (!lpfc_nlp_not_used(ndlp)) {
3463 /* If ndlp is being used by another discovery
3464 * thread, just clear NLP_DEFER_RM
3465 */
3466 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3467 }
3468 }
3469 else
3470 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003471 elsiocb->context1 = NULL;
3472 }
dea31012005-04-17 16:05:31 -05003473 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3474 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003475 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3476 /* Firmware could still be in progress of DMAing
3477 * payload, so don't free data buffer till after
3478 * a hbeat.
3479 */
3480 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3481 buf_ptr = elsiocb->context2;
3482 elsiocb->context2 = NULL;
3483 if (buf_ptr) {
3484 buf_ptr1 = NULL;
3485 spin_lock_irq(&phba->hbalock);
3486 if (!list_empty(&buf_ptr->list)) {
3487 list_remove_head(&buf_ptr->list,
3488 buf_ptr1, struct lpfc_dmabuf,
3489 list);
3490 INIT_LIST_HEAD(&buf_ptr1->list);
3491 list_add_tail(&buf_ptr1->list,
3492 &phba->elsbuf);
3493 phba->elsbuf_cnt++;
3494 }
3495 INIT_LIST_HEAD(&buf_ptr->list);
3496 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3497 phba->elsbuf_cnt++;
3498 spin_unlock_irq(&phba->hbalock);
3499 }
3500 } else {
3501 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3502 lpfc_els_free_data(phba, buf_ptr1);
3503 }
dea31012005-04-17 16:05:31 -05003504 }
3505
3506 if (elsiocb->context3) {
3507 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003508 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003509 }
James Bottomley604a3e32005-10-29 10:28:33 -05003510 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003511 return 0;
3512}
3513
James Smarte59058c2008-08-24 21:49:00 -04003514/**
James Smart3621a712009-04-06 18:47:14 -04003515 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003516 * @phba: pointer to lpfc hba data structure.
3517 * @cmdiocb: pointer to lpfc command iocb data structure.
3518 * @rspiocb: pointer to lpfc response iocb data structure.
3519 *
3520 * This routine is the completion callback function to the Logout (LOGO)
3521 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3522 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3523 * release the ndlp if it has the last reference remaining (reference count
3524 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3525 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3526 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3527 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3528 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3529 * IOCB data structure.
3530 **/
dea31012005-04-17 16:05:31 -05003531static void
James Smart2e0fef82007-06-17 19:56:36 -05003532lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3533 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003534{
James Smart2e0fef82007-06-17 19:56:36 -05003535 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3536 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003537 IOCB_t *irsp;
3538
3539 irsp = &rspiocb->iocb;
3540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3541 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3542 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003543 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003544 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3545 "0109 ACC to LOGO completes to NPort x%x "
3546 "Data: x%x x%x x%x\n",
3547 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3548 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003549
3550 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3551 /* NPort Recovery mode or node is just allocated */
3552 if (!lpfc_nlp_not_used(ndlp)) {
3553 /* If the ndlp is being used by another discovery
3554 * thread, just unregister the RPI.
3555 */
3556 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003557 } else {
3558 /* Indicate the node has already released, should
3559 * not reference to it from within lpfc_els_free_iocb.
3560 */
3561 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003562 }
dea31012005-04-17 16:05:31 -05003563 }
James Smart73d91e52011-10-10 21:32:10 -04003564
3565 /*
3566 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003567 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003568 */
dea31012005-04-17 16:05:31 -05003569 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003570
3571 /*
3572 * Remove the ndlp reference if it's a fabric node that has
3573 * sent us an unsolicted LOGO.
3574 */
3575 if (ndlp->nlp_type & NLP_FABRIC)
3576 lpfc_nlp_put(ndlp);
3577
dea31012005-04-17 16:05:31 -05003578 return;
3579}
3580
James Smarte59058c2008-08-24 21:49:00 -04003581/**
James Smart3621a712009-04-06 18:47:14 -04003582 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003583 * @phba: pointer to lpfc hba data structure.
3584 * @pmb: pointer to the driver internal queue element for mailbox command.
3585 *
3586 * This routine is the completion callback function for unregister default
3587 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3588 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3589 * decrements the ndlp reference count held for this completion callback
3590 * function. After that, it invokes the lpfc_nlp_not_used() to check
3591 * whether there is only one reference left on the ndlp. If so, it will
3592 * perform one more decrement and trigger the release of the ndlp.
3593 **/
James Smart858c9f62007-06-17 19:56:39 -05003594void
3595lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3596{
3597 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3598 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3599
3600 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003601 pmb->context2 = NULL;
3602
James Smart858c9f62007-06-17 19:56:39 -05003603 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3604 kfree(mp);
3605 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003606 if (ndlp) {
3607 if (NLP_CHK_NODE_ACT(ndlp)) {
3608 lpfc_nlp_put(ndlp);
3609 /* This is the end of the default RPI cleanup logic for
3610 * this ndlp. If no other discovery threads are using
3611 * this ndlp, free all resources associated with it.
3612 */
3613 lpfc_nlp_not_used(ndlp);
3614 } else {
3615 lpfc_drop_node(ndlp->vport, ndlp);
3616 }
James Smarta8adb832007-10-27 13:37:53 -04003617 }
James Smart3772a992009-05-22 14:50:54 -04003618
James Smart858c9f62007-06-17 19:56:39 -05003619 return;
3620}
3621
James Smarte59058c2008-08-24 21:49:00 -04003622/**
James Smart3621a712009-04-06 18:47:14 -04003623 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003624 * @phba: pointer to lpfc hba data structure.
3625 * @cmdiocb: pointer to lpfc command iocb data structure.
3626 * @rspiocb: pointer to lpfc response iocb data structure.
3627 *
3628 * This routine is the completion callback function for ELS Response IOCB
3629 * command. In normal case, this callback function just properly sets the
3630 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3631 * field in the command IOCB is not NULL, the referred mailbox command will
3632 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3633 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3634 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3635 * routine shall be invoked trying to release the ndlp if no other threads
3636 * are currently referring it.
3637 **/
dea31012005-04-17 16:05:31 -05003638static void
James Smart858c9f62007-06-17 19:56:39 -05003639lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003640 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003641{
James Smart2e0fef82007-06-17 19:56:36 -05003642 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3643 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3644 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003645 IOCB_t *irsp;
3646 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003647 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003648 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003649 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003650
James Smart33ccf8d2006-08-17 11:57:58 -04003651 irsp = &rspiocb->iocb;
3652
dea31012005-04-17 16:05:31 -05003653 if (cmdiocb->context_un.mbox)
3654 mbox = cmdiocb->context_un.mbox;
3655
James Smartfa4066b2008-01-11 01:53:27 -05003656 /* First determine if this is a LS_RJT cmpl. Note, this callback
3657 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3658 */
James Smart87af33f2007-10-27 13:37:43 -04003659 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003660 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3661 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003662 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003663 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003664 */
3665 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3666 ls_rjt = 1;
3667 }
3668
dea31012005-04-17 16:05:31 -05003669 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003670 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003671 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003672 mp = (struct lpfc_dmabuf *) mbox->context1;
3673 if (mp) {
3674 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3675 kfree(mp);
3676 }
James Smart329f9bc2007-04-25 09:53:01 -04003677 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003678 }
James Smart58da1ff2008-04-07 10:15:56 -04003679 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3680 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003681 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003682 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003683 /* Indicate the node has already released,
3684 * should not reference to it from within
3685 * the routine lpfc_els_free_iocb.
3686 */
3687 cmdiocb->context1 = NULL;
3688 }
dea31012005-04-17 16:05:31 -05003689 goto out;
3690 }
3691
James Smart858c9f62007-06-17 19:56:39 -05003692 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003693 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003694 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003695 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003696 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003697 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3698 "0110 ELS response tag x%x completes "
3699 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3700 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3701 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3702 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3703 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003704 if (mbox) {
3705 if ((rspiocb->iocb.ulpStatus == 0)
3706 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003707 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003708 /* Increment reference count to ndlp to hold the
3709 * reference to ndlp for the callback function.
3710 */
James Smart329f9bc2007-04-25 09:53:01 -04003711 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003712 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003713 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3714 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3715 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3716 }
3717 else {
3718 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3719 ndlp->nlp_prev_state = ndlp->nlp_state;
3720 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003721 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003722 }
James Smart0b727fe2007-10-27 13:37:25 -04003723 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003724 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003725 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003726 else
3727 /* Decrement the ndlp reference count we
3728 * set for this failed mailbox command.
3729 */
3730 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003731
3732 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3733 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3734 "0138 ELS rsp: Cannot issue reg_login for x%x "
3735 "Data: x%x x%x x%x\n",
3736 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3737 ndlp->nlp_rpi);
3738
James Smartfa4066b2008-01-11 01:53:27 -05003739 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003740 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003741 /* Indicate node has already been released,
3742 * should not reference to it from within
3743 * the routine lpfc_els_free_iocb.
3744 */
3745 cmdiocb->context1 = NULL;
3746 }
dea31012005-04-17 16:05:31 -05003747 } else {
James Smart858c9f62007-06-17 19:56:39 -05003748 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3749 if (!lpfc_error_lost_link(irsp) &&
3750 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003751 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003752 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003753 /* Indicate node has already been
3754 * released, should not reference
3755 * to it from within the routine
3756 * lpfc_els_free_iocb.
3757 */
3758 cmdiocb->context1 = NULL;
3759 }
dea31012005-04-17 16:05:31 -05003760 }
3761 }
James Smart14691152006-12-02 13:34:28 -05003762 mp = (struct lpfc_dmabuf *) mbox->context1;
3763 if (mp) {
3764 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3765 kfree(mp);
3766 }
3767 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003768 }
3769out:
James Smart58da1ff2008-04-07 10:15:56 -04003770 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003771 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003772 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003773 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003774
3775 /* If the node is not being used by another discovery thread,
3776 * and we are sending a reject, we are done with it.
3777 * Release driver reference count here and free associated
3778 * resources.
3779 */
3780 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003781 if (lpfc_nlp_not_used(ndlp))
3782 /* Indicate node has already been released,
3783 * should not reference to it from within
3784 * the routine lpfc_els_free_iocb.
3785 */
3786 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003787 }
James Smart87af33f2007-10-27 13:37:43 -04003788
dea31012005-04-17 16:05:31 -05003789 lpfc_els_free_iocb(phba, cmdiocb);
3790 return;
3791}
3792
James Smarte59058c2008-08-24 21:49:00 -04003793/**
James Smart3621a712009-04-06 18:47:14 -04003794 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003795 * @vport: pointer to a host virtual N_Port data structure.
3796 * @flag: the els command code to be accepted.
3797 * @oldiocb: pointer to the original lpfc command iocb data structure.
3798 * @ndlp: pointer to a node-list data structure.
3799 * @mbox: pointer to the driver internal queue element for mailbox command.
3800 *
3801 * This routine prepares and issues an Accept (ACC) response IOCB
3802 * command. It uses the @flag to properly set up the IOCB field for the
3803 * specific ACC response command to be issued and invokes the
3804 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3805 * @mbox pointer is passed in, it will be put into the context_un.mbox
3806 * field of the IOCB for the completion callback function to issue the
3807 * mailbox command to the HBA later when callback is invoked.
3808 *
3809 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3810 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3811 * will be stored into the context1 field of the IOCB for the completion
3812 * callback function to the corresponding response ELS IOCB command.
3813 *
3814 * Return code
3815 * 0 - Successfully issued acc response
3816 * 1 - Failed to issue acc response
3817 **/
dea31012005-04-17 16:05:31 -05003818int
James Smart2e0fef82007-06-17 19:56:36 -05003819lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3820 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003821 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003822{
James Smart2e0fef82007-06-17 19:56:36 -05003823 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3824 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003825 IOCB_t *icmd;
3826 IOCB_t *oldcmd;
3827 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003828 struct lpfc_sli *psli;
3829 uint8_t *pcmd;
3830 uint16_t cmdsize;
3831 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003832 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003833
3834 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003835 oldcmd = &oldiocb->iocb;
3836
3837 switch (flag) {
3838 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003839 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003840 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3841 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003842 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003843 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003844 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003845 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003846 return 1;
dea31012005-04-17 16:05:31 -05003847 }
James Smart2e0fef82007-06-17 19:56:36 -05003848
dea31012005-04-17 16:05:31 -05003849 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003850 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3851 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003852 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3853 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003854 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003855
3856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3857 "Issue ACC: did:x%x flg:x%x",
3858 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003859 break;
3860 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003861 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003862 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3863 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003864 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003865 return 1;
James Smart488d1462006-03-07 15:02:37 -05003866
dea31012005-04-17 16:05:31 -05003867 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003868 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3869 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003870 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3871
3872 if (mbox)
3873 elsiocb->context_un.mbox = mbox;
3874
3875 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003876 pcmd += sizeof(uint32_t);
3877 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003878
3879 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3880 "Issue ACC PLOGI: did:x%x flg:x%x",
3881 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003882 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003883 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003884 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003885 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003886 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3887 if (!elsiocb)
3888 return 1;
3889
3890 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003891 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3892 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003893 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3894
3895 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003896 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003897 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3898 els_pkt_ptr = (ELS_PKT *) pcmd;
3899 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003900
3901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3902 "Issue ACC PRLO: did:x%x flg:x%x",
3903 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003904 break;
dea31012005-04-17 16:05:31 -05003905 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003906 return 1;
dea31012005-04-17 16:05:31 -05003907 }
dea31012005-04-17 16:05:31 -05003908 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3910 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003911 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3912 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003913 elsiocb->iotag, elsiocb->iocb.ulpContext,
3914 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003915 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003916 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003917 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003918 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003919 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003920 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3921 } else {
James Smart858c9f62007-06-17 19:56:39 -05003922 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003923 }
3924
3925 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003926 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003927 if (rc == IOCB_ERROR) {
3928 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003929 return 1;
dea31012005-04-17 16:05:31 -05003930 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003931 return 0;
dea31012005-04-17 16:05:31 -05003932}
3933
James Smarte59058c2008-08-24 21:49:00 -04003934/**
James Smart3621a712009-04-06 18:47:14 -04003935 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003936 * @vport: pointer to a virtual N_Port data structure.
3937 * @rejectError:
3938 * @oldiocb: pointer to the original lpfc command iocb data structure.
3939 * @ndlp: pointer to a node-list data structure.
3940 * @mbox: pointer to the driver internal queue element for mailbox command.
3941 *
3942 * This routine prepares and issue an Reject (RJT) response IOCB
3943 * command. If a @mbox pointer is passed in, it will be put into the
3944 * context_un.mbox field of the IOCB for the completion callback function
3945 * to issue to the HBA later.
3946 *
3947 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3948 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3949 * will be stored into the context1 field of the IOCB for the completion
3950 * callback function to the reject response ELS IOCB command.
3951 *
3952 * Return code
3953 * 0 - Successfully issued reject response
3954 * 1 - Failed to issue reject response
3955 **/
dea31012005-04-17 16:05:31 -05003956int
James Smart2e0fef82007-06-17 19:56:36 -05003957lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003958 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3959 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003960{
James Smart2e0fef82007-06-17 19:56:36 -05003961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003962 IOCB_t *icmd;
3963 IOCB_t *oldcmd;
3964 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003965 struct lpfc_sli *psli;
3966 uint8_t *pcmd;
3967 uint16_t cmdsize;
3968 int rc;
3969
3970 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003971 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003972 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3973 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003974 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003975 return 1;
dea31012005-04-17 16:05:31 -05003976
3977 icmd = &elsiocb->iocb;
3978 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003979 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3980 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003981 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3982
3983 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003984 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003985 *((uint32_t *) (pcmd)) = rejectError;
3986
James Smart51ef4c22007-08-02 11:10:31 -04003987 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003988 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003989
dea31012005-04-17 16:05:31 -05003990 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003991 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3992 "0129 Xmit ELS RJT x%x response tag x%x "
3993 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3994 "rpi x%x\n",
3995 rejectError, elsiocb->iotag,
3996 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3997 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003998 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3999 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4000 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
4001
dea31012005-04-17 16:05:31 -05004002 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004003 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004004 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004005
dea31012005-04-17 16:05:31 -05004006 if (rc == IOCB_ERROR) {
4007 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004008 return 1;
dea31012005-04-17 16:05:31 -05004009 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004010 return 0;
dea31012005-04-17 16:05:31 -05004011}
4012
James Smarte59058c2008-08-24 21:49:00 -04004013/**
James Smart3621a712009-04-06 18:47:14 -04004014 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004015 * @vport: pointer to a virtual N_Port data structure.
4016 * @oldiocb: pointer to the original lpfc command iocb data structure.
4017 * @ndlp: pointer to a node-list data structure.
4018 *
4019 * This routine prepares and issues an Accept (ACC) response to Address
4020 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4021 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4022 *
4023 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4024 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4025 * will be stored into the context1 field of the IOCB for the completion
4026 * callback function to the ADISC Accept response ELS IOCB command.
4027 *
4028 * Return code
4029 * 0 - Successfully issued acc adisc response
4030 * 1 - Failed to issue adisc acc response
4031 **/
dea31012005-04-17 16:05:31 -05004032int
James Smart2e0fef82007-06-17 19:56:36 -05004033lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4034 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004035{
James Smart2e0fef82007-06-17 19:56:36 -05004036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004037 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004038 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004039 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004040 uint8_t *pcmd;
4041 uint16_t cmdsize;
4042 int rc;
4043
James Smart92d7f7b2007-06-17 19:56:38 -05004044 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004045 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4046 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004047 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004048 return 1;
dea31012005-04-17 16:05:31 -05004049
dea31012005-04-17 16:05:31 -05004050 icmd = &elsiocb->iocb;
4051 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004052 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4053 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004054
4055 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004056 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4057 "0130 Xmit ADISC ACC response iotag x%x xri: "
4058 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4059 elsiocb->iotag, elsiocb->iocb.ulpContext,
4060 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4061 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004062 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4063
4064 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004065 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004066
4067 ap = (ADISC *) (pcmd);
4068 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004069 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4070 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004071 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004072
James Smart858c9f62007-06-17 19:56:39 -05004073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4074 "Issue ACC ADISC: did:x%x flg:x%x",
4075 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4076
dea31012005-04-17 16:05:31 -05004077 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004078 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004079 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004080 if (rc == IOCB_ERROR) {
4081 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004082 return 1;
dea31012005-04-17 16:05:31 -05004083 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004084 return 0;
dea31012005-04-17 16:05:31 -05004085}
4086
James Smarte59058c2008-08-24 21:49:00 -04004087/**
James Smart3621a712009-04-06 18:47:14 -04004088 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004089 * @vport: pointer to a virtual N_Port data structure.
4090 * @oldiocb: pointer to the original lpfc command iocb data structure.
4091 * @ndlp: pointer to a node-list data structure.
4092 *
4093 * This routine prepares and issues an Accept (ACC) response to Process
4094 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4095 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4096 *
4097 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4098 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4099 * will be stored into the context1 field of the IOCB for the completion
4100 * callback function to the PRLI Accept response ELS IOCB command.
4101 *
4102 * Return code
4103 * 0 - Successfully issued acc prli response
4104 * 1 - Failed to issue acc prli response
4105 **/
dea31012005-04-17 16:05:31 -05004106int
James Smart2e0fef82007-06-17 19:56:36 -05004107lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004108 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004109{
James Smart2e0fef82007-06-17 19:56:36 -05004110 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004111 PRLI *npr;
4112 lpfc_vpd_t *vpd;
4113 IOCB_t *icmd;
4114 IOCB_t *oldcmd;
4115 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004116 struct lpfc_sli *psli;
4117 uint8_t *pcmd;
4118 uint16_t cmdsize;
4119 int rc;
4120
4121 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004122
James Smart92d7f7b2007-06-17 19:56:38 -05004123 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004124 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004125 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004126 if (!elsiocb)
4127 return 1;
dea31012005-04-17 16:05:31 -05004128
dea31012005-04-17 16:05:31 -05004129 icmd = &elsiocb->iocb;
4130 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004131 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4132 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4133
James Smart5b8bd0c2007-04-25 09:52:49 -04004134 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004135 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4136 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4137 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4138 elsiocb->iotag, elsiocb->iocb.ulpContext,
4139 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4140 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004141 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4142
4143 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004144 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004145
4146 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004147 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004148
4149 npr = (PRLI *) pcmd;
4150 vpd = &phba->vpd;
4151 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004152 * If the remote port is a target and our firmware version is 3.20 or
4153 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004154 */
James Smart0d2b6b82008-06-14 22:52:47 -04004155 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4156 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004157 npr->ConfmComplAllowed = 1;
4158 npr->Retry = 1;
4159 npr->TaskRetryIdReq = 1;
4160 }
4161
4162 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4163 npr->estabImagePair = 1;
4164 npr->readXferRdyDis = 1;
4165 npr->ConfmComplAllowed = 1;
4166
4167 npr->prliType = PRLI_FCP_TYPE;
4168 npr->initiatorFunc = 1;
4169
James Smart858c9f62007-06-17 19:56:39 -05004170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4171 "Issue ACC PRLI: did:x%x flg:x%x",
4172 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4173
dea31012005-04-17 16:05:31 -05004174 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004175 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004176
James Smart3772a992009-05-22 14:50:54 -04004177 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004178 if (rc == IOCB_ERROR) {
4179 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004180 return 1;
dea31012005-04-17 16:05:31 -05004181 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004182 return 0;
dea31012005-04-17 16:05:31 -05004183}
4184
James Smarte59058c2008-08-24 21:49:00 -04004185/**
James Smart3621a712009-04-06 18:47:14 -04004186 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004187 * @vport: pointer to a virtual N_Port data structure.
4188 * @format: rnid command format.
4189 * @oldiocb: pointer to the original lpfc command iocb data structure.
4190 * @ndlp: pointer to a node-list data structure.
4191 *
4192 * This routine issues a Request Node Identification Data (RNID) Accept
4193 * (ACC) response. It constructs the RNID ACC response command according to
4194 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4195 * issue the response. Note that this command does not need to hold the ndlp
4196 * reference count for the callback. So, the ndlp reference count taken by
4197 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4198 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4199 * there is no ndlp reference available.
4200 *
4201 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4202 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4203 * will be stored into the context1 field of the IOCB for the completion
4204 * callback function. However, for the RNID Accept Response ELS command,
4205 * this is undone later by this routine after the IOCB is allocated.
4206 *
4207 * Return code
4208 * 0 - Successfully issued acc rnid response
4209 * 1 - Failed to issue acc rnid response
4210 **/
dea31012005-04-17 16:05:31 -05004211static int
James Smart2e0fef82007-06-17 19:56:36 -05004212lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004213 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004214{
James Smart2e0fef82007-06-17 19:56:36 -05004215 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004216 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004217 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004218 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004219 struct lpfc_sli *psli;
4220 uint8_t *pcmd;
4221 uint16_t cmdsize;
4222 int rc;
4223
4224 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004225 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4226 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004227 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004228 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004229
James Smart2e0fef82007-06-17 19:56:36 -05004230 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4231 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004232 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004233 return 1;
dea31012005-04-17 16:05:31 -05004234
dea31012005-04-17 16:05:31 -05004235 icmd = &elsiocb->iocb;
4236 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004237 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4238 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4239
James Smart5b8bd0c2007-04-25 09:52:49 -04004240 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004241 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4242 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4243 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004244 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004245 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004246 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004247
James Smart92d7f7b2007-06-17 19:56:38 -05004248 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004249 rn = (RNID *) (pcmd);
4250 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004251 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4252 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4253 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004254 switch (format) {
4255 case 0:
4256 rn->SpecificLen = 0;
4257 break;
4258 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004259 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004260 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004261 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004262 rn->un.topologyDisc.unitType = RNID_HBA;
4263 rn->un.topologyDisc.physPort = 0;
4264 rn->un.topologyDisc.attachedNodes = 0;
4265 break;
4266 default:
4267 rn->CommonLen = 0;
4268 rn->SpecificLen = 0;
4269 break;
4270 }
4271
James Smart858c9f62007-06-17 19:56:39 -05004272 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4273 "Issue ACC RNID: did:x%x flg:x%x",
4274 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4275
dea31012005-04-17 16:05:31 -05004276 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004277 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004278
James Smart3772a992009-05-22 14:50:54 -04004279 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004280 if (rc == IOCB_ERROR) {
4281 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004282 return 1;
dea31012005-04-17 16:05:31 -05004283 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004284 return 0;
dea31012005-04-17 16:05:31 -05004285}
4286
James Smarte59058c2008-08-24 21:49:00 -04004287/**
James Smart19ca7602010-11-20 23:11:55 -05004288 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4289 * @vport: pointer to a virtual N_Port data structure.
4290 * @iocb: pointer to the lpfc command iocb data structure.
4291 * @ndlp: pointer to a node-list data structure.
4292 *
4293 * Return
4294 **/
4295static void
4296lpfc_els_clear_rrq(struct lpfc_vport *vport,
4297 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4298{
4299 struct lpfc_hba *phba = vport->phba;
4300 uint8_t *pcmd;
4301 struct RRQ *rrq;
4302 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004303 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004304 struct lpfc_node_rrq *prrq;
4305
4306
4307 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4308 pcmd += sizeof(uint32_t);
4309 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004310 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004311 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004312
4313 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4314 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4315 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004316 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004317 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004318 rxid,
4319 iocb->iotag, iocb->iocb.ulpContext);
4320
4321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4322 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4323 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004324 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004325 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004326 else
4327 xri = rxid;
4328 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004329 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004330 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004331 return;
4332}
4333
4334/**
James Smart12265f62010-10-22 11:05:53 -04004335 * lpfc_els_rsp_echo_acc - Issue echo acc response
4336 * @vport: pointer to a virtual N_Port data structure.
4337 * @data: pointer to echo data to return in the accept.
4338 * @oldiocb: pointer to the original lpfc command iocb data structure.
4339 * @ndlp: pointer to a node-list data structure.
4340 *
4341 * Return code
4342 * 0 - Successfully issued acc echo response
4343 * 1 - Failed to issue acc echo response
4344 **/
4345static int
4346lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4347 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4348{
4349 struct lpfc_hba *phba = vport->phba;
4350 struct lpfc_iocbq *elsiocb;
4351 struct lpfc_sli *psli;
4352 uint8_t *pcmd;
4353 uint16_t cmdsize;
4354 int rc;
4355
4356 psli = &phba->sli;
4357 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4358
James Smartbf086112011-08-21 21:48:13 -04004359 /* The accumulated length can exceed the BPL_SIZE. For
4360 * now, use this as the limit
4361 */
4362 if (cmdsize > LPFC_BPL_SIZE)
4363 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004364 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4365 ndlp->nlp_DID, ELS_CMD_ACC);
4366 if (!elsiocb)
4367 return 1;
4368
James Smart7851fe22011-07-22 18:36:52 -04004369 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4370 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4371
James Smart12265f62010-10-22 11:05:53 -04004372 /* Xmit ECHO ACC response tag <ulpIoTag> */
4373 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4374 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4375 elsiocb->iotag, elsiocb->iocb.ulpContext);
4376 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4377 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4378 pcmd += sizeof(uint32_t);
4379 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4380
4381 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4382 "Issue ACC ECHO: did:x%x flg:x%x",
4383 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4384
4385 phba->fc_stat.elsXmitACC++;
4386 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004387
4388 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4389 if (rc == IOCB_ERROR) {
4390 lpfc_els_free_iocb(phba, elsiocb);
4391 return 1;
4392 }
4393 return 0;
4394}
4395
4396/**
James Smart3621a712009-04-06 18:47:14 -04004397 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004398 * @vport: pointer to a host virtual N_Port data structure.
4399 *
4400 * This routine issues Address Discover (ADISC) ELS commands to those
4401 * N_Ports which are in node port recovery state and ADISC has not been issued
4402 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4403 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4404 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4405 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4406 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4407 * IOCBs quit for later pick up. On the other hand, after walking through
4408 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4409 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4410 * no more ADISC need to be sent.
4411 *
4412 * Return code
4413 * The number of N_Ports with adisc issued.
4414 **/
dea31012005-04-17 16:05:31 -05004415int
James Smart2e0fef82007-06-17 19:56:36 -05004416lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004417{
James Smart2e0fef82007-06-17 19:56:36 -05004418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004419 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004420 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004421
James Smart685f0bf2007-04-25 09:53:08 -04004422 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004423 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004424 if (!NLP_CHK_NODE_ACT(ndlp))
4425 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004426 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4427 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4428 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004429 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004430 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004431 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004432 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004433 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4434 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004435 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004436 vport->num_disc_nodes++;
4437 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004438 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004439 spin_lock_irq(shost->host_lock);
4440 vport->fc_flag |= FC_NLP_MORE;
4441 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004442 break;
dea31012005-04-17 16:05:31 -05004443 }
4444 }
4445 }
4446 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004447 spin_lock_irq(shost->host_lock);
4448 vport->fc_flag &= ~FC_NLP_MORE;
4449 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004450 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004451 return sentadisc;
dea31012005-04-17 16:05:31 -05004452}
4453
James Smarte59058c2008-08-24 21:49:00 -04004454/**
James Smart3621a712009-04-06 18:47:14 -04004455 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004456 * @vport: pointer to a host virtual N_Port data structure.
4457 *
4458 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4459 * which are in node port recovery state, with a @vport. Each time an ELS
4460 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4461 * the per @vport number of discover count (num_disc_nodes) shall be
4462 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4463 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4464 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4465 * later pick up. On the other hand, after walking through all the ndlps with
4466 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4467 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4468 * PLOGI need to be sent.
4469 *
4470 * Return code
4471 * The number of N_Ports with plogi issued.
4472 **/
dea31012005-04-17 16:05:31 -05004473int
James Smart2e0fef82007-06-17 19:56:36 -05004474lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004475{
James Smart2e0fef82007-06-17 19:56:36 -05004476 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004477 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004478 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004479
James Smart2e0fef82007-06-17 19:56:36 -05004480 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4481 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004482 if (!NLP_CHK_NODE_ACT(ndlp))
4483 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004484 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4485 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4486 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4487 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4488 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004489 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4490 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004491 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004492 vport->num_disc_nodes++;
4493 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004494 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004495 spin_lock_irq(shost->host_lock);
4496 vport->fc_flag |= FC_NLP_MORE;
4497 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004498 break;
dea31012005-04-17 16:05:31 -05004499 }
4500 }
4501 }
James Smart87af33f2007-10-27 13:37:43 -04004502 if (sentplogi) {
4503 lpfc_set_disctmo(vport);
4504 }
4505 else {
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);
dea31012005-04-17 16:05:31 -05004509 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004510 return sentplogi;
dea31012005-04-17 16:05:31 -05004511}
4512
James Smarte59058c2008-08-24 21:49:00 -04004513/**
James Smart3621a712009-04-06 18:47:14 -04004514 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004515 * @vport: pointer to a host virtual N_Port data structure.
4516 *
4517 * This routine cleans up any Registration State Change Notification
4518 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4519 * @vport together with the host_lock is used to prevent multiple thread
4520 * trying to access the RSCN array on a same @vport at the same time.
4521 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004522void
James Smart2e0fef82007-06-17 19:56:36 -05004523lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004524{
James Smart2e0fef82007-06-17 19:56:36 -05004525 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4526 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004527 int i;
4528
James Smart7f5f3d02008-02-08 18:50:14 -05004529 spin_lock_irq(shost->host_lock);
4530 if (vport->fc_rscn_flush) {
4531 /* Another thread is walking fc_rscn_id_list on this vport */
4532 spin_unlock_irq(shost->host_lock);
4533 return;
4534 }
4535 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4536 vport->fc_rscn_flush = 1;
4537 spin_unlock_irq(shost->host_lock);
4538
James Smart2e0fef82007-06-17 19:56:36 -05004539 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004540 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004541 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004542 }
James Smart2e0fef82007-06-17 19:56:36 -05004543 spin_lock_irq(shost->host_lock);
4544 vport->fc_rscn_id_cnt = 0;
4545 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4546 spin_unlock_irq(shost->host_lock);
4547 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004548 /* Indicate we are done walking this fc_rscn_id_list */
4549 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004550}
4551
James Smarte59058c2008-08-24 21:49:00 -04004552/**
James Smart3621a712009-04-06 18:47:14 -04004553 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004554 * @vport: pointer to a host virtual N_Port data structure.
4555 * @did: remote destination port identifier.
4556 *
4557 * This routine checks whether there is any pending Registration State
4558 * Configuration Notification (RSCN) to a @did on @vport.
4559 *
4560 * Return code
4561 * None zero - The @did matched with a pending rscn
4562 * 0 - not able to match @did with a pending rscn
4563 **/
dea31012005-04-17 16:05:31 -05004564int
James Smart2e0fef82007-06-17 19:56:36 -05004565lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004566{
4567 D_ID ns_did;
4568 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004569 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004570 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004571 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004572
4573 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004574
4575 /* Never match fabric nodes for RSCNs */
4576 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004577 return 0;
dea31012005-04-17 16:05:31 -05004578
4579 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004580 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004581 return did;
dea31012005-04-17 16:05:31 -05004582
James Smart7f5f3d02008-02-08 18:50:14 -05004583 spin_lock_irq(shost->host_lock);
4584 if (vport->fc_rscn_flush) {
4585 /* Another thread is walking fc_rscn_id_list on this vport */
4586 spin_unlock_irq(shost->host_lock);
4587 return 0;
4588 }
4589 /* Indicate we are walking fc_rscn_id_list on this vport */
4590 vport->fc_rscn_flush = 1;
4591 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004592 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004593 lp = vport->fc_rscn_id_list[i]->virt;
4594 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4595 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004596 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004597 rscn_did.un.word = be32_to_cpu(*lp++);
4598 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004599 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4600 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004601 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4602 && (ns_did.un.b.area == rscn_did.un.b.area)
4603 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004604 goto return_did_out;
dea31012005-04-17 16:05:31 -05004605 break;
James Smarteaf15d52008-12-04 22:39:29 -05004606 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004607 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4608 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004609 goto return_did_out;
dea31012005-04-17 16:05:31 -05004610 break;
James Smarteaf15d52008-12-04 22:39:29 -05004611 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004612 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004613 goto return_did_out;
dea31012005-04-17 16:05:31 -05004614 break;
James Smarteaf15d52008-12-04 22:39:29 -05004615 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004616 goto return_did_out;
dea31012005-04-17 16:05:31 -05004617 }
4618 }
James Smart92d7f7b2007-06-17 19:56:38 -05004619 }
James Smart7f5f3d02008-02-08 18:50:14 -05004620 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4621 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004622 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004623return_did_out:
4624 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4625 vport->fc_rscn_flush = 0;
4626 return did;
dea31012005-04-17 16:05:31 -05004627}
4628
James Smarte59058c2008-08-24 21:49:00 -04004629/**
James Smart3621a712009-04-06 18:47:14 -04004630 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004631 * @vport: pointer to a host virtual N_Port data structure.
4632 *
4633 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4634 * state machine for a @vport's nodes that are with pending RSCN (Registration
4635 * State Change Notification).
4636 *
4637 * Return code
4638 * 0 - Successful (currently alway return 0)
4639 **/
dea31012005-04-17 16:05:31 -05004640static int
James Smart2e0fef82007-06-17 19:56:36 -05004641lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004642{
James Smart685f0bf2007-04-25 09:53:08 -04004643 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004644
James Smart0d2b6b82008-06-14 22:52:47 -04004645 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004646 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004647 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004648 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4649 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004650 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004651 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004652 NLP_EVT_DEVICE_RECOVERY);
4653 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004654 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004655 return 0;
dea31012005-04-17 16:05:31 -05004656}
4657
James Smarte59058c2008-08-24 21:49:00 -04004658/**
James Smart3621a712009-04-06 18:47:14 -04004659 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004660 * @vport: pointer to a host virtual N_Port data structure.
4661 * @cmdiocb: pointer to lpfc command iocb data structure.
4662 *
4663 * lpfc_send_rscn_event sends an RSCN netlink event to management
4664 * applications.
4665 */
4666static void
4667lpfc_send_rscn_event(struct lpfc_vport *vport,
4668 struct lpfc_iocbq *cmdiocb)
4669{
4670 struct lpfc_dmabuf *pcmd;
4671 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4672 uint32_t *payload_ptr;
4673 uint32_t payload_len;
4674 struct lpfc_rscn_event_header *rscn_event_data;
4675
4676 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4677 payload_ptr = (uint32_t *) pcmd->virt;
4678 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4679
4680 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4681 payload_len, GFP_KERNEL);
4682 if (!rscn_event_data) {
4683 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4684 "0147 Failed to allocate memory for RSCN event\n");
4685 return;
4686 }
4687 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4688 rscn_event_data->payload_length = payload_len;
4689 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4690 payload_len);
4691
4692 fc_host_post_vendor_event(shost,
4693 fc_get_event_number(),
4694 sizeof(struct lpfc_els_event_header) + payload_len,
4695 (char *)rscn_event_data,
4696 LPFC_NL_VENDOR_ID);
4697
4698 kfree(rscn_event_data);
4699}
4700
4701/**
James Smart3621a712009-04-06 18:47:14 -04004702 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004703 * @vport: pointer to a host virtual N_Port data structure.
4704 * @cmdiocb: pointer to lpfc command iocb data structure.
4705 * @ndlp: pointer to a node-list data structure.
4706 *
4707 * This routine processes an unsolicited RSCN (Registration State Change
4708 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4709 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4710 * discover state machine is about to begin discovery, it just accepts the
4711 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4712 * contains N_Port IDs for other vports on this HBA, it just accepts the
4713 * RSCN and ignore processing it. If the state machine is in the recovery
4714 * state, the fc_rscn_id_list of this @vport is walked and the
4715 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4716 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4717 * routine is invoked to handle the RSCN event.
4718 *
4719 * Return code
4720 * 0 - Just sent the acc response
4721 * 1 - Sent the acc response and waited for name server completion
4722 **/
dea31012005-04-17 16:05:31 -05004723static int
James Smart2e0fef82007-06-17 19:56:36 -05004724lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004725 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004726{
James Smart2e0fef82007-06-17 19:56:36 -05004727 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4728 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004729 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004730 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004731 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004732 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004733 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004734 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004735 int i;
dea31012005-04-17 16:05:31 -05004736
4737 icmd = &cmdiocb->iocb;
4738 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4739 lp = (uint32_t *) pcmd->virt;
4740
James Smart92d7f7b2007-06-17 19:56:38 -05004741 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4742 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004743 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004744 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4745 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004746 vport->fc_flag, payload_len, *lp,
4747 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004748
4749 /* Send an RSCN event to the management application */
4750 lpfc_send_rscn_event(vport, cmdiocb);
4751
James Smartd2873e42006-08-18 17:46:43 -04004752 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004753 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004754 FCH_EVT_RSCN, lp[i]);
4755
dea31012005-04-17 16:05:31 -05004756 /* If we are about to begin discovery, just ACC the RSCN.
4757 * Discovery processing will satisfy it.
4758 */
James Smart2e0fef82007-06-17 19:56:36 -05004759 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004760 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4761 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4762 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4763
James Smart51ef4c22007-08-02 11:10:31 -04004764 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004765 return 0;
dea31012005-04-17 16:05:31 -05004766 }
4767
James Smart92d7f7b2007-06-17 19:56:38 -05004768 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4769 * just ACC and ignore it.
4770 */
4771 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004772 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004773 i = payload_len;
4774 datap = lp;
4775 while (i > 0) {
4776 nportid = *datap++;
4777 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4778 i -= sizeof(uint32_t);
4779 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004780 if (lpfc_find_vport_by_did(phba, nportid))
4781 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004782 }
4783 if (rscn_id == hba_id) {
4784 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004785 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004786 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004787 "Data: x%x x%x x%x x%x\n",
4788 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004789 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4791 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4792 ndlp->nlp_DID, vport->port_state,
4793 ndlp->nlp_flag);
4794
James Smart92d7f7b2007-06-17 19:56:38 -05004795 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004796 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004797 return 0;
4798 }
4799 }
4800
James Smart7f5f3d02008-02-08 18:50:14 -05004801 spin_lock_irq(shost->host_lock);
4802 if (vport->fc_rscn_flush) {
4803 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004804 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004805 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004806 /* Send back ACC */
4807 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004808 return 0;
4809 }
4810 /* Indicate we are walking fc_rscn_id_list on this vport */
4811 vport->fc_rscn_flush = 1;
4812 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004813 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004814 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004815 /* If we are already processing an RSCN, save the received
4816 * RSCN payload buffer, cmdiocb->context2 to process later.
4817 */
James Smart2e0fef82007-06-17 19:56:36 -05004818 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4820 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4821 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4822
James Smart09372822008-01-11 01:52:54 -05004823 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004824 vport->fc_flag |= FC_RSCN_DEFERRED;
4825 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004826 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004827 vport->fc_flag |= FC_RSCN_MODE;
4828 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004829 if (rscn_cnt) {
4830 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4831 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4832 }
4833 if ((rscn_cnt) &&
4834 (payload_len + length <= LPFC_BPL_SIZE)) {
4835 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004836 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004837 memcpy(((uint8_t *)cmd) + length, lp,
4838 payload_len);
4839 } else {
4840 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4841 vport->fc_rscn_id_cnt++;
4842 /* If we zero, cmdiocb->context2, the calling
4843 * routine will not try to free it.
4844 */
4845 cmdiocb->context2 = NULL;
4846 }
dea31012005-04-17 16:05:31 -05004847 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004848 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4849 "0235 Deferred RSCN "
4850 "Data: x%x x%x x%x\n",
4851 vport->fc_rscn_id_cnt, vport->fc_flag,
4852 vport->port_state);
dea31012005-04-17 16:05:31 -05004853 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004854 vport->fc_flag |= FC_RSCN_DISCOVERY;
4855 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004856 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004857 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4858 "0234 ReDiscovery RSCN "
4859 "Data: x%x x%x x%x\n",
4860 vport->fc_rscn_id_cnt, vport->fc_flag,
4861 vport->port_state);
dea31012005-04-17 16:05:31 -05004862 }
James Smart7f5f3d02008-02-08 18:50:14 -05004863 /* Indicate we are done walking fc_rscn_id_list on this vport */
4864 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004865 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004866 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004867 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004868 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004869 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004870 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004871 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004872 return 0;
dea31012005-04-17 16:05:31 -05004873 }
James Smart858c9f62007-06-17 19:56:39 -05004874 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4875 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4876 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4877
James Smart2e0fef82007-06-17 19:56:36 -05004878 spin_lock_irq(shost->host_lock);
4879 vport->fc_flag |= FC_RSCN_MODE;
4880 spin_unlock_irq(shost->host_lock);
4881 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004882 /* Indicate we are done walking fc_rscn_id_list on this vport */
4883 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004884 /*
4885 * If we zero, cmdiocb->context2, the calling routine will
4886 * not try to free it.
4887 */
4888 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004889 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004890 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004891 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004892 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004893 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004894 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004895}
4896
James Smarte59058c2008-08-24 21:49:00 -04004897/**
James Smart3621a712009-04-06 18:47:14 -04004898 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004899 * @vport: pointer to a host virtual N_Port data structure.
4900 *
4901 * This routine handles the Registration State Configuration Notification
4902 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4903 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4904 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4905 * NameServer shall be issued. If CT command to the NameServer fails to be
4906 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4907 * RSCN activities with the @vport.
4908 *
4909 * Return code
4910 * 0 - Cleaned up rscn on the @vport
4911 * 1 - Wait for plogi to name server before proceed
4912 **/
dea31012005-04-17 16:05:31 -05004913int
James Smart2e0fef82007-06-17 19:56:36 -05004914lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004915{
4916 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004917 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004918
James Smart92d7f7b2007-06-17 19:56:38 -05004919 /* Ignore RSCN if the port is being torn down. */
4920 if (vport->load_flag & FC_UNLOADING) {
4921 lpfc_els_flush_rscn(vport);
4922 return 0;
4923 }
4924
dea31012005-04-17 16:05:31 -05004925 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004926 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004927
4928 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004929 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4930 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4931 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4932 vport->port_state);
dea31012005-04-17 16:05:31 -05004933
4934 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004935 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004936 vport->num_disc_nodes = 0;
4937
James Smart2e0fef82007-06-17 19:56:36 -05004938 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004939 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4940 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004941 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004942 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004943 /* Wait for NameServer query cmpl before we can
4944 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004945 return 1;
dea31012005-04-17 16:05:31 -05004946 } else {
4947 /* If login to NameServer does not exist, issue one */
4948 /* Good status, issue PLOGI to NameServer */
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))
dea31012005-04-17 16:05:31 -05004951 /* Wait for NameServer login cmpl before we can
4952 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004953 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004954
James Smarte47c9092008-02-08 18:49:26 -05004955 if (ndlp) {
4956 ndlp = lpfc_enable_node(vport, ndlp,
4957 NLP_STE_PLOGI_ISSUE);
4958 if (!ndlp) {
4959 lpfc_els_flush_rscn(vport);
4960 return 0;
4961 }
4962 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004963 } else {
James Smarte47c9092008-02-08 18:49:26 -05004964 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4965 if (!ndlp) {
4966 lpfc_els_flush_rscn(vport);
4967 return 0;
4968 }
James Smart2e0fef82007-06-17 19:56:36 -05004969 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004970 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004972 }
James Smarte47c9092008-02-08 18:49:26 -05004973 ndlp->nlp_type |= NLP_FABRIC;
4974 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4975 /* Wait for NameServer login cmpl before we can
4976 * continue
4977 */
4978 return 1;
dea31012005-04-17 16:05:31 -05004979 }
4980
James Smart2e0fef82007-06-17 19:56:36 -05004981 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004982 return 0;
dea31012005-04-17 16:05:31 -05004983}
4984
James Smarte59058c2008-08-24 21:49:00 -04004985/**
James Smart3621a712009-04-06 18:47:14 -04004986 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004987 * @vport: pointer to a host virtual N_Port data structure.
4988 * @cmdiocb: pointer to lpfc command iocb data structure.
4989 * @ndlp: pointer to a node-list data structure.
4990 *
4991 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4992 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4993 * point topology. As an unsolicited FLOGI should not be received in a loop
4994 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4995 * lpfc_check_sparm() routine is invoked to check the parameters in the
4996 * unsolicited FLOGI. If parameters validation failed, the routine
4997 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4998 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4999 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5000 * will initiate PLOGI. The higher lexicographical value party shall has
5001 * higher priority (as the winning port) and will initiate PLOGI and
5002 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5003 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5004 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5005 *
5006 * Return code
5007 * 0 - Successfully processed the unsolicited flogi
5008 * 1 - Failed to process the unsolicited flogi
5009 **/
dea31012005-04-17 16:05:31 -05005010static int
James Smart2e0fef82007-06-17 19:56:36 -05005011lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005012 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005013{
James Smart2e0fef82007-06-17 19:56:36 -05005014 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5015 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005016 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5017 uint32_t *lp = (uint32_t *) pcmd->virt;
5018 IOCB_t *icmd = &cmdiocb->iocb;
5019 struct serv_parm *sp;
5020 LPFC_MBOXQ_t *mbox;
5021 struct ls_rjt stat;
5022 uint32_t cmd, did;
5023 int rc;
5024
5025 cmd = *lp++;
5026 sp = (struct serv_parm *) lp;
5027
5028 /* FLOGI received */
5029
James Smart2e0fef82007-06-17 19:56:36 -05005030 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005031
James Smart76a95d72010-11-20 23:11:48 -05005032 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005033 /* We should never receive a FLOGI in loop mode, ignore it */
5034 did = icmd->un.elsreq64.remoteID;
5035
5036 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5037 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005038 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5039 "0113 An FLOGI ELS command x%x was "
5040 "received from DID x%x in Loop Mode\n",
5041 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005042 return 1;
dea31012005-04-17 16:05:31 -05005043 }
5044
James Smart341af102010-01-26 23:07:37 -05005045 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005046 /* For a FLOGI we accept, then if our portname is greater
5047 * then the remote portname we initiate Nport login.
5048 */
5049
James Smart2e0fef82007-06-17 19:56:36 -05005050 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005051 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005052
5053 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005054 if (phba->sli_rev < LPFC_SLI_REV4) {
5055 mbox = mempool_alloc(phba->mbox_mem_pool,
5056 GFP_KERNEL);
5057 if (!mbox)
5058 return 1;
5059 lpfc_linkdown(phba);
5060 lpfc_init_link(phba, mbox,
5061 phba->cfg_topology,
5062 phba->cfg_link_speed);
5063 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5064 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5065 mbox->vport = vport;
5066 rc = lpfc_sli_issue_mbox(phba, mbox,
5067 MBX_NOWAIT);
5068 lpfc_set_loopback_flag(phba);
5069 if (rc == MBX_NOT_FINISHED)
5070 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005071 return 1;
James Smart1b511972011-12-13 13:23:09 -05005072 } else {
5073 /* abort the flogi coming back to ourselves
5074 * due to external loopback on the port.
5075 */
5076 lpfc_els_abort_flogi(phba);
5077 return 0;
dea31012005-04-17 16:05:31 -05005078 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005079 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005080 spin_lock_irq(shost->host_lock);
5081 vport->fc_flag |= FC_PT2PT_PLOGI;
5082 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005083
5084 /* If we have the high WWPN we can assign our own
5085 * myDID; otherwise, we have to WAIT for a PLOGI
5086 * from the remote NPort to find out what it
5087 * will be.
5088 */
James Smarte6446432012-05-09 21:16:42 -04005089 vport->fc_myDID = PT2PT_LocalID;
James Smart939723a2012-05-09 21:19:03 -04005090 }
5091
5092 /*
5093 * The vport state should go to LPFC_FLOGI only
5094 * AFTER we issue a FLOGI, not receive one.
5095 */
James Smart2e0fef82007-06-17 19:56:36 -05005096 spin_lock_irq(shost->host_lock);
5097 vport->fc_flag |= FC_PT2PT;
5098 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5099 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005100
5101 /*
5102 * We temporarily set fc_myDID to make it look like we are
5103 * a Fabric. This is done just so we end up with the right
5104 * did / sid on the FLOGI ACC rsp.
5105 */
5106 did = vport->fc_myDID;
5107 vport->fc_myDID = Fabric_DID;
5108
dea31012005-04-17 16:05:31 -05005109 } else {
5110 /* Reject this request because invalid parameters */
5111 stat.un.b.lsRjtRsvd0 = 0;
5112 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5113 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5114 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005115
5116 /*
5117 * We temporarily set fc_myDID to make it look like we are
5118 * a Fabric. This is done just so we end up with the right
5119 * did / sid on the FLOGI LS_RJT rsp.
5120 */
5121 did = vport->fc_myDID;
5122 vport->fc_myDID = Fabric_DID;
5123
James Smart858c9f62007-06-17 19:56:39 -05005124 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5125 NULL);
James Smart939723a2012-05-09 21:19:03 -04005126
5127 /* Now lets put fc_myDID back to what its supposed to be */
5128 vport->fc_myDID = did;
5129
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005130 return 1;
dea31012005-04-17 16:05:31 -05005131 }
5132
5133 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005134 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005135
James Smart939723a2012-05-09 21:19:03 -04005136 /* Now lets put fc_myDID back to what its supposed to be */
5137 vport->fc_myDID = did;
5138
James Smarte6446432012-05-09 21:16:42 -04005139 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005140
James Smarte6446432012-05-09 21:16:42 -04005141 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5142 if (!mbox)
5143 goto fail;
5144
5145 lpfc_config_link(phba, mbox);
5146
5147 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5148 mbox->vport = vport;
5149 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5150 if (rc == MBX_NOT_FINISHED) {
5151 mempool_free(mbox, phba->mbox_mem_pool);
5152 goto fail;
5153 }
5154 }
5155
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005156 return 0;
James Smarte6446432012-05-09 21:16:42 -04005157fail:
5158 return 1;
dea31012005-04-17 16:05:31 -05005159}
5160
James Smarte59058c2008-08-24 21:49:00 -04005161/**
James Smart3621a712009-04-06 18:47:14 -04005162 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005163 * @vport: pointer to a host virtual N_Port data structure.
5164 * @cmdiocb: pointer to lpfc command iocb data structure.
5165 * @ndlp: pointer to a node-list data structure.
5166 *
5167 * This routine processes Request Node Identification Data (RNID) IOCB
5168 * received as an ELS unsolicited event. Only when the RNID specified format
5169 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5170 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5171 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5172 * rejected by invoking the lpfc_els_rsp_reject() routine.
5173 *
5174 * Return code
5175 * 0 - Successfully processed rnid iocb (currently always return 0)
5176 **/
dea31012005-04-17 16:05:31 -05005177static int
James Smart2e0fef82007-06-17 19:56:36 -05005178lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5179 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005180{
5181 struct lpfc_dmabuf *pcmd;
5182 uint32_t *lp;
5183 IOCB_t *icmd;
5184 RNID *rn;
5185 struct ls_rjt stat;
5186 uint32_t cmd, did;
5187
5188 icmd = &cmdiocb->iocb;
5189 did = icmd->un.elsreq64.remoteID;
5190 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5191 lp = (uint32_t *) pcmd->virt;
5192
5193 cmd = *lp++;
5194 rn = (RNID *) lp;
5195
5196 /* RNID received */
5197
5198 switch (rn->Format) {
5199 case 0:
5200 case RNID_TOPOLOGY_DISC:
5201 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005202 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005203 break;
5204 default:
5205 /* Reject this request because format not supported */
5206 stat.un.b.lsRjtRsvd0 = 0;
5207 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5208 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5209 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005210 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5211 NULL);
dea31012005-04-17 16:05:31 -05005212 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005213 return 0;
dea31012005-04-17 16:05:31 -05005214}
5215
James Smarte59058c2008-08-24 21:49:00 -04005216/**
James Smart12265f62010-10-22 11:05:53 -04005217 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5218 * @vport: pointer to a host virtual N_Port data structure.
5219 * @cmdiocb: pointer to lpfc command iocb data structure.
5220 * @ndlp: pointer to a node-list data structure.
5221 *
5222 * Return code
5223 * 0 - Successfully processed echo iocb (currently always return 0)
5224 **/
5225static int
5226lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5227 struct lpfc_nodelist *ndlp)
5228{
5229 uint8_t *pcmd;
5230
5231 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5232
5233 /* skip over first word of echo command to find echo data */
5234 pcmd += sizeof(uint32_t);
5235
5236 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5237 return 0;
5238}
5239
5240/**
James Smart3621a712009-04-06 18:47:14 -04005241 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005242 * @vport: pointer to a host virtual N_Port data structure.
5243 * @cmdiocb: pointer to lpfc command iocb data structure.
5244 * @ndlp: pointer to a node-list data structure.
5245 *
5246 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5247 * received as an ELS unsolicited event. Currently, this function just invokes
5248 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5249 *
5250 * Return code
5251 * 0 - Successfully processed lirr iocb (currently always return 0)
5252 **/
dea31012005-04-17 16:05:31 -05005253static int
James Smart2e0fef82007-06-17 19:56:36 -05005254lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5255 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005256{
5257 struct ls_rjt stat;
5258
5259 /* For now, unconditionally reject this command */
5260 stat.un.b.lsRjtRsvd0 = 0;
5261 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5262 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5263 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005264 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005265 return 0;
5266}
5267
James Smarte59058c2008-08-24 21:49:00 -04005268/**
James Smart5ffc2662009-11-18 15:39:44 -05005269 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5270 * @vport: pointer to a host virtual N_Port data structure.
5271 * @cmdiocb: pointer to lpfc command iocb data structure.
5272 * @ndlp: pointer to a node-list data structure.
5273 *
5274 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5275 * received as an ELS unsolicited event. A request to RRQ shall only
5276 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5277 * Nx_Port N_Port_ID of the target Exchange is the same as the
5278 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5279 * not accepted, an LS_RJT with reason code "Unable to perform
5280 * command request" and reason code explanation "Invalid Originator
5281 * S_ID" shall be returned. For now, we just unconditionally accept
5282 * RRQ from the target.
5283 **/
5284static void
5285lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5286 struct lpfc_nodelist *ndlp)
5287{
5288 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005289 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5290 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005291}
5292
5293/**
James Smart12265f62010-10-22 11:05:53 -04005294 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5295 * @phba: pointer to lpfc hba data structure.
5296 * @pmb: pointer to the driver internal queue element for mailbox command.
5297 *
5298 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5299 * mailbox command. This callback function is to actually send the Accept
5300 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5301 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5302 * mailbox command, constructs the RPS response with the link statistics
5303 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5304 * response to the RPS.
5305 *
5306 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5307 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5308 * will be stored into the context1 field of the IOCB for the completion
5309 * callback function to the RPS Accept Response ELS IOCB command.
5310 *
5311 **/
5312static void
5313lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5314{
5315 MAILBOX_t *mb;
5316 IOCB_t *icmd;
5317 struct RLS_RSP *rls_rsp;
5318 uint8_t *pcmd;
5319 struct lpfc_iocbq *elsiocb;
5320 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005321 uint16_t oxid;
5322 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005323 uint32_t cmdsize;
5324
5325 mb = &pmb->u.mb;
5326
5327 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005328 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5329 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005330 pmb->context1 = NULL;
5331 pmb->context2 = NULL;
5332
5333 if (mb->mbxStatus) {
5334 mempool_free(pmb, phba->mbox_mem_pool);
5335 return;
5336 }
5337
5338 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005339 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5340 lpfc_max_els_tries, ndlp,
5341 ndlp->nlp_DID, ELS_CMD_ACC);
5342
5343 /* Decrement the ndlp reference count from previous mbox command */
5344 lpfc_nlp_put(ndlp);
5345
James Smart37db57e2012-05-09 21:17:16 -04005346 if (!elsiocb) {
5347 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005348 return;
James Smart37db57e2012-05-09 21:17:16 -04005349 }
James Smart12265f62010-10-22 11:05:53 -04005350
5351 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005352 icmd->ulpContext = rxid;
5353 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005354
5355 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5356 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5357 pcmd += sizeof(uint32_t); /* Skip past command */
5358 rls_rsp = (struct RLS_RSP *)pcmd;
5359
5360 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5361 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5362 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5363 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5364 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5365 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005366 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005367 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5368 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5369 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5370 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5371 elsiocb->iotag, elsiocb->iocb.ulpContext,
5372 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5373 ndlp->nlp_rpi);
5374 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5375 phba->fc_stat.elsXmitACC++;
5376 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5377 lpfc_els_free_iocb(phba, elsiocb);
5378}
5379
5380/**
James Smart3621a712009-04-06 18:47:14 -04005381 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005382 * @phba: pointer to lpfc hba data structure.
5383 * @pmb: pointer to the driver internal queue element for mailbox command.
5384 *
5385 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5386 * mailbox command. This callback function is to actually send the Accept
5387 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5388 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5389 * mailbox command, constructs the RPS response with the link statistics
5390 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5391 * response to the RPS.
5392 *
5393 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5394 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5395 * will be stored into the context1 field of the IOCB for the completion
5396 * callback function to the RPS Accept Response ELS IOCB command.
5397 *
5398 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005399static void
James Smart329f9bc2007-04-25 09:53:01 -04005400lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005401{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005402 MAILBOX_t *mb;
5403 IOCB_t *icmd;
5404 RPS_RSP *rps_rsp;
5405 uint8_t *pcmd;
5406 struct lpfc_iocbq *elsiocb;
5407 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005408 uint16_t status;
5409 uint16_t oxid;
5410 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005411 uint32_t cmdsize;
5412
James Smart04c68492009-05-22 14:52:52 -04005413 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005414
5415 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005416 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5417 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005418 pmb->context1 = NULL;
5419 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005420
5421 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005422 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005423 return;
5424 }
5425
5426 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005427 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005428 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5429 lpfc_max_els_tries, ndlp,
5430 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005431
5432 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005433 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005434
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005435 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005436 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005437
5438 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005439 icmd->ulpContext = rxid;
5440 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005441
5442 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5443 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005444 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005445 rps_rsp = (RPS_RSP *)pcmd;
5446
James Smart76a95d72010-11-20 23:11:48 -05005447 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005448 status = 0x10;
5449 else
5450 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005451 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005452 status |= 0x4;
5453
5454 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005455 rps_rsp->portStatus = cpu_to_be16(status);
5456 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5457 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5458 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5459 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5460 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5461 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005462 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005463 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5464 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5465 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5466 elsiocb->iotag, elsiocb->iocb.ulpContext,
5467 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5468 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005469 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005470 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005471 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005472 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005473 return;
5474}
5475
James Smarte59058c2008-08-24 21:49:00 -04005476/**
James Smart12265f62010-10-22 11:05:53 -04005477 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5478 * @vport: pointer to a host virtual N_Port data structure.
5479 * @cmdiocb: pointer to lpfc command iocb data structure.
5480 * @ndlp: pointer to a node-list data structure.
5481 *
5482 * This routine processes Read Port Status (RPL) IOCB received as an
5483 * ELS unsolicited event. It first checks the remote port state. If the
5484 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5485 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5486 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5487 * for reading the HBA link statistics. It is for the callback function,
5488 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5489 * to actually sending out RPL Accept (ACC) response.
5490 *
5491 * Return codes
5492 * 0 - Successfully processed rls iocb (currently always return 0)
5493 **/
5494static int
5495lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5496 struct lpfc_nodelist *ndlp)
5497{
5498 struct lpfc_hba *phba = vport->phba;
5499 LPFC_MBOXQ_t *mbox;
5500 struct lpfc_dmabuf *pcmd;
5501 struct ls_rjt stat;
5502
5503 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5504 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5505 /* reject the unsolicited RPS request and done with it */
5506 goto reject_out;
5507
5508 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5509
5510 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5511 if (mbox) {
5512 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005513 mbox->context1 = (void *)((unsigned long)
5514 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5515 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005516 mbox->context2 = lpfc_nlp_get(ndlp);
5517 mbox->vport = vport;
5518 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5519 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5520 != MBX_NOT_FINISHED)
5521 /* Mbox completion will send ELS Response */
5522 return 0;
5523 /* Decrement reference count used for the failed mbox
5524 * command.
5525 */
5526 lpfc_nlp_put(ndlp);
5527 mempool_free(mbox, phba->mbox_mem_pool);
5528 }
5529reject_out:
5530 /* issue rejection response */
5531 stat.un.b.lsRjtRsvd0 = 0;
5532 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5533 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5534 stat.un.b.vendorUnique = 0;
5535 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5536 return 0;
5537}
5538
5539/**
5540 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5541 * @vport: pointer to a host virtual N_Port data structure.
5542 * @cmdiocb: pointer to lpfc command iocb data structure.
5543 * @ndlp: pointer to a node-list data structure.
5544 *
5545 * This routine processes Read Timout Value (RTV) IOCB received as an
5546 * ELS unsolicited event. It first checks the remote port state. If the
5547 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5548 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5549 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5550 * Value (RTV) unsolicited IOCB event.
5551 *
5552 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5553 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5554 * will be stored into the context1 field of the IOCB for the completion
5555 * callback function to the RPS Accept Response ELS IOCB command.
5556 *
5557 * Return codes
5558 * 0 - Successfully processed rtv iocb (currently always return 0)
5559 **/
5560static int
5561lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5562 struct lpfc_nodelist *ndlp)
5563{
5564 struct lpfc_hba *phba = vport->phba;
5565 struct ls_rjt stat;
5566 struct RTV_RSP *rtv_rsp;
5567 uint8_t *pcmd;
5568 struct lpfc_iocbq *elsiocb;
5569 uint32_t cmdsize;
5570
5571
5572 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5573 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5574 /* reject the unsolicited RPS request and done with it */
5575 goto reject_out;
5576
5577 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5578 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5579 lpfc_max_els_tries, ndlp,
5580 ndlp->nlp_DID, ELS_CMD_ACC);
5581
5582 if (!elsiocb)
5583 return 1;
5584
5585 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5586 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5587 pcmd += sizeof(uint32_t); /* Skip past command */
5588
5589 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005590 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5591 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005592
5593 rtv_rsp = (struct RTV_RSP *)pcmd;
5594
5595 /* populate RTV payload */
5596 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5597 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5598 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5599 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5600 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5601
5602 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5603 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5604 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5605 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5606 "Data: x%x x%x x%x\n",
5607 elsiocb->iotag, elsiocb->iocb.ulpContext,
5608 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5609 ndlp->nlp_rpi,
5610 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5611 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5612 phba->fc_stat.elsXmitACC++;
5613 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5614 lpfc_els_free_iocb(phba, elsiocb);
5615 return 0;
5616
5617reject_out:
5618 /* issue rejection response */
5619 stat.un.b.lsRjtRsvd0 = 0;
5620 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5621 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5622 stat.un.b.vendorUnique = 0;
5623 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5624 return 0;
5625}
5626
5627/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005628 * @vport: pointer to a host virtual N_Port data structure.
5629 * @cmdiocb: pointer to lpfc command iocb data structure.
5630 * @ndlp: pointer to a node-list data structure.
5631 *
5632 * This routine processes Read Port Status (RPS) IOCB received as an
5633 * ELS unsolicited event. It first checks the remote port state. If the
5634 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5635 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5636 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5637 * for reading the HBA link statistics. It is for the callback function,
5638 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5639 * to actually sending out RPS Accept (ACC) response.
5640 *
5641 * Return codes
5642 * 0 - Successfully processed rps iocb (currently always return 0)
5643 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005644static int
James Smart2e0fef82007-06-17 19:56:36 -05005645lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5646 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005647{
James Smart2e0fef82007-06-17 19:56:36 -05005648 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005649 uint32_t *lp;
5650 uint8_t flag;
5651 LPFC_MBOXQ_t *mbox;
5652 struct lpfc_dmabuf *pcmd;
5653 RPS *rps;
5654 struct ls_rjt stat;
5655
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005656 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005657 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5658 /* reject the unsolicited RPS request and done with it */
5659 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005660
5661 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5662 lp = (uint32_t *) pcmd->virt;
5663 flag = (be32_to_cpu(*lp++) & 0xf);
5664 rps = (RPS *) lp;
5665
5666 if ((flag == 0) ||
5667 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005668 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005669 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005670
James Smart92d7f7b2007-06-17 19:56:38 -05005671 printk("Fix me....\n");
5672 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005673 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5674 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005675 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005676 mbox->context1 = (void *)((unsigned long)
5677 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5678 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005679 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005680 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005681 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005682 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005683 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005684 /* Mbox completion will send ELS Response */
5685 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005686 /* Decrement reference count used for the failed mbox
5687 * command.
5688 */
James Smart329f9bc2007-04-25 09:53:01 -04005689 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005690 mempool_free(mbox, phba->mbox_mem_pool);
5691 }
5692 }
James Smart90160e02008-08-24 21:49:45 -04005693
5694reject_out:
5695 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005696 stat.un.b.lsRjtRsvd0 = 0;
5697 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5698 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5699 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005700 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005701 return 0;
5702}
5703
James Smart19ca7602010-11-20 23:11:55 -05005704/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5705 * @vport: pointer to a host virtual N_Port data structure.
5706 * @ndlp: pointer to a node-list data structure.
5707 * @did: DID of the target.
5708 * @rrq: Pointer to the rrq struct.
5709 *
5710 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5711 * Successful the the completion handler will clear the RRQ.
5712 *
5713 * Return codes
5714 * 0 - Successfully sent rrq els iocb.
5715 * 1 - Failed to send rrq els iocb.
5716 **/
5717static int
5718lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5719 uint32_t did, struct lpfc_node_rrq *rrq)
5720{
5721 struct lpfc_hba *phba = vport->phba;
5722 struct RRQ *els_rrq;
5723 IOCB_t *icmd;
5724 struct lpfc_iocbq *elsiocb;
5725 uint8_t *pcmd;
5726 uint16_t cmdsize;
5727 int ret;
5728
5729
5730 if (ndlp != rrq->ndlp)
5731 ndlp = rrq->ndlp;
5732 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5733 return 1;
5734
5735 /* If ndlp is not NULL, we will bump the reference count on it */
5736 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5737 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5738 ELS_CMD_RRQ);
5739 if (!elsiocb)
5740 return 1;
5741
5742 icmd = &elsiocb->iocb;
5743 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5744
5745 /* For RRQ request, remainder of payload is Exchange IDs */
5746 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5747 pcmd += sizeof(uint32_t);
5748 els_rrq = (struct RRQ *) pcmd;
5749
James Smartee0f4fe2012-05-09 21:19:14 -04005750 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005751 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5752 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5753 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5754 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5755
5756
5757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5758 "Issue RRQ: did:x%x",
5759 did, rrq->xritag, rrq->rxid);
5760 elsiocb->context_un.rrq = rrq;
5761 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5762 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5763
5764 if (ret == IOCB_ERROR) {
5765 lpfc_els_free_iocb(phba, elsiocb);
5766 return 1;
5767 }
5768 return 0;
5769}
5770
5771/**
5772 * lpfc_send_rrq - Sends ELS RRQ if needed.
5773 * @phba: pointer to lpfc hba data structure.
5774 * @rrq: pointer to the active rrq.
5775 *
5776 * This routine will call the lpfc_issue_els_rrq if the rrq is
5777 * still active for the xri. If this function returns a failure then
5778 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5779 *
5780 * Returns 0 Success.
5781 * 1 Failure.
5782 **/
5783int
5784lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5785{
5786 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5787 rrq->nlp_DID);
5788 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5789 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5790 rrq->nlp_DID, rrq);
5791 else
5792 return 1;
5793}
5794
James Smarte59058c2008-08-24 21:49:00 -04005795/**
James Smart3621a712009-04-06 18:47:14 -04005796 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005797 * @vport: pointer to a host virtual N_Port data structure.
5798 * @cmdsize: size of the ELS command.
5799 * @oldiocb: pointer to the original lpfc command iocb data structure.
5800 * @ndlp: pointer to a node-list data structure.
5801 *
5802 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5803 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5804 *
5805 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5806 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5807 * will be stored into the context1 field of the IOCB for the completion
5808 * callback function to the RPL Accept Response ELS command.
5809 *
5810 * Return code
5811 * 0 - Successfully issued ACC RPL ELS command
5812 * 1 - Failed to issue ACC RPL ELS command
5813 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005814static int
James Smart2e0fef82007-06-17 19:56:36 -05005815lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5816 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005817{
James Smart2e0fef82007-06-17 19:56:36 -05005818 struct lpfc_hba *phba = vport->phba;
5819 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005820 RPL_RSP rpl_rsp;
5821 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005822 uint8_t *pcmd;
5823
James Smart2e0fef82007-06-17 19:56:36 -05005824 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5825 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005826
James Smart488d1462006-03-07 15:02:37 -05005827 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005828 return 1;
James Smart488d1462006-03-07 15:02:37 -05005829
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005830 icmd = &elsiocb->iocb;
5831 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005832 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5833 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005834
5835 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5836 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005837 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005838 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5839 pcmd += sizeof(uint16_t);
5840
5841 /* Setup the RPL ACC payload */
5842 rpl_rsp.listLen = be32_to_cpu(1);
5843 rpl_rsp.index = 0;
5844 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005845 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5846 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005847 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005848 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005849 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005850 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5851 "0120 Xmit ELS RPL ACC response tag x%x "
5852 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5853 "rpi x%x\n",
5854 elsiocb->iotag, elsiocb->iocb.ulpContext,
5855 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5856 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005857 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005858 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005859 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5860 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005861 lpfc_els_free_iocb(phba, elsiocb);
5862 return 1;
5863 }
5864 return 0;
5865}
5866
James Smarte59058c2008-08-24 21:49:00 -04005867/**
James Smart3621a712009-04-06 18:47:14 -04005868 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005869 * @vport: pointer to a host virtual N_Port data structure.
5870 * @cmdiocb: pointer to lpfc command iocb data structure.
5871 * @ndlp: pointer to a node-list data structure.
5872 *
5873 * This routine processes Read Port List (RPL) IOCB received as an ELS
5874 * unsolicited event. It first checks the remote port state. If the remote
5875 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5876 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5877 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5878 * to accept the RPL.
5879 *
5880 * Return code
5881 * 0 - Successfully processed rpl iocb (currently always return 0)
5882 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005883static int
James Smart2e0fef82007-06-17 19:56:36 -05005884lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5885 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005886{
5887 struct lpfc_dmabuf *pcmd;
5888 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005889 uint32_t maxsize;
5890 uint16_t cmdsize;
5891 RPL *rpl;
5892 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005893
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005894 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5895 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005896 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005897 stat.un.b.lsRjtRsvd0 = 0;
5898 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5899 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5900 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005901 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5902 NULL);
James Smart90160e02008-08-24 21:49:45 -04005903 /* rejected the unsolicited RPL request and done with it */
5904 return 0;
dea31012005-04-17 16:05:31 -05005905 }
5906
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005907 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5908 lp = (uint32_t *) pcmd->virt;
5909 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005910 maxsize = be32_to_cpu(rpl->maxsize);
5911
5912 /* We support only one port */
5913 if ((rpl->index == 0) &&
5914 ((maxsize == 0) ||
5915 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5916 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005917 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005918 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5919 }
James Smart2e0fef82007-06-17 19:56:36 -05005920 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005921
5922 return 0;
5923}
5924
James Smarte59058c2008-08-24 21:49:00 -04005925/**
James Smart3621a712009-04-06 18:47:14 -04005926 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005927 * @vport: pointer to a virtual N_Port data structure.
5928 * @cmdiocb: pointer to lpfc command iocb data structure.
5929 * @ndlp: pointer to a node-list data structure.
5930 *
5931 * This routine processes Fibre Channel Address Resolution Protocol
5932 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5933 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5934 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5935 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5936 * remote PortName is compared against the FC PortName stored in the @vport
5937 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5938 * compared against the FC NodeName stored in the @vport data structure.
5939 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5940 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5941 * invoked to send out FARP Response to the remote node. Before sending the
5942 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5943 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5944 * routine is invoked to log into the remote port first.
5945 *
5946 * Return code
5947 * 0 - Either the FARP Match Mode not supported or successfully processed
5948 **/
dea31012005-04-17 16:05:31 -05005949static int
James Smart2e0fef82007-06-17 19:56:36 -05005950lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5951 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005952{
5953 struct lpfc_dmabuf *pcmd;
5954 uint32_t *lp;
5955 IOCB_t *icmd;
5956 FARP *fp;
5957 uint32_t cmd, cnt, did;
5958
5959 icmd = &cmdiocb->iocb;
5960 did = icmd->un.elsreq64.remoteID;
5961 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5962 lp = (uint32_t *) pcmd->virt;
5963
5964 cmd = *lp++;
5965 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005966 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005967 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5968 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005969 /* We will only support match on WWPN or WWNN */
5970 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005971 return 0;
dea31012005-04-17 16:05:31 -05005972 }
5973
5974 cnt = 0;
5975 /* If this FARP command is searching for my portname */
5976 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005977 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005978 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005979 cnt = 1;
5980 }
5981
5982 /* If this FARP command is searching for my nodename */
5983 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005984 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005985 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005986 cnt = 1;
5987 }
5988
5989 if (cnt) {
5990 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5991 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5992 /* Log back into the node before sending the FARP. */
5993 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005994 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005995 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005996 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005997 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005998 }
5999
6000 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05006001 if (fp->Rflags & FARP_REQUEST_FARPR)
6002 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006003 }
6004 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006005 return 0;
dea31012005-04-17 16:05:31 -05006006}
6007
James Smarte59058c2008-08-24 21:49:00 -04006008/**
James Smart3621a712009-04-06 18:47:14 -04006009 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006010 * @vport: pointer to a host virtual N_Port data structure.
6011 * @cmdiocb: pointer to lpfc command iocb data structure.
6012 * @ndlp: pointer to a node-list data structure.
6013 *
6014 * This routine processes Fibre Channel Address Resolution Protocol
6015 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6016 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6017 * the FARP response request.
6018 *
6019 * Return code
6020 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6021 **/
dea31012005-04-17 16:05:31 -05006022static int
James Smart2e0fef82007-06-17 19:56:36 -05006023lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6024 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006025{
6026 struct lpfc_dmabuf *pcmd;
6027 uint32_t *lp;
6028 IOCB_t *icmd;
6029 uint32_t cmd, did;
6030
6031 icmd = &cmdiocb->iocb;
6032 did = icmd->un.elsreq64.remoteID;
6033 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6034 lp = (uint32_t *) pcmd->virt;
6035
6036 cmd = *lp++;
6037 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006038 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6039 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006040 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006041 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006042
6043 return 0;
6044}
6045
James Smarte59058c2008-08-24 21:49:00 -04006046/**
James Smart3621a712009-04-06 18:47:14 -04006047 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006048 * @vport: pointer to a host virtual N_Port data structure.
6049 * @cmdiocb: pointer to lpfc command iocb data structure.
6050 * @fan_ndlp: pointer to a node-list data structure.
6051 *
6052 * This routine processes a Fabric Address Notification (FAN) IOCB
6053 * command received as an ELS unsolicited event. The FAN ELS command will
6054 * only be processed on a physical port (i.e., the @vport represents the
6055 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6056 * compared against those in the phba data structure. If any of those is
6057 * different, the lpfc_initial_flogi() routine is invoked to initialize
6058 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6059 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6060 * is invoked to register login to the fabric.
6061 *
6062 * Return code
6063 * 0 - Successfully processed fan iocb (currently always return 0).
6064 **/
dea31012005-04-17 16:05:31 -05006065static int
James Smart2e0fef82007-06-17 19:56:36 -05006066lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6067 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006068{
James Smart2e0fef82007-06-17 19:56:36 -05006069 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006070 uint32_t *lp;
6071 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006072
James Smart0d2b6b82008-06-14 22:52:47 -04006073 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6074 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6075 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006076 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006077 if ((vport == phba->pport) &&
6078 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006079 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006080 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006081 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006082 sizeof(struct lpfc_name)))) {
6083 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006084 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006085 } else {
6086 /* FAN verified - skip FLOGI */
6087 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006088 if (phba->sli_rev < LPFC_SLI_REV4)
6089 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006090 else {
6091 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6092 "3138 Need register VFI: (x%x/%x)\n",
6093 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006094 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006095 }
dea31012005-04-17 16:05:31 -05006096 }
dea31012005-04-17 16:05:31 -05006097 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006098 return 0;
dea31012005-04-17 16:05:31 -05006099}
6100
James Smarte59058c2008-08-24 21:49:00 -04006101/**
James Smart3621a712009-04-06 18:47:14 -04006102 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006103 * @ptr: holder for the timer function associated data.
6104 *
6105 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6106 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6107 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6108 * up the worker thread. It is for the worker thread to invoke the routine
6109 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6110 **/
dea31012005-04-17 16:05:31 -05006111void
6112lpfc_els_timeout(unsigned long ptr)
6113{
James Smart2e0fef82007-06-17 19:56:36 -05006114 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6115 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006116 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006117 unsigned long iflag;
6118
James Smart2e0fef82007-06-17 19:56:36 -05006119 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006120 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6121 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006122 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006123 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006124
James Smart5e9d9b82008-06-14 22:52:53 -04006125 if (!tmo_posted)
6126 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006127 return;
6128}
6129
James Smart2a9bf3d2010-06-07 15:24:45 -04006130
James Smarte59058c2008-08-24 21:49:00 -04006131/**
James Smart3621a712009-04-06 18:47:14 -04006132 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006133 * @vport: pointer to a virtual N_Port data structure.
6134 *
6135 * This routine is the actual handler function that processes an ELS timeout
6136 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6137 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6138 * invoking the lpfc_sli_issue_abort_iotag() routine.
6139 **/
dea31012005-04-17 16:05:31 -05006140void
James Smart2e0fef82007-06-17 19:56:36 -05006141lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006142{
James Smart2e0fef82007-06-17 19:56:36 -05006143 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006144 struct lpfc_sli_ring *pring;
6145 struct lpfc_iocbq *tmp_iocb, *piocb;
6146 IOCB_t *cmd = NULL;
6147 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006148 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006149 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006150 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006151 LIST_HEAD(txcmplq_completions);
6152 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006153
James Smart2a9bf3d2010-06-07 15:24:45 -04006154
dea31012005-04-17 16:05:31 -05006155 timeout = (uint32_t)(phba->fc_ratov << 1);
6156
6157 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006158
James Smart2a9bf3d2010-06-07 15:24:45 -04006159 spin_lock_irq(&phba->hbalock);
6160 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6161 spin_unlock_irq(&phba->hbalock);
6162
6163 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006164 cmd = &piocb->iocb;
6165
James Smart2e0fef82007-06-17 19:56:36 -05006166 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6167 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6168 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006169 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006170
6171 if (piocb->vport != vport)
6172 continue;
6173
dea31012005-04-17 16:05:31 -05006174 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006175 if (pcmd)
6176 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006177
James Smart92d7f7b2007-06-17 19:56:38 -05006178 if (els_command == ELS_CMD_FARP ||
6179 els_command == ELS_CMD_FARPR ||
6180 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006181 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006182
dea31012005-04-17 16:05:31 -05006183 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006184 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006185 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006186 else
dea31012005-04-17 16:05:31 -05006187 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006188 continue;
6189 }
6190
James Smart2e0fef82007-06-17 19:56:36 -05006191 remote_ID = 0xffffffff;
6192 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006193 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006194 else {
6195 struct lpfc_nodelist *ndlp;
6196 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006197 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006198 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006199 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006200 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006201 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006202 spin_lock_irq(&phba->hbalock);
6203 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006204 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006205
James Smart2a9bf3d2010-06-07 15:24:45 -04006206 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6207 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6208 "0127 ELS timeout Data: x%x x%x x%x "
6209 "x%x\n", els_command,
6210 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6211 spin_lock_irq(&phba->hbalock);
6212 list_del_init(&piocb->dlist);
6213 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6214 spin_unlock_irq(&phba->hbalock);
6215 }
6216
James Smart2e0fef82007-06-17 19:56:36 -05006217 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6218 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006219}
6220
James Smarte59058c2008-08-24 21:49:00 -04006221/**
James Smart3621a712009-04-06 18:47:14 -04006222 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006223 * @vport: pointer to a host virtual N_Port data structure.
6224 *
6225 * This routine is used to clean up all the outstanding ELS commands on a
6226 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6227 * routine. After that, it walks the ELS transmit queue to remove all the
6228 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6229 * the IOCBs with a non-NULL completion callback function, the callback
6230 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6231 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6232 * callback function, the IOCB will simply be released. Finally, it walks
6233 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6234 * completion queue IOCB that is associated with the @vport and is not
6235 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6236 * part of the discovery state machine) out to HBA by invoking the
6237 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6238 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6239 * the IOCBs are aborted when this function returns.
6240 **/
dea31012005-04-17 16:05:31 -05006241void
James Smart2e0fef82007-06-17 19:56:36 -05006242lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006243{
James Smart2534ba72007-04-25 09:52:20 -04006244 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006245 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006246 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006247 struct lpfc_iocbq *tmp_iocb, *piocb;
6248 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006249
6250 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006251
James Smart2e0fef82007-06-17 19:56:36 -05006252 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006253 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6254 cmd = &piocb->iocb;
6255
6256 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6257 continue;
6258 }
6259
6260 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006261 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6262 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6263 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6264 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006265 continue;
dea31012005-04-17 16:05:31 -05006266
James Smart2e0fef82007-06-17 19:56:36 -05006267 if (piocb->vport != vport)
6268 continue;
6269
James Smart2534ba72007-04-25 09:52:20 -04006270 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006271 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006272 }
6273
6274 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006275 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6276 continue;
6277 }
dea31012005-04-17 16:05:31 -05006278
James Smart2e0fef82007-06-17 19:56:36 -05006279 if (piocb->vport != vport)
6280 continue;
6281
James Smart07951072007-04-25 09:51:38 -04006282 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006283 }
James Smart2e0fef82007-06-17 19:56:36 -05006284 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006285
James Smarta257bf92009-04-06 18:48:10 -04006286 /* Cancell all the IOCBs from the completions list */
6287 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6288 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006289
dea31012005-04-17 16:05:31 -05006290 return;
6291}
6292
James Smarte59058c2008-08-24 21:49:00 -04006293/**
James Smart3621a712009-04-06 18:47:14 -04006294 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006295 * @phba: pointer to lpfc hba data structure.
6296 *
6297 * This routine is used to clean up all the outstanding ELS commands on a
6298 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6299 * routine. After that, it walks the ELS transmit queue to remove all the
6300 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6301 * the IOCBs with the completion callback function associated, the callback
6302 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6303 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6304 * callback function associated, the IOCB will simply be released. Finally,
6305 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6306 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6307 * management plane IOCBs that are not part of the discovery state machine)
6308 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6309 **/
James Smart549e55c2007-08-02 11:09:51 -04006310void
6311lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6312{
6313 LIST_HEAD(completions);
6314 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6315 struct lpfc_iocbq *tmp_iocb, *piocb;
6316 IOCB_t *cmd = NULL;
6317
6318 lpfc_fabric_abort_hba(phba);
6319 spin_lock_irq(&phba->hbalock);
6320 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6321 cmd = &piocb->iocb;
6322 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6323 continue;
6324 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6325 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6326 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6327 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6328 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6329 continue;
6330 list_move_tail(&piocb->list, &completions);
6331 pring->txq_cnt--;
6332 }
6333 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6334 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6335 continue;
6336 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6337 }
6338 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006339
6340 /* Cancel all the IOCBs from the completions list */
6341 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6342 IOERR_SLI_ABORTED);
6343
James Smart549e55c2007-08-02 11:09:51 -04006344 return;
6345}
6346
James Smarte59058c2008-08-24 21:49:00 -04006347/**
James Smart3621a712009-04-06 18:47:14 -04006348 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006349 * @phba: Pointer to hba context object.
6350 * @cmdiocbp: Pointer to command iocb which reported error.
6351 * @rspiocbp: Pointer to response iocb which reported error.
6352 *
6353 * This function sends an event when there is an ELS command
6354 * failure.
6355 **/
6356void
6357lpfc_send_els_failure_event(struct lpfc_hba *phba,
6358 struct lpfc_iocbq *cmdiocbp,
6359 struct lpfc_iocbq *rspiocbp)
6360{
6361 struct lpfc_vport *vport = cmdiocbp->vport;
6362 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6363 struct lpfc_lsrjt_event lsrjt_event;
6364 struct lpfc_fabric_event_header fabric_event;
6365 struct ls_rjt stat;
6366 struct lpfc_nodelist *ndlp;
6367 uint32_t *pcmd;
6368
6369 ndlp = cmdiocbp->context1;
6370 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6371 return;
6372
6373 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6374 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6375 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6376 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6377 sizeof(struct lpfc_name));
6378 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6379 sizeof(struct lpfc_name));
6380 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6381 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006382 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006383 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6384 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6385 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6386 fc_host_post_vendor_event(shost,
6387 fc_get_event_number(),
6388 sizeof(lsrjt_event),
6389 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006390 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006391 return;
6392 }
6393 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6394 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6395 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6396 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6397 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6398 else
6399 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6400 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6401 sizeof(struct lpfc_name));
6402 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6403 sizeof(struct lpfc_name));
6404 fc_host_post_vendor_event(shost,
6405 fc_get_event_number(),
6406 sizeof(fabric_event),
6407 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006408 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006409 return;
6410 }
6411
6412}
6413
6414/**
James Smart3621a712009-04-06 18:47:14 -04006415 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006416 * @vport: Pointer to vport object.
6417 * @ndlp: Pointer FC node object.
6418 * @cmd: ELS command code.
6419 *
6420 * This function posts an event when there is an incoming
6421 * unsolicited ELS command.
6422 **/
6423static void
6424lpfc_send_els_event(struct lpfc_vport *vport,
6425 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006426 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006427{
James Smartddcc50f2008-12-04 22:38:46 -05006428 struct lpfc_els_event_header *els_data = NULL;
6429 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006430 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6431
James Smartddcc50f2008-12-04 22:38:46 -05006432 if (*payload == ELS_CMD_LOGO) {
6433 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6434 if (!logo_data) {
6435 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6436 "0148 Failed to allocate memory "
6437 "for LOGO event\n");
6438 return;
6439 }
6440 els_data = &logo_data->header;
6441 } else {
6442 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6443 GFP_KERNEL);
6444 if (!els_data) {
6445 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6446 "0149 Failed to allocate memory "
6447 "for ELS event\n");
6448 return;
6449 }
6450 }
6451 els_data->event_type = FC_REG_ELS_EVENT;
6452 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006453 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006454 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006455 break;
6456 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006457 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006458 break;
6459 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006460 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6461 break;
6462 case ELS_CMD_LOGO:
6463 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6464 /* Copy the WWPN in the LOGO payload */
6465 memcpy(logo_data->logo_wwpn, &payload[2],
6466 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006467 break;
6468 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006469 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006470 return;
6471 }
James Smartddcc50f2008-12-04 22:38:46 -05006472 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6473 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6474 if (*payload == ELS_CMD_LOGO) {
6475 fc_host_post_vendor_event(shost,
6476 fc_get_event_number(),
6477 sizeof(struct lpfc_logo_event),
6478 (char *)logo_data,
6479 LPFC_NL_VENDOR_ID);
6480 kfree(logo_data);
6481 } else {
6482 fc_host_post_vendor_event(shost,
6483 fc_get_event_number(),
6484 sizeof(struct lpfc_els_event_header),
6485 (char *)els_data,
6486 LPFC_NL_VENDOR_ID);
6487 kfree(els_data);
6488 }
James Smartea2151b2008-09-07 11:52:10 -04006489
6490 return;
6491}
6492
6493
6494/**
James Smart3621a712009-04-06 18:47:14 -04006495 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006496 * @phba: pointer to lpfc hba data structure.
6497 * @pring: pointer to a SLI ring.
6498 * @vport: pointer to a host virtual N_Port data structure.
6499 * @elsiocb: pointer to lpfc els command iocb data structure.
6500 *
6501 * This routine is used for processing the IOCB associated with a unsolicited
6502 * event. It first determines whether there is an existing ndlp that matches
6503 * the DID from the unsolicited IOCB. If not, it will create a new one with
6504 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6505 * IOCB is then used to invoke the proper routine and to set up proper state
6506 * of the discovery state machine.
6507 **/
James Smarted957682007-06-17 19:56:37 -05006508static void
6509lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006510 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006511{
James Smart87af33f2007-10-27 13:37:43 -04006512 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006513 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006514 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006515 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006516 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006517 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006518
James Smarte47c9092008-02-08 18:49:26 -05006519 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006520 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006521
dea31012005-04-17 16:05:31 -05006522 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006523 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6524 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006525 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006526 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006527
James Smart858c9f62007-06-17 19:56:39 -05006528 did = icmd->un.rcvels.remoteID;
6529 if (icmd->ulpStatus) {
6530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6531 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6532 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006533 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006534 }
dea31012005-04-17 16:05:31 -05006535
6536 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006537 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006538 goto dropit;
dea31012005-04-17 16:05:31 -05006539
James Smartc8685952009-11-18 15:39:16 -05006540 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006541 if (vport->load_flag & FC_UNLOADING)
6542 goto dropit;
6543
James Smart92494142011-02-16 12:39:44 -05006544 /* If NPort discovery is delayed drop incoming ELS */
6545 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6546 (cmd != ELS_CMD_PLOGI))
6547 goto dropit;
6548
James Smart2e0fef82007-06-17 19:56:36 -05006549 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006550 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006551 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006552 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006553 if (!ndlp)
dea31012005-04-17 16:05:31 -05006554 goto dropit;
dea31012005-04-17 16:05:31 -05006555
James Smart2e0fef82007-06-17 19:56:36 -05006556 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006558 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006559 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006560 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006561 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6562 ndlp = lpfc_enable_node(vport, ndlp,
6563 NLP_STE_UNUSED_NODE);
6564 if (!ndlp)
6565 goto dropit;
6566 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6567 newnode = 1;
6568 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6569 ndlp->nlp_type |= NLP_FABRIC;
6570 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6571 /* This is similar to the new node path */
6572 ndlp = lpfc_nlp_get(ndlp);
6573 if (!ndlp)
6574 goto dropit;
6575 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6576 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006577 }
dea31012005-04-17 16:05:31 -05006578
6579 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006580
James Smart329f9bc2007-04-25 09:53:01 -04006581 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006582 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006583
6584 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6585 cmd &= ELS_CMD_MASK;
6586 }
6587 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006588 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6589 "0112 ELS command x%x received from NPORT x%x "
6590 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006591 switch (cmd) {
6592 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006593 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6594 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6595 did, vport->port_state, ndlp->nlp_flag);
6596
dea31012005-04-17 16:05:31 -05006597 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006598 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6599
James Smartddcc50f2008-12-04 22:38:46 -05006600 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006601
6602 /* If Nport discovery is delayed, reject PLOGIs */
6603 if (vport->fc_flag & FC_DISC_DELAYED) {
6604 rjt_err = LSRJT_UNABLE_TPC;
6605 break;
6606 }
James Smart858c9f62007-06-17 19:56:39 -05006607 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006608 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6609 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6610 rjt_err = LSRJT_UNABLE_TPC;
6611 break;
6612 }
6613 /* We get here, and drop thru, if we are PT2PT with
6614 * another NPort and the other side has initiated
6615 * the PLOGI before responding to our FLOGI.
6616 */
dea31012005-04-17 16:05:31 -05006617 }
James Smart87af33f2007-10-27 13:37:43 -04006618
6619 shost = lpfc_shost_from_vport(vport);
6620 spin_lock_irq(shost->host_lock);
6621 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6622 spin_unlock_irq(shost->host_lock);
6623
James Smart2e0fef82007-06-17 19:56:36 -05006624 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6625 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006626
dea31012005-04-17 16:05:31 -05006627 break;
6628 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6630 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6631 did, vport->port_state, ndlp->nlp_flag);
6632
dea31012005-04-17 16:05:31 -05006633 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006634 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006635 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006636 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006637 break;
6638 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6640 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6641 did, vport->port_state, ndlp->nlp_flag);
6642
dea31012005-04-17 16:05:31 -05006643 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006644 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006645 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006646 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006647 break;
6648 }
James Smart2e0fef82007-06-17 19:56:36 -05006649 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006650 break;
6651 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006652 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6653 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6654 did, vport->port_state, ndlp->nlp_flag);
6655
dea31012005-04-17 16:05:31 -05006656 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006657 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006658 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006659 rjt_err = LSRJT_UNABLE_TPC;
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_PRLO);
dea31012005-04-17 16:05:31 -05006663 break;
6664 case ELS_CMD_RSCN:
6665 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006666 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006667 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006668 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006669 break;
6670 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6672 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6673 did, vport->port_state, ndlp->nlp_flag);
6674
James Smartddcc50f2008-12-04 22:38:46 -05006675 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006676 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006677 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006678 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006679 break;
6680 }
James Smart2e0fef82007-06-17 19:56:36 -05006681 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6682 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006683 break;
6684 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6686 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6687 did, vport->port_state, ndlp->nlp_flag);
6688
dea31012005-04-17 16:05:31 -05006689 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006690 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006691 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006692 break;
6693 }
James Smart2e0fef82007-06-17 19:56:36 -05006694 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6695 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006696 break;
6697 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006698 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6699 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6700 did, vport->port_state, ndlp->nlp_flag);
6701
dea31012005-04-17 16:05:31 -05006702 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006703 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006704 break;
6705 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6707 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6708 did, vport->port_state, ndlp->nlp_flag);
6709
dea31012005-04-17 16:05:31 -05006710 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006711 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006712 break;
6713 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006714 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6715 "RCV FAN: 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.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006719 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006720 break;
dea31012005-04-17 16:05:31 -05006721 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006722 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6723 "RCV PRLI: 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.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006727 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006728 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006729 break;
6730 }
James Smart2e0fef82007-06-17 19:56:36 -05006731 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006732 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006733 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6735 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6736 did, vport->port_state, ndlp->nlp_flag);
6737
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006738 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006739 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006740 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006741 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006742 break;
James Smart12265f62010-10-22 11:05:53 -04006743 case ELS_CMD_RLS:
6744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6745 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6746 did, vport->port_state, ndlp->nlp_flag);
6747
6748 phba->fc_stat.elsRcvRLS++;
6749 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6750 if (newnode)
6751 lpfc_nlp_put(ndlp);
6752 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006753 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006754 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6755 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6756 did, vport->port_state, ndlp->nlp_flag);
6757
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006758 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006759 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006760 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006761 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006762 break;
6763 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6765 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6766 did, vport->port_state, ndlp->nlp_flag);
6767
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006768 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006769 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006770 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006771 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006772 break;
dea31012005-04-17 16:05:31 -05006773 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006774 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6775 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6776 did, vport->port_state, ndlp->nlp_flag);
6777
dea31012005-04-17 16:05:31 -05006778 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006779 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006780 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006781 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006782 break;
James Smart12265f62010-10-22 11:05:53 -04006783 case ELS_CMD_RTV:
6784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6785 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6786 did, vport->port_state, ndlp->nlp_flag);
6787 phba->fc_stat.elsRcvRTV++;
6788 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6789 if (newnode)
6790 lpfc_nlp_put(ndlp);
6791 break;
James Smart5ffc2662009-11-18 15:39:44 -05006792 case ELS_CMD_RRQ:
6793 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6794 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6795 did, vport->port_state, ndlp->nlp_flag);
6796
6797 phba->fc_stat.elsRcvRRQ++;
6798 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6799 if (newnode)
6800 lpfc_nlp_put(ndlp);
6801 break;
James Smart12265f62010-10-22 11:05:53 -04006802 case ELS_CMD_ECHO:
6803 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6804 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6805 did, vport->port_state, ndlp->nlp_flag);
6806
6807 phba->fc_stat.elsRcvECHO++;
6808 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6809 if (newnode)
6810 lpfc_nlp_put(ndlp);
6811 break;
dea31012005-04-17 16:05:31 -05006812 default:
James Smart858c9f62007-06-17 19:56:39 -05006813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6814 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6815 cmd, did, vport->port_state);
6816
dea31012005-04-17 16:05:31 -05006817 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006818 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006819
6820 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006821 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6822 "0115 Unknown ELS command x%x "
6823 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006824 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006825 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006826 break;
6827 }
6828
6829 /* check if need to LS_RJT received ELS cmd */
6830 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006831 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006832 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006833 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006834 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6835 NULL);
dea31012005-04-17 16:05:31 -05006836 }
6837
James Smartd7c255b2008-08-24 21:50:00 -04006838 lpfc_nlp_put(elsiocb->context1);
6839 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006840 return;
6841
6842dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006843 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006844 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6845 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006846 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006847 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006848 phba->fc_stat.elsRcvDrop++;
6849}
6850
James Smarte59058c2008-08-24 21:49:00 -04006851/**
James Smart3621a712009-04-06 18:47:14 -04006852 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006853 * @phba: pointer to lpfc hba data structure.
6854 * @pring: pointer to a SLI ring.
6855 * @elsiocb: pointer to lpfc els iocb data structure.
6856 *
6857 * This routine is used to process an unsolicited event received from a SLI
6858 * (Service Level Interface) ring. The actual processing of the data buffer
6859 * associated with the unsolicited event is done by invoking the routine
6860 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6861 * SLI ring on which the unsolicited event was received.
6862 **/
James Smarted957682007-06-17 19:56:37 -05006863void
6864lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6865 struct lpfc_iocbq *elsiocb)
6866{
6867 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006868 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006869 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006870 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6871 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006872
James Smartd7c255b2008-08-24 21:50:00 -04006873 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006874 elsiocb->context2 = NULL;
6875 elsiocb->context3 = NULL;
6876
6877 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6878 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6879 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04006880 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6881 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006882 phba->fc_stat.NoRcvBuf++;
6883 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006884 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006885 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006886 return;
6887 }
6888
James Smart92d7f7b2007-06-17 19:56:38 -05006889 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6890 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6891 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6892 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6893 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006894 else
6895 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006896 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006897 }
James Smart6d368e52011-05-24 11:44:12 -04006898
James Smart7f5f3d02008-02-08 18:50:14 -05006899 /* If there are no BDEs associated
6900 * with this IOCB, there is nothing to do.
6901 */
James Smarted957682007-06-17 19:56:37 -05006902 if (icmd->ulpBdeCount == 0)
6903 return;
6904
James Smart7f5f3d02008-02-08 18:50:14 -05006905 /* type of ELS cmd is first 32bit word
6906 * in packet
6907 */
James Smarted957682007-06-17 19:56:37 -05006908 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006909 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006910 } else {
6911 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6912 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006913 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6914 paddr);
James Smarted957682007-06-17 19:56:37 -05006915 }
6916
James Smart92d7f7b2007-06-17 19:56:38 -05006917 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6918 /*
6919 * The different unsolicited event handlers would tell us
6920 * if they are done with "mp" by setting context2 to NULL.
6921 */
dea31012005-04-17 16:05:31 -05006922 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006923 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6924 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006925 }
James Smarted957682007-06-17 19:56:37 -05006926
6927 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006928 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006929 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006930 elsiocb->context2 = bdeBuf2;
6931 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006932 /* free mp if we are done with it */
6933 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006934 lpfc_in_buf_free(phba, elsiocb->context2);
6935 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006936 }
dea31012005-04-17 16:05:31 -05006937 }
dea31012005-04-17 16:05:31 -05006938}
James Smart92d7f7b2007-06-17 19:56:38 -05006939
James Smarte59058c2008-08-24 21:49:00 -04006940/**
James Smart3621a712009-04-06 18:47:14 -04006941 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006942 * @phba: pointer to lpfc hba data structure.
6943 * @vport: pointer to a virtual N_Port data structure.
6944 *
6945 * This routine issues a Port Login (PLOGI) to the Name Server with
6946 * State Change Request (SCR) for a @vport. This routine will create an
6947 * ndlp for the Name Server associated to the @vport if such node does
6948 * not already exist. The PLOGI to Name Server is issued by invoking the
6949 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6950 * (FDMI) is configured to the @vport, a FDMI node will be created and
6951 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6952 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006953void
6954lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6955{
6956 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6958
6959 /*
6960 * If lpfc_delay_discovery parameter is set and the clean address
6961 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6962 * discovery.
6963 */
6964 spin_lock_irq(shost->host_lock);
6965 if (vport->fc_flag & FC_DISC_DELAYED) {
6966 spin_unlock_irq(shost->host_lock);
6967 mod_timer(&vport->delayed_disc_tmo,
6968 jiffies + HZ * phba->fc_ratov);
6969 return;
6970 }
6971 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006972
6973 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6974 if (!ndlp) {
6975 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6976 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006977 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006978 lpfc_disc_start(vport);
6979 return;
6980 }
6981 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006982 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6983 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006984 return;
6985 }
6986 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006987 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6988 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6989 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006990 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006991 lpfc_disc_start(vport);
6992 return;
6993 }
6994 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6995 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6996 "0348 NameServer login: node freed\n");
6997 return;
6998 }
James Smart92d7f7b2007-06-17 19:56:38 -05006999 }
James Smart58da1ff2008-04-07 10:15:56 -04007000 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05007001
7002 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7003
7004 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7005 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007006 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7007 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007008 return;
7009 }
7010
James Smart3de2a652007-08-02 11:09:59 -04007011 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05007012 /* If this is the first time, allocate an ndlp and initialize
7013 * it. Otherwise, make sure the node is enabled and then do the
7014 * login.
7015 */
7016 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7017 if (!ndlp_fdmi) {
7018 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7019 GFP_KERNEL);
7020 if (ndlp_fdmi) {
7021 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7022 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7023 } else
7024 return;
7025 }
7026 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7027 ndlp_fdmi = lpfc_enable_node(vport,
7028 ndlp_fdmi,
7029 NLP_STE_NPR_NODE);
7030
James Smart92d7f7b2007-06-17 19:56:38 -05007031 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007032 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007033 NLP_STE_PLOGI_ISSUE);
7034 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007035 }
7036 }
James Smart92d7f7b2007-06-17 19:56:38 -05007037}
7038
James Smarte59058c2008-08-24 21:49:00 -04007039/**
James Smart3621a712009-04-06 18:47:14 -04007040 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007041 * @phba: pointer to lpfc hba data structure.
7042 * @pmb: pointer to the driver internal queue element for mailbox command.
7043 *
7044 * This routine is the completion callback function to register new vport
7045 * mailbox command. If the new vport mailbox command completes successfully,
7046 * the fabric registration login shall be performed on physical port (the
7047 * new vport created is actually a physical port, with VPI 0) or the port
7048 * login to Name Server for State Change Request (SCR) will be performed
7049 * on virtual port (real virtual port, with VPI greater than 0).
7050 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007051static void
7052lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7053{
7054 struct lpfc_vport *vport = pmb->vport;
7055 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7056 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007057 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007058 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007059
James Smart09372822008-01-11 01:52:54 -05007060 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007061 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007062 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007063
7064 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007065 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007066 "0915 Register VPI failed : Status: x%x"
7067 " upd bit: x%x \n", mb->mbxStatus,
7068 mb->un.varRegVpi.upd);
7069 if (phba->sli_rev == LPFC_SLI_REV4 &&
7070 mb->un.varRegVpi.upd)
7071 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007072
7073 switch (mb->mbxStatus) {
7074 case 0x11: /* unsupported feature */
7075 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007076 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007077 /* giving up on vport registration */
7078 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7079 spin_lock_irq(shost->host_lock);
7080 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7081 spin_unlock_irq(shost->host_lock);
7082 lpfc_can_disctmo(vport);
7083 break;
James Smart695a8142010-01-26 23:08:03 -05007084 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7085 case 0x20:
7086 spin_lock_irq(shost->host_lock);
7087 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7088 spin_unlock_irq(shost->host_lock);
7089 lpfc_init_vpi(phba, pmb, vport->vpi);
7090 pmb->vport = vport;
7091 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7092 rc = lpfc_sli_issue_mbox(phba, pmb,
7093 MBX_NOWAIT);
7094 if (rc == MBX_NOT_FINISHED) {
7095 lpfc_printf_vlog(vport,
7096 KERN_ERR, LOG_MBOX,
7097 "2732 Failed to issue INIT_VPI"
7098 " mailbox command\n");
7099 } else {
7100 lpfc_nlp_put(ndlp);
7101 return;
7102 }
7103
James Smart92d7f7b2007-06-17 19:56:38 -05007104 default:
7105 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007106 if (phba->sli_rev == LPFC_SLI_REV4)
7107 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007108 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007109 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007110 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007111 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007112 if (vport->port_type == LPFC_PHYSICAL_PORT
7113 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007114 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007115 else
7116 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007117 break;
7118 }
James Smart92d7f7b2007-06-17 19:56:38 -05007119 } else {
James Smart695a8142010-01-26 23:08:03 -05007120 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007121 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007122 spin_unlock_irq(shost->host_lock);
7123 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007124 if (phba->sli_rev < LPFC_SLI_REV4)
7125 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007126 else {
James Smartfc2b9892010-02-26 14:15:29 -05007127 /*
7128 * If the physical port is instantiated using
7129 * FDISC, do not start vport discovery.
7130 */
7131 if (vport->port_state != LPFC_FDISC)
7132 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007133 lpfc_do_scr_ns_plogi(phba, vport);
7134 }
7135 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007136 lpfc_do_scr_ns_plogi(phba, vport);
7137 }
James Smart38b92ef2010-08-04 16:11:39 -04007138mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007139 /* Now, we decrement the ndlp reference count held for this
7140 * callback function
7141 */
7142 lpfc_nlp_put(ndlp);
7143
James Smart92d7f7b2007-06-17 19:56:38 -05007144 mempool_free(pmb, phba->mbox_mem_pool);
7145 return;
7146}
7147
James Smarte59058c2008-08-24 21:49:00 -04007148/**
James Smart3621a712009-04-06 18:47:14 -04007149 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007150 * @phba: pointer to lpfc hba data structure.
7151 * @vport: pointer to a host virtual N_Port data structure.
7152 * @ndlp: pointer to a node-list data structure.
7153 *
7154 * This routine registers the @vport as a new virtual port with a HBA.
7155 * It is done through a registering vpi mailbox command.
7156 **/
James Smart695a8142010-01-26 23:08:03 -05007157void
James Smart92d7f7b2007-06-17 19:56:38 -05007158lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7159 struct lpfc_nodelist *ndlp)
7160{
James Smart09372822008-01-11 01:52:54 -05007161 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007162 LPFC_MBOXQ_t *mbox;
7163
7164 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7165 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007166 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007167 mbox->vport = vport;
7168 mbox->context2 = lpfc_nlp_get(ndlp);
7169 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007170 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007171 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007172 /* mailbox command not success, decrement ndlp
7173 * reference count for this command
7174 */
7175 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007176 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007177
James Smarte8b62012007-08-02 11:10:09 -04007178 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7179 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007180 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007181 }
7182 } else {
James Smarte8b62012007-08-02 11:10:09 -04007183 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7184 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007185 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007186 }
James Smartfa4066b2008-01-11 01:53:27 -05007187 return;
7188
7189mbox_err_exit:
7190 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7191 spin_lock_irq(shost->host_lock);
7192 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7193 spin_unlock_irq(shost->host_lock);
7194 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007195}
7196
James Smarte59058c2008-08-24 21:49:00 -04007197/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007198 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007199 * @phba: pointer to lpfc hba data structure.
7200 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007201 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007202 **/
7203void
James Smart0c9ab6f2010-02-26 14:15:57 -05007204lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007205{
7206 struct lpfc_vport **vports;
7207 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007208 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007209 int i;
James Smart695a8142010-01-26 23:08:03 -05007210
7211 /* Treat this failure as linkdown for all vports */
7212 link_state = phba->link_state;
7213 lpfc_linkdown(phba);
7214 phba->link_state = link_state;
7215
7216 vports = lpfc_create_vport_work_array(phba);
7217
7218 if (vports) {
7219 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7220 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7221 if (ndlp)
7222 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7223 lpfc_els_flush_cmd(vports[i]);
7224 }
7225 lpfc_destroy_vport_work_array(phba, vports);
7226 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007227}
7228
7229/**
7230 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7231 * @phba: pointer to lpfc hba data structure.
7232 *
7233 * This routine abort all pending discovery commands and
7234 * start a timer to retry FLOGI for the physical port
7235 * discovery.
7236 **/
7237void
7238lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7239{
7240 struct lpfc_nodelist *ndlp;
7241 struct Scsi_Host *shost;
7242
7243 /* Cancel the all vports retry delay retry timers */
7244 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007245
7246 /* If fabric require FLOGI, then re-instantiate physical login */
7247 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7248 if (!ndlp)
7249 return;
7250
James Smart695a8142010-01-26 23:08:03 -05007251 shost = lpfc_shost_from_vport(phba->pport);
7252 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7253 spin_lock_irq(shost->host_lock);
7254 ndlp->nlp_flag |= NLP_DELAY_TMO;
7255 spin_unlock_irq(shost->host_lock);
7256 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7257 phba->pport->port_state = LPFC_FLOGI;
7258 return;
7259}
7260
7261/**
7262 * lpfc_fabric_login_reqd - Check if FLOGI required.
7263 * @phba: pointer to lpfc hba data structure.
7264 * @cmdiocb: pointer to FDISC command iocb.
7265 * @rspiocb: pointer to FDISC response iocb.
7266 *
7267 * This routine checks if a FLOGI is reguired for FDISC
7268 * to succeed.
7269 **/
7270static int
7271lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7272 struct lpfc_iocbq *cmdiocb,
7273 struct lpfc_iocbq *rspiocb)
7274{
7275
7276 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7277 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7278 return 0;
7279 else
7280 return 1;
7281}
7282
7283/**
James Smart3621a712009-04-06 18:47:14 -04007284 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007285 * @phba: pointer to lpfc hba data structure.
7286 * @cmdiocb: pointer to lpfc command iocb data structure.
7287 * @rspiocb: pointer to lpfc response iocb data structure.
7288 *
7289 * This routine is the completion callback function to a Fabric Discover
7290 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7291 * single threaded, each FDISC completion callback function will reset
7292 * the discovery timer for all vports such that the timers will not get
7293 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7294 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7295 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7296 * assigned to the vport has been changed with the completion of the FDISC
7297 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7298 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7299 * routine is invoked to register new vport with the HBA. Otherwise, the
7300 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7301 * Server for State Change Request (SCR).
7302 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007303static void
7304lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7305 struct lpfc_iocbq *rspiocb)
7306{
7307 struct lpfc_vport *vport = cmdiocb->vport;
7308 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7309 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7310 struct lpfc_nodelist *np;
7311 struct lpfc_nodelist *next_np;
7312 IOCB_t *irsp = &rspiocb->iocb;
7313 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007314 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7315 struct serv_parm *sp;
7316 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007317
James Smarte8b62012007-08-02 11:10:09 -04007318 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7319 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7320 irsp->ulpStatus, irsp->un.ulpWord[4],
7321 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007322 /* Since all FDISCs are being single threaded, we
7323 * must reset the discovery timer for ALL vports
7324 * waiting to send FDISC when one completes.
7325 */
7326 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7327 lpfc_set_disctmo(piocb->vport);
7328 }
7329
James Smart858c9f62007-06-17 19:56:39 -05007330 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7331 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7332 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7333
James Smart92d7f7b2007-06-17 19:56:38 -05007334 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007335
7336 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7337 lpfc_retry_pport_discovery(phba);
7338 goto out;
7339 }
7340
James Smart92d7f7b2007-06-17 19:56:38 -05007341 /* Check for retry */
7342 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7343 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007344 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007345 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007346 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007347 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007348 goto fdisc_failed;
7349 }
James Smartd7c255b2008-08-24 21:50:00 -04007350 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007351 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007352 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007353 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007354 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007355 vport->fc_flag |= FC_PUBLIC_LOOP;
7356 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007357
James Smartd7c255b2008-08-24 21:50:00 -04007358 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7359 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007360 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7361 sp = prsp->virt + sizeof(uint32_t);
7362 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7363 memcpy(&vport->fabric_portname, &sp->portName,
7364 sizeof(struct lpfc_name));
7365 memcpy(&vport->fabric_nodename, &sp->nodeName,
7366 sizeof(struct lpfc_name));
7367 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007368 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7369 /* If our NportID changed, we need to ensure all
7370 * remaining NPORTs get unreg_login'ed so we can
7371 * issue unreg_vpi.
7372 */
7373 list_for_each_entry_safe(np, next_np,
7374 &vport->fc_nodes, nlp_listp) {
7375 if (!NLP_CHK_NODE_ACT(ndlp) ||
7376 (np->nlp_state != NLP_STE_NPR_NODE) ||
7377 !(np->nlp_flag & NLP_NPR_ADISC))
7378 continue;
James Smart09372822008-01-11 01:52:54 -05007379 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007380 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007381 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007382 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007383 }
James Smart78730cf2010-04-06 15:06:30 -04007384 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007385
7386 if (phba->sli_rev == LPFC_SLI_REV4)
7387 lpfc_sli4_unreg_all_rpis(vport);
7388
James Smartd7c255b2008-08-24 21:50:00 -04007389 lpfc_mbx_unreg_vpi(vport);
7390 spin_lock_irq(shost->host_lock);
7391 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007392 if (phba->sli_rev == LPFC_SLI_REV4)
7393 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007394 else
7395 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007396 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007397 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7398 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7399 /*
7400 * Driver needs to re-reg VPI in order for f/w
7401 * to update the MAC address.
7402 */
7403 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007404 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007405 }
7406
James Smartecfd03c2010-02-12 14:41:27 -05007407 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7408 lpfc_issue_init_vpi(vport);
7409 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007410 lpfc_register_new_vport(phba, vport, ndlp);
7411 else
7412 lpfc_do_scr_ns_plogi(phba, vport);
7413 goto out;
7414fdisc_failed:
7415 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7416 /* Cancel discovery timer */
7417 lpfc_can_disctmo(vport);
7418 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007419out:
7420 lpfc_els_free_iocb(phba, cmdiocb);
7421}
7422
James Smarte59058c2008-08-24 21:49:00 -04007423/**
James Smart3621a712009-04-06 18:47:14 -04007424 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007425 * @vport: pointer to a virtual N_Port data structure.
7426 * @ndlp: pointer to a node-list data structure.
7427 * @retry: number of retries to the command IOCB.
7428 *
7429 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7430 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7431 * routine to issue the IOCB, which makes sure only one outstanding fabric
7432 * IOCB will be sent off HBA at any given time.
7433 *
7434 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7435 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7436 * will be stored into the context1 field of the IOCB for the completion
7437 * callback function to the FDISC ELS command.
7438 *
7439 * Return code
7440 * 0 - Successfully issued fdisc iocb command
7441 * 1 - Failed to issue fdisc iocb command
7442 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007443static int
James Smart92d7f7b2007-06-17 19:56:38 -05007444lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7445 uint8_t retry)
7446{
7447 struct lpfc_hba *phba = vport->phba;
7448 IOCB_t *icmd;
7449 struct lpfc_iocbq *elsiocb;
7450 struct serv_parm *sp;
7451 uint8_t *pcmd;
7452 uint16_t cmdsize;
7453 int did = ndlp->nlp_DID;
7454 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007455
James Smart5ffc2662009-11-18 15:39:44 -05007456 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007457 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007458 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7459 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7460 ELS_CMD_FDISC);
7461 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007462 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007463 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7464 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007465 return 1;
7466 }
7467
7468 icmd = &elsiocb->iocb;
7469 icmd->un.elsreq64.myID = 0;
7470 icmd->un.elsreq64.fl = 1;
7471
James Smart73d91e52011-10-10 21:32:10 -04007472 /*
7473 * SLI3 ports require a different context type value than SLI4.
7474 * Catch SLI3 ports here and override the prep.
7475 */
7476 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007477 icmd->ulpCt_h = 1;
7478 icmd->ulpCt_l = 0;
7479 }
James Smart92d7f7b2007-06-17 19:56:38 -05007480
7481 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7482 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7483 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7484 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7485 sp = (struct serv_parm *) pcmd;
7486 /* Setup CSPs accordingly for Fabric */
7487 sp->cmn.e_d_tov = 0;
7488 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007489 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007490 sp->cls1.classValid = 0;
7491 sp->cls2.seqDelivery = 1;
7492 sp->cls3.seqDelivery = 1;
7493
7494 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7495 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7496 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7497 pcmd += sizeof(uint32_t); /* Port Name */
7498 memcpy(pcmd, &vport->fc_portname, 8);
7499 pcmd += sizeof(uint32_t); /* Node Name */
7500 pcmd += sizeof(uint32_t); /* Node Name */
7501 memcpy(pcmd, &vport->fc_nodename, 8);
7502
7503 lpfc_set_disctmo(vport);
7504
7505 phba->fc_stat.elsXmitFDISC++;
7506 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7507
James Smart858c9f62007-06-17 19:56:39 -05007508 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7509 "Issue FDISC: did:x%x",
7510 did, 0, 0);
7511
James Smart92d7f7b2007-06-17 19:56:38 -05007512 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7513 if (rc == IOCB_ERROR) {
7514 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007515 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007516 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7517 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007518 return 1;
7519 }
7520 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007521 return 0;
7522}
7523
James Smarte59058c2008-08-24 21:49:00 -04007524/**
James Smart3621a712009-04-06 18:47:14 -04007525 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007526 * @phba: pointer to lpfc hba data structure.
7527 * @cmdiocb: pointer to lpfc command iocb data structure.
7528 * @rspiocb: pointer to lpfc response iocb data structure.
7529 *
7530 * This routine is the completion callback function to the issuing of a LOGO
7531 * ELS command off a vport. It frees the command IOCB and then decrement the
7532 * reference count held on ndlp for this completion function, indicating that
7533 * the reference to the ndlp is no long needed. Note that the
7534 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7535 * callback function and an additional explicit ndlp reference decrementation
7536 * will trigger the actual release of the ndlp.
7537 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007538static void
7539lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7540 struct lpfc_iocbq *rspiocb)
7541{
7542 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007543 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007544 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007545 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007546
James Smart9589b062011-04-16 11:03:17 -04007547 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007548 irsp = &rspiocb->iocb;
7549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7550 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7551 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007552
7553 lpfc_els_free_iocb(phba, cmdiocb);
7554 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007555
7556 /* Trigger the release of the ndlp after logo */
7557 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007558
7559 /* NPIV LOGO completes to NPort <nlp_DID> */
7560 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7561 "2928 NPIV LOGO completes to NPort x%x "
7562 "Data: x%x x%x x%x x%x\n",
7563 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7564 irsp->ulpTimeout, vport->num_disc_nodes);
7565
7566 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7567 spin_lock_irq(shost->host_lock);
7568 vport->fc_flag &= ~FC_FABRIC;
7569 spin_unlock_irq(shost->host_lock);
7570 }
James Smart92d7f7b2007-06-17 19:56:38 -05007571}
7572
James Smarte59058c2008-08-24 21:49:00 -04007573/**
James Smart3621a712009-04-06 18:47:14 -04007574 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007575 * @vport: pointer to a virtual N_Port data structure.
7576 * @ndlp: pointer to a node-list data structure.
7577 *
7578 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7579 *
7580 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7581 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7582 * will be stored into the context1 field of the IOCB for the completion
7583 * callback function to the LOGO ELS command.
7584 *
7585 * Return codes
7586 * 0 - Successfully issued logo off the @vport
7587 * 1 - Failed to issue logo off the @vport
7588 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007589int
7590lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7591{
7592 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7593 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007594 IOCB_t *icmd;
7595 struct lpfc_iocbq *elsiocb;
7596 uint8_t *pcmd;
7597 uint16_t cmdsize;
7598
7599 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7600 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7601 ELS_CMD_LOGO);
7602 if (!elsiocb)
7603 return 1;
7604
7605 icmd = &elsiocb->iocb;
7606 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7607 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7608 pcmd += sizeof(uint32_t);
7609
7610 /* Fill in LOGO payload */
7611 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7612 pcmd += sizeof(uint32_t);
7613 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7614
James Smart858c9f62007-06-17 19:56:39 -05007615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7616 "Issue LOGO npiv did:x%x flg:x%x",
7617 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7618
James Smart92d7f7b2007-06-17 19:56:38 -05007619 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7620 spin_lock_irq(shost->host_lock);
7621 ndlp->nlp_flag |= NLP_LOGO_SND;
7622 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007623 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7624 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007625 spin_lock_irq(shost->host_lock);
7626 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7627 spin_unlock_irq(shost->host_lock);
7628 lpfc_els_free_iocb(phba, elsiocb);
7629 return 1;
7630 }
7631 return 0;
7632}
7633
James Smarte59058c2008-08-24 21:49:00 -04007634/**
James Smart3621a712009-04-06 18:47:14 -04007635 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007636 * @ptr: holder for the timer function associated data.
7637 *
7638 * This routine is invoked by the fabric iocb block timer after
7639 * timeout. It posts the fabric iocb block timeout event by setting the
7640 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7641 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7642 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7643 * posted event WORKER_FABRIC_BLOCK_TMO.
7644 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007645void
7646lpfc_fabric_block_timeout(unsigned long ptr)
7647{
7648 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7649 unsigned long iflags;
7650 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007651
James Smart92d7f7b2007-06-17 19:56:38 -05007652 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7653 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7654 if (!tmo_posted)
7655 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7656 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7657
James Smart5e9d9b82008-06-14 22:52:53 -04007658 if (!tmo_posted)
7659 lpfc_worker_wake_up(phba);
7660 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007661}
7662
James Smarte59058c2008-08-24 21:49:00 -04007663/**
James Smart3621a712009-04-06 18:47:14 -04007664 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007665 * @phba: pointer to lpfc hba data structure.
7666 *
7667 * This routine issues one fabric iocb from the driver internal list to
7668 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7669 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7670 * remove one pending fabric iocb from the driver internal list and invokes
7671 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7672 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007673static void
7674lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7675{
7676 struct lpfc_iocbq *iocb;
7677 unsigned long iflags;
7678 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007679 IOCB_t *cmd;
7680
7681repeat:
7682 iocb = NULL;
7683 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007684 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007685 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7686 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7687 list);
7688 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007689 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007690 atomic_inc(&phba->fabric_iocb_count);
7691 }
7692 spin_unlock_irqrestore(&phba->hbalock, iflags);
7693 if (iocb) {
7694 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7695 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7696 iocb->iocb_flag |= LPFC_IO_FABRIC;
7697
James Smart858c9f62007-06-17 19:56:39 -05007698 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7699 "Fabric sched1: ste:x%x",
7700 iocb->vport->port_state, 0, 0);
7701
James Smart3772a992009-05-22 14:50:54 -04007702 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007703
7704 if (ret == IOCB_ERROR) {
7705 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7706 iocb->fabric_iocb_cmpl = NULL;
7707 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7708 cmd = &iocb->iocb;
7709 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7710 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7711 iocb->iocb_cmpl(phba, iocb, iocb);
7712
7713 atomic_dec(&phba->fabric_iocb_count);
7714 goto repeat;
7715 }
7716 }
7717
7718 return;
7719}
7720
James Smarte59058c2008-08-24 21:49:00 -04007721/**
James Smart3621a712009-04-06 18:47:14 -04007722 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007723 * @phba: pointer to lpfc hba data structure.
7724 *
7725 * This routine unblocks the issuing fabric iocb command. The function
7726 * will clear the fabric iocb block bit and then invoke the routine
7727 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7728 * from the driver internal fabric iocb list.
7729 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007730void
7731lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7732{
7733 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7734
7735 lpfc_resume_fabric_iocbs(phba);
7736 return;
7737}
7738
James Smarte59058c2008-08-24 21:49:00 -04007739/**
James Smart3621a712009-04-06 18:47:14 -04007740 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007741 * @phba: pointer to lpfc hba data structure.
7742 *
7743 * This routine blocks the issuing fabric iocb for a specified amount of
7744 * time (currently 100 ms). This is done by set the fabric iocb block bit
7745 * and set up a timeout timer for 100ms. When the block bit is set, no more
7746 * fabric iocb will be issued out of the HBA.
7747 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007748static void
7749lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7750{
7751 int blocked;
7752
7753 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007754 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007755 if (!blocked)
7756 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7757
7758 return;
7759}
7760
James Smarte59058c2008-08-24 21:49:00 -04007761/**
James Smart3621a712009-04-06 18:47:14 -04007762 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007763 * @phba: pointer to lpfc hba data structure.
7764 * @cmdiocb: pointer to lpfc command iocb data structure.
7765 * @rspiocb: pointer to lpfc response iocb data structure.
7766 *
7767 * This routine is the callback function that is put to the fabric iocb's
7768 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7769 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7770 * function first restores and invokes the original iocb's callback function
7771 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7772 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7773 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007774static void
7775lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7776 struct lpfc_iocbq *rspiocb)
7777{
7778 struct ls_rjt stat;
7779
7780 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7781 BUG();
7782
7783 switch (rspiocb->iocb.ulpStatus) {
7784 case IOSTAT_NPORT_RJT:
7785 case IOSTAT_FABRIC_RJT:
7786 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7787 lpfc_block_fabric_iocbs(phba);
7788 }
7789 break;
7790
7791 case IOSTAT_NPORT_BSY:
7792 case IOSTAT_FABRIC_BSY:
7793 lpfc_block_fabric_iocbs(phba);
7794 break;
7795
7796 case IOSTAT_LS_RJT:
7797 stat.un.lsRjtError =
7798 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7799 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7800 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7801 lpfc_block_fabric_iocbs(phba);
7802 break;
7803 }
7804
7805 if (atomic_read(&phba->fabric_iocb_count) == 0)
7806 BUG();
7807
7808 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7809 cmdiocb->fabric_iocb_cmpl = NULL;
7810 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7811 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7812
7813 atomic_dec(&phba->fabric_iocb_count);
7814 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007815 /* Post any pending iocbs to HBA */
7816 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007817 }
7818}
7819
James Smarte59058c2008-08-24 21:49:00 -04007820/**
James Smart3621a712009-04-06 18:47:14 -04007821 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007822 * @phba: pointer to lpfc hba data structure.
7823 * @iocb: pointer to lpfc command iocb data structure.
7824 *
7825 * This routine is used as the top-level API for issuing a fabric iocb command
7826 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7827 * function makes sure that only one fabric bound iocb will be outstanding at
7828 * any given time. As such, this function will first check to see whether there
7829 * is already an outstanding fabric iocb on the wire. If so, it will put the
7830 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7831 * issued later. Otherwise, it will issue the iocb on the wire and update the
7832 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7833 *
7834 * Note, this implementation has a potential sending out fabric IOCBs out of
7835 * order. The problem is caused by the construction of the "ready" boolen does
7836 * not include the condition that the internal fabric IOCB list is empty. As
7837 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7838 * ahead of the fabric IOCBs in the internal list.
7839 *
7840 * Return code
7841 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7842 * IOCB_ERROR - failed to issue fabric iocb
7843 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007844static int
James Smart92d7f7b2007-06-17 19:56:38 -05007845lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7846{
7847 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007848 int ready;
7849 int ret;
7850
7851 if (atomic_read(&phba->fabric_iocb_count) > 1)
7852 BUG();
7853
7854 spin_lock_irqsave(&phba->hbalock, iflags);
7855 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7856 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7857
James Smart7f5f3d02008-02-08 18:50:14 -05007858 if (ready)
7859 /* Increment fabric iocb count to hold the position */
7860 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007861 spin_unlock_irqrestore(&phba->hbalock, iflags);
7862 if (ready) {
7863 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7864 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7865 iocb->iocb_flag |= LPFC_IO_FABRIC;
7866
James Smart858c9f62007-06-17 19:56:39 -05007867 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7868 "Fabric sched2: ste:x%x",
7869 iocb->vport->port_state, 0, 0);
7870
James Smart3772a992009-05-22 14:50:54 -04007871 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007872
7873 if (ret == IOCB_ERROR) {
7874 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7875 iocb->fabric_iocb_cmpl = NULL;
7876 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7877 atomic_dec(&phba->fabric_iocb_count);
7878 }
7879 } else {
7880 spin_lock_irqsave(&phba->hbalock, iflags);
7881 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7882 spin_unlock_irqrestore(&phba->hbalock, iflags);
7883 ret = IOCB_SUCCESS;
7884 }
7885 return ret;
7886}
7887
James Smarte59058c2008-08-24 21:49:00 -04007888/**
James Smart3621a712009-04-06 18:47:14 -04007889 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007890 * @vport: pointer to a virtual N_Port data structure.
7891 *
7892 * This routine aborts all the IOCBs associated with a @vport from the
7893 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7894 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7895 * list, removes each IOCB associated with the @vport off the list, set the
7896 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7897 * associated with the IOCB.
7898 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007899static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007900{
7901 LIST_HEAD(completions);
7902 struct lpfc_hba *phba = vport->phba;
7903 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007904
7905 spin_lock_irq(&phba->hbalock);
7906 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7907 list) {
7908
7909 if (piocb->vport != vport)
7910 continue;
7911
7912 list_move_tail(&piocb->list, &completions);
7913 }
7914 spin_unlock_irq(&phba->hbalock);
7915
James Smarta257bf92009-04-06 18:48:10 -04007916 /* Cancel all the IOCBs from the completions list */
7917 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7918 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007919}
7920
James Smarte59058c2008-08-24 21:49:00 -04007921/**
James Smart3621a712009-04-06 18:47:14 -04007922 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007923 * @ndlp: pointer to a node-list data structure.
7924 *
7925 * This routine aborts all the IOCBs associated with an @ndlp from the
7926 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7927 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7928 * list, removes each IOCB associated with the @ndlp off the list, set the
7929 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7930 * associated with the IOCB.
7931 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007932void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7933{
7934 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007935 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007936 struct lpfc_iocbq *tmp_iocb, *piocb;
7937 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007938
7939 spin_lock_irq(&phba->hbalock);
7940 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7941 list) {
7942 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7943
7944 list_move_tail(&piocb->list, &completions);
7945 }
7946 }
7947 spin_unlock_irq(&phba->hbalock);
7948
James Smarta257bf92009-04-06 18:48:10 -04007949 /* Cancel all the IOCBs from the completions list */
7950 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7951 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007952}
7953
James Smarte59058c2008-08-24 21:49:00 -04007954/**
James Smart3621a712009-04-06 18:47:14 -04007955 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007956 * @phba: pointer to lpfc hba data structure.
7957 *
7958 * This routine aborts all the IOCBs currently on the driver internal
7959 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7960 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7961 * list, removes IOCBs off the list, set the status feild to
7962 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7963 * the IOCB.
7964 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007965void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7966{
7967 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007968
7969 spin_lock_irq(&phba->hbalock);
7970 list_splice_init(&phba->fabric_iocb_list, &completions);
7971 spin_unlock_irq(&phba->hbalock);
7972
James Smarta257bf92009-04-06 18:48:10 -04007973 /* Cancel all the IOCBs from the completions list */
7974 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7975 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007976}
James Smart6fb120a2009-05-22 14:52:59 -04007977
7978/**
James Smart1151e3e2011-02-16 12:39:35 -05007979 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7980 * @vport: pointer to lpfc vport data structure.
7981 *
7982 * This routine is invoked by the vport cleanup for deletions and the cleanup
7983 * for an ndlp on removal.
7984 **/
7985void
7986lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7987{
7988 struct lpfc_hba *phba = vport->phba;
7989 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7990 unsigned long iflag = 0;
7991
7992 spin_lock_irqsave(&phba->hbalock, iflag);
7993 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7994 list_for_each_entry_safe(sglq_entry, sglq_next,
7995 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7996 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7997 sglq_entry->ndlp = NULL;
7998 }
7999 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
8000 spin_unlock_irqrestore(&phba->hbalock, iflag);
8001 return;
8002}
8003
8004/**
James Smart6fb120a2009-05-22 14:52:59 -04008005 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8006 * @phba: pointer to lpfc hba data structure.
8007 * @axri: pointer to the els xri abort wcqe structure.
8008 *
8009 * This routine is invoked by the worker thread to process a SLI4 slow-path
8010 * ELS aborted xri.
8011 **/
8012void
8013lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8014 struct sli4_wcqe_xri_aborted *axri)
8015{
8016 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008017 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008018 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008019
James Smart6fb120a2009-05-22 14:52:59 -04008020 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8021 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008022 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008023 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008024
James Smart0f65ff62010-02-26 14:14:23 -05008025 spin_lock_irqsave(&phba->hbalock, iflag);
8026 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008027 list_for_each_entry_safe(sglq_entry, sglq_next,
8028 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8029 if (sglq_entry->sli4_xritag == xri) {
8030 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008031 ndlp = sglq_entry->ndlp;
8032 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04008033 list_add_tail(&sglq_entry->list,
8034 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008035 sglq_entry->state = SGL_FREED;
8036 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008037 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008038 lpfc_set_rrq_active(phba, ndlp,
8039 sglq_entry->sli4_lxritag,
8040 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008041
8042 /* Check if TXQ queue needs to be serviced */
8043 if (pring->txq_cnt)
8044 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008045 return;
8046 }
8047 }
James Smart0f65ff62010-02-26 14:14:23 -05008048 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008049 lxri = lpfc_sli4_xri_inrange(phba, xri);
8050 if (lxri == NO_XRI) {
8051 spin_unlock_irqrestore(&phba->hbalock, iflag);
8052 return;
8053 }
8054 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008055 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8056 spin_unlock_irqrestore(&phba->hbalock, iflag);
8057 return;
8058 }
8059 sglq_entry->state = SGL_XRI_ABORTED;
8060 spin_unlock_irqrestore(&phba->hbalock, iflag);
8061 return;
James Smart6fb120a2009-05-22 14:52:59 -04008062}
James Smart086a3452012-08-14 14:25:21 -04008063
8064/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8065 * @vport: pointer to virtual port object.
8066 * @ndlp: nodelist pointer for the impacted node.
8067 *
8068 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8069 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8070 * the driver is required to send a LOGO to the remote node before it
8071 * attempts to recover its login to the remote node.
8072 */
8073void
8074lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8075 struct lpfc_nodelist *ndlp)
8076{
8077 struct Scsi_Host *shost;
8078 struct lpfc_hba *phba;
8079 unsigned long flags = 0;
8080
8081 shost = lpfc_shost_from_vport(vport);
8082 phba = vport->phba;
8083 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8084 lpfc_printf_log(phba, KERN_INFO,
8085 LOG_SLI, "3093 No rport recovery needed. "
8086 "rport in state 0x%x\n", ndlp->nlp_state);
8087 return;
8088 }
8089 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8090 "3094 Start rport recovery on shost id 0x%x "
8091 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8092 "flags 0x%x\n",
8093 shost->host_no, ndlp->nlp_DID,
8094 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8095 ndlp->nlp_flag);
8096 /*
8097 * The rport is not responding. Remove the FCP-2 flag to prevent
8098 * an ADISC in the follow-up recovery code.
8099 */
8100 spin_lock_irqsave(shost->host_lock, flags);
8101 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8102 spin_unlock_irqrestore(shost->host_lock, flags);
8103 lpfc_issue_els_logo(vport, ndlp, 0);
8104 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8105}
8106