blob: cfe533bc97909cbda098734e3a4e2e99cee1de85 [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));
dea31012005-04-17 16:05:31 -0500812 if (rc >= 0) {
813 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500814 spin_lock_irq(shost->host_lock);
815 vport->fc_flag |= FC_PT2PT_PLOGI;
816 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500817
818 /*
819 * N_Port ID cannot be 0, set our to LocalID the other
820 * side will be RemoteID.
821 */
822
823 /* not equal */
824 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500825 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500826
827 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
828 if (!mbox)
829 goto fail;
830
831 lpfc_config_link(phba, mbox);
832
833 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500834 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400835 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500836 if (rc == MBX_NOT_FINISHED) {
837 mempool_free(mbox, phba->mbox_mem_pool);
838 goto fail;
839 }
James Smart939723a2012-05-09 21:19:03 -0400840
841 /*
842 * For SLI4, the VFI/VPI are registered AFTER the
843 * Nport with the higher WWPN sends the PLOGI with
844 * an assigned NPortId.
845 */
846
847 /* not equal */
848 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
849 lpfc_issue_reg_vfi(vport);
850
James Smarte47c9092008-02-08 18:49:26 -0500851 /* Decrement ndlp reference count indicating that ndlp can be
852 * safely released when other references to it are done.
853 */
James Smart329f9bc2007-04-25 09:53:01 -0400854 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500855
James Smart2e0fef82007-06-17 19:56:36 -0500856 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500857 if (!ndlp) {
858 /*
859 * Cannot find existing Fabric ndlp, so allocate a
860 * new one
861 */
862 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
863 if (!ndlp)
864 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500865 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500866 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
867 ndlp = lpfc_enable_node(vport, ndlp,
868 NLP_STE_UNUSED_NODE);
869 if(!ndlp)
870 goto fail;
dea31012005-04-17 16:05:31 -0500871 }
872
873 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500874 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500875 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500876 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500877 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500878 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
879 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500880 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500882 } else
883 /* This side will wait for the PLOGI, decrement ndlp reference
884 * count indicating that ndlp can be released when other
885 * references to it are done.
886 */
James Smart329f9bc2007-04-25 09:53:01 -0400887 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500888
James Smart09372822008-01-11 01:52:54 -0500889 /* If we are pt2pt with another NPort, force NPIV off! */
890 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
891
James Smart2e0fef82007-06-17 19:56:36 -0500892 spin_lock_irq(shost->host_lock);
893 vport->fc_flag |= FC_PT2PT;
894 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500895
896 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500897 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500898 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500899fail:
dea31012005-04-17 16:05:31 -0500900 return -ENXIO;
901}
902
James Smarte59058c2008-08-24 21:49:00 -0400903/**
James Smart3621a712009-04-06 18:47:14 -0400904 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400905 * @phba: pointer to lpfc hba data structure.
906 * @cmdiocb: pointer to lpfc command iocb data structure.
907 * @rspiocb: pointer to lpfc response iocb data structure.
908 *
909 * This routine is the top-level completion callback function for issuing
910 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
911 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
912 * retry has been made (either immediately or delayed with lpfc_els_retry()
913 * returning 1), the command IOCB will be released and function returned.
914 * If the retry attempt has been given up (possibly reach the maximum
915 * number of retries), one additional decrement of ndlp reference shall be
916 * invoked before going out after releasing the command IOCB. This will
917 * actually release the remote node (Note, lpfc_els_free_iocb() will also
918 * invoke one decrement of ndlp reference count). If no error reported in
919 * the IOCB status, the command Port ID field is used to determine whether
920 * this is a point-to-point topology or a fabric topology: if the Port ID
921 * field is assigned, it is a fabric topology; otherwise, it is a
922 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
923 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
924 * specific topology completion conditions.
925 **/
dea31012005-04-17 16:05:31 -0500926static void
James Smart329f9bc2007-04-25 09:53:01 -0400927lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
928 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500929{
James Smart2e0fef82007-06-17 19:56:36 -0500930 struct lpfc_vport *vport = cmdiocb->vport;
931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500932 IOCB_t *irsp = &rspiocb->iocb;
933 struct lpfc_nodelist *ndlp = cmdiocb->context1;
934 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
935 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500936 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500937 int rc;
938
939 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500940 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500941 /* One additional decrement on node reference count to
942 * trigger the release of the node
943 */
James Smart329f9bc2007-04-25 09:53:01 -0400944 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500945 goto out;
946 }
947
James Smart858c9f62007-06-17 19:56:39 -0500948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
949 "FLOGI cmpl: status:x%x/x%x state:x%x",
950 irsp->ulpStatus, irsp->un.ulpWord[4],
951 vport->port_state);
952
dea31012005-04-17 16:05:31 -0500953 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500954 /*
James Smarta93ff372010-10-22 11:06:08 -0400955 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500956 * due to new FCF discovery
957 */
958 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500959 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
960 if (phba->link_state < LPFC_LINK_UP)
961 goto stop_rr_fcf_flogi;
962 if ((phba->fcoe_cvl_eventtag_attn ==
963 phba->fcoe_cvl_eventtag) &&
964 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400965 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
966 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -0500967 goto stop_rr_fcf_flogi;
968 else
969 phba->fcoe_cvl_eventtag_attn =
970 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500971 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400972 "2611 FLOGI failed on FCF (x%x), "
973 "status:x%x/x%x, tmo:x%x, perform "
974 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400975 phba->fcf.current_rec.fcf_indx,
976 irsp->ulpStatus, irsp->un.ulpWord[4],
977 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400978 lpfc_sli4_set_fcf_flogi_fail(phba,
979 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500980 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400981 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
982 if (rc)
983 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500984 }
985
James Smart80c17842012-03-01 22:35:45 -0500986stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400987 /* FLOGI failure */
988 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
989 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
990 irsp->ulpStatus, irsp->un.ulpWord[4],
991 irsp->ulpTimeout);
992
dea31012005-04-17 16:05:31 -0500993 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500994 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500995 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500996
James Smart76a95d72010-11-20 23:11:48 -0500997 /* FLOGI failure */
998 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
999 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1000 irsp->ulpStatus, irsp->un.ulpWord[4],
1001 irsp->ulpTimeout);
1002
dea31012005-04-17 16:05:31 -05001003 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001004 spin_lock_irq(shost->host_lock);
1005 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1006 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001007
James Smart329f9bc2007-04-25 09:53:01 -04001008 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001009 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1010 * alpa map would take too long otherwise.
1011 */
James Smart1b511972011-12-13 13:23:09 -05001012 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001013 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001014 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1015 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1016 (vport->fc_prevDID != vport->fc_myDID))) {
1017 if (vport->fc_flag & FC_VFI_REGISTERED)
1018 lpfc_sli4_unreg_all_rpis(vport);
1019 lpfc_issue_reg_vfi(vport);
1020 lpfc_nlp_put(ndlp);
1021 goto out;
dea31012005-04-17 16:05:31 -05001022 }
dea31012005-04-17 16:05:31 -05001023 goto flogifail;
1024 }
James Smart695a8142010-01-26 23:08:03 -05001025 spin_lock_irq(shost->host_lock);
1026 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001027 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001028 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001029
1030 /*
1031 * The FLogI succeeded. Sync the data for the CPU before
1032 * accessing it.
1033 */
1034 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1035
1036 sp = prsp->virt + sizeof(uint32_t);
1037
1038 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001039 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001040 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001041 "Data: x%x x%x x%x x%x\n",
1042 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1043 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001044
James Smart2e0fef82007-06-17 19:56:36 -05001045 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001046 /*
1047 * If Common Service Parameters indicate Nport
1048 * we are point to point, if Fport we are Fabric.
1049 */
1050 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001051 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001052 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001053 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001054 else {
1055 lpfc_printf_vlog(vport, KERN_ERR,
1056 LOG_FIP | LOG_ELS,
1057 "2831 FLOGI response with cleared Fabric "
1058 "bit fcf_index 0x%x "
1059 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1060 "Fabric Name "
1061 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1062 phba->fcf.current_rec.fcf_indx,
1063 phba->fcf.current_rec.switch_name[0],
1064 phba->fcf.current_rec.switch_name[1],
1065 phba->fcf.current_rec.switch_name[2],
1066 phba->fcf.current_rec.switch_name[3],
1067 phba->fcf.current_rec.switch_name[4],
1068 phba->fcf.current_rec.switch_name[5],
1069 phba->fcf.current_rec.switch_name[6],
1070 phba->fcf.current_rec.switch_name[7],
1071 phba->fcf.current_rec.fabric_name[0],
1072 phba->fcf.current_rec.fabric_name[1],
1073 phba->fcf.current_rec.fabric_name[2],
1074 phba->fcf.current_rec.fabric_name[3],
1075 phba->fcf.current_rec.fabric_name[4],
1076 phba->fcf.current_rec.fabric_name[5],
1077 phba->fcf.current_rec.fabric_name[6],
1078 phba->fcf.current_rec.fabric_name[7]);
1079 lpfc_nlp_put(ndlp);
1080 spin_lock_irq(&phba->hbalock);
1081 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001082 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001083 spin_unlock_irq(&phba->hbalock);
1084 goto out;
1085 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001086 if (!rc) {
1087 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001088 if (phba->hba_flag & HBA_FIP_SUPPORT)
1089 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1090 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001091 "2769 FLOGI to FCF (x%x) "
1092 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001093 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001094 spin_lock_irq(&phba->hbalock);
1095 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001096 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001097 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001098 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001099 }
dea31012005-04-17 16:05:31 -05001100 }
1101
1102flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001103 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001104
James Smart858c9f62007-06-17 19:56:39 -05001105 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001106 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001107 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001108
1109 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001110 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001111 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001112 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1113 IOERR_SLI_ABORTED) &&
1114 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1115 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001116 (phba->link_state != LPFC_CLEAR_LA)) {
1117 /* If FLOGI failed enable link interrupt. */
1118 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001119 }
dea31012005-04-17 16:05:31 -05001120out:
1121 lpfc_els_free_iocb(phba, cmdiocb);
1122}
1123
James Smarte59058c2008-08-24 21:49:00 -04001124/**
James Smart3621a712009-04-06 18:47:14 -04001125 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001126 * @vport: pointer to a host virtual N_Port data structure.
1127 * @ndlp: pointer to a node-list data structure.
1128 * @retry: number of retries to the command IOCB.
1129 *
1130 * This routine issues a Fabric Login (FLOGI) Request ELS command
1131 * for a @vport. The initiator service parameters are put into the payload
1132 * of the FLOGI Request IOCB and the top-level callback function pointer
1133 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1134 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1135 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1136 *
1137 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1138 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1139 * will be stored into the context1 field of the IOCB for the completion
1140 * callback function to the FLOGI ELS command.
1141 *
1142 * Return code
1143 * 0 - successfully issued flogi iocb for @vport
1144 * 1 - failed to issue flogi iocb for @vport
1145 **/
dea31012005-04-17 16:05:31 -05001146static int
James Smart2e0fef82007-06-17 19:56:36 -05001147lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001148 uint8_t retry)
1149{
James Smart2e0fef82007-06-17 19:56:36 -05001150 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001151 struct serv_parm *sp;
1152 IOCB_t *icmd;
1153 struct lpfc_iocbq *elsiocb;
1154 struct lpfc_sli_ring *pring;
1155 uint8_t *pcmd;
1156 uint16_t cmdsize;
1157 uint32_t tmo;
1158 int rc;
1159
1160 pring = &phba->sli.ring[LPFC_ELS_RING];
1161
James Smart92d7f7b2007-06-17 19:56:38 -05001162 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001163 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1164 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001165
James Smart488d1462006-03-07 15:02:37 -05001166 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001167 return 1;
dea31012005-04-17 16:05:31 -05001168
1169 icmd = &elsiocb->iocb;
1170 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1171
1172 /* For FLOGI request, remainder of payload is service parameters */
1173 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001174 pcmd += sizeof(uint32_t);
1175 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001176 sp = (struct serv_parm *) pcmd;
1177
1178 /* Setup CSPs accordingly for Fabric */
1179 sp->cmn.e_d_tov = 0;
1180 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001181 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001182 sp->cls1.classValid = 0;
1183 sp->cls2.seqDelivery = 1;
1184 sp->cls3.seqDelivery = 1;
1185 if (sp->cmn.fcphLow < FC_PH3)
1186 sp->cmn.fcphLow = FC_PH3;
1187 if (sp->cmn.fcphHigh < FC_PH3)
1188 sp->cmn.fcphHigh = FC_PH3;
1189
James Smartc31098c2011-04-16 11:03:33 -04001190 if (phba->sli_rev == LPFC_SLI_REV4) {
1191 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1192 LPFC_SLI_INTF_IF_TYPE_0) {
1193 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1194 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1195 /* FLOGI needs to be 3 for WQE FCFI */
1196 /* Set the fcfi to the fcfi we registered with */
1197 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1198 }
James Smart5248a742011-07-22 18:37:06 -04001199 } else {
1200 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1201 sp->cmn.request_multiple_Nport = 1;
1202 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1203 icmd->ulpCt_h = 1;
1204 icmd->ulpCt_l = 0;
1205 } else
1206 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001207 }
1208
James Smart76a95d72010-11-20 23:11:48 -05001209 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001210 icmd->un.elsreq64.myID = 0;
1211 icmd->un.elsreq64.fl = 1;
1212 }
1213
dea31012005-04-17 16:05:31 -05001214 tmo = phba->fc_ratov;
1215 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001216 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001217 phba->fc_ratov = tmo;
1218
1219 phba->fc_stat.elsXmitFLOGI++;
1220 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001221
1222 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1223 "Issue FLOGI: opt:x%x",
1224 phba->sli3_options, 0, 0);
1225
James Smart92d7f7b2007-06-17 19:56:38 -05001226 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001227 if (rc == IOCB_ERROR) {
1228 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001229 return 1;
dea31012005-04-17 16:05:31 -05001230 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return 0;
dea31012005-04-17 16:05:31 -05001232}
1233
James Smarte59058c2008-08-24 21:49:00 -04001234/**
James Smart3621a712009-04-06 18:47:14 -04001235 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001236 * @phba: pointer to lpfc hba data structure.
1237 *
1238 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1239 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1240 * list and issues an abort IOCB commond on each outstanding IOCB that
1241 * contains a active Fabric_DID ndlp. Note that this function is to issue
1242 * the abort IOCB command on all the outstanding IOCBs, thus when this
1243 * function returns, it does not guarantee all the IOCBs are actually aborted.
1244 *
1245 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001246 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001247 **/
dea31012005-04-17 16:05:31 -05001248int
James Smart2e0fef82007-06-17 19:56:36 -05001249lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001250{
1251 struct lpfc_sli_ring *pring;
1252 struct lpfc_iocbq *iocb, *next_iocb;
1253 struct lpfc_nodelist *ndlp;
1254 IOCB_t *icmd;
1255
1256 /* Abort outstanding I/O on NPort <nlp_DID> */
1257 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001258 "0201 Abort outstanding I/O on NPort x%x\n",
1259 Fabric_DID);
dea31012005-04-17 16:05:31 -05001260
1261 pring = &phba->sli.ring[LPFC_ELS_RING];
1262
1263 /*
1264 * Check the txcmplq for an iocb that matches the nport the driver is
1265 * searching for.
1266 */
James Smart2e0fef82007-06-17 19:56:36 -05001267 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001268 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1269 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001270 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001271 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001272 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1273 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001274 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001275 }
1276 }
James Smart2e0fef82007-06-17 19:56:36 -05001277 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001278
1279 return 0;
1280}
1281
James Smarte59058c2008-08-24 21:49:00 -04001282/**
James Smart3621a712009-04-06 18:47:14 -04001283 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001284 * @vport: pointer to a host virtual N_Port data structure.
1285 *
1286 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1287 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1288 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1289 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1290 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1291 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1292 * @vport.
1293 *
1294 * Return code
1295 * 0 - failed to issue initial flogi for @vport
1296 * 1 - successfully issued initial flogi for @vport
1297 **/
dea31012005-04-17 16:05:31 -05001298int
James Smart2e0fef82007-06-17 19:56:36 -05001299lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001300{
James Smart2e0fef82007-06-17 19:56:36 -05001301 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001302 struct lpfc_nodelist *ndlp;
1303
James Smart98c9ea52007-10-27 13:37:33 -04001304 vport->port_state = LPFC_FLOGI;
1305 lpfc_set_disctmo(vport);
1306
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001307 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001308 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001309 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001310 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001311 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1312 if (!ndlp)
1313 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001315 /* Set the node type */
1316 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001317 /* Put ndlp onto node list */
1318 lpfc_enqueue_node(vport, ndlp);
1319 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1320 /* re-setup ndlp without removing from node list */
1321 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1322 if (!ndlp)
1323 return 0;
dea31012005-04-17 16:05:31 -05001324 }
James Smart87af33f2007-10-27 13:37:43 -04001325
James Smart5ac6b302010-10-22 11:05:36 -04001326 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001327 /* This decrement of reference count to node shall kick off
1328 * the release of the node.
1329 */
James Smart329f9bc2007-04-25 09:53:01 -04001330 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001331 return 0;
1332 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001333 return 1;
dea31012005-04-17 16:05:31 -05001334}
1335
James Smarte59058c2008-08-24 21:49:00 -04001336/**
James Smart3621a712009-04-06 18:47:14 -04001337 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001338 * @vport: pointer to a host virtual N_Port data structure.
1339 *
1340 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1341 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1342 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1343 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1344 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1345 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1346 * @vport.
1347 *
1348 * Return code
1349 * 0 - failed to issue initial fdisc for @vport
1350 * 1 - successfully issued initial fdisc for @vport
1351 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001352int
1353lpfc_initial_fdisc(struct lpfc_vport *vport)
1354{
1355 struct lpfc_hba *phba = vport->phba;
1356 struct lpfc_nodelist *ndlp;
1357
1358 /* First look for the Fabric ndlp */
1359 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1360 if (!ndlp) {
1361 /* Cannot find existing Fabric ndlp, so allocate a new one */
1362 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1363 if (!ndlp)
1364 return 0;
1365 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001366 /* Put ndlp onto node list */
1367 lpfc_enqueue_node(vport, ndlp);
1368 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1369 /* re-setup ndlp without removing from node list */
1370 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1371 if (!ndlp)
1372 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001373 }
James Smarte47c9092008-02-08 18:49:26 -05001374
James Smart92d7f7b2007-06-17 19:56:38 -05001375 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001376 /* decrement node reference count to trigger the release of
1377 * the node.
1378 */
James Smart92d7f7b2007-06-17 19:56:38 -05001379 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001380 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001381 }
1382 return 1;
1383}
James Smart87af33f2007-10-27 13:37:43 -04001384
James Smarte59058c2008-08-24 21:49:00 -04001385/**
James Smart3621a712009-04-06 18:47:14 -04001386 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001387 * @vport: pointer to a host virtual N_Port data structure.
1388 *
1389 * This routine checks whether there are more remaining Port Logins
1390 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1391 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1392 * to issue ELS PLOGIs up to the configured discover threads with the
1393 * @vport (@vport->cfg_discovery_threads). The function also decrement
1394 * the @vport's num_disc_node by 1 if it is not already 0.
1395 **/
James Smart87af33f2007-10-27 13:37:43 -04001396void
James Smart2e0fef82007-06-17 19:56:36 -05001397lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001398{
1399 int sentplogi;
1400
James Smart2e0fef82007-06-17 19:56:36 -05001401 if (vport->num_disc_nodes)
1402 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001403
1404 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001405 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1406 "0232 Continue discovery with %d PLOGIs to go "
1407 "Data: x%x x%x x%x\n",
1408 vport->num_disc_nodes, vport->fc_plogi_cnt,
1409 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001410 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001411 if (vport->fc_flag & FC_NLP_MORE)
1412 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1413 sentplogi = lpfc_els_disc_plogi(vport);
1414
dea31012005-04-17 16:05:31 -05001415 return;
1416}
1417
James Smarte59058c2008-08-24 21:49:00 -04001418/**
James Smart3621a712009-04-06 18:47:14 -04001419 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001420 * @phba: pointer to lpfc hba data structure.
1421 * @prsp: pointer to response IOCB payload.
1422 * @ndlp: pointer to a node-list data structure.
1423 *
1424 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1425 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1426 * The following cases are considered N_Port confirmed:
1427 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1428 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1429 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1430 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1431 * 1) if there is a node on vport list other than the @ndlp with the same
1432 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1433 * on that node to release the RPI associated with the node; 2) if there is
1434 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1435 * into, a new node shall be allocated (or activated). In either case, the
1436 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1437 * be released and the new_ndlp shall be put on to the vport node list and
1438 * its pointer returned as the confirmed node.
1439 *
1440 * Note that before the @ndlp got "released", the keepDID from not-matching
1441 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1442 * of the @ndlp. This is because the release of @ndlp is actually to put it
1443 * into an inactive state on the vport node list and the vport node list
1444 * management algorithm does not allow two node with a same DID.
1445 *
1446 * Return code
1447 * pointer to the PLOGI N_Port @ndlp
1448 **/
James Smart488d1462006-03-07 15:02:37 -05001449static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001450lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001451 struct lpfc_nodelist *ndlp)
1452{
James Smart2e0fef82007-06-17 19:56:36 -05001453 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001454 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001455 struct lpfc_rport_data *rdata;
1456 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001457 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001458 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001459 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001460 int put_node;
1461 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001462 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001463
James Smart2fb9bd82006-12-02 13:33:57 -05001464 /* Fabric nodes can have the same WWPN so we don't bother searching
1465 * by WWPN. Just return the ndlp that was given to us.
1466 */
1467 if (ndlp->nlp_type & NLP_FABRIC)
1468 return ndlp;
1469
James Smart92d7f7b2007-06-17 19:56:38 -05001470 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001471 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001472
James Smart685f0bf2007-04-25 09:53:08 -04001473 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001474 * we have for that ndlp. If not, we have some work to do.
1475 */
James Smart2e0fef82007-06-17 19:56:36 -05001476 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001477
James Smarte47c9092008-02-08 18:49:26 -05001478 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001479 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001480 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001481
James Smart34f5ad82012-08-03 12:35:03 -04001482 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1483 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1484 ndlp, ndlp->nlp_DID, new_ndlp);
1485
James Smart488d1462006-03-07 15:02:37 -05001486 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001487 rc = memcmp(&ndlp->nlp_portname, name,
1488 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001489 if (!rc)
1490 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001491 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1492 if (!new_ndlp)
1493 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001494 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001495 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001496 rc = memcmp(&ndlp->nlp_portname, name,
1497 sizeof(struct lpfc_name));
1498 if (!rc)
1499 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001500 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1501 NLP_STE_UNUSED_NODE);
1502 if (!new_ndlp)
1503 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001504 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001505 if (phba->sli_rev == LPFC_SLI_REV4)
1506 memcpy(&rrq.xri_bitmap,
1507 &new_ndlp->active_rrqs.xri_bitmap,
1508 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1509 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001510 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001511 if (phba->sli_rev == LPFC_SLI_REV4)
1512 memcpy(&rrq.xri_bitmap,
1513 &new_ndlp->active_rrqs.xri_bitmap,
1514 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1515 }
James Smart488d1462006-03-07 15:02:37 -05001516
James Smart2e0fef82007-06-17 19:56:36 -05001517 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001518 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001519 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001520 if (phba->sli_rev == LPFC_SLI_REV4)
1521 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1522 &ndlp->active_rrqs.xri_bitmap,
1523 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001524
1525 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1526 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1527 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1528
James Smarte47c9092008-02-08 18:49:26 -05001529 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001530 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001531
James Smart2e0fef82007-06-17 19:56:36 -05001532 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001533 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1534 /* The new_ndlp is replacing ndlp totally, so we need
1535 * to put ndlp on UNUSED list and try to free it.
1536 */
James Smart34f5ad82012-08-03 12:35:03 -04001537 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1538 "3179 PLOGI confirm NEW: %x %x\n",
1539 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001540
1541 /* Fix up the rport accordingly */
1542 rport = ndlp->rport;
1543 if (rport) {
1544 rdata = rport->dd_data;
1545 if (rdata->pnode == ndlp) {
1546 lpfc_nlp_put(ndlp);
1547 ndlp->rport = NULL;
1548 rdata->pnode = lpfc_nlp_get(new_ndlp);
1549 new_ndlp->rport = rport;
1550 }
1551 new_ndlp->nlp_type = ndlp->nlp_type;
1552 }
James Smart58da1ff2008-04-07 10:15:56 -04001553 /* We shall actually free the ndlp with both nlp_DID and
1554 * nlp_portname fields equals 0 to avoid any ndlp on the
1555 * nodelist never to be used.
1556 */
1557 if (ndlp->nlp_DID == 0) {
1558 spin_lock_irq(&phba->ndlp_lock);
1559 NLP_SET_FREE_REQ(ndlp);
1560 spin_unlock_irq(&phba->ndlp_lock);
1561 }
James Smart0ff10d42008-01-11 01:52:36 -05001562
James Smart58da1ff2008-04-07 10:15:56 -04001563 /* Two ndlps cannot have the same did on the nodelist */
1564 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001565 if (phba->sli_rev == LPFC_SLI_REV4)
1566 memcpy(&ndlp->active_rrqs.xri_bitmap,
1567 &rrq.xri_bitmap,
1568 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001569 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001570 }
James Smart92795652006-07-06 15:50:02 -04001571 else {
James Smart34f5ad82012-08-03 12:35:03 -04001572 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1573 "3180 PLOGI confirm SWAP: %x %x\n",
1574 new_ndlp->nlp_DID, keepDID);
1575
James Smart2e0fef82007-06-17 19:56:36 -05001576 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001577
James Smart58da1ff2008-04-07 10:15:56 -04001578 /* Two ndlps cannot have the same did */
1579 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001580 if (phba->sli_rev == LPFC_SLI_REV4)
1581 memcpy(&ndlp->active_rrqs.xri_bitmap,
1582 &rrq.xri_bitmap,
1583 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001584
James Smart38b92ef2010-08-04 16:11:39 -04001585 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001586 * and the did has already been swapped, copy over state.
1587 * The new WWNs are already in new_ndlp since thats what
1588 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001589 */
James Smart38b92ef2010-08-04 16:11:39 -04001590 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001591
1592 /* Since we are switching over to the new_ndlp, the old
1593 * ndlp should be put in the NPR state, unless we have
1594 * already started re-discovery on it.
1595 */
1596 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1597 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1599
James Smart38b92ef2010-08-04 16:11:39 -04001600 /* Fix up the rport accordingly */
1601 rport = ndlp->rport;
1602 if (rport) {
1603 rdata = rport->dd_data;
1604 put_node = rdata->pnode != NULL;
1605 put_rport = ndlp->rport != NULL;
1606 rdata->pnode = NULL;
1607 ndlp->rport = NULL;
1608 if (put_node)
1609 lpfc_nlp_put(ndlp);
1610 if (put_rport)
1611 put_device(&rport->dev);
1612 }
James Smart92795652006-07-06 15:50:02 -04001613 }
James Smart488d1462006-03-07 15:02:37 -05001614 return new_ndlp;
1615}
1616
James Smarte59058c2008-08-24 21:49:00 -04001617/**
James Smart3621a712009-04-06 18:47:14 -04001618 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001619 * @vport: pointer to a host virtual N_Port data structure.
1620 *
1621 * This routine checks whether more Registration State Change
1622 * Notifications (RSCNs) came in while the discovery state machine was in
1623 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1624 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1625 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1626 * handling the RSCNs.
1627 **/
James Smart87af33f2007-10-27 13:37:43 -04001628void
1629lpfc_end_rscn(struct lpfc_vport *vport)
1630{
1631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1632
1633 if (vport->fc_flag & FC_RSCN_MODE) {
1634 /*
1635 * Check to see if more RSCNs came in while we were
1636 * processing this one.
1637 */
1638 if (vport->fc_rscn_id_cnt ||
1639 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1640 lpfc_els_handle_rscn(vport);
1641 else {
1642 spin_lock_irq(shost->host_lock);
1643 vport->fc_flag &= ~FC_RSCN_MODE;
1644 spin_unlock_irq(shost->host_lock);
1645 }
1646 }
1647}
1648
James Smarte59058c2008-08-24 21:49:00 -04001649/**
James Smart19ca7602010-11-20 23:11:55 -05001650 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1651 * @phba: pointer to lpfc hba data structure.
1652 * @cmdiocb: pointer to lpfc command iocb data structure.
1653 * @rspiocb: pointer to lpfc response iocb data structure.
1654 *
1655 * This routine will call the clear rrq function to free the rrq and
1656 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1657 * exist then the clear_rrq is still called because the rrq needs to
1658 * be freed.
1659 **/
1660
1661static void
1662lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1663 struct lpfc_iocbq *rspiocb)
1664{
1665 struct lpfc_vport *vport = cmdiocb->vport;
1666 IOCB_t *irsp;
1667 struct lpfc_nodelist *ndlp;
1668 struct lpfc_node_rrq *rrq;
1669
1670 /* we pass cmdiocb to state machine which needs rspiocb as well */
1671 rrq = cmdiocb->context_un.rrq;
1672 cmdiocb->context_un.rsp_iocb = rspiocb;
1673
1674 irsp = &rspiocb->iocb;
1675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1676 "RRQ cmpl: status:x%x/x%x did:x%x",
1677 irsp->ulpStatus, irsp->un.ulpWord[4],
1678 irsp->un.elsreq64.remoteID);
1679
1680 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1681 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1682 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1683 "2882 RRQ completes to NPort x%x "
1684 "with no ndlp. Data: x%x x%x x%x\n",
1685 irsp->un.elsreq64.remoteID,
1686 irsp->ulpStatus, irsp->un.ulpWord[4],
1687 irsp->ulpIoTag);
1688 goto out;
1689 }
1690
1691 /* rrq completes to NPort <nlp_DID> */
1692 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1693 "2880 RRQ completes to NPort x%x "
1694 "Data: x%x x%x x%x x%x x%x\n",
1695 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1696 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1697
1698 if (irsp->ulpStatus) {
1699 /* Check for retry */
1700 /* RRQ failed Don't print the vport to vport rjts */
1701 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1702 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1703 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1704 (phba)->pport->cfg_log_verbose & LOG_ELS)
1705 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1706 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1707 ndlp->nlp_DID, irsp->ulpStatus,
1708 irsp->un.ulpWord[4]);
1709 }
1710out:
1711 if (rrq)
1712 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1713 lpfc_els_free_iocb(phba, cmdiocb);
1714 return;
1715}
1716/**
James Smart3621a712009-04-06 18:47:14 -04001717 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001718 * @phba: pointer to lpfc hba data structure.
1719 * @cmdiocb: pointer to lpfc command iocb data structure.
1720 * @rspiocb: pointer to lpfc response iocb data structure.
1721 *
1722 * This routine is the completion callback function for issuing the Port
1723 * Login (PLOGI) command. For PLOGI completion, there must be an active
1724 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001725 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001726 * ignored and command IOCB released. The PLOGI response IOCB status is
1727 * checked for error conditons. If there is error status reported, PLOGI
1728 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1729 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1730 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1731 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1732 * there are additional N_Port nodes with the vport that need to perform
1733 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1734 * PLOGIs.
1735 **/
dea31012005-04-17 16:05:31 -05001736static void
James Smart2e0fef82007-06-17 19:56:36 -05001737lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1738 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001739{
James Smart2e0fef82007-06-17 19:56:36 -05001740 struct lpfc_vport *vport = cmdiocb->vport;
1741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001742 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001743 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001744 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001745 int disc, rc, did, type;
1746
dea31012005-04-17 16:05:31 -05001747 /* we pass cmdiocb to state machine which needs rspiocb as well */
1748 cmdiocb->context_un.rsp_iocb = rspiocb;
1749
1750 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1752 "PLOGI cmpl: status:x%x/x%x did:x%x",
1753 irsp->ulpStatus, irsp->un.ulpWord[4],
1754 irsp->un.elsreq64.remoteID);
1755
James Smart2e0fef82007-06-17 19:56:36 -05001756 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001757 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001758 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1759 "0136 PLOGI completes to NPort x%x "
1760 "with no ndlp. Data: x%x x%x x%x\n",
1761 irsp->un.elsreq64.remoteID,
1762 irsp->ulpStatus, irsp->un.ulpWord[4],
1763 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001764 goto out;
James Smarted957682007-06-17 19:56:37 -05001765 }
dea31012005-04-17 16:05:31 -05001766
1767 /* Since ndlp can be freed in the disc state machine, note if this node
1768 * is being used during discovery.
1769 */
James Smart2e0fef82007-06-17 19:56:36 -05001770 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001771 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001772 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001773 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001774 rc = 0;
1775
1776 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001777 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1778 "0102 PLOGI completes to NPort x%x "
1779 "Data: x%x x%x x%x x%x x%x\n",
1780 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1781 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001782 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001783 if (lpfc_els_chk_latt(vport)) {
1784 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001785 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001786 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001787 goto out;
1788 }
1789
1790 /* ndlp could be freed in DSM, save these values now */
1791 type = ndlp->nlp_type;
1792 did = ndlp->nlp_DID;
1793
1794 if (irsp->ulpStatus) {
1795 /* Check for retry */
1796 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1797 /* ELS command is being retried */
1798 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001799 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001800 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001801 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001802 }
1803 goto out;
1804 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001805 /* PLOGI failed Don't print the vport to vport rjts */
1806 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1807 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1808 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1809 (phba)->pport->cfg_log_verbose & LOG_ELS)
1810 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001811 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1812 ndlp->nlp_DID, irsp->ulpStatus,
1813 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001814 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001815 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001816 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001817 else
James Smart2e0fef82007-06-17 19:56:36 -05001818 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001819 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001820 } else {
1821 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001822 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001823 cmdiocb->context2)->list.next,
1824 struct lpfc_dmabuf, list);
1825 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001826 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001827 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001828 }
1829
James Smart2e0fef82007-06-17 19:56:36 -05001830 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001831 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001832 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001833
James Smart2e0fef82007-06-17 19:56:36 -05001834 if (vport->num_disc_nodes == 0) {
1835 spin_lock_irq(shost->host_lock);
1836 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1837 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001838
James Smart2e0fef82007-06-17 19:56:36 -05001839 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001840 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001841 }
1842 }
1843
1844out:
1845 lpfc_els_free_iocb(phba, cmdiocb);
1846 return;
1847}
1848
James Smarte59058c2008-08-24 21:49:00 -04001849/**
James Smart3621a712009-04-06 18:47:14 -04001850 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001851 * @vport: pointer to a host virtual N_Port data structure.
1852 * @did: destination port identifier.
1853 * @retry: number of retries to the command IOCB.
1854 *
1855 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1856 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1857 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1858 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1859 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1860 *
1861 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1862 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1863 * will be stored into the context1 field of the IOCB for the completion
1864 * callback function to the PLOGI ELS command.
1865 *
1866 * Return code
1867 * 0 - Successfully issued a plogi for @vport
1868 * 1 - failed to issue a plogi for @vport
1869 **/
dea31012005-04-17 16:05:31 -05001870int
James Smart2e0fef82007-06-17 19:56:36 -05001871lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001872{
James Smart2e0fef82007-06-17 19:56:36 -05001873 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001874 struct serv_parm *sp;
1875 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001876 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001877 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001878 struct lpfc_sli *psli;
1879 uint8_t *pcmd;
1880 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001881 int ret;
dea31012005-04-17 16:05:31 -05001882
1883 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001884
James Smart98c9ea52007-10-27 13:37:33 -04001885 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001886 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1887 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001888
James Smarte47c9092008-02-08 18:49:26 -05001889 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001890 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001891 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001892 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001893 if (!elsiocb)
1894 return 1;
dea31012005-04-17 16:05:31 -05001895
1896 icmd = &elsiocb->iocb;
1897 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1898
1899 /* For PLOGI request, remainder of payload is service parameters */
1900 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001901 pcmd += sizeof(uint32_t);
1902 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001903 sp = (struct serv_parm *) pcmd;
1904
James Smart5ac6b302010-10-22 11:05:36 -04001905 /*
1906 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1907 * to device on remote loops work.
1908 */
1909 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1910 sp->cmn.altBbCredit = 1;
1911
dea31012005-04-17 16:05:31 -05001912 if (sp->cmn.fcphLow < FC_PH_4_3)
1913 sp->cmn.fcphLow = FC_PH_4_3;
1914
1915 if (sp->cmn.fcphHigh < FC_PH3)
1916 sp->cmn.fcphHigh = FC_PH3;
1917
James Smart858c9f62007-06-17 19:56:39 -05001918 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1919 "Issue PLOGI: did:x%x",
1920 did, 0, 0);
1921
dea31012005-04-17 16:05:31 -05001922 phba->fc_stat.elsXmitPLOGI++;
1923 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001924 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001925
1926 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001927 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001928 return 1;
dea31012005-04-17 16:05:31 -05001929 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001930 return 0;
dea31012005-04-17 16:05:31 -05001931}
1932
James Smarte59058c2008-08-24 21:49:00 -04001933/**
James Smart3621a712009-04-06 18:47:14 -04001934 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001935 * @phba: pointer to lpfc hba data structure.
1936 * @cmdiocb: pointer to lpfc command iocb data structure.
1937 * @rspiocb: pointer to lpfc response iocb data structure.
1938 *
1939 * This routine is the completion callback function for a Process Login
1940 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1941 * status. If there is error status reported, PRLI retry shall be attempted
1942 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1943 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1944 * ndlp to mark the PRLI completion.
1945 **/
dea31012005-04-17 16:05:31 -05001946static void
James Smart2e0fef82007-06-17 19:56:36 -05001947lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1948 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001949{
James Smart2e0fef82007-06-17 19:56:36 -05001950 struct lpfc_vport *vport = cmdiocb->vport;
1951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001952 IOCB_t *irsp;
1953 struct lpfc_sli *psli;
1954 struct lpfc_nodelist *ndlp;
1955
1956 psli = &phba->sli;
1957 /* we pass cmdiocb to state machine which needs rspiocb as well */
1958 cmdiocb->context_un.rsp_iocb = rspiocb;
1959
1960 irsp = &(rspiocb->iocb);
1961 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001962 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001963 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001964 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965
James Smart858c9f62007-06-17 19:56:39 -05001966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1967 "PRLI cmpl: status:x%x/x%x did:x%x",
1968 irsp->ulpStatus, irsp->un.ulpWord[4],
1969 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001970 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001971 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1972 "0103 PRLI completes to NPort x%x "
1973 "Data: x%x x%x x%x x%x\n",
1974 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1975 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001976
James Smart2e0fef82007-06-17 19:56:36 -05001977 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001978 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001979 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001980 goto out;
1981
1982 if (irsp->ulpStatus) {
1983 /* Check for retry */
1984 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1985 /* ELS command is being retried */
1986 goto out;
1987 }
1988 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001989 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1990 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1991 ndlp->nlp_DID, irsp->ulpStatus,
1992 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001993 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001994 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001995 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001996 else
James Smart2e0fef82007-06-17 19:56:36 -05001997 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001998 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001999 } else
dea31012005-04-17 16:05:31 -05002000 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002002 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002003out:
2004 lpfc_els_free_iocb(phba, cmdiocb);
2005 return;
2006}
2007
James Smarte59058c2008-08-24 21:49:00 -04002008/**
James Smart3621a712009-04-06 18:47:14 -04002009 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002010 * @vport: pointer to a host virtual N_Port data structure.
2011 * @ndlp: pointer to a node-list data structure.
2012 * @retry: number of retries to the command IOCB.
2013 *
2014 * This routine issues a Process Login (PRLI) ELS command for the
2015 * @vport. The PRLI service parameters are set up in the payload of the
2016 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2017 * is put to the IOCB completion callback func field before invoking the
2018 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2019 *
2020 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2021 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2022 * will be stored into the context1 field of the IOCB for the completion
2023 * callback function to the PRLI ELS command.
2024 *
2025 * Return code
2026 * 0 - successfully issued prli iocb command for @vport
2027 * 1 - failed to issue prli iocb command for @vport
2028 **/
dea31012005-04-17 16:05:31 -05002029int
James Smart2e0fef82007-06-17 19:56:36 -05002030lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002031 uint8_t retry)
2032{
James Smart2e0fef82007-06-17 19:56:36 -05002033 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2034 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002035 PRLI *npr;
2036 IOCB_t *icmd;
2037 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002038 uint8_t *pcmd;
2039 uint16_t cmdsize;
2040
James Smart92d7f7b2007-06-17 19:56:38 -05002041 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002042 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2043 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002044 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002045 return 1;
dea31012005-04-17 16:05:31 -05002046
2047 icmd = &elsiocb->iocb;
2048 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2049
2050 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002051 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002052 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002053 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002054
2055 /* For PRLI, remainder of payload is PRLI parameter page */
2056 npr = (PRLI *) pcmd;
2057 /*
2058 * If our firmware version is 3.20 or later,
2059 * set the following bits for FC-TAPE support.
2060 */
2061 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2062 npr->ConfmComplAllowed = 1;
2063 npr->Retry = 1;
2064 npr->TaskRetryIdReq = 1;
2065 }
2066 npr->estabImagePair = 1;
2067 npr->readXferRdyDis = 1;
2068
2069 /* For FCP support */
2070 npr->prliType = PRLI_FCP_TYPE;
2071 npr->initiatorFunc = 1;
2072
James Smart858c9f62007-06-17 19:56:39 -05002073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2074 "Issue PRLI: did:x%x",
2075 ndlp->nlp_DID, 0, 0);
2076
dea31012005-04-17 16:05:31 -05002077 phba->fc_stat.elsXmitPRLI++;
2078 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002079 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002080 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002081 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002082 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2083 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002084 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002085 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002086 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002087 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002088 return 1;
dea31012005-04-17 16:05:31 -05002089 }
James Smart2e0fef82007-06-17 19:56:36 -05002090 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002091 return 0;
dea31012005-04-17 16:05:31 -05002092}
2093
James Smarte59058c2008-08-24 21:49:00 -04002094/**
James Smart3621a712009-04-06 18:47:14 -04002095 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002096 * @vport: pointer to a host virtual N_Port data structure.
2097 *
2098 * This routine performs Registration State Change Notification (RSCN)
2099 * discovery for a @vport. If the @vport's node port recovery count is not
2100 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2101 * the nodes that need recovery. If none of the PLOGI were needed through
2102 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2103 * invoked to check and handle possible more RSCN came in during the period
2104 * of processing the current ones.
2105 **/
2106static void
2107lpfc_rscn_disc(struct lpfc_vport *vport)
2108{
2109 lpfc_can_disctmo(vport);
2110
2111 /* RSCN discovery */
2112 /* go thru NPR nodes and issue ELS PLOGIs */
2113 if (vport->fc_npr_cnt)
2114 if (lpfc_els_disc_plogi(vport))
2115 return;
2116
2117 lpfc_end_rscn(vport);
2118}
2119
2120/**
James Smart3621a712009-04-06 18:47:14 -04002121 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002122 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2123 *
2124 * This function is called when the final ADISC is completed during discovery.
2125 * This function handles clearing link attention or issuing reg_vpi depending
2126 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2127 * discovery.
2128 * This function is called with no locks held.
2129 **/
2130static void
2131lpfc_adisc_done(struct lpfc_vport *vport)
2132{
2133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2134 struct lpfc_hba *phba = vport->phba;
2135
2136 /*
2137 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2138 * and continue discovery.
2139 */
2140 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002141 !(vport->fc_flag & FC_RSCN_MODE) &&
2142 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002143 lpfc_issue_reg_vpi(phba, vport);
2144 return;
2145 }
2146 /*
2147 * For SLI2, we need to set port_state to READY
2148 * and continue discovery.
2149 */
2150 if (vport->port_state < LPFC_VPORT_READY) {
2151 /* If we get here, there is nothing to ADISC */
2152 if (vport->port_type == LPFC_PHYSICAL_PORT)
2153 lpfc_issue_clear_la(phba, vport);
2154 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2155 vport->num_disc_nodes = 0;
2156 /* go thru NPR list, issue ELS PLOGIs */
2157 if (vport->fc_npr_cnt)
2158 lpfc_els_disc_plogi(vport);
2159 if (!vport->num_disc_nodes) {
2160 spin_lock_irq(shost->host_lock);
2161 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2162 spin_unlock_irq(shost->host_lock);
2163 lpfc_can_disctmo(vport);
2164 lpfc_end_rscn(vport);
2165 }
2166 }
2167 vport->port_state = LPFC_VPORT_READY;
2168 } else
2169 lpfc_rscn_disc(vport);
2170}
2171
2172/**
James Smart3621a712009-04-06 18:47:14 -04002173 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002174 * @vport: pointer to a host virtual N_Port data structure.
2175 *
2176 * This routine determines whether there are more ndlps on a @vport
2177 * node list need to have Address Discover (ADISC) issued. If so, it will
2178 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2179 * remaining nodes which need to have ADISC sent.
2180 **/
James Smart0ff10d42008-01-11 01:52:36 -05002181void
James Smart2e0fef82007-06-17 19:56:36 -05002182lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002183{
2184 int sentadisc;
2185
James Smart2e0fef82007-06-17 19:56:36 -05002186 if (vport->num_disc_nodes)
2187 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002188 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002189 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2190 "0210 Continue discovery with %d ADISCs to go "
2191 "Data: x%x x%x x%x\n",
2192 vport->num_disc_nodes, vport->fc_adisc_cnt,
2193 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002194 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002195 if (vport->fc_flag & FC_NLP_MORE) {
2196 lpfc_set_disctmo(vport);
2197 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2198 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002199 }
James Smart90160e02008-08-24 21:49:45 -04002200 if (!vport->num_disc_nodes)
2201 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002202 return;
2203}
2204
James Smarte59058c2008-08-24 21:49:00 -04002205/**
James Smart3621a712009-04-06 18:47:14 -04002206 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002207 * @phba: pointer to lpfc hba data structure.
2208 * @cmdiocb: pointer to lpfc command iocb data structure.
2209 * @rspiocb: pointer to lpfc response iocb data structure.
2210 *
2211 * This routine is the completion function for issuing the Address Discover
2212 * (ADISC) command. It first checks to see whether link went down during
2213 * the discovery process. If so, the node will be marked as node port
2214 * recovery for issuing discover IOCB by the link attention handler and
2215 * exit. Otherwise, the response status is checked. If error was reported
2216 * in the response status, the ADISC command shall be retried by invoking
2217 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2218 * the response status, the state machine is invoked to set transition
2219 * with respect to NLP_EVT_CMPL_ADISC event.
2220 **/
dea31012005-04-17 16:05:31 -05002221static void
James Smart2e0fef82007-06-17 19:56:36 -05002222lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2223 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002224{
James Smart2e0fef82007-06-17 19:56:36 -05002225 struct lpfc_vport *vport = cmdiocb->vport;
2226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002227 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002228 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002229 int disc;
dea31012005-04-17 16:05:31 -05002230
2231 /* we pass cmdiocb to state machine which needs rspiocb as well */
2232 cmdiocb->context_un.rsp_iocb = rspiocb;
2233
2234 irsp = &(rspiocb->iocb);
2235 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002236
James Smart858c9f62007-06-17 19:56:39 -05002237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2238 "ADISC cmpl: status:x%x/x%x did:x%x",
2239 irsp->ulpStatus, irsp->un.ulpWord[4],
2240 ndlp->nlp_DID);
2241
dea31012005-04-17 16:05:31 -05002242 /* Since ndlp can be freed in the disc state machine, note if this node
2243 * is being used during discovery.
2244 */
James Smart2e0fef82007-06-17 19:56:36 -05002245 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002246 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002247 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002248 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002249 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002250 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2251 "0104 ADISC completes to NPort x%x "
2252 "Data: x%x x%x x%x x%x x%x\n",
2253 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2254 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002255 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002256 if (lpfc_els_chk_latt(vport)) {
2257 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002258 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002259 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002260 goto out;
2261 }
2262
2263 if (irsp->ulpStatus) {
2264 /* Check for retry */
2265 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2266 /* ELS command is being retried */
2267 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002268 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002269 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002270 spin_unlock_irq(shost->host_lock);
2271 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002272 }
2273 goto out;
2274 }
2275 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002276 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2277 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2278 ndlp->nlp_DID, irsp->ulpStatus,
2279 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002280 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002281 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002282 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002283 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002284 } else
dea31012005-04-17 16:05:31 -05002285 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002286 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002287 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002288
James Smart90160e02008-08-24 21:49:45 -04002289 /* Check to see if there are more ADISCs to be sent */
2290 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002291 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002292out:
2293 lpfc_els_free_iocb(phba, cmdiocb);
2294 return;
2295}
2296
James Smarte59058c2008-08-24 21:49:00 -04002297/**
James Smart3621a712009-04-06 18:47:14 -04002298 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002299 * @vport: pointer to a virtual N_Port data structure.
2300 * @ndlp: pointer to a node-list data structure.
2301 * @retry: number of retries to the command IOCB.
2302 *
2303 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2304 * @vport. It prepares the payload of the ADISC ELS command, updates the
2305 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2306 * to issue the ADISC ELS command.
2307 *
2308 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2309 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2310 * will be stored into the context1 field of the IOCB for the completion
2311 * callback function to the ADISC ELS command.
2312 *
2313 * Return code
2314 * 0 - successfully issued adisc
2315 * 1 - failed to issue adisc
2316 **/
dea31012005-04-17 16:05:31 -05002317int
James Smart2e0fef82007-06-17 19:56:36 -05002318lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002319 uint8_t retry)
2320{
James Smart2e0fef82007-06-17 19:56:36 -05002321 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2322 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002323 ADISC *ap;
2324 IOCB_t *icmd;
2325 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002326 uint8_t *pcmd;
2327 uint16_t cmdsize;
2328
James Smart92d7f7b2007-06-17 19:56:38 -05002329 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002330 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2331 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002332 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002333 return 1;
dea31012005-04-17 16:05:31 -05002334
2335 icmd = &elsiocb->iocb;
2336 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2337
2338 /* For ADISC request, remainder of payload is service parameters */
2339 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002340 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002341
2342 /* Fill in ADISC payload */
2343 ap = (ADISC *) pcmd;
2344 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002345 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2346 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002347 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002348
James Smart858c9f62007-06-17 19:56:39 -05002349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2350 "Issue ADISC: did:x%x",
2351 ndlp->nlp_DID, 0, 0);
2352
dea31012005-04-17 16:05:31 -05002353 phba->fc_stat.elsXmitADISC++;
2354 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002355 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002356 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002358 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2359 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002360 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002361 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002363 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002364 return 1;
dea31012005-04-17 16:05:31 -05002365 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002366 return 0;
dea31012005-04-17 16:05:31 -05002367}
2368
James Smarte59058c2008-08-24 21:49:00 -04002369/**
James Smart3621a712009-04-06 18:47:14 -04002370 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002371 * @phba: pointer to lpfc hba data structure.
2372 * @cmdiocb: pointer to lpfc command iocb data structure.
2373 * @rspiocb: pointer to lpfc response iocb data structure.
2374 *
2375 * This routine is the completion function for issuing the ELS Logout (LOGO)
2376 * command. If no error status was reported from the LOGO response, the
2377 * state machine of the associated ndlp shall be invoked for transition with
2378 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2379 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2380 **/
dea31012005-04-17 16:05:31 -05002381static void
James Smart2e0fef82007-06-17 19:56:36 -05002382lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2383 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002384{
James Smart2e0fef82007-06-17 19:56:36 -05002385 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2386 struct lpfc_vport *vport = ndlp->vport;
2387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002388 IOCB_t *irsp;
2389 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002390 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002391 unsigned long flags;
2392 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002393
2394 psli = &phba->sli;
2395 /* we pass cmdiocb to state machine which needs rspiocb as well */
2396 cmdiocb->context_un.rsp_iocb = rspiocb;
2397
2398 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002399 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002400 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002401 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002402
James Smart858c9f62007-06-17 19:56:39 -05002403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2404 "LOGO cmpl: status:x%x/x%x did:x%x",
2405 irsp->ulpStatus, irsp->un.ulpWord[4],
2406 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002407
dea31012005-04-17 16:05:31 -05002408 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002409 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2410 "0105 LOGO completes to NPort x%x "
2411 "Data: x%x x%x x%x x%x\n",
2412 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2413 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002414
James Smart086a3452012-08-14 14:25:21 -04002415 if (lpfc_els_chk_latt(vport)) {
2416 skip_recovery = 1;
2417 goto out;
2418 }
2419
2420 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002421 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2422 /* NLP_EVT_DEVICE_RM should unregister the RPI
2423 * which should abort all outstanding IOs.
2424 */
2425 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2426 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002427 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002428 goto out;
2429 }
2430
dea31012005-04-17 16:05:31 -05002431 if (irsp->ulpStatus) {
2432 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002433 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002434 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002435 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002436 goto out;
James Smart086a3452012-08-14 14:25:21 -04002437 }
dea31012005-04-17 16:05:31 -05002438 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2440 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2441 ndlp->nlp_DID, irsp->ulpStatus,
2442 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002443 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002444 if (lpfc_error_lost_link(irsp)) {
2445 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002446 goto out;
James Smart086a3452012-08-14 14:25:21 -04002447 }
2448 }
2449
2450 /* Call state machine. This will unregister the rpi if needed. */
2451 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2452
dea31012005-04-17 16:05:31 -05002453out:
2454 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002455 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2456 if ((vport->fc_flag & FC_PT2PT) &&
2457 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2458 phba->pport->fc_myDID = 0;
2459 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2460 if (mbox) {
2461 lpfc_config_link(phba, mbox);
2462 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2463 mbox->vport = vport;
2464 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2465 MBX_NOT_FINISHED) {
2466 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002467 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002468 }
2469 }
2470 }
James Smart086a3452012-08-14 14:25:21 -04002471
2472 /*
2473 * If the node is a target, the handling attempts to recover the port.
2474 * For any other port type, the rpi is unregistered as an implicit
2475 * LOGO.
2476 */
2477 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2478 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2479 spin_lock_irqsave(shost->host_lock, flags);
2480 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2481 spin_unlock_irqrestore(shost->host_lock, flags);
2482
2483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2484 "3187 LOGO completes to NPort x%x: Start "
2485 "Recovery Data: x%x x%x x%x x%x\n",
2486 ndlp->nlp_DID, irsp->ulpStatus,
2487 irsp->un.ulpWord[4], irsp->ulpTimeout,
2488 vport->num_disc_nodes);
2489 lpfc_disc_start(vport);
2490 }
dea31012005-04-17 16:05:31 -05002491 return;
2492}
2493
James Smarte59058c2008-08-24 21:49:00 -04002494/**
James Smart3621a712009-04-06 18:47:14 -04002495 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002496 * @vport: pointer to a virtual N_Port data structure.
2497 * @ndlp: pointer to a node-list data structure.
2498 * @retry: number of retries to the command IOCB.
2499 *
2500 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2501 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2502 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2503 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2504 *
2505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2507 * will be stored into the context1 field of the IOCB for the completion
2508 * callback function to the LOGO ELS command.
2509 *
2510 * Return code
2511 * 0 - successfully issued logo
2512 * 1 - failed to issue logo
2513 **/
dea31012005-04-17 16:05:31 -05002514int
James Smart2e0fef82007-06-17 19:56:36 -05002515lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002516 uint8_t retry)
2517{
James Smart2e0fef82007-06-17 19:56:36 -05002518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2519 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002520 IOCB_t *icmd;
2521 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002522 uint8_t *pcmd;
2523 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002524 int rc;
dea31012005-04-17 16:05:31 -05002525
James Smart98c9ea52007-10-27 13:37:33 -04002526 spin_lock_irq(shost->host_lock);
2527 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2528 spin_unlock_irq(shost->host_lock);
2529 return 0;
2530 }
2531 spin_unlock_irq(shost->host_lock);
2532
James Smart92d7f7b2007-06-17 19:56:38 -05002533 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002534 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2535 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002536 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002537 return 1;
dea31012005-04-17 16:05:31 -05002538
2539 icmd = &elsiocb->iocb;
2540 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2541 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002542 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002543
2544 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002545 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002546 pcmd += sizeof(uint32_t);
2547 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002548
James Smart858c9f62007-06-17 19:56:39 -05002549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2550 "Issue LOGO: did:x%x",
2551 ndlp->nlp_DID, 0, 0);
2552
James Smart086a3452012-08-14 14:25:21 -04002553 /*
2554 * If we are issuing a LOGO, we may try to recover the remote NPort
2555 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2556 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2557 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2558 * for that ELS cmd. To avoid this situation, lets get rid of the
2559 * RPI right now, before any ELS cmds are sent.
2560 */
2561 spin_lock_irq(shost->host_lock);
2562 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2563 spin_unlock_irq(shost->host_lock);
2564 if (lpfc_unreg_rpi(vport, ndlp)) {
2565 lpfc_els_free_iocb(phba, elsiocb);
2566 return 0;
2567 }
2568
dea31012005-04-17 16:05:31 -05002569 phba->fc_stat.elsXmitLOGO++;
2570 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002571 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002572 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002573 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002574 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002575 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002576
2577 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002578 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002579 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002580 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002581 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002582 return 1;
dea31012005-04-17 16:05:31 -05002583 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002584 return 0;
dea31012005-04-17 16:05:31 -05002585}
2586
James Smarte59058c2008-08-24 21:49:00 -04002587/**
James Smart3621a712009-04-06 18:47:14 -04002588 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002589 * @phba: pointer to lpfc hba data structure.
2590 * @cmdiocb: pointer to lpfc command iocb data structure.
2591 * @rspiocb: pointer to lpfc response iocb data structure.
2592 *
2593 * This routine is a generic completion callback function for ELS commands.
2594 * Specifically, it is the callback function which does not need to perform
2595 * any command specific operations. It is currently used by the ELS command
2596 * issuing routines for the ELS State Change Request (SCR),
2597 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2598 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2599 * certain debug loggings, this callback function simply invokes the
2600 * lpfc_els_chk_latt() routine to check whether link went down during the
2601 * discovery process.
2602 **/
dea31012005-04-17 16:05:31 -05002603static void
James Smart2e0fef82007-06-17 19:56:36 -05002604lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2605 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002606{
James Smart2e0fef82007-06-17 19:56:36 -05002607 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002608 IOCB_t *irsp;
2609
2610 irsp = &rspiocb->iocb;
2611
James Smart858c9f62007-06-17 19:56:39 -05002612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2613 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2614 irsp->ulpStatus, irsp->un.ulpWord[4],
2615 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002616 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002617 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2618 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2619 irsp->ulpIoTag, irsp->ulpStatus,
2620 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002621 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002622 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002623 lpfc_els_free_iocb(phba, cmdiocb);
2624 return;
2625}
2626
James Smarte59058c2008-08-24 21:49:00 -04002627/**
James Smart3621a712009-04-06 18:47:14 -04002628 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002629 * @vport: pointer to a host virtual N_Port data structure.
2630 * @nportid: N_Port identifier to the remote node.
2631 * @retry: number of retries to the command IOCB.
2632 *
2633 * This routine issues a State Change Request (SCR) to a fabric node
2634 * on a @vport. The remote node @nportid is passed into the function. It
2635 * first search the @vport node list to find the matching ndlp. If no such
2636 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2637 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2638 * routine is invoked to send the SCR IOCB.
2639 *
2640 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2641 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2642 * will be stored into the context1 field of the IOCB for the completion
2643 * callback function to the SCR ELS command.
2644 *
2645 * Return code
2646 * 0 - Successfully issued scr command
2647 * 1 - Failed to issue scr command
2648 **/
dea31012005-04-17 16:05:31 -05002649int
James Smart2e0fef82007-06-17 19:56:36 -05002650lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002651{
James Smart2e0fef82007-06-17 19:56:36 -05002652 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002653 IOCB_t *icmd;
2654 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002655 struct lpfc_sli *psli;
2656 uint8_t *pcmd;
2657 uint16_t cmdsize;
2658 struct lpfc_nodelist *ndlp;
2659
2660 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002661 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002662
James Smarte47c9092008-02-08 18:49:26 -05002663 ndlp = lpfc_findnode_did(vport, nportid);
2664 if (!ndlp) {
2665 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2666 if (!ndlp)
2667 return 1;
2668 lpfc_nlp_init(vport, ndlp, nportid);
2669 lpfc_enqueue_node(vport, ndlp);
2670 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2671 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2672 if (!ndlp)
2673 return 1;
2674 }
dea31012005-04-17 16:05:31 -05002675
James Smart2e0fef82007-06-17 19:56:36 -05002676 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2677 ndlp->nlp_DID, ELS_CMD_SCR);
2678
James Smart488d1462006-03-07 15:02:37 -05002679 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002680 /* This will trigger the release of the node just
2681 * allocated
2682 */
James Smart329f9bc2007-04-25 09:53:01 -04002683 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002684 return 1;
dea31012005-04-17 16:05:31 -05002685 }
2686
2687 icmd = &elsiocb->iocb;
2688 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2689
2690 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002691 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002692
2693 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002694 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002695 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2696
James Smart858c9f62007-06-17 19:56:39 -05002697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2698 "Issue SCR: did:x%x",
2699 ndlp->nlp_DID, 0, 0);
2700
dea31012005-04-17 16:05:31 -05002701 phba->fc_stat.elsXmitSCR++;
2702 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002703 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2704 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002705 /* The additional lpfc_nlp_put will cause the following
2706 * lpfc_els_free_iocb routine to trigger the rlease of
2707 * the node.
2708 */
James Smart329f9bc2007-04-25 09:53:01 -04002709 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002710 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002711 return 1;
dea31012005-04-17 16:05:31 -05002712 }
James Smartfa4066b2008-01-11 01:53:27 -05002713 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2714 * trigger the release of node.
2715 */
James Smart329f9bc2007-04-25 09:53:01 -04002716 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002717 return 0;
dea31012005-04-17 16:05:31 -05002718}
2719
James Smarte59058c2008-08-24 21:49:00 -04002720/**
James Smart3621a712009-04-06 18:47:14 -04002721 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002722 * @vport: pointer to a host virtual N_Port data structure.
2723 * @nportid: N_Port identifier to the remote node.
2724 * @retry: number of retries to the command IOCB.
2725 *
2726 * This routine issues a Fibre Channel Address Resolution Response
2727 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2728 * is passed into the function. It first search the @vport node list to find
2729 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2730 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2731 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2732 *
2733 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2734 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2735 * will be stored into the context1 field of the IOCB for the completion
2736 * callback function to the PARPR ELS command.
2737 *
2738 * Return code
2739 * 0 - Successfully issued farpr command
2740 * 1 - Failed to issue farpr command
2741 **/
dea31012005-04-17 16:05:31 -05002742static int
James Smart2e0fef82007-06-17 19:56:36 -05002743lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002744{
James Smart2e0fef82007-06-17 19:56:36 -05002745 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002746 IOCB_t *icmd;
2747 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002748 struct lpfc_sli *psli;
2749 FARP *fp;
2750 uint8_t *pcmd;
2751 uint32_t *lp;
2752 uint16_t cmdsize;
2753 struct lpfc_nodelist *ondlp;
2754 struct lpfc_nodelist *ndlp;
2755
2756 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002757 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002758
James Smarte47c9092008-02-08 18:49:26 -05002759 ndlp = lpfc_findnode_did(vport, nportid);
2760 if (!ndlp) {
2761 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2762 if (!ndlp)
2763 return 1;
2764 lpfc_nlp_init(vport, ndlp, nportid);
2765 lpfc_enqueue_node(vport, ndlp);
2766 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2767 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2768 if (!ndlp)
2769 return 1;
2770 }
James Smart2e0fef82007-06-17 19:56:36 -05002771
2772 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2773 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002774 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002775 /* This will trigger the release of the node just
2776 * allocated
2777 */
James Smart329f9bc2007-04-25 09:53:01 -04002778 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002779 return 1;
dea31012005-04-17 16:05:31 -05002780 }
2781
2782 icmd = &elsiocb->iocb;
2783 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2784
2785 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002786 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002787
2788 /* Fill in FARPR payload */
2789 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002790 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002791 lp = (uint32_t *) pcmd;
2792 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002793 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002794 fp->Rflags = 0;
2795 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2796
James Smart92d7f7b2007-06-17 19:56:38 -05002797 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2798 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002799 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002800 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002801 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002802 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002803 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002804 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002805 }
2806
James Smart858c9f62007-06-17 19:56:39 -05002807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2808 "Issue FARPR: did:x%x",
2809 ndlp->nlp_DID, 0, 0);
2810
dea31012005-04-17 16:05:31 -05002811 phba->fc_stat.elsXmitFARPR++;
2812 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002813 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2814 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002815 /* The additional lpfc_nlp_put will cause the following
2816 * lpfc_els_free_iocb routine to trigger the release of
2817 * the node.
2818 */
James Smart329f9bc2007-04-25 09:53:01 -04002819 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002820 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002821 return 1;
dea31012005-04-17 16:05:31 -05002822 }
James Smartfa4066b2008-01-11 01:53:27 -05002823 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2824 * trigger the release of the node.
2825 */
James Smart329f9bc2007-04-25 09:53:01 -04002826 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002827 return 0;
dea31012005-04-17 16:05:31 -05002828}
2829
James Smarte59058c2008-08-24 21:49:00 -04002830/**
James Smart3621a712009-04-06 18:47:14 -04002831 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002832 * @vport: pointer to a host virtual N_Port data structure.
2833 * @nlp: pointer to a node-list data structure.
2834 *
2835 * This routine cancels the timer with a delayed IOCB-command retry for
2836 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2837 * removes the ELS retry event if it presents. In addition, if the
2838 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2839 * commands are sent for the @vport's nodes that require issuing discovery
2840 * ADISC.
2841 **/
dea31012005-04-17 16:05:31 -05002842void
James Smart2e0fef82007-06-17 19:56:36 -05002843lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002844{
James Smart2e0fef82007-06-17 19:56:36 -05002845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002846 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002847
James Smart0d2b6b82008-06-14 22:52:47 -04002848 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2849 return;
James Smart2e0fef82007-06-17 19:56:36 -05002850 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002851 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002852 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002853 del_timer_sync(&nlp->nlp_delayfunc);
2854 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002855 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002856 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002857 /* Decrement nlp reference count held for the delayed retry */
2858 evtp = &nlp->els_retry_evt;
2859 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2860 }
James Smartfdcebe22006-03-07 15:04:01 -05002861 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002862 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002863 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_unlock_irq(shost->host_lock);
2865 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002866 if (vport->port_state < LPFC_VPORT_READY) {
2867 /* Check if there are more ADISCs to be sent */
2868 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002869 } else {
2870 /* Check if there are more PLOGIs to be sent */
2871 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002872 if (vport->num_disc_nodes == 0) {
2873 spin_lock_irq(shost->host_lock);
2874 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2875 spin_unlock_irq(shost->host_lock);
2876 lpfc_can_disctmo(vport);
2877 lpfc_end_rscn(vport);
2878 }
James Smartfdcebe22006-03-07 15:04:01 -05002879 }
2880 }
2881 }
2882 return;
2883}
2884
James Smarte59058c2008-08-24 21:49:00 -04002885/**
James Smart3621a712009-04-06 18:47:14 -04002886 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002887 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2888 *
2889 * This routine is invoked by the ndlp delayed-function timer to check
2890 * whether there is any pending ELS retry event(s) with the node. If not, it
2891 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2892 * adds the delayed events to the HBA work list and invokes the
2893 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2894 * event. Note that lpfc_nlp_get() is called before posting the event to
2895 * the work list to hold reference count of ndlp so that it guarantees the
2896 * reference to ndlp will still be available when the worker thread gets
2897 * to the event associated with the ndlp.
2898 **/
James Smartfdcebe22006-03-07 15:04:01 -05002899void
dea31012005-04-17 16:05:31 -05002900lpfc_els_retry_delay(unsigned long ptr)
2901{
James Smart2e0fef82007-06-17 19:56:36 -05002902 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2903 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002904 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002905 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002906 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002907
James Smart92d7f7b2007-06-17 19:56:38 -05002908 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002909 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002910 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002911 return;
2912 }
2913
James Smartfa4066b2008-01-11 01:53:27 -05002914 /* We need to hold the node by incrementing the reference
2915 * count until the queued work is done
2916 */
2917 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002918 if (evtp->evt_arg1) {
2919 evtp->evt = LPFC_EVT_ELS_RETRY;
2920 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002921 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002922 }
James Smart92d7f7b2007-06-17 19:56:38 -05002923 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002924 return;
2925}
2926
James Smarte59058c2008-08-24 21:49:00 -04002927/**
James Smart3621a712009-04-06 18:47:14 -04002928 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002929 * @ndlp: pointer to a node-list data structure.
2930 *
2931 * This routine is the worker-thread handler for processing the @ndlp delayed
2932 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2933 * the last ELS command from the associated ndlp and invokes the proper ELS
2934 * function according to the delayed ELS command to retry the command.
2935 **/
dea31012005-04-17 16:05:31 -05002936void
2937lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2938{
James Smart2e0fef82007-06-17 19:56:36 -05002939 struct lpfc_vport *vport = ndlp->vport;
2940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2941 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002942
James Smart2e0fef82007-06-17 19:56:36 -05002943 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002944 did = ndlp->nlp_DID;
2945 cmd = ndlp->nlp_last_elscmd;
2946 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002947
2948 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002949 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002950 return;
2951 }
2952
2953 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002954 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002955 /*
2956 * If a discovery event readded nlp_delayfunc after timer
2957 * firing and before processing the timer, cancel the
2958 * nlp_delayfunc.
2959 */
2960 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002961 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002962 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002963
2964 switch (cmd) {
2965 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002966 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002967 break;
2968 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002969 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002970 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002972 }
dea31012005-04-17 16:05:31 -05002973 break;
2974 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002975 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002976 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002978 }
dea31012005-04-17 16:05:31 -05002979 break;
2980 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002981 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002982 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002984 }
dea31012005-04-17 16:05:31 -05002985 break;
2986 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002987 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002988 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04002989 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002990 }
dea31012005-04-17 16:05:31 -05002991 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002992 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002993 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2994 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002995 break;
dea31012005-04-17 16:05:31 -05002996 }
2997 return;
2998}
2999
James Smarte59058c2008-08-24 21:49:00 -04003000/**
James Smart3621a712009-04-06 18:47:14 -04003001 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003002 * @phba: pointer to lpfc hba data structure.
3003 * @cmdiocb: pointer to lpfc command iocb data structure.
3004 * @rspiocb: pointer to lpfc response iocb data structure.
3005 *
3006 * This routine makes a retry decision on an ELS command IOCB, which has
3007 * failed. The following ELS IOCBs use this function for retrying the command
3008 * when previously issued command responsed with error status: FLOGI, PLOGI,
3009 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3010 * returned error status, it makes the decision whether a retry shall be
3011 * issued for the command, and whether a retry shall be made immediately or
3012 * delayed. In the former case, the corresponding ELS command issuing-function
3013 * is called to retry the command. In the later case, the ELS command shall
3014 * be posted to the ndlp delayed event and delayed function timer set to the
3015 * ndlp for the delayed command issusing.
3016 *
3017 * Return code
3018 * 0 - No retry of els command is made
3019 * 1 - Immediate or delayed retry of els command is made
3020 **/
dea31012005-04-17 16:05:31 -05003021static int
James Smart2e0fef82007-06-17 19:56:36 -05003022lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3023 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003024{
James Smart2e0fef82007-06-17 19:56:36 -05003025 struct lpfc_vport *vport = cmdiocb->vport;
3026 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3027 IOCB_t *irsp = &rspiocb->iocb;
3028 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3029 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003030 uint32_t *elscmd;
3031 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003032 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003033 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003034 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003035 uint32_t did;
dea31012005-04-17 16:05:31 -05003036
James Smart488d1462006-03-07 15:02:37 -05003037
dea31012005-04-17 16:05:31 -05003038 /* Note: context2 may be 0 for internal driver abort
3039 * of delays ELS command.
3040 */
3041
3042 if (pcmd && pcmd->virt) {
3043 elscmd = (uint32_t *) (pcmd->virt);
3044 cmd = *elscmd++;
3045 }
3046
James Smarte47c9092008-02-08 18:49:26 -05003047 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003048 did = ndlp->nlp_DID;
3049 else {
3050 /* We should only hit this case for retrying PLOGI */
3051 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003052 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003053 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3054 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003055 return 1;
3056 }
3057
James Smart858c9f62007-06-17 19:56:39 -05003058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3059 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3060 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3061
dea31012005-04-17 16:05:31 -05003062 switch (irsp->ulpStatus) {
3063 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003064 break;
James Smart1151e3e2011-02-16 12:39:35 -05003065 case IOSTAT_REMOTE_STOP:
3066 if (phba->sli_rev == LPFC_SLI_REV4) {
3067 /* This IO was aborted by the target, we don't
3068 * know the rxid and because we did not send the
3069 * ABTS we cannot generate and RRQ.
3070 */
3071 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003072 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003073 }
3074 break;
dea31012005-04-17 16:05:31 -05003075 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003076 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003077 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003078 if (cmd == ELS_CMD_FLOGI) {
3079 if (PCI_DEVICE_ID_HORNET ==
3080 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003081 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003082 phba->pport->fc_myDID = 0;
3083 phba->alpa_map[0] = 0;
3084 phba->alpa_map[1] = 0;
3085 }
3086 }
James Smart2e0fef82007-06-17 19:56:36 -05003087 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003088 delay = 1000;
dea31012005-04-17 16:05:31 -05003089 retry = 1;
3090 break;
3091
James Smart92d7f7b2007-06-17 19:56:38 -05003092 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003093 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3094 "0124 Retry illegal cmd x%x "
3095 "retry:x%x delay:x%x\n",
3096 cmd, cmdiocb->retry, delay);
3097 retry = 1;
3098 /* All command's retry policy */
3099 maxretry = 8;
3100 if (cmdiocb->retry > 2)
3101 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003102 break;
3103
dea31012005-04-17 16:05:31 -05003104 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003105 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003106 retry = 1;
3107 if (cmdiocb->retry > 100)
3108 delay = 100;
3109 maxretry = 250;
3110 break;
3111
3112 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003113 delay = 100;
dea31012005-04-17 16:05:31 -05003114 retry = 1;
3115 break;
3116
James Smart858c9f62007-06-17 19:56:39 -05003117 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003118 case IOERR_INVALID_RPI:
3119 retry = 1;
3120 break;
3121 }
3122 break;
3123
3124 case IOSTAT_NPORT_RJT:
3125 case IOSTAT_FABRIC_RJT:
3126 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3127 retry = 1;
3128 break;
3129 }
3130 break;
3131
3132 case IOSTAT_NPORT_BSY:
3133 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003134 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003135 retry = 1;
3136 break;
3137
3138 case IOSTAT_LS_RJT:
3139 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3140 /* Added for Vendor specifc support
3141 * Just keep retrying for these Rsn / Exp codes
3142 */
3143 switch (stat.un.b.lsRjtRsnCode) {
3144 case LSRJT_UNABLE_TPC:
3145 if (stat.un.b.lsRjtRsnCodeExp ==
3146 LSEXP_CMD_IN_PROGRESS) {
3147 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003148 delay = 1000;
dea31012005-04-17 16:05:31 -05003149 maxretry = 48;
3150 }
3151 retry = 1;
3152 break;
3153 }
James Smartffc95492010-06-07 15:23:17 -04003154 if (stat.un.b.lsRjtRsnCodeExp ==
3155 LSEXP_CANT_GIVE_DATA) {
3156 if (cmd == ELS_CMD_PLOGI) {
3157 delay = 1000;
3158 maxretry = 48;
3159 }
3160 retry = 1;
3161 break;
3162 }
dea31012005-04-17 16:05:31 -05003163 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003164 delay = 1000;
dea31012005-04-17 16:05:31 -05003165 maxretry = lpfc_max_els_tries + 1;
3166 retry = 1;
3167 break;
3168 }
James Smart92d7f7b2007-06-17 19:56:38 -05003169 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3170 (cmd == ELS_CMD_FDISC) &&
3171 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003172 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3173 "0125 FDISC Failed (x%x). "
3174 "Fabric out of resources\n",
3175 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003176 lpfc_vport_set_state(vport,
3177 FC_VPORT_NO_FABRIC_RSCS);
3178 }
dea31012005-04-17 16:05:31 -05003179 break;
3180
3181 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003182 if ((cmd == ELS_CMD_PLOGI) ||
3183 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003184 delay = 1000;
dea31012005-04-17 16:05:31 -05003185 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003186 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003187 /* FDISC retry policy */
3188 maxretry = 48;
3189 if (cmdiocb->retry >= 32)
3190 delay = 1000;
dea31012005-04-17 16:05:31 -05003191 }
3192 retry = 1;
3193 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003194
3195 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003196 /* There are some cases where switches return this
3197 * error when they are not ready and should be returning
3198 * Logical Busy. We should delay every time.
3199 */
3200 if (cmd == ELS_CMD_FDISC &&
3201 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3202 maxretry = 3;
3203 delay = 1000;
3204 retry = 1;
3205 break;
3206 }
James Smart92d7f7b2007-06-17 19:56:38 -05003207 case LSRJT_PROTOCOL_ERR:
3208 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3209 (cmd == ELS_CMD_FDISC) &&
3210 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3211 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3212 ) {
James Smarte8b62012007-08-02 11:10:09 -04003213 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003214 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003215 "Fabric Detected Bad WWN\n",
3216 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003217 lpfc_vport_set_state(vport,
3218 FC_VPORT_FABRIC_REJ_WWN);
3219 }
3220 break;
dea31012005-04-17 16:05:31 -05003221 }
3222 break;
3223
3224 case IOSTAT_INTERMED_RSP:
3225 case IOSTAT_BA_RJT:
3226 break;
3227
3228 default:
3229 break;
3230 }
3231
James Smart488d1462006-03-07 15:02:37 -05003232 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003233 retry = 1;
dea31012005-04-17 16:05:31 -05003234
James Smartdf9e1b52011-12-13 13:22:17 -05003235 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003236 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003237 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003238 /* FLOGI retry policy */
3239 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003240 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003241 maxretry = 0;
3242 if (cmdiocb->retry >= 100)
3243 delay = 5000;
3244 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003245 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003246 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3247 /* retry FDISCs every second up to devloss */
3248 retry = 1;
3249 maxretry = vport->cfg_devloss_tmo;
3250 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003251 }
3252
James Smart6669f9b2009-10-02 15:16:45 -04003253 cmdiocb->retry++;
3254 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003255 phba->fc_stat.elsRetryExceeded++;
3256 retry = 0;
3257 }
3258
James Smarted957682007-06-17 19:56:37 -05003259 if ((vport->load_flag & FC_UNLOADING) != 0)
3260 retry = 0;
3261
dea31012005-04-17 16:05:31 -05003262 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003263 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3264 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3265 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3266 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3267 "2849 Stop retry ELS command "
3268 "x%x to remote NPORT x%x, "
3269 "Data: x%x x%x\n", cmd, did,
3270 cmdiocb->retry, delay);
3271 return 0;
3272 }
3273 }
dea31012005-04-17 16:05:31 -05003274
3275 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003276 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3277 "0107 Retry ELS command x%x to remote "
3278 "NPORT x%x Data: x%x x%x\n",
3279 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003280
James Smart858c9f62007-06-17 19:56:39 -05003281 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3282 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003283 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3284 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003285 /* Don't reset timer for no resources */
3286
dea31012005-04-17 16:05:31 -05003287 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003288 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003289 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003290 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003291 }
3292
3293 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003294 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003295 phba->fc_stat.elsDelayRetry++;
3296 ndlp->nlp_retry = cmdiocb->retry;
3297
James Smart92d7f7b2007-06-17 19:56:38 -05003298 /* delay is specified in milliseconds */
3299 mod_timer(&ndlp->nlp_delayfunc,
3300 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003301 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003302 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003303 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003304
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003305 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003306 if (cmd == ELS_CMD_PRLI)
3307 lpfc_nlp_set_state(vport, ndlp,
3308 NLP_STE_REG_LOGIN_ISSUE);
3309 else
3310 lpfc_nlp_set_state(vport, ndlp,
3311 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003312 ndlp->nlp_last_elscmd = cmd;
3313
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003314 return 1;
dea31012005-04-17 16:05:31 -05003315 }
3316 switch (cmd) {
3317 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003318 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003319 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003320 case ELS_CMD_FDISC:
3321 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3322 return 1;
dea31012005-04-17 16:05:31 -05003323 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003324 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003325 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003326 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003327 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003328 }
James Smart2e0fef82007-06-17 19:56:36 -05003329 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003330 return 1;
dea31012005-04-17 16:05:31 -05003331 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003332 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003333 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3334 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003335 return 1;
dea31012005-04-17 16:05:31 -05003336 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003337 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003338 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3339 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003340 return 1;
dea31012005-04-17 16:05:31 -05003341 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003342 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003343 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003344 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003345 return 1;
dea31012005-04-17 16:05:31 -05003346 }
3347 }
dea31012005-04-17 16:05:31 -05003348 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003349 if (logerr) {
3350 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3351 "0137 No retry ELS command x%x to remote "
3352 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3353 cmd, did, irsp->ulpStatus,
3354 irsp->un.ulpWord[4]);
3355 }
3356 else {
3357 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003358 "0108 No retry ELS command x%x to remote "
3359 "NPORT x%x Retried:%d Error:x%x/%x\n",
3360 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3361 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003362 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003363 return 0;
dea31012005-04-17 16:05:31 -05003364}
3365
James Smarte59058c2008-08-24 21:49:00 -04003366/**
James Smart3621a712009-04-06 18:47:14 -04003367 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003368 * @phba: pointer to lpfc hba data structure.
3369 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3370 *
3371 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3372 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3373 * checks to see whether there is a lpfc DMA buffer associated with the
3374 * response of the command IOCB. If so, it will be released before releasing
3375 * the lpfc DMA buffer associated with the IOCB itself.
3376 *
3377 * Return code
3378 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3379 **/
James Smart09372822008-01-11 01:52:54 -05003380static int
James Smart87af33f2007-10-27 13:37:43 -04003381lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3382{
3383 struct lpfc_dmabuf *buf_ptr;
3384
James Smarte59058c2008-08-24 21:49:00 -04003385 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003386 if (!list_empty(&buf_ptr1->list)) {
3387 list_remove_head(&buf_ptr1->list, buf_ptr,
3388 struct lpfc_dmabuf,
3389 list);
3390 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3391 kfree(buf_ptr);
3392 }
3393 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3394 kfree(buf_ptr1);
3395 return 0;
3396}
3397
James Smarte59058c2008-08-24 21:49:00 -04003398/**
James Smart3621a712009-04-06 18:47:14 -04003399 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003400 * @phba: pointer to lpfc hba data structure.
3401 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3402 *
3403 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3404 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3405 * pool.
3406 *
3407 * Return code
3408 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3409 **/
James Smart09372822008-01-11 01:52:54 -05003410static int
James Smart87af33f2007-10-27 13:37:43 -04003411lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3412{
3413 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3414 kfree(buf_ptr);
3415 return 0;
3416}
3417
James Smarte59058c2008-08-24 21:49:00 -04003418/**
James Smart3621a712009-04-06 18:47:14 -04003419 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003420 * @phba: pointer to lpfc hba data structure.
3421 * @elsiocb: pointer to lpfc els command iocb data structure.
3422 *
3423 * This routine frees a command IOCB and its associated resources. The
3424 * command IOCB data structure contains the reference to various associated
3425 * resources, these fields must be set to NULL if the associated reference
3426 * not present:
3427 * context1 - reference to ndlp
3428 * context2 - reference to cmd
3429 * context2->next - reference to rsp
3430 * context3 - reference to bpl
3431 *
3432 * It first properly decrements the reference count held on ndlp for the
3433 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3434 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3435 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3436 * adds the DMA buffer the @phba data structure for the delayed release.
3437 * If reference to the Buffer Pointer List (BPL) is present, the
3438 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3439 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3440 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3441 *
3442 * Return code
3443 * 0 - Success (currently, always return 0)
3444 **/
James Smart87af33f2007-10-27 13:37:43 -04003445int
James Smart329f9bc2007-04-25 09:53:01 -04003446lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003447{
3448 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003449 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003450
James Smarta8adb832007-10-27 13:37:53 -04003451 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3452 if (ndlp) {
3453 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3454 lpfc_nlp_put(ndlp);
3455
3456 /* If the ndlp is not being used by another discovery
3457 * thread, free it.
3458 */
3459 if (!lpfc_nlp_not_used(ndlp)) {
3460 /* If ndlp is being used by another discovery
3461 * thread, just clear NLP_DEFER_RM
3462 */
3463 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3464 }
3465 }
3466 else
3467 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003468 elsiocb->context1 = NULL;
3469 }
dea31012005-04-17 16:05:31 -05003470 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3471 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003472 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3473 /* Firmware could still be in progress of DMAing
3474 * payload, so don't free data buffer till after
3475 * a hbeat.
3476 */
3477 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3478 buf_ptr = elsiocb->context2;
3479 elsiocb->context2 = NULL;
3480 if (buf_ptr) {
3481 buf_ptr1 = NULL;
3482 spin_lock_irq(&phba->hbalock);
3483 if (!list_empty(&buf_ptr->list)) {
3484 list_remove_head(&buf_ptr->list,
3485 buf_ptr1, struct lpfc_dmabuf,
3486 list);
3487 INIT_LIST_HEAD(&buf_ptr1->list);
3488 list_add_tail(&buf_ptr1->list,
3489 &phba->elsbuf);
3490 phba->elsbuf_cnt++;
3491 }
3492 INIT_LIST_HEAD(&buf_ptr->list);
3493 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3494 phba->elsbuf_cnt++;
3495 spin_unlock_irq(&phba->hbalock);
3496 }
3497 } else {
3498 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3499 lpfc_els_free_data(phba, buf_ptr1);
3500 }
dea31012005-04-17 16:05:31 -05003501 }
3502
3503 if (elsiocb->context3) {
3504 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003505 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003506 }
James Bottomley604a3e32005-10-29 10:28:33 -05003507 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003508 return 0;
3509}
3510
James Smarte59058c2008-08-24 21:49:00 -04003511/**
James Smart3621a712009-04-06 18:47:14 -04003512 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003513 * @phba: pointer to lpfc hba data structure.
3514 * @cmdiocb: pointer to lpfc command iocb data structure.
3515 * @rspiocb: pointer to lpfc response iocb data structure.
3516 *
3517 * This routine is the completion callback function to the Logout (LOGO)
3518 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3519 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3520 * release the ndlp if it has the last reference remaining (reference count
3521 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3522 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3523 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3524 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3525 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3526 * IOCB data structure.
3527 **/
dea31012005-04-17 16:05:31 -05003528static void
James Smart2e0fef82007-06-17 19:56:36 -05003529lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3530 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003531{
James Smart2e0fef82007-06-17 19:56:36 -05003532 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3533 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003534 IOCB_t *irsp;
3535
3536 irsp = &rspiocb->iocb;
3537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3538 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3539 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003540 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003541 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3542 "0109 ACC to LOGO completes to NPort x%x "
3543 "Data: x%x x%x x%x\n",
3544 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3545 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003546
3547 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3548 /* NPort Recovery mode or node is just allocated */
3549 if (!lpfc_nlp_not_used(ndlp)) {
3550 /* If the ndlp is being used by another discovery
3551 * thread, just unregister the RPI.
3552 */
3553 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003554 } else {
3555 /* Indicate the node has already released, should
3556 * not reference to it from within lpfc_els_free_iocb.
3557 */
3558 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003559 }
dea31012005-04-17 16:05:31 -05003560 }
James Smart73d91e52011-10-10 21:32:10 -04003561
3562 /*
3563 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003564 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003565 */
dea31012005-04-17 16:05:31 -05003566 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003567
3568 /*
3569 * Remove the ndlp reference if it's a fabric node that has
3570 * sent us an unsolicted LOGO.
3571 */
3572 if (ndlp->nlp_type & NLP_FABRIC)
3573 lpfc_nlp_put(ndlp);
3574
dea31012005-04-17 16:05:31 -05003575 return;
3576}
3577
James Smarte59058c2008-08-24 21:49:00 -04003578/**
James Smart3621a712009-04-06 18:47:14 -04003579 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003580 * @phba: pointer to lpfc hba data structure.
3581 * @pmb: pointer to the driver internal queue element for mailbox command.
3582 *
3583 * This routine is the completion callback function for unregister default
3584 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3585 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3586 * decrements the ndlp reference count held for this completion callback
3587 * function. After that, it invokes the lpfc_nlp_not_used() to check
3588 * whether there is only one reference left on the ndlp. If so, it will
3589 * perform one more decrement and trigger the release of the ndlp.
3590 **/
James Smart858c9f62007-06-17 19:56:39 -05003591void
3592lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3593{
3594 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3595 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3596
3597 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003598 pmb->context2 = NULL;
3599
James Smart858c9f62007-06-17 19:56:39 -05003600 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3601 kfree(mp);
3602 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003603 if (ndlp) {
3604 if (NLP_CHK_NODE_ACT(ndlp)) {
3605 lpfc_nlp_put(ndlp);
3606 /* This is the end of the default RPI cleanup logic for
3607 * this ndlp. If no other discovery threads are using
3608 * this ndlp, free all resources associated with it.
3609 */
3610 lpfc_nlp_not_used(ndlp);
3611 } else {
3612 lpfc_drop_node(ndlp->vport, ndlp);
3613 }
James Smarta8adb832007-10-27 13:37:53 -04003614 }
James Smart3772a992009-05-22 14:50:54 -04003615
James Smart858c9f62007-06-17 19:56:39 -05003616 return;
3617}
3618
James Smarte59058c2008-08-24 21:49:00 -04003619/**
James Smart3621a712009-04-06 18:47:14 -04003620 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003621 * @phba: pointer to lpfc hba data structure.
3622 * @cmdiocb: pointer to lpfc command iocb data structure.
3623 * @rspiocb: pointer to lpfc response iocb data structure.
3624 *
3625 * This routine is the completion callback function for ELS Response IOCB
3626 * command. In normal case, this callback function just properly sets the
3627 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3628 * field in the command IOCB is not NULL, the referred mailbox command will
3629 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3630 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3631 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3632 * routine shall be invoked trying to release the ndlp if no other threads
3633 * are currently referring it.
3634 **/
dea31012005-04-17 16:05:31 -05003635static void
James Smart858c9f62007-06-17 19:56:39 -05003636lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003637 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003638{
James Smart2e0fef82007-06-17 19:56:36 -05003639 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3640 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3641 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003642 IOCB_t *irsp;
3643 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003644 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003645 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003646 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003647
James Smart33ccf8d2006-08-17 11:57:58 -04003648 irsp = &rspiocb->iocb;
3649
dea31012005-04-17 16:05:31 -05003650 if (cmdiocb->context_un.mbox)
3651 mbox = cmdiocb->context_un.mbox;
3652
James Smartfa4066b2008-01-11 01:53:27 -05003653 /* First determine if this is a LS_RJT cmpl. Note, this callback
3654 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3655 */
James Smart87af33f2007-10-27 13:37:43 -04003656 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003657 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3658 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003659 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003660 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003661 */
3662 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3663 ls_rjt = 1;
3664 }
3665
dea31012005-04-17 16:05:31 -05003666 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003667 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003668 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003669 mp = (struct lpfc_dmabuf *) mbox->context1;
3670 if (mp) {
3671 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3672 kfree(mp);
3673 }
James Smart329f9bc2007-04-25 09:53:01 -04003674 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003675 }
James Smart58da1ff2008-04-07 10:15:56 -04003676 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3677 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003678 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003679 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003680 /* Indicate the node has already released,
3681 * should not reference to it from within
3682 * the routine lpfc_els_free_iocb.
3683 */
3684 cmdiocb->context1 = NULL;
3685 }
dea31012005-04-17 16:05:31 -05003686 goto out;
3687 }
3688
James Smart858c9f62007-06-17 19:56:39 -05003689 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003690 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003691 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003692 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003693 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003694 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3695 "0110 ELS response tag x%x completes "
3696 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3697 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3698 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3699 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3700 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003701 if (mbox) {
3702 if ((rspiocb->iocb.ulpStatus == 0)
3703 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003704 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003705 /* Increment reference count to ndlp to hold the
3706 * reference to ndlp for the callback function.
3707 */
James Smart329f9bc2007-04-25 09:53:01 -04003708 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003709 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003710 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3711 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3712 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3713 }
3714 else {
3715 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3716 ndlp->nlp_prev_state = ndlp->nlp_state;
3717 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003718 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003719 }
James Smart0b727fe2007-10-27 13:37:25 -04003720 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003721 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003722 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003723 else
3724 /* Decrement the ndlp reference count we
3725 * set for this failed mailbox command.
3726 */
3727 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003728
3729 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3730 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3731 "0138 ELS rsp: Cannot issue reg_login for x%x "
3732 "Data: x%x x%x x%x\n",
3733 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3734 ndlp->nlp_rpi);
3735
James Smartfa4066b2008-01-11 01:53:27 -05003736 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003737 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003738 /* Indicate node has already been released,
3739 * should not reference to it from within
3740 * the routine lpfc_els_free_iocb.
3741 */
3742 cmdiocb->context1 = NULL;
3743 }
dea31012005-04-17 16:05:31 -05003744 } else {
James Smart858c9f62007-06-17 19:56:39 -05003745 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3746 if (!lpfc_error_lost_link(irsp) &&
3747 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003748 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003749 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003750 /* Indicate node has already been
3751 * released, should not reference
3752 * to it from within the routine
3753 * lpfc_els_free_iocb.
3754 */
3755 cmdiocb->context1 = NULL;
3756 }
dea31012005-04-17 16:05:31 -05003757 }
3758 }
James Smart14691152006-12-02 13:34:28 -05003759 mp = (struct lpfc_dmabuf *) mbox->context1;
3760 if (mp) {
3761 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3762 kfree(mp);
3763 }
3764 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003765 }
3766out:
James Smart58da1ff2008-04-07 10:15:56 -04003767 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003768 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003769 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003770 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003771
3772 /* If the node is not being used by another discovery thread,
3773 * and we are sending a reject, we are done with it.
3774 * Release driver reference count here and free associated
3775 * resources.
3776 */
3777 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003778 if (lpfc_nlp_not_used(ndlp))
3779 /* Indicate node has already been released,
3780 * should not reference to it from within
3781 * the routine lpfc_els_free_iocb.
3782 */
3783 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003784 }
James Smart87af33f2007-10-27 13:37:43 -04003785
dea31012005-04-17 16:05:31 -05003786 lpfc_els_free_iocb(phba, cmdiocb);
3787 return;
3788}
3789
James Smarte59058c2008-08-24 21:49:00 -04003790/**
James Smart3621a712009-04-06 18:47:14 -04003791 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003792 * @vport: pointer to a host virtual N_Port data structure.
3793 * @flag: the els command code to be accepted.
3794 * @oldiocb: pointer to the original lpfc command iocb data structure.
3795 * @ndlp: pointer to a node-list data structure.
3796 * @mbox: pointer to the driver internal queue element for mailbox command.
3797 *
3798 * This routine prepares and issues an Accept (ACC) response IOCB
3799 * command. It uses the @flag to properly set up the IOCB field for the
3800 * specific ACC response command to be issued and invokes the
3801 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3802 * @mbox pointer is passed in, it will be put into the context_un.mbox
3803 * field of the IOCB for the completion callback function to issue the
3804 * mailbox command to the HBA later when callback is invoked.
3805 *
3806 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3807 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3808 * will be stored into the context1 field of the IOCB for the completion
3809 * callback function to the corresponding response ELS IOCB command.
3810 *
3811 * Return code
3812 * 0 - Successfully issued acc response
3813 * 1 - Failed to issue acc response
3814 **/
dea31012005-04-17 16:05:31 -05003815int
James Smart2e0fef82007-06-17 19:56:36 -05003816lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3817 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003818 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003819{
James Smart2e0fef82007-06-17 19:56:36 -05003820 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3821 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003822 IOCB_t *icmd;
3823 IOCB_t *oldcmd;
3824 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003825 struct lpfc_sli *psli;
3826 uint8_t *pcmd;
3827 uint16_t cmdsize;
3828 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003829 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003830
3831 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003832 oldcmd = &oldiocb->iocb;
3833
3834 switch (flag) {
3835 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003836 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003837 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3838 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003839 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003840 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003841 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003842 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003843 return 1;
dea31012005-04-17 16:05:31 -05003844 }
James Smart2e0fef82007-06-17 19:56:36 -05003845
dea31012005-04-17 16:05:31 -05003846 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003847 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3848 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003849 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3850 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003851 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003852
3853 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3854 "Issue ACC: did:x%x flg:x%x",
3855 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003856 break;
3857 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003858 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003859 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3860 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003861 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003862 return 1;
James Smart488d1462006-03-07 15:02:37 -05003863
dea31012005-04-17 16:05:31 -05003864 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003865 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3866 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003867 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3868
3869 if (mbox)
3870 elsiocb->context_un.mbox = mbox;
3871
3872 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003873 pcmd += sizeof(uint32_t);
3874 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003875
3876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3877 "Issue ACC PLOGI: did:x%x flg:x%x",
3878 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003879 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003880 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003881 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003882 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003883 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3884 if (!elsiocb)
3885 return 1;
3886
3887 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003888 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3889 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003890 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3891
3892 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003893 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003894 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3895 els_pkt_ptr = (ELS_PKT *) pcmd;
3896 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003897
3898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3899 "Issue ACC PRLO: did:x%x flg:x%x",
3900 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003901 break;
dea31012005-04-17 16:05:31 -05003902 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003903 return 1;
dea31012005-04-17 16:05:31 -05003904 }
dea31012005-04-17 16:05:31 -05003905 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003906 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3907 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003908 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3909 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003910 elsiocb->iotag, elsiocb->iocb.ulpContext,
3911 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003912 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003913 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003914 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003915 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003916 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003917 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3918 } else {
James Smart858c9f62007-06-17 19:56:39 -05003919 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003920 }
3921
3922 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003923 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003924 if (rc == IOCB_ERROR) {
3925 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003926 return 1;
dea31012005-04-17 16:05:31 -05003927 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003928 return 0;
dea31012005-04-17 16:05:31 -05003929}
3930
James Smarte59058c2008-08-24 21:49:00 -04003931/**
James Smart3621a712009-04-06 18:47:14 -04003932 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003933 * @vport: pointer to a virtual N_Port data structure.
3934 * @rejectError:
3935 * @oldiocb: pointer to the original lpfc command iocb data structure.
3936 * @ndlp: pointer to a node-list data structure.
3937 * @mbox: pointer to the driver internal queue element for mailbox command.
3938 *
3939 * This routine prepares and issue an Reject (RJT) response IOCB
3940 * command. If a @mbox pointer is passed in, it will be put into the
3941 * context_un.mbox field of the IOCB for the completion callback function
3942 * to issue to the HBA later.
3943 *
3944 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3945 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3946 * will be stored into the context1 field of the IOCB for the completion
3947 * callback function to the reject response ELS IOCB command.
3948 *
3949 * Return code
3950 * 0 - Successfully issued reject response
3951 * 1 - Failed to issue reject response
3952 **/
dea31012005-04-17 16:05:31 -05003953int
James Smart2e0fef82007-06-17 19:56:36 -05003954lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003955 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3956 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003957{
James Smart2e0fef82007-06-17 19:56:36 -05003958 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003959 IOCB_t *icmd;
3960 IOCB_t *oldcmd;
3961 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003962 struct lpfc_sli *psli;
3963 uint8_t *pcmd;
3964 uint16_t cmdsize;
3965 int rc;
3966
3967 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003968 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003969 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3970 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003971 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003972 return 1;
dea31012005-04-17 16:05:31 -05003973
3974 icmd = &elsiocb->iocb;
3975 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003976 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3977 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003978 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3979
3980 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003981 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003982 *((uint32_t *) (pcmd)) = rejectError;
3983
James Smart51ef4c22007-08-02 11:10:31 -04003984 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003985 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003986
dea31012005-04-17 16:05:31 -05003987 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3989 "0129 Xmit ELS RJT x%x response tag x%x "
3990 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3991 "rpi x%x\n",
3992 rejectError, elsiocb->iotag,
3993 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3994 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003995 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3996 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3997 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3998
dea31012005-04-17 16:05:31 -05003999 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004000 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004001 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004002
dea31012005-04-17 16:05:31 -05004003 if (rc == IOCB_ERROR) {
4004 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004005 return 1;
dea31012005-04-17 16:05:31 -05004006 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004007 return 0;
dea31012005-04-17 16:05:31 -05004008}
4009
James Smarte59058c2008-08-24 21:49:00 -04004010/**
James Smart3621a712009-04-06 18:47:14 -04004011 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004012 * @vport: pointer to a virtual N_Port data structure.
4013 * @oldiocb: pointer to the original lpfc command iocb data structure.
4014 * @ndlp: pointer to a node-list data structure.
4015 *
4016 * This routine prepares and issues an Accept (ACC) response to Address
4017 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4018 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4019 *
4020 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4021 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4022 * will be stored into the context1 field of the IOCB for the completion
4023 * callback function to the ADISC Accept response ELS IOCB command.
4024 *
4025 * Return code
4026 * 0 - Successfully issued acc adisc response
4027 * 1 - Failed to issue adisc acc response
4028 **/
dea31012005-04-17 16:05:31 -05004029int
James Smart2e0fef82007-06-17 19:56:36 -05004030lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4031 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004032{
James Smart2e0fef82007-06-17 19:56:36 -05004033 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004034 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004035 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004036 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004037 uint8_t *pcmd;
4038 uint16_t cmdsize;
4039 int rc;
4040
James Smart92d7f7b2007-06-17 19:56:38 -05004041 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004042 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4043 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004044 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004045 return 1;
dea31012005-04-17 16:05:31 -05004046
dea31012005-04-17 16:05:31 -05004047 icmd = &elsiocb->iocb;
4048 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004049 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4050 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004051
4052 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004053 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4054 "0130 Xmit ADISC ACC response iotag x%x xri: "
4055 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4056 elsiocb->iotag, elsiocb->iocb.ulpContext,
4057 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4058 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004059 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4060
4061 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004062 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004063
4064 ap = (ADISC *) (pcmd);
4065 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004066 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4067 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004068 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004069
James Smart858c9f62007-06-17 19:56:39 -05004070 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4071 "Issue ACC ADISC: did:x%x flg:x%x",
4072 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4073
dea31012005-04-17 16:05:31 -05004074 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004075 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004076 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004077 if (rc == IOCB_ERROR) {
4078 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004079 return 1;
dea31012005-04-17 16:05:31 -05004080 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004081 return 0;
dea31012005-04-17 16:05:31 -05004082}
4083
James Smarte59058c2008-08-24 21:49:00 -04004084/**
James Smart3621a712009-04-06 18:47:14 -04004085 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004086 * @vport: pointer to a virtual N_Port data structure.
4087 * @oldiocb: pointer to the original lpfc command iocb data structure.
4088 * @ndlp: pointer to a node-list data structure.
4089 *
4090 * This routine prepares and issues an Accept (ACC) response to Process
4091 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4092 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4093 *
4094 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4095 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4096 * will be stored into the context1 field of the IOCB for the completion
4097 * callback function to the PRLI Accept response ELS IOCB command.
4098 *
4099 * Return code
4100 * 0 - Successfully issued acc prli response
4101 * 1 - Failed to issue acc prli response
4102 **/
dea31012005-04-17 16:05:31 -05004103int
James Smart2e0fef82007-06-17 19:56:36 -05004104lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004105 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004106{
James Smart2e0fef82007-06-17 19:56:36 -05004107 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004108 PRLI *npr;
4109 lpfc_vpd_t *vpd;
4110 IOCB_t *icmd;
4111 IOCB_t *oldcmd;
4112 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004113 struct lpfc_sli *psli;
4114 uint8_t *pcmd;
4115 uint16_t cmdsize;
4116 int rc;
4117
4118 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004119
James Smart92d7f7b2007-06-17 19:56:38 -05004120 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004121 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004122 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004123 if (!elsiocb)
4124 return 1;
dea31012005-04-17 16:05:31 -05004125
dea31012005-04-17 16:05:31 -05004126 icmd = &elsiocb->iocb;
4127 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004128 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4129 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4130
James Smart5b8bd0c2007-04-25 09:52:49 -04004131 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004132 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4133 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4134 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4135 elsiocb->iotag, elsiocb->iocb.ulpContext,
4136 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4137 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004138 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4139
4140 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004141 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004142
4143 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004144 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004145
4146 npr = (PRLI *) pcmd;
4147 vpd = &phba->vpd;
4148 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004149 * If the remote port is a target and our firmware version is 3.20 or
4150 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004151 */
James Smart0d2b6b82008-06-14 22:52:47 -04004152 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4153 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004154 npr->ConfmComplAllowed = 1;
4155 npr->Retry = 1;
4156 npr->TaskRetryIdReq = 1;
4157 }
4158
4159 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4160 npr->estabImagePair = 1;
4161 npr->readXferRdyDis = 1;
4162 npr->ConfmComplAllowed = 1;
4163
4164 npr->prliType = PRLI_FCP_TYPE;
4165 npr->initiatorFunc = 1;
4166
James Smart858c9f62007-06-17 19:56:39 -05004167 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4168 "Issue ACC PRLI: did:x%x flg:x%x",
4169 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4170
dea31012005-04-17 16:05:31 -05004171 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004172 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004173
James Smart3772a992009-05-22 14:50:54 -04004174 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004175 if (rc == IOCB_ERROR) {
4176 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004177 return 1;
dea31012005-04-17 16:05:31 -05004178 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004179 return 0;
dea31012005-04-17 16:05:31 -05004180}
4181
James Smarte59058c2008-08-24 21:49:00 -04004182/**
James Smart3621a712009-04-06 18:47:14 -04004183 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004184 * @vport: pointer to a virtual N_Port data structure.
4185 * @format: rnid command format.
4186 * @oldiocb: pointer to the original lpfc command iocb data structure.
4187 * @ndlp: pointer to a node-list data structure.
4188 *
4189 * This routine issues a Request Node Identification Data (RNID) Accept
4190 * (ACC) response. It constructs the RNID ACC response command according to
4191 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4192 * issue the response. Note that this command does not need to hold the ndlp
4193 * reference count for the callback. So, the ndlp reference count taken by
4194 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4195 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4196 * there is no ndlp reference available.
4197 *
4198 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4199 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4200 * will be stored into the context1 field of the IOCB for the completion
4201 * callback function. However, for the RNID Accept Response ELS command,
4202 * this is undone later by this routine after the IOCB is allocated.
4203 *
4204 * Return code
4205 * 0 - Successfully issued acc rnid response
4206 * 1 - Failed to issue acc rnid response
4207 **/
dea31012005-04-17 16:05:31 -05004208static int
James Smart2e0fef82007-06-17 19:56:36 -05004209lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004210 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004211{
James Smart2e0fef82007-06-17 19:56:36 -05004212 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004213 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004214 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004215 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004216 struct lpfc_sli *psli;
4217 uint8_t *pcmd;
4218 uint16_t cmdsize;
4219 int rc;
4220
4221 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004222 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4223 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004224 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004225 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004226
James Smart2e0fef82007-06-17 19:56:36 -05004227 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4228 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004229 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004230 return 1;
dea31012005-04-17 16:05:31 -05004231
dea31012005-04-17 16:05:31 -05004232 icmd = &elsiocb->iocb;
4233 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004234 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4235 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4236
James Smart5b8bd0c2007-04-25 09:52:49 -04004237 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4239 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4240 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004241 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004242 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004243 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004244
James Smart92d7f7b2007-06-17 19:56:38 -05004245 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004246 rn = (RNID *) (pcmd);
4247 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004248 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4249 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4250 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004251 switch (format) {
4252 case 0:
4253 rn->SpecificLen = 0;
4254 break;
4255 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004256 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004257 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004258 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004259 rn->un.topologyDisc.unitType = RNID_HBA;
4260 rn->un.topologyDisc.physPort = 0;
4261 rn->un.topologyDisc.attachedNodes = 0;
4262 break;
4263 default:
4264 rn->CommonLen = 0;
4265 rn->SpecificLen = 0;
4266 break;
4267 }
4268
James Smart858c9f62007-06-17 19:56:39 -05004269 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4270 "Issue ACC RNID: did:x%x flg:x%x",
4271 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4272
dea31012005-04-17 16:05:31 -05004273 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004274 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004275
James Smart3772a992009-05-22 14:50:54 -04004276 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004277 if (rc == IOCB_ERROR) {
4278 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004279 return 1;
dea31012005-04-17 16:05:31 -05004280 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004281 return 0;
dea31012005-04-17 16:05:31 -05004282}
4283
James Smarte59058c2008-08-24 21:49:00 -04004284/**
James Smart19ca7602010-11-20 23:11:55 -05004285 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4286 * @vport: pointer to a virtual N_Port data structure.
4287 * @iocb: pointer to the lpfc command iocb data structure.
4288 * @ndlp: pointer to a node-list data structure.
4289 *
4290 * Return
4291 **/
4292static void
4293lpfc_els_clear_rrq(struct lpfc_vport *vport,
4294 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4295{
4296 struct lpfc_hba *phba = vport->phba;
4297 uint8_t *pcmd;
4298 struct RRQ *rrq;
4299 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004300 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004301 struct lpfc_node_rrq *prrq;
4302
4303
4304 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4305 pcmd += sizeof(uint32_t);
4306 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004307 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004308 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004309
4310 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4311 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4312 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004313 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004314 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004315 rxid,
4316 iocb->iotag, iocb->iocb.ulpContext);
4317
4318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4319 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4320 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004321 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004322 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004323 else
4324 xri = rxid;
4325 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004326 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004327 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004328 return;
4329}
4330
4331/**
James Smart12265f62010-10-22 11:05:53 -04004332 * lpfc_els_rsp_echo_acc - Issue echo acc response
4333 * @vport: pointer to a virtual N_Port data structure.
4334 * @data: pointer to echo data to return in the accept.
4335 * @oldiocb: pointer to the original lpfc command iocb data structure.
4336 * @ndlp: pointer to a node-list data structure.
4337 *
4338 * Return code
4339 * 0 - Successfully issued acc echo response
4340 * 1 - Failed to issue acc echo response
4341 **/
4342static int
4343lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4344 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4345{
4346 struct lpfc_hba *phba = vport->phba;
4347 struct lpfc_iocbq *elsiocb;
4348 struct lpfc_sli *psli;
4349 uint8_t *pcmd;
4350 uint16_t cmdsize;
4351 int rc;
4352
4353 psli = &phba->sli;
4354 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4355
James Smartbf086112011-08-21 21:48:13 -04004356 /* The accumulated length can exceed the BPL_SIZE. For
4357 * now, use this as the limit
4358 */
4359 if (cmdsize > LPFC_BPL_SIZE)
4360 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004361 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4362 ndlp->nlp_DID, ELS_CMD_ACC);
4363 if (!elsiocb)
4364 return 1;
4365
James Smart7851fe22011-07-22 18:36:52 -04004366 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4367 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4368
James Smart12265f62010-10-22 11:05:53 -04004369 /* Xmit ECHO ACC response tag <ulpIoTag> */
4370 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4371 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4372 elsiocb->iotag, elsiocb->iocb.ulpContext);
4373 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4374 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4375 pcmd += sizeof(uint32_t);
4376 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4377
4378 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4379 "Issue ACC ECHO: did:x%x flg:x%x",
4380 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4381
4382 phba->fc_stat.elsXmitACC++;
4383 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004384
4385 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4386 if (rc == IOCB_ERROR) {
4387 lpfc_els_free_iocb(phba, elsiocb);
4388 return 1;
4389 }
4390 return 0;
4391}
4392
4393/**
James Smart3621a712009-04-06 18:47:14 -04004394 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004395 * @vport: pointer to a host virtual N_Port data structure.
4396 *
4397 * This routine issues Address Discover (ADISC) ELS commands to those
4398 * N_Ports which are in node port recovery state and ADISC has not been issued
4399 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4400 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4401 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4402 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4403 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4404 * IOCBs quit for later pick up. On the other hand, after walking through
4405 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4406 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4407 * no more ADISC need to be sent.
4408 *
4409 * Return code
4410 * The number of N_Ports with adisc issued.
4411 **/
dea31012005-04-17 16:05:31 -05004412int
James Smart2e0fef82007-06-17 19:56:36 -05004413lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004414{
James Smart2e0fef82007-06-17 19:56:36 -05004415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004416 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004417 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004418
James Smart685f0bf2007-04-25 09:53:08 -04004419 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004420 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004421 if (!NLP_CHK_NODE_ACT(ndlp))
4422 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004423 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4424 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4425 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004426 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004427 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004428 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004429 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004430 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4431 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004432 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004433 vport->num_disc_nodes++;
4434 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004435 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004436 spin_lock_irq(shost->host_lock);
4437 vport->fc_flag |= FC_NLP_MORE;
4438 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004439 break;
dea31012005-04-17 16:05:31 -05004440 }
4441 }
4442 }
4443 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004444 spin_lock_irq(shost->host_lock);
4445 vport->fc_flag &= ~FC_NLP_MORE;
4446 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004447 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004448 return sentadisc;
dea31012005-04-17 16:05:31 -05004449}
4450
James Smarte59058c2008-08-24 21:49:00 -04004451/**
James Smart3621a712009-04-06 18:47:14 -04004452 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004453 * @vport: pointer to a host virtual N_Port data structure.
4454 *
4455 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4456 * which are in node port recovery state, with a @vport. Each time an ELS
4457 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4458 * the per @vport number of discover count (num_disc_nodes) shall be
4459 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4460 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4461 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4462 * later pick up. On the other hand, after walking through all the ndlps with
4463 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4464 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4465 * PLOGI need to be sent.
4466 *
4467 * Return code
4468 * The number of N_Ports with plogi issued.
4469 **/
dea31012005-04-17 16:05:31 -05004470int
James Smart2e0fef82007-06-17 19:56:36 -05004471lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004472{
James Smart2e0fef82007-06-17 19:56:36 -05004473 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004474 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004475 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004476
James Smart2e0fef82007-06-17 19:56:36 -05004477 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4478 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004479 if (!NLP_CHK_NODE_ACT(ndlp))
4480 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004481 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4482 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4483 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4484 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4485 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004486 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4487 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004488 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004489 vport->num_disc_nodes++;
4490 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004491 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004492 spin_lock_irq(shost->host_lock);
4493 vport->fc_flag |= FC_NLP_MORE;
4494 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004495 break;
dea31012005-04-17 16:05:31 -05004496 }
4497 }
4498 }
James Smart87af33f2007-10-27 13:37:43 -04004499 if (sentplogi) {
4500 lpfc_set_disctmo(vport);
4501 }
4502 else {
James Smart2e0fef82007-06-17 19:56:36 -05004503 spin_lock_irq(shost->host_lock);
4504 vport->fc_flag &= ~FC_NLP_MORE;
4505 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004506 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004507 return sentplogi;
dea31012005-04-17 16:05:31 -05004508}
4509
James Smarte59058c2008-08-24 21:49:00 -04004510/**
James Smart3621a712009-04-06 18:47:14 -04004511 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004512 * @vport: pointer to a host virtual N_Port data structure.
4513 *
4514 * This routine cleans up any Registration State Change Notification
4515 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4516 * @vport together with the host_lock is used to prevent multiple thread
4517 * trying to access the RSCN array on a same @vport at the same time.
4518 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004519void
James Smart2e0fef82007-06-17 19:56:36 -05004520lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004521{
James Smart2e0fef82007-06-17 19:56:36 -05004522 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4523 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004524 int i;
4525
James Smart7f5f3d02008-02-08 18:50:14 -05004526 spin_lock_irq(shost->host_lock);
4527 if (vport->fc_rscn_flush) {
4528 /* Another thread is walking fc_rscn_id_list on this vport */
4529 spin_unlock_irq(shost->host_lock);
4530 return;
4531 }
4532 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4533 vport->fc_rscn_flush = 1;
4534 spin_unlock_irq(shost->host_lock);
4535
James Smart2e0fef82007-06-17 19:56:36 -05004536 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004537 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004538 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004539 }
James Smart2e0fef82007-06-17 19:56:36 -05004540 spin_lock_irq(shost->host_lock);
4541 vport->fc_rscn_id_cnt = 0;
4542 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4543 spin_unlock_irq(shost->host_lock);
4544 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004545 /* Indicate we are done walking this fc_rscn_id_list */
4546 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004547}
4548
James Smarte59058c2008-08-24 21:49:00 -04004549/**
James Smart3621a712009-04-06 18:47:14 -04004550 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004551 * @vport: pointer to a host virtual N_Port data structure.
4552 * @did: remote destination port identifier.
4553 *
4554 * This routine checks whether there is any pending Registration State
4555 * Configuration Notification (RSCN) to a @did on @vport.
4556 *
4557 * Return code
4558 * None zero - The @did matched with a pending rscn
4559 * 0 - not able to match @did with a pending rscn
4560 **/
dea31012005-04-17 16:05:31 -05004561int
James Smart2e0fef82007-06-17 19:56:36 -05004562lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004563{
4564 D_ID ns_did;
4565 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004566 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004567 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004568 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004569
4570 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004571
4572 /* Never match fabric nodes for RSCNs */
4573 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004574 return 0;
dea31012005-04-17 16:05:31 -05004575
4576 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004577 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004578 return did;
dea31012005-04-17 16:05:31 -05004579
James Smart7f5f3d02008-02-08 18:50:14 -05004580 spin_lock_irq(shost->host_lock);
4581 if (vport->fc_rscn_flush) {
4582 /* Another thread is walking fc_rscn_id_list on this vport */
4583 spin_unlock_irq(shost->host_lock);
4584 return 0;
4585 }
4586 /* Indicate we are walking fc_rscn_id_list on this vport */
4587 vport->fc_rscn_flush = 1;
4588 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004589 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004590 lp = vport->fc_rscn_id_list[i]->virt;
4591 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4592 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004593 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004594 rscn_did.un.word = be32_to_cpu(*lp++);
4595 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004596 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4597 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004598 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4599 && (ns_did.un.b.area == rscn_did.un.b.area)
4600 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004601 goto return_did_out;
dea31012005-04-17 16:05:31 -05004602 break;
James Smarteaf15d52008-12-04 22:39:29 -05004603 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004604 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4605 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004606 goto return_did_out;
dea31012005-04-17 16:05:31 -05004607 break;
James Smarteaf15d52008-12-04 22:39:29 -05004608 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004609 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004610 goto return_did_out;
dea31012005-04-17 16:05:31 -05004611 break;
James Smarteaf15d52008-12-04 22:39:29 -05004612 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004613 goto return_did_out;
dea31012005-04-17 16:05:31 -05004614 }
4615 }
James Smart92d7f7b2007-06-17 19:56:38 -05004616 }
James Smart7f5f3d02008-02-08 18:50:14 -05004617 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4618 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004619 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004620return_did_out:
4621 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4622 vport->fc_rscn_flush = 0;
4623 return did;
dea31012005-04-17 16:05:31 -05004624}
4625
James Smarte59058c2008-08-24 21:49:00 -04004626/**
James Smart3621a712009-04-06 18:47:14 -04004627 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004628 * @vport: pointer to a host virtual N_Port data structure.
4629 *
4630 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4631 * state machine for a @vport's nodes that are with pending RSCN (Registration
4632 * State Change Notification).
4633 *
4634 * Return code
4635 * 0 - Successful (currently alway return 0)
4636 **/
dea31012005-04-17 16:05:31 -05004637static int
James Smart2e0fef82007-06-17 19:56:36 -05004638lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004639{
James Smart685f0bf2007-04-25 09:53:08 -04004640 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004641
James Smart0d2b6b82008-06-14 22:52:47 -04004642 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004643 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004644 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004645 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4646 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004647 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004648 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004649 NLP_EVT_DEVICE_RECOVERY);
4650 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004651 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004652 return 0;
dea31012005-04-17 16:05:31 -05004653}
4654
James Smarte59058c2008-08-24 21:49:00 -04004655/**
James Smart3621a712009-04-06 18:47:14 -04004656 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004657 * @vport: pointer to a host virtual N_Port data structure.
4658 * @cmdiocb: pointer to lpfc command iocb data structure.
4659 *
4660 * lpfc_send_rscn_event sends an RSCN netlink event to management
4661 * applications.
4662 */
4663static void
4664lpfc_send_rscn_event(struct lpfc_vport *vport,
4665 struct lpfc_iocbq *cmdiocb)
4666{
4667 struct lpfc_dmabuf *pcmd;
4668 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4669 uint32_t *payload_ptr;
4670 uint32_t payload_len;
4671 struct lpfc_rscn_event_header *rscn_event_data;
4672
4673 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4674 payload_ptr = (uint32_t *) pcmd->virt;
4675 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4676
4677 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4678 payload_len, GFP_KERNEL);
4679 if (!rscn_event_data) {
4680 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4681 "0147 Failed to allocate memory for RSCN event\n");
4682 return;
4683 }
4684 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4685 rscn_event_data->payload_length = payload_len;
4686 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4687 payload_len);
4688
4689 fc_host_post_vendor_event(shost,
4690 fc_get_event_number(),
4691 sizeof(struct lpfc_els_event_header) + payload_len,
4692 (char *)rscn_event_data,
4693 LPFC_NL_VENDOR_ID);
4694
4695 kfree(rscn_event_data);
4696}
4697
4698/**
James Smart3621a712009-04-06 18:47:14 -04004699 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004700 * @vport: pointer to a host virtual N_Port data structure.
4701 * @cmdiocb: pointer to lpfc command iocb data structure.
4702 * @ndlp: pointer to a node-list data structure.
4703 *
4704 * This routine processes an unsolicited RSCN (Registration State Change
4705 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4706 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4707 * discover state machine is about to begin discovery, it just accepts the
4708 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4709 * contains N_Port IDs for other vports on this HBA, it just accepts the
4710 * RSCN and ignore processing it. If the state machine is in the recovery
4711 * state, the fc_rscn_id_list of this @vport is walked and the
4712 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4713 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4714 * routine is invoked to handle the RSCN event.
4715 *
4716 * Return code
4717 * 0 - Just sent the acc response
4718 * 1 - Sent the acc response and waited for name server completion
4719 **/
dea31012005-04-17 16:05:31 -05004720static int
James Smart2e0fef82007-06-17 19:56:36 -05004721lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004722 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004723{
James Smart2e0fef82007-06-17 19:56:36 -05004724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4725 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004726 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004727 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004728 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004729 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004730 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004731 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004732 int i;
dea31012005-04-17 16:05:31 -05004733
4734 icmd = &cmdiocb->iocb;
4735 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4736 lp = (uint32_t *) pcmd->virt;
4737
James Smart92d7f7b2007-06-17 19:56:38 -05004738 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4739 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004740 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004741 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4742 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004743 vport->fc_flag, payload_len, *lp,
4744 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004745
4746 /* Send an RSCN event to the management application */
4747 lpfc_send_rscn_event(vport, cmdiocb);
4748
James Smartd2873e42006-08-18 17:46:43 -04004749 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004750 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004751 FCH_EVT_RSCN, lp[i]);
4752
dea31012005-04-17 16:05:31 -05004753 /* If we are about to begin discovery, just ACC the RSCN.
4754 * Discovery processing will satisfy it.
4755 */
James Smart2e0fef82007-06-17 19:56:36 -05004756 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4758 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4759 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4760
James Smart51ef4c22007-08-02 11:10:31 -04004761 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004762 return 0;
dea31012005-04-17 16:05:31 -05004763 }
4764
James Smart92d7f7b2007-06-17 19:56:38 -05004765 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4766 * just ACC and ignore it.
4767 */
4768 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004769 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004770 i = payload_len;
4771 datap = lp;
4772 while (i > 0) {
4773 nportid = *datap++;
4774 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4775 i -= sizeof(uint32_t);
4776 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004777 if (lpfc_find_vport_by_did(phba, nportid))
4778 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004779 }
4780 if (rscn_id == hba_id) {
4781 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004782 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004783 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004784 "Data: x%x x%x x%x x%x\n",
4785 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004786 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4788 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4789 ndlp->nlp_DID, vport->port_state,
4790 ndlp->nlp_flag);
4791
James Smart92d7f7b2007-06-17 19:56:38 -05004792 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004793 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004794 return 0;
4795 }
4796 }
4797
James Smart7f5f3d02008-02-08 18:50:14 -05004798 spin_lock_irq(shost->host_lock);
4799 if (vport->fc_rscn_flush) {
4800 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004801 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004802 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004803 /* Send back ACC */
4804 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004805 return 0;
4806 }
4807 /* Indicate we are walking fc_rscn_id_list on this vport */
4808 vport->fc_rscn_flush = 1;
4809 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004810 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004811 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004812 /* If we are already processing an RSCN, save the received
4813 * RSCN payload buffer, cmdiocb->context2 to process later.
4814 */
James Smart2e0fef82007-06-17 19:56:36 -05004815 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4817 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4818 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4819
James Smart09372822008-01-11 01:52:54 -05004820 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004821 vport->fc_flag |= FC_RSCN_DEFERRED;
4822 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004823 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004824 vport->fc_flag |= FC_RSCN_MODE;
4825 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004826 if (rscn_cnt) {
4827 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4828 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4829 }
4830 if ((rscn_cnt) &&
4831 (payload_len + length <= LPFC_BPL_SIZE)) {
4832 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004833 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004834 memcpy(((uint8_t *)cmd) + length, lp,
4835 payload_len);
4836 } else {
4837 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4838 vport->fc_rscn_id_cnt++;
4839 /* If we zero, cmdiocb->context2, the calling
4840 * routine will not try to free it.
4841 */
4842 cmdiocb->context2 = NULL;
4843 }
dea31012005-04-17 16:05:31 -05004844 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004845 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4846 "0235 Deferred RSCN "
4847 "Data: x%x x%x x%x\n",
4848 vport->fc_rscn_id_cnt, vport->fc_flag,
4849 vport->port_state);
dea31012005-04-17 16:05:31 -05004850 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004851 vport->fc_flag |= FC_RSCN_DISCOVERY;
4852 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004853 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004854 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4855 "0234 ReDiscovery RSCN "
4856 "Data: x%x x%x x%x\n",
4857 vport->fc_rscn_id_cnt, vport->fc_flag,
4858 vport->port_state);
dea31012005-04-17 16:05:31 -05004859 }
James Smart7f5f3d02008-02-08 18:50:14 -05004860 /* Indicate we are done walking fc_rscn_id_list on this vport */
4861 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004862 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004863 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004864 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004865 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004866 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004867 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004868 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004869 return 0;
dea31012005-04-17 16:05:31 -05004870 }
James Smart858c9f62007-06-17 19:56:39 -05004871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4872 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4873 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4874
James Smart2e0fef82007-06-17 19:56:36 -05004875 spin_lock_irq(shost->host_lock);
4876 vport->fc_flag |= FC_RSCN_MODE;
4877 spin_unlock_irq(shost->host_lock);
4878 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004879 /* Indicate we are done walking fc_rscn_id_list on this vport */
4880 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004881 /*
4882 * If we zero, cmdiocb->context2, the calling routine will
4883 * not try to free it.
4884 */
4885 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004886 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004887 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004888 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004889 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004890 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004891 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004892}
4893
James Smarte59058c2008-08-24 21:49:00 -04004894/**
James Smart3621a712009-04-06 18:47:14 -04004895 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004896 * @vport: pointer to a host virtual N_Port data structure.
4897 *
4898 * This routine handles the Registration State Configuration Notification
4899 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4900 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4901 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4902 * NameServer shall be issued. If CT command to the NameServer fails to be
4903 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4904 * RSCN activities with the @vport.
4905 *
4906 * Return code
4907 * 0 - Cleaned up rscn on the @vport
4908 * 1 - Wait for plogi to name server before proceed
4909 **/
dea31012005-04-17 16:05:31 -05004910int
James Smart2e0fef82007-06-17 19:56:36 -05004911lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004912{
4913 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004914 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004915
James Smart92d7f7b2007-06-17 19:56:38 -05004916 /* Ignore RSCN if the port is being torn down. */
4917 if (vport->load_flag & FC_UNLOADING) {
4918 lpfc_els_flush_rscn(vport);
4919 return 0;
4920 }
4921
dea31012005-04-17 16:05:31 -05004922 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004923 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004924
4925 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004926 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4927 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4928 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4929 vport->port_state);
dea31012005-04-17 16:05:31 -05004930
4931 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004932 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004933 vport->num_disc_nodes = 0;
4934
James Smart2e0fef82007-06-17 19:56:36 -05004935 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004936 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4937 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004938 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004939 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004940 /* Wait for NameServer query cmpl before we can
4941 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004942 return 1;
dea31012005-04-17 16:05:31 -05004943 } else {
4944 /* If login to NameServer does not exist, issue one */
4945 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004946 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004947 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004948 /* Wait for NameServer login cmpl before we can
4949 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004950 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004951
James Smarte47c9092008-02-08 18:49:26 -05004952 if (ndlp) {
4953 ndlp = lpfc_enable_node(vport, ndlp,
4954 NLP_STE_PLOGI_ISSUE);
4955 if (!ndlp) {
4956 lpfc_els_flush_rscn(vport);
4957 return 0;
4958 }
4959 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004960 } else {
James Smarte47c9092008-02-08 18:49:26 -05004961 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4962 if (!ndlp) {
4963 lpfc_els_flush_rscn(vport);
4964 return 0;
4965 }
James Smart2e0fef82007-06-17 19:56:36 -05004966 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004967 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004968 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004969 }
James Smarte47c9092008-02-08 18:49:26 -05004970 ndlp->nlp_type |= NLP_FABRIC;
4971 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4972 /* Wait for NameServer login cmpl before we can
4973 * continue
4974 */
4975 return 1;
dea31012005-04-17 16:05:31 -05004976 }
4977
James Smart2e0fef82007-06-17 19:56:36 -05004978 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004979 return 0;
dea31012005-04-17 16:05:31 -05004980}
4981
James Smarte59058c2008-08-24 21:49:00 -04004982/**
James Smart3621a712009-04-06 18:47:14 -04004983 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004984 * @vport: pointer to a host virtual N_Port data structure.
4985 * @cmdiocb: pointer to lpfc command iocb data structure.
4986 * @ndlp: pointer to a node-list data structure.
4987 *
4988 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4989 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4990 * point topology. As an unsolicited FLOGI should not be received in a loop
4991 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4992 * lpfc_check_sparm() routine is invoked to check the parameters in the
4993 * unsolicited FLOGI. If parameters validation failed, the routine
4994 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4995 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4996 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4997 * will initiate PLOGI. The higher lexicographical value party shall has
4998 * higher priority (as the winning port) and will initiate PLOGI and
4999 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5000 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5001 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5002 *
5003 * Return code
5004 * 0 - Successfully processed the unsolicited flogi
5005 * 1 - Failed to process the unsolicited flogi
5006 **/
dea31012005-04-17 16:05:31 -05005007static int
James Smart2e0fef82007-06-17 19:56:36 -05005008lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005009 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005010{
James Smart2e0fef82007-06-17 19:56:36 -05005011 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5012 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005013 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5014 uint32_t *lp = (uint32_t *) pcmd->virt;
5015 IOCB_t *icmd = &cmdiocb->iocb;
5016 struct serv_parm *sp;
5017 LPFC_MBOXQ_t *mbox;
5018 struct ls_rjt stat;
5019 uint32_t cmd, did;
5020 int rc;
5021
5022 cmd = *lp++;
5023 sp = (struct serv_parm *) lp;
5024
5025 /* FLOGI received */
5026
James Smart2e0fef82007-06-17 19:56:36 -05005027 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005028
James Smart76a95d72010-11-20 23:11:48 -05005029 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005030 /* We should never receive a FLOGI in loop mode, ignore it */
5031 did = icmd->un.elsreq64.remoteID;
5032
5033 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5034 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005035 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5036 "0113 An FLOGI ELS command x%x was "
5037 "received from DID x%x in Loop Mode\n",
5038 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005039 return 1;
dea31012005-04-17 16:05:31 -05005040 }
5041
James Smart341af102010-01-26 23:07:37 -05005042 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005043 /* For a FLOGI we accept, then if our portname is greater
5044 * then the remote portname we initiate Nport login.
5045 */
5046
James Smart2e0fef82007-06-17 19:56:36 -05005047 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005048 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005049
5050 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005051 if (phba->sli_rev < LPFC_SLI_REV4) {
5052 mbox = mempool_alloc(phba->mbox_mem_pool,
5053 GFP_KERNEL);
5054 if (!mbox)
5055 return 1;
5056 lpfc_linkdown(phba);
5057 lpfc_init_link(phba, mbox,
5058 phba->cfg_topology,
5059 phba->cfg_link_speed);
5060 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5061 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5062 mbox->vport = vport;
5063 rc = lpfc_sli_issue_mbox(phba, mbox,
5064 MBX_NOWAIT);
5065 lpfc_set_loopback_flag(phba);
5066 if (rc == MBX_NOT_FINISHED)
5067 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005068 return 1;
James Smart1b511972011-12-13 13:23:09 -05005069 } else {
5070 /* abort the flogi coming back to ourselves
5071 * due to external loopback on the port.
5072 */
5073 lpfc_els_abort_flogi(phba);
5074 return 0;
dea31012005-04-17 16:05:31 -05005075 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005076 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005077 spin_lock_irq(shost->host_lock);
5078 vport->fc_flag |= FC_PT2PT_PLOGI;
5079 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005080
5081 /* If we have the high WWPN we can assign our own
5082 * myDID; otherwise, we have to WAIT for a PLOGI
5083 * from the remote NPort to find out what it
5084 * will be.
5085 */
James Smarte6446432012-05-09 21:16:42 -04005086 vport->fc_myDID = PT2PT_LocalID;
James Smart939723a2012-05-09 21:19:03 -04005087 }
5088
5089 /*
5090 * The vport state should go to LPFC_FLOGI only
5091 * AFTER we issue a FLOGI, not receive one.
5092 */
James Smart2e0fef82007-06-17 19:56:36 -05005093 spin_lock_irq(shost->host_lock);
5094 vport->fc_flag |= FC_PT2PT;
5095 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5096 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005097
5098 /*
5099 * We temporarily set fc_myDID to make it look like we are
5100 * a Fabric. This is done just so we end up with the right
5101 * did / sid on the FLOGI ACC rsp.
5102 */
5103 did = vport->fc_myDID;
5104 vport->fc_myDID = Fabric_DID;
5105
dea31012005-04-17 16:05:31 -05005106 } else {
5107 /* Reject this request because invalid parameters */
5108 stat.un.b.lsRjtRsvd0 = 0;
5109 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5110 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5111 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005112
5113 /*
5114 * We temporarily set fc_myDID to make it look like we are
5115 * a Fabric. This is done just so we end up with the right
5116 * did / sid on the FLOGI LS_RJT rsp.
5117 */
5118 did = vport->fc_myDID;
5119 vport->fc_myDID = Fabric_DID;
5120
James Smart858c9f62007-06-17 19:56:39 -05005121 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5122 NULL);
James Smart939723a2012-05-09 21:19:03 -04005123
5124 /* Now lets put fc_myDID back to what its supposed to be */
5125 vport->fc_myDID = did;
5126
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005127 return 1;
dea31012005-04-17 16:05:31 -05005128 }
5129
5130 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005131 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005132
James Smart939723a2012-05-09 21:19:03 -04005133 /* Now lets put fc_myDID back to what its supposed to be */
5134 vport->fc_myDID = did;
5135
James Smarte6446432012-05-09 21:16:42 -04005136 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005137
James Smarte6446432012-05-09 21:16:42 -04005138 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5139 if (!mbox)
5140 goto fail;
5141
5142 lpfc_config_link(phba, mbox);
5143
5144 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5145 mbox->vport = vport;
5146 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5147 if (rc == MBX_NOT_FINISHED) {
5148 mempool_free(mbox, phba->mbox_mem_pool);
5149 goto fail;
5150 }
5151 }
5152
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005153 return 0;
James Smarte6446432012-05-09 21:16:42 -04005154fail:
5155 return 1;
dea31012005-04-17 16:05:31 -05005156}
5157
James Smarte59058c2008-08-24 21:49:00 -04005158/**
James Smart3621a712009-04-06 18:47:14 -04005159 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005160 * @vport: pointer to a host virtual N_Port data structure.
5161 * @cmdiocb: pointer to lpfc command iocb data structure.
5162 * @ndlp: pointer to a node-list data structure.
5163 *
5164 * This routine processes Request Node Identification Data (RNID) IOCB
5165 * received as an ELS unsolicited event. Only when the RNID specified format
5166 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5167 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5168 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5169 * rejected by invoking the lpfc_els_rsp_reject() routine.
5170 *
5171 * Return code
5172 * 0 - Successfully processed rnid iocb (currently always return 0)
5173 **/
dea31012005-04-17 16:05:31 -05005174static int
James Smart2e0fef82007-06-17 19:56:36 -05005175lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5176 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005177{
5178 struct lpfc_dmabuf *pcmd;
5179 uint32_t *lp;
5180 IOCB_t *icmd;
5181 RNID *rn;
5182 struct ls_rjt stat;
5183 uint32_t cmd, did;
5184
5185 icmd = &cmdiocb->iocb;
5186 did = icmd->un.elsreq64.remoteID;
5187 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5188 lp = (uint32_t *) pcmd->virt;
5189
5190 cmd = *lp++;
5191 rn = (RNID *) lp;
5192
5193 /* RNID received */
5194
5195 switch (rn->Format) {
5196 case 0:
5197 case RNID_TOPOLOGY_DISC:
5198 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005199 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005200 break;
5201 default:
5202 /* Reject this request because format not supported */
5203 stat.un.b.lsRjtRsvd0 = 0;
5204 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5205 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5206 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005207 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5208 NULL);
dea31012005-04-17 16:05:31 -05005209 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005210 return 0;
dea31012005-04-17 16:05:31 -05005211}
5212
James Smarte59058c2008-08-24 21:49:00 -04005213/**
James Smart12265f62010-10-22 11:05:53 -04005214 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5215 * @vport: pointer to a host virtual N_Port data structure.
5216 * @cmdiocb: pointer to lpfc command iocb data structure.
5217 * @ndlp: pointer to a node-list data structure.
5218 *
5219 * Return code
5220 * 0 - Successfully processed echo iocb (currently always return 0)
5221 **/
5222static int
5223lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5224 struct lpfc_nodelist *ndlp)
5225{
5226 uint8_t *pcmd;
5227
5228 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5229
5230 /* skip over first word of echo command to find echo data */
5231 pcmd += sizeof(uint32_t);
5232
5233 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5234 return 0;
5235}
5236
5237/**
James Smart3621a712009-04-06 18:47:14 -04005238 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005239 * @vport: pointer to a host virtual N_Port data structure.
5240 * @cmdiocb: pointer to lpfc command iocb data structure.
5241 * @ndlp: pointer to a node-list data structure.
5242 *
5243 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5244 * received as an ELS unsolicited event. Currently, this function just invokes
5245 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5246 *
5247 * Return code
5248 * 0 - Successfully processed lirr iocb (currently always return 0)
5249 **/
dea31012005-04-17 16:05:31 -05005250static int
James Smart2e0fef82007-06-17 19:56:36 -05005251lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5252 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005253{
5254 struct ls_rjt stat;
5255
5256 /* For now, unconditionally reject this command */
5257 stat.un.b.lsRjtRsvd0 = 0;
5258 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5259 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5260 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005261 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005262 return 0;
5263}
5264
James Smarte59058c2008-08-24 21:49:00 -04005265/**
James Smart5ffc2662009-11-18 15:39:44 -05005266 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5267 * @vport: pointer to a host virtual N_Port data structure.
5268 * @cmdiocb: pointer to lpfc command iocb data structure.
5269 * @ndlp: pointer to a node-list data structure.
5270 *
5271 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5272 * received as an ELS unsolicited event. A request to RRQ shall only
5273 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5274 * Nx_Port N_Port_ID of the target Exchange is the same as the
5275 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5276 * not accepted, an LS_RJT with reason code "Unable to perform
5277 * command request" and reason code explanation "Invalid Originator
5278 * S_ID" shall be returned. For now, we just unconditionally accept
5279 * RRQ from the target.
5280 **/
5281static void
5282lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5283 struct lpfc_nodelist *ndlp)
5284{
5285 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005286 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5287 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005288}
5289
5290/**
James Smart12265f62010-10-22 11:05:53 -04005291 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5292 * @phba: pointer to lpfc hba data structure.
5293 * @pmb: pointer to the driver internal queue element for mailbox command.
5294 *
5295 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5296 * mailbox command. This callback function is to actually send the Accept
5297 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5298 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5299 * mailbox command, constructs the RPS response with the link statistics
5300 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5301 * response to the RPS.
5302 *
5303 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5304 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5305 * will be stored into the context1 field of the IOCB for the completion
5306 * callback function to the RPS Accept Response ELS IOCB command.
5307 *
5308 **/
5309static void
5310lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5311{
5312 MAILBOX_t *mb;
5313 IOCB_t *icmd;
5314 struct RLS_RSP *rls_rsp;
5315 uint8_t *pcmd;
5316 struct lpfc_iocbq *elsiocb;
5317 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005318 uint16_t oxid;
5319 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005320 uint32_t cmdsize;
5321
5322 mb = &pmb->u.mb;
5323
5324 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005325 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5326 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005327 pmb->context1 = NULL;
5328 pmb->context2 = NULL;
5329
5330 if (mb->mbxStatus) {
5331 mempool_free(pmb, phba->mbox_mem_pool);
5332 return;
5333 }
5334
5335 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005336 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5337 lpfc_max_els_tries, ndlp,
5338 ndlp->nlp_DID, ELS_CMD_ACC);
5339
5340 /* Decrement the ndlp reference count from previous mbox command */
5341 lpfc_nlp_put(ndlp);
5342
James Smart37db57e2012-05-09 21:17:16 -04005343 if (!elsiocb) {
5344 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005345 return;
James Smart37db57e2012-05-09 21:17:16 -04005346 }
James Smart12265f62010-10-22 11:05:53 -04005347
5348 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005349 icmd->ulpContext = rxid;
5350 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005351
5352 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5353 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5354 pcmd += sizeof(uint32_t); /* Skip past command */
5355 rls_rsp = (struct RLS_RSP *)pcmd;
5356
5357 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5358 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5359 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5360 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5361 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5362 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005363 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005364 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5365 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5366 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5367 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5368 elsiocb->iotag, elsiocb->iocb.ulpContext,
5369 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5370 ndlp->nlp_rpi);
5371 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5372 phba->fc_stat.elsXmitACC++;
5373 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5374 lpfc_els_free_iocb(phba, elsiocb);
5375}
5376
5377/**
James Smart3621a712009-04-06 18:47:14 -04005378 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005379 * @phba: pointer to lpfc hba data structure.
5380 * @pmb: pointer to the driver internal queue element for mailbox command.
5381 *
5382 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5383 * mailbox command. This callback function is to actually send the Accept
5384 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5385 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5386 * mailbox command, constructs the RPS response with the link statistics
5387 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5388 * response to the RPS.
5389 *
5390 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5391 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5392 * will be stored into the context1 field of the IOCB for the completion
5393 * callback function to the RPS Accept Response ELS IOCB command.
5394 *
5395 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005396static void
James Smart329f9bc2007-04-25 09:53:01 -04005397lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005398{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005399 MAILBOX_t *mb;
5400 IOCB_t *icmd;
5401 RPS_RSP *rps_rsp;
5402 uint8_t *pcmd;
5403 struct lpfc_iocbq *elsiocb;
5404 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005405 uint16_t status;
5406 uint16_t oxid;
5407 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005408 uint32_t cmdsize;
5409
James Smart04c68492009-05-22 14:52:52 -04005410 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005411
5412 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005413 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5414 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005415 pmb->context1 = NULL;
5416 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005417
5418 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005419 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005420 return;
5421 }
5422
5423 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005424 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005425 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5426 lpfc_max_els_tries, ndlp,
5427 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005428
5429 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005430 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005431
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005432 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005433 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005434
5435 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005436 icmd->ulpContext = rxid;
5437 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005438
5439 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5440 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005441 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005442 rps_rsp = (RPS_RSP *)pcmd;
5443
James Smart76a95d72010-11-20 23:11:48 -05005444 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005445 status = 0x10;
5446 else
5447 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005448 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005449 status |= 0x4;
5450
5451 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005452 rps_rsp->portStatus = cpu_to_be16(status);
5453 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5454 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5455 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5456 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5457 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5458 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005459 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005460 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5461 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5462 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5463 elsiocb->iotag, elsiocb->iocb.ulpContext,
5464 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5465 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005466 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005467 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005468 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005469 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005470 return;
5471}
5472
James Smarte59058c2008-08-24 21:49:00 -04005473/**
James Smart12265f62010-10-22 11:05:53 -04005474 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5475 * @vport: pointer to a host virtual N_Port data structure.
5476 * @cmdiocb: pointer to lpfc command iocb data structure.
5477 * @ndlp: pointer to a node-list data structure.
5478 *
5479 * This routine processes Read Port Status (RPL) IOCB received as an
5480 * ELS unsolicited event. It first checks the remote port state. If the
5481 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5482 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5483 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5484 * for reading the HBA link statistics. It is for the callback function,
5485 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5486 * to actually sending out RPL Accept (ACC) response.
5487 *
5488 * Return codes
5489 * 0 - Successfully processed rls iocb (currently always return 0)
5490 **/
5491static int
5492lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5493 struct lpfc_nodelist *ndlp)
5494{
5495 struct lpfc_hba *phba = vport->phba;
5496 LPFC_MBOXQ_t *mbox;
5497 struct lpfc_dmabuf *pcmd;
5498 struct ls_rjt stat;
5499
5500 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5501 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5502 /* reject the unsolicited RPS request and done with it */
5503 goto reject_out;
5504
5505 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5506
5507 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5508 if (mbox) {
5509 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005510 mbox->context1 = (void *)((unsigned long)
5511 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5512 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005513 mbox->context2 = lpfc_nlp_get(ndlp);
5514 mbox->vport = vport;
5515 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5516 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5517 != MBX_NOT_FINISHED)
5518 /* Mbox completion will send ELS Response */
5519 return 0;
5520 /* Decrement reference count used for the failed mbox
5521 * command.
5522 */
5523 lpfc_nlp_put(ndlp);
5524 mempool_free(mbox, phba->mbox_mem_pool);
5525 }
5526reject_out:
5527 /* issue rejection response */
5528 stat.un.b.lsRjtRsvd0 = 0;
5529 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5530 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5531 stat.un.b.vendorUnique = 0;
5532 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5533 return 0;
5534}
5535
5536/**
5537 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5538 * @vport: pointer to a host virtual N_Port data structure.
5539 * @cmdiocb: pointer to lpfc command iocb data structure.
5540 * @ndlp: pointer to a node-list data structure.
5541 *
5542 * This routine processes Read Timout Value (RTV) IOCB received as an
5543 * ELS unsolicited event. It first checks the remote port state. If the
5544 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5545 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5546 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5547 * Value (RTV) unsolicited IOCB event.
5548 *
5549 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5550 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5551 * will be stored into the context1 field of the IOCB for the completion
5552 * callback function to the RPS Accept Response ELS IOCB command.
5553 *
5554 * Return codes
5555 * 0 - Successfully processed rtv iocb (currently always return 0)
5556 **/
5557static int
5558lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5559 struct lpfc_nodelist *ndlp)
5560{
5561 struct lpfc_hba *phba = vport->phba;
5562 struct ls_rjt stat;
5563 struct RTV_RSP *rtv_rsp;
5564 uint8_t *pcmd;
5565 struct lpfc_iocbq *elsiocb;
5566 uint32_t cmdsize;
5567
5568
5569 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5570 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5571 /* reject the unsolicited RPS request and done with it */
5572 goto reject_out;
5573
5574 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5575 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5576 lpfc_max_els_tries, ndlp,
5577 ndlp->nlp_DID, ELS_CMD_ACC);
5578
5579 if (!elsiocb)
5580 return 1;
5581
5582 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5583 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5584 pcmd += sizeof(uint32_t); /* Skip past command */
5585
5586 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005587 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5588 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005589
5590 rtv_rsp = (struct RTV_RSP *)pcmd;
5591
5592 /* populate RTV payload */
5593 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5594 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5595 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5596 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5597 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5598
5599 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5600 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5601 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5602 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5603 "Data: x%x x%x x%x\n",
5604 elsiocb->iotag, elsiocb->iocb.ulpContext,
5605 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5606 ndlp->nlp_rpi,
5607 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5608 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5609 phba->fc_stat.elsXmitACC++;
5610 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5611 lpfc_els_free_iocb(phba, elsiocb);
5612 return 0;
5613
5614reject_out:
5615 /* issue rejection response */
5616 stat.un.b.lsRjtRsvd0 = 0;
5617 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5618 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5619 stat.un.b.vendorUnique = 0;
5620 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5621 return 0;
5622}
5623
5624/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005625 * @vport: pointer to a host virtual N_Port data structure.
5626 * @cmdiocb: pointer to lpfc command iocb data structure.
5627 * @ndlp: pointer to a node-list data structure.
5628 *
5629 * This routine processes Read Port Status (RPS) IOCB received as an
5630 * ELS unsolicited event. It first checks the remote port state. If the
5631 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5632 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5633 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5634 * for reading the HBA link statistics. It is for the callback function,
5635 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5636 * to actually sending out RPS Accept (ACC) response.
5637 *
5638 * Return codes
5639 * 0 - Successfully processed rps iocb (currently always return 0)
5640 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005641static int
James Smart2e0fef82007-06-17 19:56:36 -05005642lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5643 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005644{
James Smart2e0fef82007-06-17 19:56:36 -05005645 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005646 uint32_t *lp;
5647 uint8_t flag;
5648 LPFC_MBOXQ_t *mbox;
5649 struct lpfc_dmabuf *pcmd;
5650 RPS *rps;
5651 struct ls_rjt stat;
5652
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005653 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005654 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5655 /* reject the unsolicited RPS request and done with it */
5656 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005657
5658 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5659 lp = (uint32_t *) pcmd->virt;
5660 flag = (be32_to_cpu(*lp++) & 0xf);
5661 rps = (RPS *) lp;
5662
5663 if ((flag == 0) ||
5664 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005665 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005666 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005667
James Smart92d7f7b2007-06-17 19:56:38 -05005668 printk("Fix me....\n");
5669 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005670 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5671 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005672 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005673 mbox->context1 = (void *)((unsigned long)
5674 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5675 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005676 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005677 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005678 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005679 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005680 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005681 /* Mbox completion will send ELS Response */
5682 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005683 /* Decrement reference count used for the failed mbox
5684 * command.
5685 */
James Smart329f9bc2007-04-25 09:53:01 -04005686 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005687 mempool_free(mbox, phba->mbox_mem_pool);
5688 }
5689 }
James Smart90160e02008-08-24 21:49:45 -04005690
5691reject_out:
5692 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005693 stat.un.b.lsRjtRsvd0 = 0;
5694 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5695 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5696 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005697 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005698 return 0;
5699}
5700
James Smart19ca7602010-11-20 23:11:55 -05005701/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5702 * @vport: pointer to a host virtual N_Port data structure.
5703 * @ndlp: pointer to a node-list data structure.
5704 * @did: DID of the target.
5705 * @rrq: Pointer to the rrq struct.
5706 *
5707 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5708 * Successful the the completion handler will clear the RRQ.
5709 *
5710 * Return codes
5711 * 0 - Successfully sent rrq els iocb.
5712 * 1 - Failed to send rrq els iocb.
5713 **/
5714static int
5715lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5716 uint32_t did, struct lpfc_node_rrq *rrq)
5717{
5718 struct lpfc_hba *phba = vport->phba;
5719 struct RRQ *els_rrq;
5720 IOCB_t *icmd;
5721 struct lpfc_iocbq *elsiocb;
5722 uint8_t *pcmd;
5723 uint16_t cmdsize;
5724 int ret;
5725
5726
5727 if (ndlp != rrq->ndlp)
5728 ndlp = rrq->ndlp;
5729 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5730 return 1;
5731
5732 /* If ndlp is not NULL, we will bump the reference count on it */
5733 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5734 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5735 ELS_CMD_RRQ);
5736 if (!elsiocb)
5737 return 1;
5738
5739 icmd = &elsiocb->iocb;
5740 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5741
5742 /* For RRQ request, remainder of payload is Exchange IDs */
5743 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5744 pcmd += sizeof(uint32_t);
5745 els_rrq = (struct RRQ *) pcmd;
5746
James Smartee0f4fe2012-05-09 21:19:14 -04005747 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005748 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5749 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5750 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5751 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5752
5753
5754 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5755 "Issue RRQ: did:x%x",
5756 did, rrq->xritag, rrq->rxid);
5757 elsiocb->context_un.rrq = rrq;
5758 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5759 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5760
5761 if (ret == IOCB_ERROR) {
5762 lpfc_els_free_iocb(phba, elsiocb);
5763 return 1;
5764 }
5765 return 0;
5766}
5767
5768/**
5769 * lpfc_send_rrq - Sends ELS RRQ if needed.
5770 * @phba: pointer to lpfc hba data structure.
5771 * @rrq: pointer to the active rrq.
5772 *
5773 * This routine will call the lpfc_issue_els_rrq if the rrq is
5774 * still active for the xri. If this function returns a failure then
5775 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5776 *
5777 * Returns 0 Success.
5778 * 1 Failure.
5779 **/
5780int
5781lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5782{
5783 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5784 rrq->nlp_DID);
5785 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5786 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5787 rrq->nlp_DID, rrq);
5788 else
5789 return 1;
5790}
5791
James Smarte59058c2008-08-24 21:49:00 -04005792/**
James Smart3621a712009-04-06 18:47:14 -04005793 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005794 * @vport: pointer to a host virtual N_Port data structure.
5795 * @cmdsize: size of the ELS command.
5796 * @oldiocb: pointer to the original lpfc command iocb data structure.
5797 * @ndlp: pointer to a node-list data structure.
5798 *
5799 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5800 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5801 *
5802 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5803 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5804 * will be stored into the context1 field of the IOCB for the completion
5805 * callback function to the RPL Accept Response ELS command.
5806 *
5807 * Return code
5808 * 0 - Successfully issued ACC RPL ELS command
5809 * 1 - Failed to issue ACC RPL ELS command
5810 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005811static int
James Smart2e0fef82007-06-17 19:56:36 -05005812lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5813 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005814{
James Smart2e0fef82007-06-17 19:56:36 -05005815 struct lpfc_hba *phba = vport->phba;
5816 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005817 RPL_RSP rpl_rsp;
5818 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005819 uint8_t *pcmd;
5820
James Smart2e0fef82007-06-17 19:56:36 -05005821 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5822 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005823
James Smart488d1462006-03-07 15:02:37 -05005824 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005825 return 1;
James Smart488d1462006-03-07 15:02:37 -05005826
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005827 icmd = &elsiocb->iocb;
5828 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005829 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5830 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005831
5832 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5833 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005834 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005835 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5836 pcmd += sizeof(uint16_t);
5837
5838 /* Setup the RPL ACC payload */
5839 rpl_rsp.listLen = be32_to_cpu(1);
5840 rpl_rsp.index = 0;
5841 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005842 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5843 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005844 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005845 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005846 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005847 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5848 "0120 Xmit ELS RPL ACC response tag x%x "
5849 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5850 "rpi x%x\n",
5851 elsiocb->iotag, elsiocb->iocb.ulpContext,
5852 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5853 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005854 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005855 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005856 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5857 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005858 lpfc_els_free_iocb(phba, elsiocb);
5859 return 1;
5860 }
5861 return 0;
5862}
5863
James Smarte59058c2008-08-24 21:49:00 -04005864/**
James Smart3621a712009-04-06 18:47:14 -04005865 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005866 * @vport: pointer to a host virtual N_Port data structure.
5867 * @cmdiocb: pointer to lpfc command iocb data structure.
5868 * @ndlp: pointer to a node-list data structure.
5869 *
5870 * This routine processes Read Port List (RPL) IOCB received as an ELS
5871 * unsolicited event. It first checks the remote port state. If the remote
5872 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5873 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5874 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5875 * to accept the RPL.
5876 *
5877 * Return code
5878 * 0 - Successfully processed rpl iocb (currently always return 0)
5879 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005880static int
James Smart2e0fef82007-06-17 19:56:36 -05005881lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5882 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005883{
5884 struct lpfc_dmabuf *pcmd;
5885 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005886 uint32_t maxsize;
5887 uint16_t cmdsize;
5888 RPL *rpl;
5889 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005890
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005891 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5892 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005893 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005894 stat.un.b.lsRjtRsvd0 = 0;
5895 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5896 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5897 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005898 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5899 NULL);
James Smart90160e02008-08-24 21:49:45 -04005900 /* rejected the unsolicited RPL request and done with it */
5901 return 0;
dea31012005-04-17 16:05:31 -05005902 }
5903
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005904 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5905 lp = (uint32_t *) pcmd->virt;
5906 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005907 maxsize = be32_to_cpu(rpl->maxsize);
5908
5909 /* We support only one port */
5910 if ((rpl->index == 0) &&
5911 ((maxsize == 0) ||
5912 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5913 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005914 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005915 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5916 }
James Smart2e0fef82007-06-17 19:56:36 -05005917 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005918
5919 return 0;
5920}
5921
James Smarte59058c2008-08-24 21:49:00 -04005922/**
James Smart3621a712009-04-06 18:47:14 -04005923 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005924 * @vport: pointer to a virtual N_Port data structure.
5925 * @cmdiocb: pointer to lpfc command iocb data structure.
5926 * @ndlp: pointer to a node-list data structure.
5927 *
5928 * This routine processes Fibre Channel Address Resolution Protocol
5929 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5930 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5931 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5932 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5933 * remote PortName is compared against the FC PortName stored in the @vport
5934 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5935 * compared against the FC NodeName stored in the @vport data structure.
5936 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5937 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5938 * invoked to send out FARP Response to the remote node. Before sending the
5939 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5940 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5941 * routine is invoked to log into the remote port first.
5942 *
5943 * Return code
5944 * 0 - Either the FARP Match Mode not supported or successfully processed
5945 **/
dea31012005-04-17 16:05:31 -05005946static int
James Smart2e0fef82007-06-17 19:56:36 -05005947lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5948 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005949{
5950 struct lpfc_dmabuf *pcmd;
5951 uint32_t *lp;
5952 IOCB_t *icmd;
5953 FARP *fp;
5954 uint32_t cmd, cnt, did;
5955
5956 icmd = &cmdiocb->iocb;
5957 did = icmd->un.elsreq64.remoteID;
5958 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5959 lp = (uint32_t *) pcmd->virt;
5960
5961 cmd = *lp++;
5962 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005963 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005964 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5965 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005966 /* We will only support match on WWPN or WWNN */
5967 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005968 return 0;
dea31012005-04-17 16:05:31 -05005969 }
5970
5971 cnt = 0;
5972 /* If this FARP command is searching for my portname */
5973 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005974 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005975 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005976 cnt = 1;
5977 }
5978
5979 /* If this FARP command is searching for my nodename */
5980 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005981 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005982 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005983 cnt = 1;
5984 }
5985
5986 if (cnt) {
5987 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5988 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5989 /* Log back into the node before sending the FARP. */
5990 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005991 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005992 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005993 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005994 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005995 }
5996
5997 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005998 if (fp->Rflags & FARP_REQUEST_FARPR)
5999 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006000 }
6001 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006002 return 0;
dea31012005-04-17 16:05:31 -05006003}
6004
James Smarte59058c2008-08-24 21:49:00 -04006005/**
James Smart3621a712009-04-06 18:47:14 -04006006 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006007 * @vport: pointer to a host virtual N_Port data structure.
6008 * @cmdiocb: pointer to lpfc command iocb data structure.
6009 * @ndlp: pointer to a node-list data structure.
6010 *
6011 * This routine processes Fibre Channel Address Resolution Protocol
6012 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6013 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6014 * the FARP response request.
6015 *
6016 * Return code
6017 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6018 **/
dea31012005-04-17 16:05:31 -05006019static int
James Smart2e0fef82007-06-17 19:56:36 -05006020lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6021 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006022{
6023 struct lpfc_dmabuf *pcmd;
6024 uint32_t *lp;
6025 IOCB_t *icmd;
6026 uint32_t cmd, did;
6027
6028 icmd = &cmdiocb->iocb;
6029 did = icmd->un.elsreq64.remoteID;
6030 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6031 lp = (uint32_t *) pcmd->virt;
6032
6033 cmd = *lp++;
6034 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006035 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6036 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006037 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006038 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006039
6040 return 0;
6041}
6042
James Smarte59058c2008-08-24 21:49:00 -04006043/**
James Smart3621a712009-04-06 18:47:14 -04006044 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006045 * @vport: pointer to a host virtual N_Port data structure.
6046 * @cmdiocb: pointer to lpfc command iocb data structure.
6047 * @fan_ndlp: pointer to a node-list data structure.
6048 *
6049 * This routine processes a Fabric Address Notification (FAN) IOCB
6050 * command received as an ELS unsolicited event. The FAN ELS command will
6051 * only be processed on a physical port (i.e., the @vport represents the
6052 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6053 * compared against those in the phba data structure. If any of those is
6054 * different, the lpfc_initial_flogi() routine is invoked to initialize
6055 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6056 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6057 * is invoked to register login to the fabric.
6058 *
6059 * Return code
6060 * 0 - Successfully processed fan iocb (currently always return 0).
6061 **/
dea31012005-04-17 16:05:31 -05006062static int
James Smart2e0fef82007-06-17 19:56:36 -05006063lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6064 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006065{
James Smart2e0fef82007-06-17 19:56:36 -05006066 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006067 uint32_t *lp;
6068 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006069
James Smart0d2b6b82008-06-14 22:52:47 -04006070 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6071 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6072 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006073 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006074 if ((vport == phba->pport) &&
6075 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006076 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006077 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006078 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006079 sizeof(struct lpfc_name)))) {
6080 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006081 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006082 } else {
6083 /* FAN verified - skip FLOGI */
6084 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006085 if (phba->sli_rev < LPFC_SLI_REV4)
6086 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006087 else {
6088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6089 "3138 Need register VFI: (x%x/%x)\n",
6090 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006091 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006092 }
dea31012005-04-17 16:05:31 -05006093 }
dea31012005-04-17 16:05:31 -05006094 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006095 return 0;
dea31012005-04-17 16:05:31 -05006096}
6097
James Smarte59058c2008-08-24 21:49:00 -04006098/**
James Smart3621a712009-04-06 18:47:14 -04006099 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006100 * @ptr: holder for the timer function associated data.
6101 *
6102 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6103 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6104 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6105 * up the worker thread. It is for the worker thread to invoke the routine
6106 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6107 **/
dea31012005-04-17 16:05:31 -05006108void
6109lpfc_els_timeout(unsigned long ptr)
6110{
James Smart2e0fef82007-06-17 19:56:36 -05006111 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6112 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006113 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006114 unsigned long iflag;
6115
James Smart2e0fef82007-06-17 19:56:36 -05006116 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006117 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6118 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006119 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006120 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006121
James Smart5e9d9b82008-06-14 22:52:53 -04006122 if (!tmo_posted)
6123 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006124 return;
6125}
6126
James Smart2a9bf3d2010-06-07 15:24:45 -04006127
James Smarte59058c2008-08-24 21:49:00 -04006128/**
James Smart3621a712009-04-06 18:47:14 -04006129 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006130 * @vport: pointer to a virtual N_Port data structure.
6131 *
6132 * This routine is the actual handler function that processes an ELS timeout
6133 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6134 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6135 * invoking the lpfc_sli_issue_abort_iotag() routine.
6136 **/
dea31012005-04-17 16:05:31 -05006137void
James Smart2e0fef82007-06-17 19:56:36 -05006138lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006139{
James Smart2e0fef82007-06-17 19:56:36 -05006140 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006141 struct lpfc_sli_ring *pring;
6142 struct lpfc_iocbq *tmp_iocb, *piocb;
6143 IOCB_t *cmd = NULL;
6144 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006145 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006146 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006147 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006148 LIST_HEAD(txcmplq_completions);
6149 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006150
James Smart2a9bf3d2010-06-07 15:24:45 -04006151
dea31012005-04-17 16:05:31 -05006152 timeout = (uint32_t)(phba->fc_ratov << 1);
6153
6154 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006155
James Smart2a9bf3d2010-06-07 15:24:45 -04006156 spin_lock_irq(&phba->hbalock);
6157 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6158 spin_unlock_irq(&phba->hbalock);
6159
6160 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006161 cmd = &piocb->iocb;
6162
James Smart2e0fef82007-06-17 19:56:36 -05006163 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6164 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6165 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006166 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006167
6168 if (piocb->vport != vport)
6169 continue;
6170
dea31012005-04-17 16:05:31 -05006171 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006172 if (pcmd)
6173 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006174
James Smart92d7f7b2007-06-17 19:56:38 -05006175 if (els_command == ELS_CMD_FARP ||
6176 els_command == ELS_CMD_FARPR ||
6177 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006178 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006179
dea31012005-04-17 16:05:31 -05006180 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006181 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006182 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006183 else
dea31012005-04-17 16:05:31 -05006184 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006185 continue;
6186 }
6187
James Smart2e0fef82007-06-17 19:56:36 -05006188 remote_ID = 0xffffffff;
6189 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006190 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006191 else {
6192 struct lpfc_nodelist *ndlp;
6193 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006194 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006195 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006196 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006197 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006198 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006199 spin_lock_irq(&phba->hbalock);
6200 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006201 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006202
James Smart2a9bf3d2010-06-07 15:24:45 -04006203 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6204 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6205 "0127 ELS timeout Data: x%x x%x x%x "
6206 "x%x\n", els_command,
6207 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6208 spin_lock_irq(&phba->hbalock);
6209 list_del_init(&piocb->dlist);
6210 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6211 spin_unlock_irq(&phba->hbalock);
6212 }
6213
James Smart2e0fef82007-06-17 19:56:36 -05006214 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6215 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006216}
6217
James Smarte59058c2008-08-24 21:49:00 -04006218/**
James Smart3621a712009-04-06 18:47:14 -04006219 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006220 * @vport: pointer to a host virtual N_Port data structure.
6221 *
6222 * This routine is used to clean up all the outstanding ELS commands on a
6223 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6224 * routine. After that, it walks the ELS transmit queue to remove all the
6225 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6226 * the IOCBs with a non-NULL completion callback function, the callback
6227 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6228 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6229 * callback function, the IOCB will simply be released. Finally, it walks
6230 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6231 * completion queue IOCB that is associated with the @vport and is not
6232 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6233 * part of the discovery state machine) out to HBA by invoking the
6234 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6235 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6236 * the IOCBs are aborted when this function returns.
6237 **/
dea31012005-04-17 16:05:31 -05006238void
James Smart2e0fef82007-06-17 19:56:36 -05006239lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006240{
James Smart2534ba72007-04-25 09:52:20 -04006241 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006242 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006243 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006244 struct lpfc_iocbq *tmp_iocb, *piocb;
6245 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006246
6247 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006248
James Smart2e0fef82007-06-17 19:56:36 -05006249 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006250 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6251 cmd = &piocb->iocb;
6252
6253 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6254 continue;
6255 }
6256
6257 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006258 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6259 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6260 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6261 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006262 continue;
dea31012005-04-17 16:05:31 -05006263
James Smart2e0fef82007-06-17 19:56:36 -05006264 if (piocb->vport != vport)
6265 continue;
6266
James Smart2534ba72007-04-25 09:52:20 -04006267 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006268 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006269 }
6270
6271 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006272 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6273 continue;
6274 }
dea31012005-04-17 16:05:31 -05006275
James Smart2e0fef82007-06-17 19:56:36 -05006276 if (piocb->vport != vport)
6277 continue;
6278
James Smart07951072007-04-25 09:51:38 -04006279 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006280 }
James Smart2e0fef82007-06-17 19:56:36 -05006281 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006282
James Smarta257bf92009-04-06 18:48:10 -04006283 /* Cancell all the IOCBs from the completions list */
6284 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6285 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006286
dea31012005-04-17 16:05:31 -05006287 return;
6288}
6289
James Smarte59058c2008-08-24 21:49:00 -04006290/**
James Smart3621a712009-04-06 18:47:14 -04006291 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006292 * @phba: pointer to lpfc hba data structure.
6293 *
6294 * This routine is used to clean up all the outstanding ELS commands on a
6295 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6296 * routine. After that, it walks the ELS transmit queue to remove all the
6297 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6298 * the IOCBs with the completion callback function associated, the callback
6299 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6300 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6301 * callback function associated, the IOCB will simply be released. Finally,
6302 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6303 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6304 * management plane IOCBs that are not part of the discovery state machine)
6305 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6306 **/
James Smart549e55c2007-08-02 11:09:51 -04006307void
6308lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6309{
6310 LIST_HEAD(completions);
6311 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6312 struct lpfc_iocbq *tmp_iocb, *piocb;
6313 IOCB_t *cmd = NULL;
6314
6315 lpfc_fabric_abort_hba(phba);
6316 spin_lock_irq(&phba->hbalock);
6317 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6318 cmd = &piocb->iocb;
6319 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6320 continue;
6321 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6322 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6323 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6324 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6325 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6326 continue;
6327 list_move_tail(&piocb->list, &completions);
6328 pring->txq_cnt--;
6329 }
6330 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6331 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6332 continue;
6333 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6334 }
6335 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006336
6337 /* Cancel all the IOCBs from the completions list */
6338 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6339 IOERR_SLI_ABORTED);
6340
James Smart549e55c2007-08-02 11:09:51 -04006341 return;
6342}
6343
James Smarte59058c2008-08-24 21:49:00 -04006344/**
James Smart3621a712009-04-06 18:47:14 -04006345 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006346 * @phba: Pointer to hba context object.
6347 * @cmdiocbp: Pointer to command iocb which reported error.
6348 * @rspiocbp: Pointer to response iocb which reported error.
6349 *
6350 * This function sends an event when there is an ELS command
6351 * failure.
6352 **/
6353void
6354lpfc_send_els_failure_event(struct lpfc_hba *phba,
6355 struct lpfc_iocbq *cmdiocbp,
6356 struct lpfc_iocbq *rspiocbp)
6357{
6358 struct lpfc_vport *vport = cmdiocbp->vport;
6359 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6360 struct lpfc_lsrjt_event lsrjt_event;
6361 struct lpfc_fabric_event_header fabric_event;
6362 struct ls_rjt stat;
6363 struct lpfc_nodelist *ndlp;
6364 uint32_t *pcmd;
6365
6366 ndlp = cmdiocbp->context1;
6367 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6368 return;
6369
6370 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6371 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6372 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6373 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6374 sizeof(struct lpfc_name));
6375 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6376 sizeof(struct lpfc_name));
6377 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6378 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006379 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006380 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6381 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6382 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6383 fc_host_post_vendor_event(shost,
6384 fc_get_event_number(),
6385 sizeof(lsrjt_event),
6386 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006387 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006388 return;
6389 }
6390 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6391 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6392 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6393 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6394 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6395 else
6396 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6397 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6398 sizeof(struct lpfc_name));
6399 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6400 sizeof(struct lpfc_name));
6401 fc_host_post_vendor_event(shost,
6402 fc_get_event_number(),
6403 sizeof(fabric_event),
6404 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006405 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006406 return;
6407 }
6408
6409}
6410
6411/**
James Smart3621a712009-04-06 18:47:14 -04006412 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006413 * @vport: Pointer to vport object.
6414 * @ndlp: Pointer FC node object.
6415 * @cmd: ELS command code.
6416 *
6417 * This function posts an event when there is an incoming
6418 * unsolicited ELS command.
6419 **/
6420static void
6421lpfc_send_els_event(struct lpfc_vport *vport,
6422 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006423 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006424{
James Smartddcc50f2008-12-04 22:38:46 -05006425 struct lpfc_els_event_header *els_data = NULL;
6426 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006427 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6428
James Smartddcc50f2008-12-04 22:38:46 -05006429 if (*payload == ELS_CMD_LOGO) {
6430 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6431 if (!logo_data) {
6432 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6433 "0148 Failed to allocate memory "
6434 "for LOGO event\n");
6435 return;
6436 }
6437 els_data = &logo_data->header;
6438 } else {
6439 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6440 GFP_KERNEL);
6441 if (!els_data) {
6442 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6443 "0149 Failed to allocate memory "
6444 "for ELS event\n");
6445 return;
6446 }
6447 }
6448 els_data->event_type = FC_REG_ELS_EVENT;
6449 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006450 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006451 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006452 break;
6453 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006454 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006455 break;
6456 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006457 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6458 break;
6459 case ELS_CMD_LOGO:
6460 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6461 /* Copy the WWPN in the LOGO payload */
6462 memcpy(logo_data->logo_wwpn, &payload[2],
6463 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006464 break;
6465 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006466 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006467 return;
6468 }
James Smartddcc50f2008-12-04 22:38:46 -05006469 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6470 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6471 if (*payload == ELS_CMD_LOGO) {
6472 fc_host_post_vendor_event(shost,
6473 fc_get_event_number(),
6474 sizeof(struct lpfc_logo_event),
6475 (char *)logo_data,
6476 LPFC_NL_VENDOR_ID);
6477 kfree(logo_data);
6478 } else {
6479 fc_host_post_vendor_event(shost,
6480 fc_get_event_number(),
6481 sizeof(struct lpfc_els_event_header),
6482 (char *)els_data,
6483 LPFC_NL_VENDOR_ID);
6484 kfree(els_data);
6485 }
James Smartea2151b2008-09-07 11:52:10 -04006486
6487 return;
6488}
6489
6490
6491/**
James Smart3621a712009-04-06 18:47:14 -04006492 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006493 * @phba: pointer to lpfc hba data structure.
6494 * @pring: pointer to a SLI ring.
6495 * @vport: pointer to a host virtual N_Port data structure.
6496 * @elsiocb: pointer to lpfc els command iocb data structure.
6497 *
6498 * This routine is used for processing the IOCB associated with a unsolicited
6499 * event. It first determines whether there is an existing ndlp that matches
6500 * the DID from the unsolicited IOCB. If not, it will create a new one with
6501 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6502 * IOCB is then used to invoke the proper routine and to set up proper state
6503 * of the discovery state machine.
6504 **/
James Smarted957682007-06-17 19:56:37 -05006505static void
6506lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006507 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006508{
James Smart87af33f2007-10-27 13:37:43 -04006509 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006510 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006511 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006512 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006513 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006514 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006515
James Smarte47c9092008-02-08 18:49:26 -05006516 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006517 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006518
dea31012005-04-17 16:05:31 -05006519 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006520 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6521 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006522 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006523 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006524
James Smart858c9f62007-06-17 19:56:39 -05006525 did = icmd->un.rcvels.remoteID;
6526 if (icmd->ulpStatus) {
6527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6528 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6529 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006530 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006531 }
dea31012005-04-17 16:05:31 -05006532
6533 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006534 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006535 goto dropit;
dea31012005-04-17 16:05:31 -05006536
James Smartc8685952009-11-18 15:39:16 -05006537 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006538 if (vport->load_flag & FC_UNLOADING)
6539 goto dropit;
6540
James Smart92494142011-02-16 12:39:44 -05006541 /* If NPort discovery is delayed drop incoming ELS */
6542 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6543 (cmd != ELS_CMD_PLOGI))
6544 goto dropit;
6545
James Smart2e0fef82007-06-17 19:56:36 -05006546 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006547 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006548 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006549 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006550 if (!ndlp)
dea31012005-04-17 16:05:31 -05006551 goto dropit;
dea31012005-04-17 16:05:31 -05006552
James Smart2e0fef82007-06-17 19:56:36 -05006553 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006554 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006555 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006556 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006557 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006558 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6559 ndlp = lpfc_enable_node(vport, ndlp,
6560 NLP_STE_UNUSED_NODE);
6561 if (!ndlp)
6562 goto dropit;
6563 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6564 newnode = 1;
6565 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6566 ndlp->nlp_type |= NLP_FABRIC;
6567 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6568 /* This is similar to the new node path */
6569 ndlp = lpfc_nlp_get(ndlp);
6570 if (!ndlp)
6571 goto dropit;
6572 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6573 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006574 }
dea31012005-04-17 16:05:31 -05006575
6576 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006577
James Smart329f9bc2007-04-25 09:53:01 -04006578 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006579 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006580
6581 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6582 cmd &= ELS_CMD_MASK;
6583 }
6584 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006585 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6586 "0112 ELS command x%x received from NPORT x%x "
6587 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006588 switch (cmd) {
6589 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006590 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6591 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6592 did, vport->port_state, ndlp->nlp_flag);
6593
dea31012005-04-17 16:05:31 -05006594 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006595 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6596
James Smartddcc50f2008-12-04 22:38:46 -05006597 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006598
6599 /* If Nport discovery is delayed, reject PLOGIs */
6600 if (vport->fc_flag & FC_DISC_DELAYED) {
6601 rjt_err = LSRJT_UNABLE_TPC;
6602 break;
6603 }
James Smart858c9f62007-06-17 19:56:39 -05006604 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006605 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6606 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6607 rjt_err = LSRJT_UNABLE_TPC;
6608 break;
6609 }
6610 /* We get here, and drop thru, if we are PT2PT with
6611 * another NPort and the other side has initiated
6612 * the PLOGI before responding to our FLOGI.
6613 */
dea31012005-04-17 16:05:31 -05006614 }
James Smart87af33f2007-10-27 13:37:43 -04006615
6616 shost = lpfc_shost_from_vport(vport);
6617 spin_lock_irq(shost->host_lock);
6618 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6619 spin_unlock_irq(shost->host_lock);
6620
James Smart2e0fef82007-06-17 19:56:36 -05006621 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6622 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006623
dea31012005-04-17 16:05:31 -05006624 break;
6625 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006626 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6627 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6628 did, vport->port_state, ndlp->nlp_flag);
6629
dea31012005-04-17 16:05:31 -05006630 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006631 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006632 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006633 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006634 break;
6635 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006636 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6637 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6638 did, vport->port_state, ndlp->nlp_flag);
6639
dea31012005-04-17 16:05:31 -05006640 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006641 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006642 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006643 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006644 break;
6645 }
James Smart2e0fef82007-06-17 19:56:36 -05006646 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006647 break;
6648 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006649 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6650 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6651 did, vport->port_state, ndlp->nlp_flag);
6652
dea31012005-04-17 16:05:31 -05006653 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006654 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006655 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006656 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006657 break;
6658 }
James Smart2e0fef82007-06-17 19:56:36 -05006659 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006660 break;
6661 case ELS_CMD_RSCN:
6662 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006663 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006664 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006665 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006666 break;
6667 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006668 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6669 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6670 did, vport->port_state, ndlp->nlp_flag);
6671
James Smartddcc50f2008-12-04 22:38:46 -05006672 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006673 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006674 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006675 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006676 break;
6677 }
James Smart2e0fef82007-06-17 19:56:36 -05006678 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6679 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006680 break;
6681 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006682 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6683 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6684 did, vport->port_state, ndlp->nlp_flag);
6685
dea31012005-04-17 16:05:31 -05006686 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006687 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006688 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006689 break;
6690 }
James Smart2e0fef82007-06-17 19:56:36 -05006691 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6692 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006693 break;
6694 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006695 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6696 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6697 did, vport->port_state, ndlp->nlp_flag);
6698
dea31012005-04-17 16:05:31 -05006699 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006700 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006701 break;
6702 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006703 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6704 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6705 did, vport->port_state, ndlp->nlp_flag);
6706
dea31012005-04-17 16:05:31 -05006707 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006708 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006709 break;
6710 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6712 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6713 did, vport->port_state, ndlp->nlp_flag);
6714
dea31012005-04-17 16:05:31 -05006715 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006716 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006717 break;
dea31012005-04-17 16:05:31 -05006718 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006719 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6720 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6721 did, vport->port_state, ndlp->nlp_flag);
6722
dea31012005-04-17 16:05:31 -05006723 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006724 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006725 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006726 break;
6727 }
James Smart2e0fef82007-06-17 19:56:36 -05006728 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006729 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006730 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6732 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6733 did, vport->port_state, ndlp->nlp_flag);
6734
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006735 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006736 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006737 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006738 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006739 break;
James Smart12265f62010-10-22 11:05:53 -04006740 case ELS_CMD_RLS:
6741 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6742 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6743 did, vport->port_state, ndlp->nlp_flag);
6744
6745 phba->fc_stat.elsRcvRLS++;
6746 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6747 if (newnode)
6748 lpfc_nlp_put(ndlp);
6749 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006750 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6752 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6753 did, vport->port_state, ndlp->nlp_flag);
6754
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006755 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006756 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006757 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006758 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006759 break;
6760 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006761 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6762 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6763 did, vport->port_state, ndlp->nlp_flag);
6764
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006765 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006766 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006767 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006768 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006769 break;
dea31012005-04-17 16:05:31 -05006770 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006771 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6772 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6773 did, vport->port_state, ndlp->nlp_flag);
6774
dea31012005-04-17 16:05:31 -05006775 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006776 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006777 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006778 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006779 break;
James Smart12265f62010-10-22 11:05:53 -04006780 case ELS_CMD_RTV:
6781 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6782 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6783 did, vport->port_state, ndlp->nlp_flag);
6784 phba->fc_stat.elsRcvRTV++;
6785 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6786 if (newnode)
6787 lpfc_nlp_put(ndlp);
6788 break;
James Smart5ffc2662009-11-18 15:39:44 -05006789 case ELS_CMD_RRQ:
6790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6791 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6792 did, vport->port_state, ndlp->nlp_flag);
6793
6794 phba->fc_stat.elsRcvRRQ++;
6795 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6796 if (newnode)
6797 lpfc_nlp_put(ndlp);
6798 break;
James Smart12265f62010-10-22 11:05:53 -04006799 case ELS_CMD_ECHO:
6800 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6801 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6802 did, vport->port_state, ndlp->nlp_flag);
6803
6804 phba->fc_stat.elsRcvECHO++;
6805 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6806 if (newnode)
6807 lpfc_nlp_put(ndlp);
6808 break;
dea31012005-04-17 16:05:31 -05006809 default:
James Smart858c9f62007-06-17 19:56:39 -05006810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6811 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6812 cmd, did, vport->port_state);
6813
dea31012005-04-17 16:05:31 -05006814 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006815 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006816
6817 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006818 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6819 "0115 Unknown ELS command x%x "
6820 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006821 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006822 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006823 break;
6824 }
6825
6826 /* check if need to LS_RJT received ELS cmd */
6827 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006828 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006829 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006830 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006831 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6832 NULL);
dea31012005-04-17 16:05:31 -05006833 }
6834
James Smartd7c255b2008-08-24 21:50:00 -04006835 lpfc_nlp_put(elsiocb->context1);
6836 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006837 return;
6838
6839dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006840 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006841 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6842 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006843 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006844 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006845 phba->fc_stat.elsRcvDrop++;
6846}
6847
James Smarte59058c2008-08-24 21:49:00 -04006848/**
James Smart3621a712009-04-06 18:47:14 -04006849 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006850 * @phba: pointer to lpfc hba data structure.
6851 * @pring: pointer to a SLI ring.
6852 * @elsiocb: pointer to lpfc els iocb data structure.
6853 *
6854 * This routine is used to process an unsolicited event received from a SLI
6855 * (Service Level Interface) ring. The actual processing of the data buffer
6856 * associated with the unsolicited event is done by invoking the routine
6857 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6858 * SLI ring on which the unsolicited event was received.
6859 **/
James Smarted957682007-06-17 19:56:37 -05006860void
6861lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6862 struct lpfc_iocbq *elsiocb)
6863{
6864 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006865 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006866 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006867 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6868 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006869
James Smartd7c255b2008-08-24 21:50:00 -04006870 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006871 elsiocb->context2 = NULL;
6872 elsiocb->context3 = NULL;
6873
6874 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6875 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6876 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04006877 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6878 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006879 phba->fc_stat.NoRcvBuf++;
6880 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006881 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006882 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006883 return;
6884 }
6885
James Smart92d7f7b2007-06-17 19:56:38 -05006886 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6887 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6888 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6889 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6890 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006891 else
6892 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006893 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006894 }
James Smart6d368e52011-05-24 11:44:12 -04006895
James Smart7f5f3d02008-02-08 18:50:14 -05006896 /* If there are no BDEs associated
6897 * with this IOCB, there is nothing to do.
6898 */
James Smarted957682007-06-17 19:56:37 -05006899 if (icmd->ulpBdeCount == 0)
6900 return;
6901
James Smart7f5f3d02008-02-08 18:50:14 -05006902 /* type of ELS cmd is first 32bit word
6903 * in packet
6904 */
James Smarted957682007-06-17 19:56:37 -05006905 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006906 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006907 } else {
6908 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6909 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006910 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6911 paddr);
James Smarted957682007-06-17 19:56:37 -05006912 }
6913
James Smart92d7f7b2007-06-17 19:56:38 -05006914 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6915 /*
6916 * The different unsolicited event handlers would tell us
6917 * if they are done with "mp" by setting context2 to NULL.
6918 */
dea31012005-04-17 16:05:31 -05006919 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006920 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6921 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006922 }
James Smarted957682007-06-17 19:56:37 -05006923
6924 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006925 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006926 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006927 elsiocb->context2 = bdeBuf2;
6928 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006929 /* free mp if we are done with it */
6930 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006931 lpfc_in_buf_free(phba, elsiocb->context2);
6932 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006933 }
dea31012005-04-17 16:05:31 -05006934 }
dea31012005-04-17 16:05:31 -05006935}
James Smart92d7f7b2007-06-17 19:56:38 -05006936
James Smarte59058c2008-08-24 21:49:00 -04006937/**
James Smart3621a712009-04-06 18:47:14 -04006938 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006939 * @phba: pointer to lpfc hba data structure.
6940 * @vport: pointer to a virtual N_Port data structure.
6941 *
6942 * This routine issues a Port Login (PLOGI) to the Name Server with
6943 * State Change Request (SCR) for a @vport. This routine will create an
6944 * ndlp for the Name Server associated to the @vport if such node does
6945 * not already exist. The PLOGI to Name Server is issued by invoking the
6946 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6947 * (FDMI) is configured to the @vport, a FDMI node will be created and
6948 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6949 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006950void
6951lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6952{
6953 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6955
6956 /*
6957 * If lpfc_delay_discovery parameter is set and the clean address
6958 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6959 * discovery.
6960 */
6961 spin_lock_irq(shost->host_lock);
6962 if (vport->fc_flag & FC_DISC_DELAYED) {
6963 spin_unlock_irq(shost->host_lock);
6964 mod_timer(&vport->delayed_disc_tmo,
6965 jiffies + HZ * phba->fc_ratov);
6966 return;
6967 }
6968 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006969
6970 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6971 if (!ndlp) {
6972 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6973 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006974 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006975 lpfc_disc_start(vport);
6976 return;
6977 }
6978 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006979 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6980 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006981 return;
6982 }
6983 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006984 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6985 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6986 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006987 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006988 lpfc_disc_start(vport);
6989 return;
6990 }
6991 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6992 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6993 "0348 NameServer login: node freed\n");
6994 return;
6995 }
James Smart92d7f7b2007-06-17 19:56:38 -05006996 }
James Smart58da1ff2008-04-07 10:15:56 -04006997 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006998
6999 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7000
7001 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7002 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007003 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7004 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007005 return;
7006 }
7007
James Smart3de2a652007-08-02 11:09:59 -04007008 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05007009 /* If this is the first time, allocate an ndlp and initialize
7010 * it. Otherwise, make sure the node is enabled and then do the
7011 * login.
7012 */
7013 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7014 if (!ndlp_fdmi) {
7015 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7016 GFP_KERNEL);
7017 if (ndlp_fdmi) {
7018 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7019 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7020 } else
7021 return;
7022 }
7023 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7024 ndlp_fdmi = lpfc_enable_node(vport,
7025 ndlp_fdmi,
7026 NLP_STE_NPR_NODE);
7027
James Smart92d7f7b2007-06-17 19:56:38 -05007028 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007029 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007030 NLP_STE_PLOGI_ISSUE);
7031 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007032 }
7033 }
James Smart92d7f7b2007-06-17 19:56:38 -05007034}
7035
James Smarte59058c2008-08-24 21:49:00 -04007036/**
James Smart3621a712009-04-06 18:47:14 -04007037 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007038 * @phba: pointer to lpfc hba data structure.
7039 * @pmb: pointer to the driver internal queue element for mailbox command.
7040 *
7041 * This routine is the completion callback function to register new vport
7042 * mailbox command. If the new vport mailbox command completes successfully,
7043 * the fabric registration login shall be performed on physical port (the
7044 * new vport created is actually a physical port, with VPI 0) or the port
7045 * login to Name Server for State Change Request (SCR) will be performed
7046 * on virtual port (real virtual port, with VPI greater than 0).
7047 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007048static void
7049lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7050{
7051 struct lpfc_vport *vport = pmb->vport;
7052 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7053 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007054 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007055 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007056
James Smart09372822008-01-11 01:52:54 -05007057 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007058 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007059 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007060
7061 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007062 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007063 "0915 Register VPI failed : Status: x%x"
7064 " upd bit: x%x \n", mb->mbxStatus,
7065 mb->un.varRegVpi.upd);
7066 if (phba->sli_rev == LPFC_SLI_REV4 &&
7067 mb->un.varRegVpi.upd)
7068 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007069
7070 switch (mb->mbxStatus) {
7071 case 0x11: /* unsupported feature */
7072 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007073 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007074 /* giving up on vport registration */
7075 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7076 spin_lock_irq(shost->host_lock);
7077 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7078 spin_unlock_irq(shost->host_lock);
7079 lpfc_can_disctmo(vport);
7080 break;
James Smart695a8142010-01-26 23:08:03 -05007081 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7082 case 0x20:
7083 spin_lock_irq(shost->host_lock);
7084 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7085 spin_unlock_irq(shost->host_lock);
7086 lpfc_init_vpi(phba, pmb, vport->vpi);
7087 pmb->vport = vport;
7088 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7089 rc = lpfc_sli_issue_mbox(phba, pmb,
7090 MBX_NOWAIT);
7091 if (rc == MBX_NOT_FINISHED) {
7092 lpfc_printf_vlog(vport,
7093 KERN_ERR, LOG_MBOX,
7094 "2732 Failed to issue INIT_VPI"
7095 " mailbox command\n");
7096 } else {
7097 lpfc_nlp_put(ndlp);
7098 return;
7099 }
7100
James Smart92d7f7b2007-06-17 19:56:38 -05007101 default:
7102 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007103 if (phba->sli_rev == LPFC_SLI_REV4)
7104 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007105 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007106 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007107 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007108 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007109 if (vport->port_type == LPFC_PHYSICAL_PORT
7110 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007111 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007112 else
7113 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007114 break;
7115 }
James Smart92d7f7b2007-06-17 19:56:38 -05007116 } else {
James Smart695a8142010-01-26 23:08:03 -05007117 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007118 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007119 spin_unlock_irq(shost->host_lock);
7120 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007121 if (phba->sli_rev < LPFC_SLI_REV4)
7122 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007123 else {
James Smartfc2b9892010-02-26 14:15:29 -05007124 /*
7125 * If the physical port is instantiated using
7126 * FDISC, do not start vport discovery.
7127 */
7128 if (vport->port_state != LPFC_FDISC)
7129 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007130 lpfc_do_scr_ns_plogi(phba, vport);
7131 }
7132 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007133 lpfc_do_scr_ns_plogi(phba, vport);
7134 }
James Smart38b92ef2010-08-04 16:11:39 -04007135mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007136 /* Now, we decrement the ndlp reference count held for this
7137 * callback function
7138 */
7139 lpfc_nlp_put(ndlp);
7140
James Smart92d7f7b2007-06-17 19:56:38 -05007141 mempool_free(pmb, phba->mbox_mem_pool);
7142 return;
7143}
7144
James Smarte59058c2008-08-24 21:49:00 -04007145/**
James Smart3621a712009-04-06 18:47:14 -04007146 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007147 * @phba: pointer to lpfc hba data structure.
7148 * @vport: pointer to a host virtual N_Port data structure.
7149 * @ndlp: pointer to a node-list data structure.
7150 *
7151 * This routine registers the @vport as a new virtual port with a HBA.
7152 * It is done through a registering vpi mailbox command.
7153 **/
James Smart695a8142010-01-26 23:08:03 -05007154void
James Smart92d7f7b2007-06-17 19:56:38 -05007155lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7156 struct lpfc_nodelist *ndlp)
7157{
James Smart09372822008-01-11 01:52:54 -05007158 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007159 LPFC_MBOXQ_t *mbox;
7160
7161 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7162 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007163 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007164 mbox->vport = vport;
7165 mbox->context2 = lpfc_nlp_get(ndlp);
7166 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007167 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007168 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007169 /* mailbox command not success, decrement ndlp
7170 * reference count for this command
7171 */
7172 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007173 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007174
James Smarte8b62012007-08-02 11:10:09 -04007175 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7176 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007177 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007178 }
7179 } else {
James Smarte8b62012007-08-02 11:10:09 -04007180 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7181 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007182 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007183 }
James Smartfa4066b2008-01-11 01:53:27 -05007184 return;
7185
7186mbox_err_exit:
7187 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7188 spin_lock_irq(shost->host_lock);
7189 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7190 spin_unlock_irq(shost->host_lock);
7191 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007192}
7193
James Smarte59058c2008-08-24 21:49:00 -04007194/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007195 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007196 * @phba: pointer to lpfc hba data structure.
7197 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007198 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007199 **/
7200void
James Smart0c9ab6f2010-02-26 14:15:57 -05007201lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007202{
7203 struct lpfc_vport **vports;
7204 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007205 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007206 int i;
James Smart695a8142010-01-26 23:08:03 -05007207
7208 /* Treat this failure as linkdown for all vports */
7209 link_state = phba->link_state;
7210 lpfc_linkdown(phba);
7211 phba->link_state = link_state;
7212
7213 vports = lpfc_create_vport_work_array(phba);
7214
7215 if (vports) {
7216 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7217 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7218 if (ndlp)
7219 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7220 lpfc_els_flush_cmd(vports[i]);
7221 }
7222 lpfc_destroy_vport_work_array(phba, vports);
7223 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007224}
7225
7226/**
7227 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7228 * @phba: pointer to lpfc hba data structure.
7229 *
7230 * This routine abort all pending discovery commands and
7231 * start a timer to retry FLOGI for the physical port
7232 * discovery.
7233 **/
7234void
7235lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7236{
7237 struct lpfc_nodelist *ndlp;
7238 struct Scsi_Host *shost;
7239
7240 /* Cancel the all vports retry delay retry timers */
7241 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007242
7243 /* If fabric require FLOGI, then re-instantiate physical login */
7244 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7245 if (!ndlp)
7246 return;
7247
James Smart695a8142010-01-26 23:08:03 -05007248 shost = lpfc_shost_from_vport(phba->pport);
7249 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7250 spin_lock_irq(shost->host_lock);
7251 ndlp->nlp_flag |= NLP_DELAY_TMO;
7252 spin_unlock_irq(shost->host_lock);
7253 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7254 phba->pport->port_state = LPFC_FLOGI;
7255 return;
7256}
7257
7258/**
7259 * lpfc_fabric_login_reqd - Check if FLOGI required.
7260 * @phba: pointer to lpfc hba data structure.
7261 * @cmdiocb: pointer to FDISC command iocb.
7262 * @rspiocb: pointer to FDISC response iocb.
7263 *
7264 * This routine checks if a FLOGI is reguired for FDISC
7265 * to succeed.
7266 **/
7267static int
7268lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7269 struct lpfc_iocbq *cmdiocb,
7270 struct lpfc_iocbq *rspiocb)
7271{
7272
7273 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7274 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7275 return 0;
7276 else
7277 return 1;
7278}
7279
7280/**
James Smart3621a712009-04-06 18:47:14 -04007281 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007282 * @phba: pointer to lpfc hba data structure.
7283 * @cmdiocb: pointer to lpfc command iocb data structure.
7284 * @rspiocb: pointer to lpfc response iocb data structure.
7285 *
7286 * This routine is the completion callback function to a Fabric Discover
7287 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7288 * single threaded, each FDISC completion callback function will reset
7289 * the discovery timer for all vports such that the timers will not get
7290 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7291 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7292 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7293 * assigned to the vport has been changed with the completion of the FDISC
7294 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7295 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7296 * routine is invoked to register new vport with the HBA. Otherwise, the
7297 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7298 * Server for State Change Request (SCR).
7299 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007300static void
7301lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7302 struct lpfc_iocbq *rspiocb)
7303{
7304 struct lpfc_vport *vport = cmdiocb->vport;
7305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7306 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7307 struct lpfc_nodelist *np;
7308 struct lpfc_nodelist *next_np;
7309 IOCB_t *irsp = &rspiocb->iocb;
7310 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007311 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7312 struct serv_parm *sp;
7313 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007314
James Smarte8b62012007-08-02 11:10:09 -04007315 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7316 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7317 irsp->ulpStatus, irsp->un.ulpWord[4],
7318 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007319 /* Since all FDISCs are being single threaded, we
7320 * must reset the discovery timer for ALL vports
7321 * waiting to send FDISC when one completes.
7322 */
7323 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7324 lpfc_set_disctmo(piocb->vport);
7325 }
7326
James Smart858c9f62007-06-17 19:56:39 -05007327 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7328 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7329 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7330
James Smart92d7f7b2007-06-17 19:56:38 -05007331 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007332
7333 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7334 lpfc_retry_pport_discovery(phba);
7335 goto out;
7336 }
7337
James Smart92d7f7b2007-06-17 19:56:38 -05007338 /* Check for retry */
7339 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7340 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007341 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007342 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007343 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007344 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007345 goto fdisc_failed;
7346 }
James Smartd7c255b2008-08-24 21:50:00 -04007347 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007348 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007349 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007350 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007351 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007352 vport->fc_flag |= FC_PUBLIC_LOOP;
7353 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007354
James Smartd7c255b2008-08-24 21:50:00 -04007355 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7356 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007357 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7358 sp = prsp->virt + sizeof(uint32_t);
7359 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7360 memcpy(&vport->fabric_portname, &sp->portName,
7361 sizeof(struct lpfc_name));
7362 memcpy(&vport->fabric_nodename, &sp->nodeName,
7363 sizeof(struct lpfc_name));
7364 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007365 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7366 /* If our NportID changed, we need to ensure all
7367 * remaining NPORTs get unreg_login'ed so we can
7368 * issue unreg_vpi.
7369 */
7370 list_for_each_entry_safe(np, next_np,
7371 &vport->fc_nodes, nlp_listp) {
7372 if (!NLP_CHK_NODE_ACT(ndlp) ||
7373 (np->nlp_state != NLP_STE_NPR_NODE) ||
7374 !(np->nlp_flag & NLP_NPR_ADISC))
7375 continue;
James Smart09372822008-01-11 01:52:54 -05007376 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007377 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007378 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007379 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007380 }
James Smart78730cf2010-04-06 15:06:30 -04007381 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007382
7383 if (phba->sli_rev == LPFC_SLI_REV4)
7384 lpfc_sli4_unreg_all_rpis(vport);
7385
James Smartd7c255b2008-08-24 21:50:00 -04007386 lpfc_mbx_unreg_vpi(vport);
7387 spin_lock_irq(shost->host_lock);
7388 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007389 if (phba->sli_rev == LPFC_SLI_REV4)
7390 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007391 else
7392 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007393 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007394 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7395 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7396 /*
7397 * Driver needs to re-reg VPI in order for f/w
7398 * to update the MAC address.
7399 */
7400 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007401 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007402 }
7403
James Smartecfd03c2010-02-12 14:41:27 -05007404 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7405 lpfc_issue_init_vpi(vport);
7406 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007407 lpfc_register_new_vport(phba, vport, ndlp);
7408 else
7409 lpfc_do_scr_ns_plogi(phba, vport);
7410 goto out;
7411fdisc_failed:
7412 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7413 /* Cancel discovery timer */
7414 lpfc_can_disctmo(vport);
7415 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007416out:
7417 lpfc_els_free_iocb(phba, cmdiocb);
7418}
7419
James Smarte59058c2008-08-24 21:49:00 -04007420/**
James Smart3621a712009-04-06 18:47:14 -04007421 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007422 * @vport: pointer to a virtual N_Port data structure.
7423 * @ndlp: pointer to a node-list data structure.
7424 * @retry: number of retries to the command IOCB.
7425 *
7426 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7427 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7428 * routine to issue the IOCB, which makes sure only one outstanding fabric
7429 * IOCB will be sent off HBA at any given time.
7430 *
7431 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7432 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7433 * will be stored into the context1 field of the IOCB for the completion
7434 * callback function to the FDISC ELS command.
7435 *
7436 * Return code
7437 * 0 - Successfully issued fdisc iocb command
7438 * 1 - Failed to issue fdisc iocb command
7439 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007440static int
James Smart92d7f7b2007-06-17 19:56:38 -05007441lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7442 uint8_t retry)
7443{
7444 struct lpfc_hba *phba = vport->phba;
7445 IOCB_t *icmd;
7446 struct lpfc_iocbq *elsiocb;
7447 struct serv_parm *sp;
7448 uint8_t *pcmd;
7449 uint16_t cmdsize;
7450 int did = ndlp->nlp_DID;
7451 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007452
James Smart5ffc2662009-11-18 15:39:44 -05007453 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007454 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007455 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7456 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7457 ELS_CMD_FDISC);
7458 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007459 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007460 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7461 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007462 return 1;
7463 }
7464
7465 icmd = &elsiocb->iocb;
7466 icmd->un.elsreq64.myID = 0;
7467 icmd->un.elsreq64.fl = 1;
7468
James Smart73d91e52011-10-10 21:32:10 -04007469 /*
7470 * SLI3 ports require a different context type value than SLI4.
7471 * Catch SLI3 ports here and override the prep.
7472 */
7473 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007474 icmd->ulpCt_h = 1;
7475 icmd->ulpCt_l = 0;
7476 }
James Smart92d7f7b2007-06-17 19:56:38 -05007477
7478 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7479 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7480 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7481 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7482 sp = (struct serv_parm *) pcmd;
7483 /* Setup CSPs accordingly for Fabric */
7484 sp->cmn.e_d_tov = 0;
7485 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007486 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007487 sp->cls1.classValid = 0;
7488 sp->cls2.seqDelivery = 1;
7489 sp->cls3.seqDelivery = 1;
7490
7491 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7492 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7493 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7494 pcmd += sizeof(uint32_t); /* Port Name */
7495 memcpy(pcmd, &vport->fc_portname, 8);
7496 pcmd += sizeof(uint32_t); /* Node Name */
7497 pcmd += sizeof(uint32_t); /* Node Name */
7498 memcpy(pcmd, &vport->fc_nodename, 8);
7499
7500 lpfc_set_disctmo(vport);
7501
7502 phba->fc_stat.elsXmitFDISC++;
7503 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7504
James Smart858c9f62007-06-17 19:56:39 -05007505 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7506 "Issue FDISC: did:x%x",
7507 did, 0, 0);
7508
James Smart92d7f7b2007-06-17 19:56:38 -05007509 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7510 if (rc == IOCB_ERROR) {
7511 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007512 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007513 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7514 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007515 return 1;
7516 }
7517 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007518 return 0;
7519}
7520
James Smarte59058c2008-08-24 21:49:00 -04007521/**
James Smart3621a712009-04-06 18:47:14 -04007522 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007523 * @phba: pointer to lpfc hba data structure.
7524 * @cmdiocb: pointer to lpfc command iocb data structure.
7525 * @rspiocb: pointer to lpfc response iocb data structure.
7526 *
7527 * This routine is the completion callback function to the issuing of a LOGO
7528 * ELS command off a vport. It frees the command IOCB and then decrement the
7529 * reference count held on ndlp for this completion function, indicating that
7530 * the reference to the ndlp is no long needed. Note that the
7531 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7532 * callback function and an additional explicit ndlp reference decrementation
7533 * will trigger the actual release of the ndlp.
7534 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007535static void
7536lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7537 struct lpfc_iocbq *rspiocb)
7538{
7539 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007540 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007541 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007543
James Smart9589b062011-04-16 11:03:17 -04007544 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007545 irsp = &rspiocb->iocb;
7546 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7547 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7548 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007549
7550 lpfc_els_free_iocb(phba, cmdiocb);
7551 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007552
7553 /* Trigger the release of the ndlp after logo */
7554 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007555
7556 /* NPIV LOGO completes to NPort <nlp_DID> */
7557 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7558 "2928 NPIV LOGO completes to NPort x%x "
7559 "Data: x%x x%x x%x x%x\n",
7560 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7561 irsp->ulpTimeout, vport->num_disc_nodes);
7562
7563 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7564 spin_lock_irq(shost->host_lock);
7565 vport->fc_flag &= ~FC_FABRIC;
7566 spin_unlock_irq(shost->host_lock);
7567 }
James Smart92d7f7b2007-06-17 19:56:38 -05007568}
7569
James Smarte59058c2008-08-24 21:49:00 -04007570/**
James Smart3621a712009-04-06 18:47:14 -04007571 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007572 * @vport: pointer to a virtual N_Port data structure.
7573 * @ndlp: pointer to a node-list data structure.
7574 *
7575 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7576 *
7577 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7578 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7579 * will be stored into the context1 field of the IOCB for the completion
7580 * callback function to the LOGO ELS command.
7581 *
7582 * Return codes
7583 * 0 - Successfully issued logo off the @vport
7584 * 1 - Failed to issue logo off the @vport
7585 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007586int
7587lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7588{
7589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7590 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007591 IOCB_t *icmd;
7592 struct lpfc_iocbq *elsiocb;
7593 uint8_t *pcmd;
7594 uint16_t cmdsize;
7595
7596 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7597 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7598 ELS_CMD_LOGO);
7599 if (!elsiocb)
7600 return 1;
7601
7602 icmd = &elsiocb->iocb;
7603 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7604 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7605 pcmd += sizeof(uint32_t);
7606
7607 /* Fill in LOGO payload */
7608 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7609 pcmd += sizeof(uint32_t);
7610 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7611
James Smart858c9f62007-06-17 19:56:39 -05007612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7613 "Issue LOGO npiv did:x%x flg:x%x",
7614 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7615
James Smart92d7f7b2007-06-17 19:56:38 -05007616 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7617 spin_lock_irq(shost->host_lock);
7618 ndlp->nlp_flag |= NLP_LOGO_SND;
7619 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007620 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7621 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007622 spin_lock_irq(shost->host_lock);
7623 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7624 spin_unlock_irq(shost->host_lock);
7625 lpfc_els_free_iocb(phba, elsiocb);
7626 return 1;
7627 }
7628 return 0;
7629}
7630
James Smarte59058c2008-08-24 21:49:00 -04007631/**
James Smart3621a712009-04-06 18:47:14 -04007632 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007633 * @ptr: holder for the timer function associated data.
7634 *
7635 * This routine is invoked by the fabric iocb block timer after
7636 * timeout. It posts the fabric iocb block timeout event by setting the
7637 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7638 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7639 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7640 * posted event WORKER_FABRIC_BLOCK_TMO.
7641 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007642void
7643lpfc_fabric_block_timeout(unsigned long ptr)
7644{
7645 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7646 unsigned long iflags;
7647 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007648
James Smart92d7f7b2007-06-17 19:56:38 -05007649 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7650 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7651 if (!tmo_posted)
7652 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7653 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7654
James Smart5e9d9b82008-06-14 22:52:53 -04007655 if (!tmo_posted)
7656 lpfc_worker_wake_up(phba);
7657 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007658}
7659
James Smarte59058c2008-08-24 21:49:00 -04007660/**
James Smart3621a712009-04-06 18:47:14 -04007661 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007662 * @phba: pointer to lpfc hba data structure.
7663 *
7664 * This routine issues one fabric iocb from the driver internal list to
7665 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7666 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7667 * remove one pending fabric iocb from the driver internal list and invokes
7668 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7669 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007670static void
7671lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7672{
7673 struct lpfc_iocbq *iocb;
7674 unsigned long iflags;
7675 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007676 IOCB_t *cmd;
7677
7678repeat:
7679 iocb = NULL;
7680 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007681 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007682 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7683 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7684 list);
7685 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007686 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007687 atomic_inc(&phba->fabric_iocb_count);
7688 }
7689 spin_unlock_irqrestore(&phba->hbalock, iflags);
7690 if (iocb) {
7691 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7692 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7693 iocb->iocb_flag |= LPFC_IO_FABRIC;
7694
James Smart858c9f62007-06-17 19:56:39 -05007695 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7696 "Fabric sched1: ste:x%x",
7697 iocb->vport->port_state, 0, 0);
7698
James Smart3772a992009-05-22 14:50:54 -04007699 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007700
7701 if (ret == IOCB_ERROR) {
7702 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7703 iocb->fabric_iocb_cmpl = NULL;
7704 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7705 cmd = &iocb->iocb;
7706 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7707 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7708 iocb->iocb_cmpl(phba, iocb, iocb);
7709
7710 atomic_dec(&phba->fabric_iocb_count);
7711 goto repeat;
7712 }
7713 }
7714
7715 return;
7716}
7717
James Smarte59058c2008-08-24 21:49:00 -04007718/**
James Smart3621a712009-04-06 18:47:14 -04007719 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007720 * @phba: pointer to lpfc hba data structure.
7721 *
7722 * This routine unblocks the issuing fabric iocb command. The function
7723 * will clear the fabric iocb block bit and then invoke the routine
7724 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7725 * from the driver internal fabric iocb list.
7726 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007727void
7728lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7729{
7730 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7731
7732 lpfc_resume_fabric_iocbs(phba);
7733 return;
7734}
7735
James Smarte59058c2008-08-24 21:49:00 -04007736/**
James Smart3621a712009-04-06 18:47:14 -04007737 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007738 * @phba: pointer to lpfc hba data structure.
7739 *
7740 * This routine blocks the issuing fabric iocb for a specified amount of
7741 * time (currently 100 ms). This is done by set the fabric iocb block bit
7742 * and set up a timeout timer for 100ms. When the block bit is set, no more
7743 * fabric iocb will be issued out of the HBA.
7744 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007745static void
7746lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7747{
7748 int blocked;
7749
7750 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007751 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007752 if (!blocked)
7753 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7754
7755 return;
7756}
7757
James Smarte59058c2008-08-24 21:49:00 -04007758/**
James Smart3621a712009-04-06 18:47:14 -04007759 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007760 * @phba: pointer to lpfc hba data structure.
7761 * @cmdiocb: pointer to lpfc command iocb data structure.
7762 * @rspiocb: pointer to lpfc response iocb data structure.
7763 *
7764 * This routine is the callback function that is put to the fabric iocb's
7765 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7766 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7767 * function first restores and invokes the original iocb's callback function
7768 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7769 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7770 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007771static void
7772lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7773 struct lpfc_iocbq *rspiocb)
7774{
7775 struct ls_rjt stat;
7776
7777 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7778 BUG();
7779
7780 switch (rspiocb->iocb.ulpStatus) {
7781 case IOSTAT_NPORT_RJT:
7782 case IOSTAT_FABRIC_RJT:
7783 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7784 lpfc_block_fabric_iocbs(phba);
7785 }
7786 break;
7787
7788 case IOSTAT_NPORT_BSY:
7789 case IOSTAT_FABRIC_BSY:
7790 lpfc_block_fabric_iocbs(phba);
7791 break;
7792
7793 case IOSTAT_LS_RJT:
7794 stat.un.lsRjtError =
7795 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7796 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7797 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7798 lpfc_block_fabric_iocbs(phba);
7799 break;
7800 }
7801
7802 if (atomic_read(&phba->fabric_iocb_count) == 0)
7803 BUG();
7804
7805 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7806 cmdiocb->fabric_iocb_cmpl = NULL;
7807 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7808 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7809
7810 atomic_dec(&phba->fabric_iocb_count);
7811 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007812 /* Post any pending iocbs to HBA */
7813 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007814 }
7815}
7816
James Smarte59058c2008-08-24 21:49:00 -04007817/**
James Smart3621a712009-04-06 18:47:14 -04007818 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007819 * @phba: pointer to lpfc hba data structure.
7820 * @iocb: pointer to lpfc command iocb data structure.
7821 *
7822 * This routine is used as the top-level API for issuing a fabric iocb command
7823 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7824 * function makes sure that only one fabric bound iocb will be outstanding at
7825 * any given time. As such, this function will first check to see whether there
7826 * is already an outstanding fabric iocb on the wire. If so, it will put the
7827 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7828 * issued later. Otherwise, it will issue the iocb on the wire and update the
7829 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7830 *
7831 * Note, this implementation has a potential sending out fabric IOCBs out of
7832 * order. The problem is caused by the construction of the "ready" boolen does
7833 * not include the condition that the internal fabric IOCB list is empty. As
7834 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7835 * ahead of the fabric IOCBs in the internal list.
7836 *
7837 * Return code
7838 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7839 * IOCB_ERROR - failed to issue fabric iocb
7840 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007841static int
James Smart92d7f7b2007-06-17 19:56:38 -05007842lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7843{
7844 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007845 int ready;
7846 int ret;
7847
7848 if (atomic_read(&phba->fabric_iocb_count) > 1)
7849 BUG();
7850
7851 spin_lock_irqsave(&phba->hbalock, iflags);
7852 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7853 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7854
James Smart7f5f3d02008-02-08 18:50:14 -05007855 if (ready)
7856 /* Increment fabric iocb count to hold the position */
7857 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007858 spin_unlock_irqrestore(&phba->hbalock, iflags);
7859 if (ready) {
7860 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7861 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7862 iocb->iocb_flag |= LPFC_IO_FABRIC;
7863
James Smart858c9f62007-06-17 19:56:39 -05007864 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7865 "Fabric sched2: ste:x%x",
7866 iocb->vport->port_state, 0, 0);
7867
James Smart3772a992009-05-22 14:50:54 -04007868 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007869
7870 if (ret == IOCB_ERROR) {
7871 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7872 iocb->fabric_iocb_cmpl = NULL;
7873 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7874 atomic_dec(&phba->fabric_iocb_count);
7875 }
7876 } else {
7877 spin_lock_irqsave(&phba->hbalock, iflags);
7878 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7879 spin_unlock_irqrestore(&phba->hbalock, iflags);
7880 ret = IOCB_SUCCESS;
7881 }
7882 return ret;
7883}
7884
James Smarte59058c2008-08-24 21:49:00 -04007885/**
James Smart3621a712009-04-06 18:47:14 -04007886 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007887 * @vport: pointer to a virtual N_Port data structure.
7888 *
7889 * This routine aborts all the IOCBs associated with a @vport from the
7890 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7891 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7892 * list, removes each IOCB associated with the @vport off the list, set the
7893 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7894 * associated with the IOCB.
7895 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007896static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007897{
7898 LIST_HEAD(completions);
7899 struct lpfc_hba *phba = vport->phba;
7900 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007901
7902 spin_lock_irq(&phba->hbalock);
7903 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7904 list) {
7905
7906 if (piocb->vport != vport)
7907 continue;
7908
7909 list_move_tail(&piocb->list, &completions);
7910 }
7911 spin_unlock_irq(&phba->hbalock);
7912
James Smarta257bf92009-04-06 18:48:10 -04007913 /* Cancel all the IOCBs from the completions list */
7914 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7915 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007916}
7917
James Smarte59058c2008-08-24 21:49:00 -04007918/**
James Smart3621a712009-04-06 18:47:14 -04007919 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007920 * @ndlp: pointer to a node-list data structure.
7921 *
7922 * This routine aborts all the IOCBs associated with an @ndlp from the
7923 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7924 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7925 * list, removes each IOCB associated with the @ndlp off the list, set the
7926 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7927 * associated with the IOCB.
7928 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007929void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7930{
7931 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007932 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007933 struct lpfc_iocbq *tmp_iocb, *piocb;
7934 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007935
7936 spin_lock_irq(&phba->hbalock);
7937 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7938 list) {
7939 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7940
7941 list_move_tail(&piocb->list, &completions);
7942 }
7943 }
7944 spin_unlock_irq(&phba->hbalock);
7945
James Smarta257bf92009-04-06 18:48:10 -04007946 /* Cancel all the IOCBs from the completions list */
7947 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7948 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007949}
7950
James Smarte59058c2008-08-24 21:49:00 -04007951/**
James Smart3621a712009-04-06 18:47:14 -04007952 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007953 * @phba: pointer to lpfc hba data structure.
7954 *
7955 * This routine aborts all the IOCBs currently on the driver internal
7956 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7957 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7958 * list, removes IOCBs off the list, set the status feild to
7959 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7960 * the IOCB.
7961 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007962void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7963{
7964 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007965
7966 spin_lock_irq(&phba->hbalock);
7967 list_splice_init(&phba->fabric_iocb_list, &completions);
7968 spin_unlock_irq(&phba->hbalock);
7969
James Smarta257bf92009-04-06 18:48:10 -04007970 /* Cancel all the IOCBs from the completions list */
7971 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7972 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007973}
James Smart6fb120a2009-05-22 14:52:59 -04007974
7975/**
James Smart1151e3e2011-02-16 12:39:35 -05007976 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7977 * @vport: pointer to lpfc vport data structure.
7978 *
7979 * This routine is invoked by the vport cleanup for deletions and the cleanup
7980 * for an ndlp on removal.
7981 **/
7982void
7983lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7984{
7985 struct lpfc_hba *phba = vport->phba;
7986 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7987 unsigned long iflag = 0;
7988
7989 spin_lock_irqsave(&phba->hbalock, iflag);
7990 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7991 list_for_each_entry_safe(sglq_entry, sglq_next,
7992 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7993 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7994 sglq_entry->ndlp = NULL;
7995 }
7996 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7997 spin_unlock_irqrestore(&phba->hbalock, iflag);
7998 return;
7999}
8000
8001/**
James Smart6fb120a2009-05-22 14:52:59 -04008002 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8003 * @phba: pointer to lpfc hba data structure.
8004 * @axri: pointer to the els xri abort wcqe structure.
8005 *
8006 * This routine is invoked by the worker thread to process a SLI4 slow-path
8007 * ELS aborted xri.
8008 **/
8009void
8010lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8011 struct sli4_wcqe_xri_aborted *axri)
8012{
8013 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008014 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008015 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008016
James Smart6fb120a2009-05-22 14:52:59 -04008017 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8018 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008019 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008020 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008021
James Smart0f65ff62010-02-26 14:14:23 -05008022 spin_lock_irqsave(&phba->hbalock, iflag);
8023 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008024 list_for_each_entry_safe(sglq_entry, sglq_next,
8025 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8026 if (sglq_entry->sli4_xritag == xri) {
8027 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008028 ndlp = sglq_entry->ndlp;
8029 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04008030 list_add_tail(&sglq_entry->list,
8031 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008032 sglq_entry->state = SGL_FREED;
8033 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008034 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008035 lpfc_set_rrq_active(phba, ndlp,
8036 sglq_entry->sli4_lxritag,
8037 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008038
8039 /* Check if TXQ queue needs to be serviced */
8040 if (pring->txq_cnt)
8041 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008042 return;
8043 }
8044 }
James Smart0f65ff62010-02-26 14:14:23 -05008045 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008046 lxri = lpfc_sli4_xri_inrange(phba, xri);
8047 if (lxri == NO_XRI) {
8048 spin_unlock_irqrestore(&phba->hbalock, iflag);
8049 return;
8050 }
8051 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008052 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8053 spin_unlock_irqrestore(&phba->hbalock, iflag);
8054 return;
8055 }
8056 sglq_entry->state = SGL_XRI_ABORTED;
8057 spin_unlock_irqrestore(&phba->hbalock, iflag);
8058 return;
James Smart6fb120a2009-05-22 14:52:59 -04008059}
James Smart086a3452012-08-14 14:25:21 -04008060
8061/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8062 * @vport: pointer to virtual port object.
8063 * @ndlp: nodelist pointer for the impacted node.
8064 *
8065 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8066 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8067 * the driver is required to send a LOGO to the remote node before it
8068 * attempts to recover its login to the remote node.
8069 */
8070void
8071lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8072 struct lpfc_nodelist *ndlp)
8073{
8074 struct Scsi_Host *shost;
8075 struct lpfc_hba *phba;
8076 unsigned long flags = 0;
8077
8078 shost = lpfc_shost_from_vport(vport);
8079 phba = vport->phba;
8080 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8081 lpfc_printf_log(phba, KERN_INFO,
8082 LOG_SLI, "3093 No rport recovery needed. "
8083 "rport in state 0x%x\n", ndlp->nlp_state);
8084 return;
8085 }
8086 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8087 "3094 Start rport recovery on shost id 0x%x "
8088 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8089 "flags 0x%x\n",
8090 shost->host_no, ndlp->nlp_DID,
8091 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8092 ndlp->nlp_flag);
8093 /*
8094 * The rport is not responding. Remove the FCP-2 flag to prevent
8095 * an ADISC in the follow-up recovery code.
8096 */
8097 spin_lock_irqsave(shost->host_lock, flags);
8098 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8099 spin_unlock_irqrestore(shost->host_lock, flags);
8100 lpfc_issue_els_logo(vport, ndlp, 0);
8101 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8102}
8103