blob: e0e0dd0a5df2b617d0a9eb8b360d69dd7f8acadc [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) &&
965 (irsp->un.ulpWord[4] == IOERR_SLI_ABORTED))
966 goto stop_rr_fcf_flogi;
967 else
968 phba->fcoe_cvl_eventtag_attn =
969 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500970 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400971 "2611 FLOGI failed on FCF (x%x), "
972 "status:x%x/x%x, tmo:x%x, perform "
973 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400974 phba->fcf.current_rec.fcf_indx,
975 irsp->ulpStatus, irsp->un.ulpWord[4],
976 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400977 lpfc_sli4_set_fcf_flogi_fail(phba,
978 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500979 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400980 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
981 if (rc)
982 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500983 }
984
James Smart80c17842012-03-01 22:35:45 -0500985stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400986 /* FLOGI failure */
987 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
988 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
989 irsp->ulpStatus, irsp->un.ulpWord[4],
990 irsp->ulpTimeout);
991
dea31012005-04-17 16:05:31 -0500992 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500993 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500994 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500995
James Smart76a95d72010-11-20 23:11:48 -0500996 /* FLOGI failure */
997 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
998 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
999 irsp->ulpStatus, irsp->un.ulpWord[4],
1000 irsp->ulpTimeout);
1001
dea31012005-04-17 16:05:31 -05001002 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001003 spin_lock_irq(shost->host_lock);
1004 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1005 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001006
James Smart329f9bc2007-04-25 09:53:01 -04001007 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001008 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1009 * alpa map would take too long otherwise.
1010 */
James Smart1b511972011-12-13 13:23:09 -05001011 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001012 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001013 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1014 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1015 (vport->fc_prevDID != vport->fc_myDID))) {
1016 if (vport->fc_flag & FC_VFI_REGISTERED)
1017 lpfc_sli4_unreg_all_rpis(vport);
1018 lpfc_issue_reg_vfi(vport);
1019 lpfc_nlp_put(ndlp);
1020 goto out;
dea31012005-04-17 16:05:31 -05001021 }
dea31012005-04-17 16:05:31 -05001022 goto flogifail;
1023 }
James Smart695a8142010-01-26 23:08:03 -05001024 spin_lock_irq(shost->host_lock);
1025 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001026 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001027 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001028
1029 /*
1030 * The FLogI succeeded. Sync the data for the CPU before
1031 * accessing it.
1032 */
1033 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1034
1035 sp = prsp->virt + sizeof(uint32_t);
1036
1037 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001038 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001039 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001040 "Data: x%x x%x x%x x%x\n",
1041 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1042 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001043
James Smart2e0fef82007-06-17 19:56:36 -05001044 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001045 /*
1046 * If Common Service Parameters indicate Nport
1047 * we are point to point, if Fport we are Fabric.
1048 */
1049 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001050 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001051 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001052 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001053 else {
1054 lpfc_printf_vlog(vport, KERN_ERR,
1055 LOG_FIP | LOG_ELS,
1056 "2831 FLOGI response with cleared Fabric "
1057 "bit fcf_index 0x%x "
1058 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1059 "Fabric Name "
1060 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1061 phba->fcf.current_rec.fcf_indx,
1062 phba->fcf.current_rec.switch_name[0],
1063 phba->fcf.current_rec.switch_name[1],
1064 phba->fcf.current_rec.switch_name[2],
1065 phba->fcf.current_rec.switch_name[3],
1066 phba->fcf.current_rec.switch_name[4],
1067 phba->fcf.current_rec.switch_name[5],
1068 phba->fcf.current_rec.switch_name[6],
1069 phba->fcf.current_rec.switch_name[7],
1070 phba->fcf.current_rec.fabric_name[0],
1071 phba->fcf.current_rec.fabric_name[1],
1072 phba->fcf.current_rec.fabric_name[2],
1073 phba->fcf.current_rec.fabric_name[3],
1074 phba->fcf.current_rec.fabric_name[4],
1075 phba->fcf.current_rec.fabric_name[5],
1076 phba->fcf.current_rec.fabric_name[6],
1077 phba->fcf.current_rec.fabric_name[7]);
1078 lpfc_nlp_put(ndlp);
1079 spin_lock_irq(&phba->hbalock);
1080 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001081 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001082 spin_unlock_irq(&phba->hbalock);
1083 goto out;
1084 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001085 if (!rc) {
1086 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001087 if (phba->hba_flag & HBA_FIP_SUPPORT)
1088 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1089 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001090 "2769 FLOGI to FCF (x%x) "
1091 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001092 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001093 spin_lock_irq(&phba->hbalock);
1094 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001095 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001096 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001097 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001098 }
dea31012005-04-17 16:05:31 -05001099 }
1100
1101flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001102 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001103
James Smart858c9f62007-06-17 19:56:39 -05001104 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001105 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001106 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001107
1108 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001110 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1111 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1112 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
1113 (phba->link_state != LPFC_CLEAR_LA)) {
1114 /* If FLOGI failed enable link interrupt. */
1115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001116 }
dea31012005-04-17 16:05:31 -05001117out:
1118 lpfc_els_free_iocb(phba, cmdiocb);
1119}
1120
James Smarte59058c2008-08-24 21:49:00 -04001121/**
James Smart3621a712009-04-06 18:47:14 -04001122 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001123 * @vport: pointer to a host virtual N_Port data structure.
1124 * @ndlp: pointer to a node-list data structure.
1125 * @retry: number of retries to the command IOCB.
1126 *
1127 * This routine issues a Fabric Login (FLOGI) Request ELS command
1128 * for a @vport. The initiator service parameters are put into the payload
1129 * of the FLOGI Request IOCB and the top-level callback function pointer
1130 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1131 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1132 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1133 *
1134 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1135 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1136 * will be stored into the context1 field of the IOCB for the completion
1137 * callback function to the FLOGI ELS command.
1138 *
1139 * Return code
1140 * 0 - successfully issued flogi iocb for @vport
1141 * 1 - failed to issue flogi iocb for @vport
1142 **/
dea31012005-04-17 16:05:31 -05001143static int
James Smart2e0fef82007-06-17 19:56:36 -05001144lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001145 uint8_t retry)
1146{
James Smart2e0fef82007-06-17 19:56:36 -05001147 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001148 struct serv_parm *sp;
1149 IOCB_t *icmd;
1150 struct lpfc_iocbq *elsiocb;
1151 struct lpfc_sli_ring *pring;
1152 uint8_t *pcmd;
1153 uint16_t cmdsize;
1154 uint32_t tmo;
1155 int rc;
1156
1157 pring = &phba->sli.ring[LPFC_ELS_RING];
1158
James Smart92d7f7b2007-06-17 19:56:38 -05001159 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001160 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1161 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001162
James Smart488d1462006-03-07 15:02:37 -05001163 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001164 return 1;
dea31012005-04-17 16:05:31 -05001165
1166 icmd = &elsiocb->iocb;
1167 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1168
1169 /* For FLOGI request, remainder of payload is service parameters */
1170 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001171 pcmd += sizeof(uint32_t);
1172 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001173 sp = (struct serv_parm *) pcmd;
1174
1175 /* Setup CSPs accordingly for Fabric */
1176 sp->cmn.e_d_tov = 0;
1177 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001178 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001179 sp->cls1.classValid = 0;
1180 sp->cls2.seqDelivery = 1;
1181 sp->cls3.seqDelivery = 1;
1182 if (sp->cmn.fcphLow < FC_PH3)
1183 sp->cmn.fcphLow = FC_PH3;
1184 if (sp->cmn.fcphHigh < FC_PH3)
1185 sp->cmn.fcphHigh = FC_PH3;
1186
James Smartc31098c2011-04-16 11:03:33 -04001187 if (phba->sli_rev == LPFC_SLI_REV4) {
1188 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1189 LPFC_SLI_INTF_IF_TYPE_0) {
1190 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1191 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1192 /* FLOGI needs to be 3 for WQE FCFI */
1193 /* Set the fcfi to the fcfi we registered with */
1194 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1195 }
James Smart5248a742011-07-22 18:37:06 -04001196 } else {
1197 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1198 sp->cmn.request_multiple_Nport = 1;
1199 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1200 icmd->ulpCt_h = 1;
1201 icmd->ulpCt_l = 0;
1202 } else
1203 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001204 }
1205
James Smart76a95d72010-11-20 23:11:48 -05001206 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001207 icmd->un.elsreq64.myID = 0;
1208 icmd->un.elsreq64.fl = 1;
1209 }
1210
dea31012005-04-17 16:05:31 -05001211 tmo = phba->fc_ratov;
1212 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001213 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001214 phba->fc_ratov = tmo;
1215
1216 phba->fc_stat.elsXmitFLOGI++;
1217 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001218
1219 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1220 "Issue FLOGI: opt:x%x",
1221 phba->sli3_options, 0, 0);
1222
James Smart92d7f7b2007-06-17 19:56:38 -05001223 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001224 if (rc == IOCB_ERROR) {
1225 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001226 return 1;
dea31012005-04-17 16:05:31 -05001227 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001228 return 0;
dea31012005-04-17 16:05:31 -05001229}
1230
James Smarte59058c2008-08-24 21:49:00 -04001231/**
James Smart3621a712009-04-06 18:47:14 -04001232 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001233 * @phba: pointer to lpfc hba data structure.
1234 *
1235 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1236 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1237 * list and issues an abort IOCB commond on each outstanding IOCB that
1238 * contains a active Fabric_DID ndlp. Note that this function is to issue
1239 * the abort IOCB command on all the outstanding IOCBs, thus when this
1240 * function returns, it does not guarantee all the IOCBs are actually aborted.
1241 *
1242 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001243 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001244 **/
dea31012005-04-17 16:05:31 -05001245int
James Smart2e0fef82007-06-17 19:56:36 -05001246lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001247{
1248 struct lpfc_sli_ring *pring;
1249 struct lpfc_iocbq *iocb, *next_iocb;
1250 struct lpfc_nodelist *ndlp;
1251 IOCB_t *icmd;
1252
1253 /* Abort outstanding I/O on NPort <nlp_DID> */
1254 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001255 "0201 Abort outstanding I/O on NPort x%x\n",
1256 Fabric_DID);
dea31012005-04-17 16:05:31 -05001257
1258 pring = &phba->sli.ring[LPFC_ELS_RING];
1259
1260 /*
1261 * Check the txcmplq for an iocb that matches the nport the driver is
1262 * searching for.
1263 */
James Smart2e0fef82007-06-17 19:56:36 -05001264 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001265 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1266 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001267 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001268 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001269 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1270 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001271 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001272 }
1273 }
James Smart2e0fef82007-06-17 19:56:36 -05001274 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001275
1276 return 0;
1277}
1278
James Smarte59058c2008-08-24 21:49:00 -04001279/**
James Smart3621a712009-04-06 18:47:14 -04001280 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001281 * @vport: pointer to a host virtual N_Port data structure.
1282 *
1283 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1284 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1285 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1286 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1287 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1288 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1289 * @vport.
1290 *
1291 * Return code
1292 * 0 - failed to issue initial flogi for @vport
1293 * 1 - successfully issued initial flogi for @vport
1294 **/
dea31012005-04-17 16:05:31 -05001295int
James Smart2e0fef82007-06-17 19:56:36 -05001296lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001297{
James Smart2e0fef82007-06-17 19:56:36 -05001298 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001299 struct lpfc_nodelist *ndlp;
1300
James Smart98c9ea52007-10-27 13:37:33 -04001301 vport->port_state = LPFC_FLOGI;
1302 lpfc_set_disctmo(vport);
1303
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001304 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001305 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001306 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001307 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001308 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1309 if (!ndlp)
1310 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001312 /* Set the node type */
1313 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001314 /* Put ndlp onto node list */
1315 lpfc_enqueue_node(vport, ndlp);
1316 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1317 /* re-setup ndlp without removing from node list */
1318 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1319 if (!ndlp)
1320 return 0;
dea31012005-04-17 16:05:31 -05001321 }
James Smart87af33f2007-10-27 13:37:43 -04001322
James Smart5ac6b302010-10-22 11:05:36 -04001323 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001324 /* This decrement of reference count to node shall kick off
1325 * the release of the node.
1326 */
James Smart329f9bc2007-04-25 09:53:01 -04001327 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001328 return 0;
1329 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001330 return 1;
dea31012005-04-17 16:05:31 -05001331}
1332
James Smarte59058c2008-08-24 21:49:00 -04001333/**
James Smart3621a712009-04-06 18:47:14 -04001334 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001335 * @vport: pointer to a host virtual N_Port data structure.
1336 *
1337 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1338 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1339 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1340 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1341 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1342 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1343 * @vport.
1344 *
1345 * Return code
1346 * 0 - failed to issue initial fdisc for @vport
1347 * 1 - successfully issued initial fdisc for @vport
1348 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001349int
1350lpfc_initial_fdisc(struct lpfc_vport *vport)
1351{
1352 struct lpfc_hba *phba = vport->phba;
1353 struct lpfc_nodelist *ndlp;
1354
1355 /* First look for the Fabric ndlp */
1356 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1357 if (!ndlp) {
1358 /* Cannot find existing Fabric ndlp, so allocate a new one */
1359 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1360 if (!ndlp)
1361 return 0;
1362 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001363 /* Put ndlp onto node list */
1364 lpfc_enqueue_node(vport, ndlp);
1365 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1366 /* re-setup ndlp without removing from node list */
1367 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1368 if (!ndlp)
1369 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001370 }
James Smarte47c9092008-02-08 18:49:26 -05001371
James Smart92d7f7b2007-06-17 19:56:38 -05001372 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001373 /* decrement node reference count to trigger the release of
1374 * the node.
1375 */
James Smart92d7f7b2007-06-17 19:56:38 -05001376 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001377 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001378 }
1379 return 1;
1380}
James Smart87af33f2007-10-27 13:37:43 -04001381
James Smarte59058c2008-08-24 21:49:00 -04001382/**
James Smart3621a712009-04-06 18:47:14 -04001383 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001384 * @vport: pointer to a host virtual N_Port data structure.
1385 *
1386 * This routine checks whether there are more remaining Port Logins
1387 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1388 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1389 * to issue ELS PLOGIs up to the configured discover threads with the
1390 * @vport (@vport->cfg_discovery_threads). The function also decrement
1391 * the @vport's num_disc_node by 1 if it is not already 0.
1392 **/
James Smart87af33f2007-10-27 13:37:43 -04001393void
James Smart2e0fef82007-06-17 19:56:36 -05001394lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001395{
1396 int sentplogi;
1397
James Smart2e0fef82007-06-17 19:56:36 -05001398 if (vport->num_disc_nodes)
1399 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001400
1401 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001402 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1403 "0232 Continue discovery with %d PLOGIs to go "
1404 "Data: x%x x%x x%x\n",
1405 vport->num_disc_nodes, vport->fc_plogi_cnt,
1406 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001407 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001408 if (vport->fc_flag & FC_NLP_MORE)
1409 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1410 sentplogi = lpfc_els_disc_plogi(vport);
1411
dea31012005-04-17 16:05:31 -05001412 return;
1413}
1414
James Smarte59058c2008-08-24 21:49:00 -04001415/**
James Smart3621a712009-04-06 18:47:14 -04001416 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001417 * @phba: pointer to lpfc hba data structure.
1418 * @prsp: pointer to response IOCB payload.
1419 * @ndlp: pointer to a node-list data structure.
1420 *
1421 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1422 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1423 * The following cases are considered N_Port confirmed:
1424 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1425 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1426 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1427 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1428 * 1) if there is a node on vport list other than the @ndlp with the same
1429 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1430 * on that node to release the RPI associated with the node; 2) if there is
1431 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1432 * into, a new node shall be allocated (or activated). In either case, the
1433 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1434 * be released and the new_ndlp shall be put on to the vport node list and
1435 * its pointer returned as the confirmed node.
1436 *
1437 * Note that before the @ndlp got "released", the keepDID from not-matching
1438 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1439 * of the @ndlp. This is because the release of @ndlp is actually to put it
1440 * into an inactive state on the vport node list and the vport node list
1441 * management algorithm does not allow two node with a same DID.
1442 *
1443 * Return code
1444 * pointer to the PLOGI N_Port @ndlp
1445 **/
James Smart488d1462006-03-07 15:02:37 -05001446static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001447lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001448 struct lpfc_nodelist *ndlp)
1449{
James Smart2e0fef82007-06-17 19:56:36 -05001450 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001451 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001452 struct lpfc_rport_data *rdata;
1453 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001454 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001455 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001456 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001457 int put_node;
1458 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001459 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001460
James Smart2fb9bd82006-12-02 13:33:57 -05001461 /* Fabric nodes can have the same WWPN so we don't bother searching
1462 * by WWPN. Just return the ndlp that was given to us.
1463 */
1464 if (ndlp->nlp_type & NLP_FABRIC)
1465 return ndlp;
1466
James Smart92d7f7b2007-06-17 19:56:38 -05001467 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001468 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001469
James Smart685f0bf2007-04-25 09:53:08 -04001470 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001471 * we have for that ndlp. If not, we have some work to do.
1472 */
James Smart2e0fef82007-06-17 19:56:36 -05001473 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001474
James Smarte47c9092008-02-08 18:49:26 -05001475 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001476 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001477 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001478
James Smart34f5ad82012-08-03 12:35:03 -04001479 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1480 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1481 ndlp, ndlp->nlp_DID, new_ndlp);
1482
James Smart488d1462006-03-07 15:02:37 -05001483 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001484 rc = memcmp(&ndlp->nlp_portname, name,
1485 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001486 if (!rc)
1487 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001488 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1489 if (!new_ndlp)
1490 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001491 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001492 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001493 rc = memcmp(&ndlp->nlp_portname, name,
1494 sizeof(struct lpfc_name));
1495 if (!rc)
1496 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001497 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1498 NLP_STE_UNUSED_NODE);
1499 if (!new_ndlp)
1500 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001501 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001502 if (phba->sli_rev == LPFC_SLI_REV4)
1503 memcpy(&rrq.xri_bitmap,
1504 &new_ndlp->active_rrqs.xri_bitmap,
1505 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1506 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001507 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001508 if (phba->sli_rev == LPFC_SLI_REV4)
1509 memcpy(&rrq.xri_bitmap,
1510 &new_ndlp->active_rrqs.xri_bitmap,
1511 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1512 }
James Smart488d1462006-03-07 15:02:37 -05001513
James Smart2e0fef82007-06-17 19:56:36 -05001514 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001515 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001516 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001517 if (phba->sli_rev == LPFC_SLI_REV4)
1518 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1519 &ndlp->active_rrqs.xri_bitmap,
1520 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001521
1522 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1523 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1524 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1525
James Smarte47c9092008-02-08 18:49:26 -05001526 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001527 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001528
James Smart2e0fef82007-06-17 19:56:36 -05001529 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001530 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1531 /* The new_ndlp is replacing ndlp totally, so we need
1532 * to put ndlp on UNUSED list and try to free it.
1533 */
James Smart34f5ad82012-08-03 12:35:03 -04001534 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1535 "3179 PLOGI confirm NEW: %x %x\n",
1536 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001537
1538 /* Fix up the rport accordingly */
1539 rport = ndlp->rport;
1540 if (rport) {
1541 rdata = rport->dd_data;
1542 if (rdata->pnode == ndlp) {
1543 lpfc_nlp_put(ndlp);
1544 ndlp->rport = NULL;
1545 rdata->pnode = lpfc_nlp_get(new_ndlp);
1546 new_ndlp->rport = rport;
1547 }
1548 new_ndlp->nlp_type = ndlp->nlp_type;
1549 }
James Smart58da1ff2008-04-07 10:15:56 -04001550 /* We shall actually free the ndlp with both nlp_DID and
1551 * nlp_portname fields equals 0 to avoid any ndlp on the
1552 * nodelist never to be used.
1553 */
1554 if (ndlp->nlp_DID == 0) {
1555 spin_lock_irq(&phba->ndlp_lock);
1556 NLP_SET_FREE_REQ(ndlp);
1557 spin_unlock_irq(&phba->ndlp_lock);
1558 }
James Smart0ff10d42008-01-11 01:52:36 -05001559
James Smart58da1ff2008-04-07 10:15:56 -04001560 /* Two ndlps cannot have the same did on the nodelist */
1561 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001562 if (phba->sli_rev == LPFC_SLI_REV4)
1563 memcpy(&ndlp->active_rrqs.xri_bitmap,
1564 &rrq.xri_bitmap,
1565 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001566 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001567 }
James Smart92795652006-07-06 15:50:02 -04001568 else {
James Smart34f5ad82012-08-03 12:35:03 -04001569 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1570 "3180 PLOGI confirm SWAP: %x %x\n",
1571 new_ndlp->nlp_DID, keepDID);
1572
James Smart2e0fef82007-06-17 19:56:36 -05001573 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001574
James Smart58da1ff2008-04-07 10:15:56 -04001575 /* Two ndlps cannot have the same did */
1576 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001577 if (phba->sli_rev == LPFC_SLI_REV4)
1578 memcpy(&ndlp->active_rrqs.xri_bitmap,
1579 &rrq.xri_bitmap,
1580 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001581
James Smart38b92ef2010-08-04 16:11:39 -04001582 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001583 * and the did has already been swapped, copy over state.
1584 * The new WWNs are already in new_ndlp since thats what
1585 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001586 */
James Smart38b92ef2010-08-04 16:11:39 -04001587 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001588
1589 /* Since we are switching over to the new_ndlp, the old
1590 * ndlp should be put in the NPR state, unless we have
1591 * already started re-discovery on it.
1592 */
1593 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1594 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1595 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1596
James Smart38b92ef2010-08-04 16:11:39 -04001597 /* Fix up the rport accordingly */
1598 rport = ndlp->rport;
1599 if (rport) {
1600 rdata = rport->dd_data;
1601 put_node = rdata->pnode != NULL;
1602 put_rport = ndlp->rport != NULL;
1603 rdata->pnode = NULL;
1604 ndlp->rport = NULL;
1605 if (put_node)
1606 lpfc_nlp_put(ndlp);
1607 if (put_rport)
1608 put_device(&rport->dev);
1609 }
James Smart92795652006-07-06 15:50:02 -04001610 }
James Smart488d1462006-03-07 15:02:37 -05001611 return new_ndlp;
1612}
1613
James Smarte59058c2008-08-24 21:49:00 -04001614/**
James Smart3621a712009-04-06 18:47:14 -04001615 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001616 * @vport: pointer to a host virtual N_Port data structure.
1617 *
1618 * This routine checks whether more Registration State Change
1619 * Notifications (RSCNs) came in while the discovery state machine was in
1620 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1621 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1622 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1623 * handling the RSCNs.
1624 **/
James Smart87af33f2007-10-27 13:37:43 -04001625void
1626lpfc_end_rscn(struct lpfc_vport *vport)
1627{
1628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1629
1630 if (vport->fc_flag & FC_RSCN_MODE) {
1631 /*
1632 * Check to see if more RSCNs came in while we were
1633 * processing this one.
1634 */
1635 if (vport->fc_rscn_id_cnt ||
1636 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1637 lpfc_els_handle_rscn(vport);
1638 else {
1639 spin_lock_irq(shost->host_lock);
1640 vport->fc_flag &= ~FC_RSCN_MODE;
1641 spin_unlock_irq(shost->host_lock);
1642 }
1643 }
1644}
1645
James Smarte59058c2008-08-24 21:49:00 -04001646/**
James Smart19ca7602010-11-20 23:11:55 -05001647 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1648 * @phba: pointer to lpfc hba data structure.
1649 * @cmdiocb: pointer to lpfc command iocb data structure.
1650 * @rspiocb: pointer to lpfc response iocb data structure.
1651 *
1652 * This routine will call the clear rrq function to free the rrq and
1653 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1654 * exist then the clear_rrq is still called because the rrq needs to
1655 * be freed.
1656 **/
1657
1658static void
1659lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1660 struct lpfc_iocbq *rspiocb)
1661{
1662 struct lpfc_vport *vport = cmdiocb->vport;
1663 IOCB_t *irsp;
1664 struct lpfc_nodelist *ndlp;
1665 struct lpfc_node_rrq *rrq;
1666
1667 /* we pass cmdiocb to state machine which needs rspiocb as well */
1668 rrq = cmdiocb->context_un.rrq;
1669 cmdiocb->context_un.rsp_iocb = rspiocb;
1670
1671 irsp = &rspiocb->iocb;
1672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1673 "RRQ cmpl: status:x%x/x%x did:x%x",
1674 irsp->ulpStatus, irsp->un.ulpWord[4],
1675 irsp->un.elsreq64.remoteID);
1676
1677 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1678 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1679 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1680 "2882 RRQ completes to NPort x%x "
1681 "with no ndlp. Data: x%x x%x x%x\n",
1682 irsp->un.elsreq64.remoteID,
1683 irsp->ulpStatus, irsp->un.ulpWord[4],
1684 irsp->ulpIoTag);
1685 goto out;
1686 }
1687
1688 /* rrq completes to NPort <nlp_DID> */
1689 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1690 "2880 RRQ completes to NPort x%x "
1691 "Data: x%x x%x x%x x%x x%x\n",
1692 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1693 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1694
1695 if (irsp->ulpStatus) {
1696 /* Check for retry */
1697 /* RRQ failed Don't print the vport to vport rjts */
1698 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1699 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1700 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1701 (phba)->pport->cfg_log_verbose & LOG_ELS)
1702 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1703 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1704 ndlp->nlp_DID, irsp->ulpStatus,
1705 irsp->un.ulpWord[4]);
1706 }
1707out:
1708 if (rrq)
1709 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1710 lpfc_els_free_iocb(phba, cmdiocb);
1711 return;
1712}
1713/**
James Smart3621a712009-04-06 18:47:14 -04001714 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001715 * @phba: pointer to lpfc hba data structure.
1716 * @cmdiocb: pointer to lpfc command iocb data structure.
1717 * @rspiocb: pointer to lpfc response iocb data structure.
1718 *
1719 * This routine is the completion callback function for issuing the Port
1720 * Login (PLOGI) command. For PLOGI completion, there must be an active
1721 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001722 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001723 * ignored and command IOCB released. The PLOGI response IOCB status is
1724 * checked for error conditons. If there is error status reported, PLOGI
1725 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1726 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1727 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1728 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1729 * there are additional N_Port nodes with the vport that need to perform
1730 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1731 * PLOGIs.
1732 **/
dea31012005-04-17 16:05:31 -05001733static void
James Smart2e0fef82007-06-17 19:56:36 -05001734lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1735 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001736{
James Smart2e0fef82007-06-17 19:56:36 -05001737 struct lpfc_vport *vport = cmdiocb->vport;
1738 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001739 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001740 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001741 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001742 int disc, rc, did, type;
1743
dea31012005-04-17 16:05:31 -05001744 /* we pass cmdiocb to state machine which needs rspiocb as well */
1745 cmdiocb->context_un.rsp_iocb = rspiocb;
1746
1747 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1749 "PLOGI cmpl: status:x%x/x%x did:x%x",
1750 irsp->ulpStatus, irsp->un.ulpWord[4],
1751 irsp->un.elsreq64.remoteID);
1752
James Smart2e0fef82007-06-17 19:56:36 -05001753 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001754 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001755 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1756 "0136 PLOGI completes to NPort x%x "
1757 "with no ndlp. Data: x%x x%x x%x\n",
1758 irsp->un.elsreq64.remoteID,
1759 irsp->ulpStatus, irsp->un.ulpWord[4],
1760 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001761 goto out;
James Smarted957682007-06-17 19:56:37 -05001762 }
dea31012005-04-17 16:05:31 -05001763
1764 /* Since ndlp can be freed in the disc state machine, note if this node
1765 * is being used during discovery.
1766 */
James Smart2e0fef82007-06-17 19:56:36 -05001767 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001768 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001769 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001770 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001771 rc = 0;
1772
1773 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001774 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1775 "0102 PLOGI completes to NPort x%x "
1776 "Data: x%x x%x x%x x%x x%x\n",
1777 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1778 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001779 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001780 if (lpfc_els_chk_latt(vport)) {
1781 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001782 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001783 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001784 goto out;
1785 }
1786
1787 /* ndlp could be freed in DSM, save these values now */
1788 type = ndlp->nlp_type;
1789 did = ndlp->nlp_DID;
1790
1791 if (irsp->ulpStatus) {
1792 /* Check for retry */
1793 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1794 /* ELS command is being retried */
1795 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001796 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001797 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001798 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001799 }
1800 goto out;
1801 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001802 /* PLOGI failed Don't print the vport to vport rjts */
1803 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1804 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1805 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1806 (phba)->pport->cfg_log_verbose & LOG_ELS)
1807 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001808 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1809 ndlp->nlp_DID, irsp->ulpStatus,
1810 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001811 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001812 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001813 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001814 else
James Smart2e0fef82007-06-17 19:56:36 -05001815 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001816 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001817 } else {
1818 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001819 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001820 cmdiocb->context2)->list.next,
1821 struct lpfc_dmabuf, list);
1822 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001823 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001824 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001825 }
1826
James Smart2e0fef82007-06-17 19:56:36 -05001827 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001828 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001829 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001830
James Smart2e0fef82007-06-17 19:56:36 -05001831 if (vport->num_disc_nodes == 0) {
1832 spin_lock_irq(shost->host_lock);
1833 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1834 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001835
James Smart2e0fef82007-06-17 19:56:36 -05001836 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001837 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001838 }
1839 }
1840
1841out:
1842 lpfc_els_free_iocb(phba, cmdiocb);
1843 return;
1844}
1845
James Smarte59058c2008-08-24 21:49:00 -04001846/**
James Smart3621a712009-04-06 18:47:14 -04001847 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001848 * @vport: pointer to a host virtual N_Port data structure.
1849 * @did: destination port identifier.
1850 * @retry: number of retries to the command IOCB.
1851 *
1852 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1853 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1854 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1855 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1856 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1857 *
1858 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1859 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1860 * will be stored into the context1 field of the IOCB for the completion
1861 * callback function to the PLOGI ELS command.
1862 *
1863 * Return code
1864 * 0 - Successfully issued a plogi for @vport
1865 * 1 - failed to issue a plogi for @vport
1866 **/
dea31012005-04-17 16:05:31 -05001867int
James Smart2e0fef82007-06-17 19:56:36 -05001868lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001869{
James Smart2e0fef82007-06-17 19:56:36 -05001870 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001871 struct serv_parm *sp;
1872 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001873 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001874 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001875 struct lpfc_sli *psli;
1876 uint8_t *pcmd;
1877 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001878 int ret;
dea31012005-04-17 16:05:31 -05001879
1880 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001881
James Smart98c9ea52007-10-27 13:37:33 -04001882 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001883 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1884 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001885
James Smarte47c9092008-02-08 18:49:26 -05001886 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001887 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001888 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001889 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001890 if (!elsiocb)
1891 return 1;
dea31012005-04-17 16:05:31 -05001892
1893 icmd = &elsiocb->iocb;
1894 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1895
1896 /* For PLOGI request, remainder of payload is service parameters */
1897 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001898 pcmd += sizeof(uint32_t);
1899 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001900 sp = (struct serv_parm *) pcmd;
1901
James Smart5ac6b302010-10-22 11:05:36 -04001902 /*
1903 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1904 * to device on remote loops work.
1905 */
1906 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1907 sp->cmn.altBbCredit = 1;
1908
dea31012005-04-17 16:05:31 -05001909 if (sp->cmn.fcphLow < FC_PH_4_3)
1910 sp->cmn.fcphLow = FC_PH_4_3;
1911
1912 if (sp->cmn.fcphHigh < FC_PH3)
1913 sp->cmn.fcphHigh = FC_PH3;
1914
James Smart858c9f62007-06-17 19:56:39 -05001915 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1916 "Issue PLOGI: did:x%x",
1917 did, 0, 0);
1918
dea31012005-04-17 16:05:31 -05001919 phba->fc_stat.elsXmitPLOGI++;
1920 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001921 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001922
1923 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001924 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001925 return 1;
dea31012005-04-17 16:05:31 -05001926 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001927 return 0;
dea31012005-04-17 16:05:31 -05001928}
1929
James Smarte59058c2008-08-24 21:49:00 -04001930/**
James Smart3621a712009-04-06 18:47:14 -04001931 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001932 * @phba: pointer to lpfc hba data structure.
1933 * @cmdiocb: pointer to lpfc command iocb data structure.
1934 * @rspiocb: pointer to lpfc response iocb data structure.
1935 *
1936 * This routine is the completion callback function for a Process Login
1937 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1938 * status. If there is error status reported, PRLI retry shall be attempted
1939 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1940 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1941 * ndlp to mark the PRLI completion.
1942 **/
dea31012005-04-17 16:05:31 -05001943static void
James Smart2e0fef82007-06-17 19:56:36 -05001944lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1945 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001946{
James Smart2e0fef82007-06-17 19:56:36 -05001947 struct lpfc_vport *vport = cmdiocb->vport;
1948 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001949 IOCB_t *irsp;
1950 struct lpfc_sli *psli;
1951 struct lpfc_nodelist *ndlp;
1952
1953 psli = &phba->sli;
1954 /* we pass cmdiocb to state machine which needs rspiocb as well */
1955 cmdiocb->context_un.rsp_iocb = rspiocb;
1956
1957 irsp = &(rspiocb->iocb);
1958 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001962
James Smart858c9f62007-06-17 19:56:39 -05001963 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1964 "PRLI cmpl: status:x%x/x%x did:x%x",
1965 irsp->ulpStatus, irsp->un.ulpWord[4],
1966 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001967 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001968 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1969 "0103 PRLI completes to NPort x%x "
1970 "Data: x%x x%x x%x x%x\n",
1971 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1972 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001973
James Smart2e0fef82007-06-17 19:56:36 -05001974 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001975 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001976 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001977 goto out;
1978
1979 if (irsp->ulpStatus) {
1980 /* Check for retry */
1981 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1982 /* ELS command is being retried */
1983 goto out;
1984 }
1985 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001986 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1987 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1988 ndlp->nlp_DID, irsp->ulpStatus,
1989 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001990 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001991 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001992 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001993 else
James Smart2e0fef82007-06-17 19:56:36 -05001994 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001995 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001996 } else
dea31012005-04-17 16:05:31 -05001997 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001998 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001999 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002000out:
2001 lpfc_els_free_iocb(phba, cmdiocb);
2002 return;
2003}
2004
James Smarte59058c2008-08-24 21:49:00 -04002005/**
James Smart3621a712009-04-06 18:47:14 -04002006 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002007 * @vport: pointer to a host virtual N_Port data structure.
2008 * @ndlp: pointer to a node-list data structure.
2009 * @retry: number of retries to the command IOCB.
2010 *
2011 * This routine issues a Process Login (PRLI) ELS command for the
2012 * @vport. The PRLI service parameters are set up in the payload of the
2013 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2014 * is put to the IOCB completion callback func field before invoking the
2015 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2016 *
2017 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2018 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2019 * will be stored into the context1 field of the IOCB for the completion
2020 * callback function to the PRLI ELS command.
2021 *
2022 * Return code
2023 * 0 - successfully issued prli iocb command for @vport
2024 * 1 - failed to issue prli iocb command for @vport
2025 **/
dea31012005-04-17 16:05:31 -05002026int
James Smart2e0fef82007-06-17 19:56:36 -05002027lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002028 uint8_t retry)
2029{
James Smart2e0fef82007-06-17 19:56:36 -05002030 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2031 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002032 PRLI *npr;
2033 IOCB_t *icmd;
2034 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002035 uint8_t *pcmd;
2036 uint16_t cmdsize;
2037
James Smart92d7f7b2007-06-17 19:56:38 -05002038 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002039 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2040 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002041 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002042 return 1;
dea31012005-04-17 16:05:31 -05002043
2044 icmd = &elsiocb->iocb;
2045 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2046
2047 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002048 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002049 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002050 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002051
2052 /* For PRLI, remainder of payload is PRLI parameter page */
2053 npr = (PRLI *) pcmd;
2054 /*
2055 * If our firmware version is 3.20 or later,
2056 * set the following bits for FC-TAPE support.
2057 */
2058 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2059 npr->ConfmComplAllowed = 1;
2060 npr->Retry = 1;
2061 npr->TaskRetryIdReq = 1;
2062 }
2063 npr->estabImagePair = 1;
2064 npr->readXferRdyDis = 1;
2065
2066 /* For FCP support */
2067 npr->prliType = PRLI_FCP_TYPE;
2068 npr->initiatorFunc = 1;
2069
James Smart858c9f62007-06-17 19:56:39 -05002070 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2071 "Issue PRLI: did:x%x",
2072 ndlp->nlp_DID, 0, 0);
2073
dea31012005-04-17 16:05:31 -05002074 phba->fc_stat.elsXmitPRLI++;
2075 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002076 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002077 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002078 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002079 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2080 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002081 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002082 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002083 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002084 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002085 return 1;
dea31012005-04-17 16:05:31 -05002086 }
James Smart2e0fef82007-06-17 19:56:36 -05002087 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002088 return 0;
dea31012005-04-17 16:05:31 -05002089}
2090
James Smarte59058c2008-08-24 21:49:00 -04002091/**
James Smart3621a712009-04-06 18:47:14 -04002092 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002093 * @vport: pointer to a host virtual N_Port data structure.
2094 *
2095 * This routine performs Registration State Change Notification (RSCN)
2096 * discovery for a @vport. If the @vport's node port recovery count is not
2097 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2098 * the nodes that need recovery. If none of the PLOGI were needed through
2099 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2100 * invoked to check and handle possible more RSCN came in during the period
2101 * of processing the current ones.
2102 **/
2103static void
2104lpfc_rscn_disc(struct lpfc_vport *vport)
2105{
2106 lpfc_can_disctmo(vport);
2107
2108 /* RSCN discovery */
2109 /* go thru NPR nodes and issue ELS PLOGIs */
2110 if (vport->fc_npr_cnt)
2111 if (lpfc_els_disc_plogi(vport))
2112 return;
2113
2114 lpfc_end_rscn(vport);
2115}
2116
2117/**
James Smart3621a712009-04-06 18:47:14 -04002118 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002119 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2120 *
2121 * This function is called when the final ADISC is completed during discovery.
2122 * This function handles clearing link attention or issuing reg_vpi depending
2123 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2124 * discovery.
2125 * This function is called with no locks held.
2126 **/
2127static void
2128lpfc_adisc_done(struct lpfc_vport *vport)
2129{
2130 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2131 struct lpfc_hba *phba = vport->phba;
2132
2133 /*
2134 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2135 * and continue discovery.
2136 */
2137 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002138 !(vport->fc_flag & FC_RSCN_MODE) &&
2139 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002140 lpfc_issue_reg_vpi(phba, vport);
2141 return;
2142 }
2143 /*
2144 * For SLI2, we need to set port_state to READY
2145 * and continue discovery.
2146 */
2147 if (vport->port_state < LPFC_VPORT_READY) {
2148 /* If we get here, there is nothing to ADISC */
2149 if (vport->port_type == LPFC_PHYSICAL_PORT)
2150 lpfc_issue_clear_la(phba, vport);
2151 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2152 vport->num_disc_nodes = 0;
2153 /* go thru NPR list, issue ELS PLOGIs */
2154 if (vport->fc_npr_cnt)
2155 lpfc_els_disc_plogi(vport);
2156 if (!vport->num_disc_nodes) {
2157 spin_lock_irq(shost->host_lock);
2158 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2159 spin_unlock_irq(shost->host_lock);
2160 lpfc_can_disctmo(vport);
2161 lpfc_end_rscn(vport);
2162 }
2163 }
2164 vport->port_state = LPFC_VPORT_READY;
2165 } else
2166 lpfc_rscn_disc(vport);
2167}
2168
2169/**
James Smart3621a712009-04-06 18:47:14 -04002170 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002171 * @vport: pointer to a host virtual N_Port data structure.
2172 *
2173 * This routine determines whether there are more ndlps on a @vport
2174 * node list need to have Address Discover (ADISC) issued. If so, it will
2175 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2176 * remaining nodes which need to have ADISC sent.
2177 **/
James Smart0ff10d42008-01-11 01:52:36 -05002178void
James Smart2e0fef82007-06-17 19:56:36 -05002179lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002180{
2181 int sentadisc;
2182
James Smart2e0fef82007-06-17 19:56:36 -05002183 if (vport->num_disc_nodes)
2184 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002185 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2187 "0210 Continue discovery with %d ADISCs to go "
2188 "Data: x%x x%x x%x\n",
2189 vport->num_disc_nodes, vport->fc_adisc_cnt,
2190 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002191 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002192 if (vport->fc_flag & FC_NLP_MORE) {
2193 lpfc_set_disctmo(vport);
2194 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2195 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002196 }
James Smart90160e02008-08-24 21:49:45 -04002197 if (!vport->num_disc_nodes)
2198 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002199 return;
2200}
2201
James Smarte59058c2008-08-24 21:49:00 -04002202/**
James Smart3621a712009-04-06 18:47:14 -04002203 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002204 * @phba: pointer to lpfc hba data structure.
2205 * @cmdiocb: pointer to lpfc command iocb data structure.
2206 * @rspiocb: pointer to lpfc response iocb data structure.
2207 *
2208 * This routine is the completion function for issuing the Address Discover
2209 * (ADISC) command. It first checks to see whether link went down during
2210 * the discovery process. If so, the node will be marked as node port
2211 * recovery for issuing discover IOCB by the link attention handler and
2212 * exit. Otherwise, the response status is checked. If error was reported
2213 * in the response status, the ADISC command shall be retried by invoking
2214 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2215 * the response status, the state machine is invoked to set transition
2216 * with respect to NLP_EVT_CMPL_ADISC event.
2217 **/
dea31012005-04-17 16:05:31 -05002218static void
James Smart2e0fef82007-06-17 19:56:36 -05002219lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2220 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002221{
James Smart2e0fef82007-06-17 19:56:36 -05002222 struct lpfc_vport *vport = cmdiocb->vport;
2223 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002224 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002225 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002226 int disc;
dea31012005-04-17 16:05:31 -05002227
2228 /* we pass cmdiocb to state machine which needs rspiocb as well */
2229 cmdiocb->context_un.rsp_iocb = rspiocb;
2230
2231 irsp = &(rspiocb->iocb);
2232 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002233
James Smart858c9f62007-06-17 19:56:39 -05002234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2235 "ADISC cmpl: status:x%x/x%x did:x%x",
2236 irsp->ulpStatus, irsp->un.ulpWord[4],
2237 ndlp->nlp_DID);
2238
dea31012005-04-17 16:05:31 -05002239 /* Since ndlp can be freed in the disc state machine, note if this node
2240 * is being used during discovery.
2241 */
James Smart2e0fef82007-06-17 19:56:36 -05002242 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002243 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002244 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002245 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002246 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002247 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2248 "0104 ADISC completes to NPort x%x "
2249 "Data: x%x x%x x%x x%x x%x\n",
2250 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2251 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002252 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002253 if (lpfc_els_chk_latt(vport)) {
2254 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002255 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002256 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002257 goto out;
2258 }
2259
2260 if (irsp->ulpStatus) {
2261 /* Check for retry */
2262 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2263 /* ELS command is being retried */
2264 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002265 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002266 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002267 spin_unlock_irq(shost->host_lock);
2268 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002269 }
2270 goto out;
2271 }
2272 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002273 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2274 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2275 ndlp->nlp_DID, irsp->ulpStatus,
2276 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002277 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002278 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002279 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002280 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002281 } else
dea31012005-04-17 16:05:31 -05002282 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002283 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002284 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002285
James Smart90160e02008-08-24 21:49:45 -04002286 /* Check to see if there are more ADISCs to be sent */
2287 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002288 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002289out:
2290 lpfc_els_free_iocb(phba, cmdiocb);
2291 return;
2292}
2293
James Smarte59058c2008-08-24 21:49:00 -04002294/**
James Smart3621a712009-04-06 18:47:14 -04002295 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002296 * @vport: pointer to a virtual N_Port data structure.
2297 * @ndlp: pointer to a node-list data structure.
2298 * @retry: number of retries to the command IOCB.
2299 *
2300 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2301 * @vport. It prepares the payload of the ADISC ELS command, updates the
2302 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2303 * to issue the ADISC ELS command.
2304 *
2305 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2306 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2307 * will be stored into the context1 field of the IOCB for the completion
2308 * callback function to the ADISC ELS command.
2309 *
2310 * Return code
2311 * 0 - successfully issued adisc
2312 * 1 - failed to issue adisc
2313 **/
dea31012005-04-17 16:05:31 -05002314int
James Smart2e0fef82007-06-17 19:56:36 -05002315lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002316 uint8_t retry)
2317{
James Smart2e0fef82007-06-17 19:56:36 -05002318 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2319 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002320 ADISC *ap;
2321 IOCB_t *icmd;
2322 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002323 uint8_t *pcmd;
2324 uint16_t cmdsize;
2325
James Smart92d7f7b2007-06-17 19:56:38 -05002326 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002327 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2328 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002329 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002330 return 1;
dea31012005-04-17 16:05:31 -05002331
2332 icmd = &elsiocb->iocb;
2333 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2334
2335 /* For ADISC request, remainder of payload is service parameters */
2336 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002337 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002338
2339 /* Fill in ADISC payload */
2340 ap = (ADISC *) pcmd;
2341 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002342 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2343 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002344 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002345
James Smart858c9f62007-06-17 19:56:39 -05002346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2347 "Issue ADISC: did:x%x",
2348 ndlp->nlp_DID, 0, 0);
2349
dea31012005-04-17 16:05:31 -05002350 phba->fc_stat.elsXmitADISC++;
2351 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002352 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002353 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002354 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002355 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2356 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002358 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002359 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002360 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002361 return 1;
dea31012005-04-17 16:05:31 -05002362 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002363 return 0;
dea31012005-04-17 16:05:31 -05002364}
2365
James Smarte59058c2008-08-24 21:49:00 -04002366/**
James Smart3621a712009-04-06 18:47:14 -04002367 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002368 * @phba: pointer to lpfc hba data structure.
2369 * @cmdiocb: pointer to lpfc command iocb data structure.
2370 * @rspiocb: pointer to lpfc response iocb data structure.
2371 *
2372 * This routine is the completion function for issuing the ELS Logout (LOGO)
2373 * command. If no error status was reported from the LOGO response, the
2374 * state machine of the associated ndlp shall be invoked for transition with
2375 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2376 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2377 **/
dea31012005-04-17 16:05:31 -05002378static void
James Smart2e0fef82007-06-17 19:56:36 -05002379lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2380 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002381{
James Smart2e0fef82007-06-17 19:56:36 -05002382 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2383 struct lpfc_vport *vport = ndlp->vport;
2384 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002385 IOCB_t *irsp;
2386 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002387 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002388 unsigned long flags;
2389 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002390
2391 psli = &phba->sli;
2392 /* we pass cmdiocb to state machine which needs rspiocb as well */
2393 cmdiocb->context_un.rsp_iocb = rspiocb;
2394
2395 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002396 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002397 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002398 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002399
James Smart858c9f62007-06-17 19:56:39 -05002400 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2401 "LOGO cmpl: status:x%x/x%x did:x%x",
2402 irsp->ulpStatus, irsp->un.ulpWord[4],
2403 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002404
dea31012005-04-17 16:05:31 -05002405 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002406 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2407 "0105 LOGO completes to NPort x%x "
2408 "Data: x%x x%x x%x x%x\n",
2409 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2410 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002411
James Smart086a3452012-08-14 14:25:21 -04002412 if (lpfc_els_chk_latt(vport)) {
2413 skip_recovery = 1;
2414 goto out;
2415 }
2416
2417 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002418 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2419 /* NLP_EVT_DEVICE_RM should unregister the RPI
2420 * which should abort all outstanding IOs.
2421 */
2422 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2423 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002424 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002425 goto out;
2426 }
2427
dea31012005-04-17 16:05:31 -05002428 if (irsp->ulpStatus) {
2429 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002430 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002431 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002432 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002433 goto out;
James Smart086a3452012-08-14 14:25:21 -04002434 }
dea31012005-04-17 16:05:31 -05002435 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002436 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2437 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2438 ndlp->nlp_DID, irsp->ulpStatus,
2439 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002440 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002441 if (lpfc_error_lost_link(irsp)) {
2442 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002443 goto out;
James Smart086a3452012-08-14 14:25:21 -04002444 }
2445 }
2446
2447 /* Call state machine. This will unregister the rpi if needed. */
2448 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2449
dea31012005-04-17 16:05:31 -05002450out:
2451 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002452 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2453 if ((vport->fc_flag & FC_PT2PT) &&
2454 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2455 phba->pport->fc_myDID = 0;
2456 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2457 if (mbox) {
2458 lpfc_config_link(phba, mbox);
2459 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2460 mbox->vport = vport;
2461 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2462 MBX_NOT_FINISHED) {
2463 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002464 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002465 }
2466 }
2467 }
James Smart086a3452012-08-14 14:25:21 -04002468
2469 /*
2470 * If the node is a target, the handling attempts to recover the port.
2471 * For any other port type, the rpi is unregistered as an implicit
2472 * LOGO.
2473 */
2474 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2475 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2476 spin_lock_irqsave(shost->host_lock, flags);
2477 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2478 spin_unlock_irqrestore(shost->host_lock, flags);
2479
2480 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2481 "3187 LOGO completes to NPort x%x: Start "
2482 "Recovery Data: x%x x%x x%x x%x\n",
2483 ndlp->nlp_DID, irsp->ulpStatus,
2484 irsp->un.ulpWord[4], irsp->ulpTimeout,
2485 vport->num_disc_nodes);
2486 lpfc_disc_start(vport);
2487 }
dea31012005-04-17 16:05:31 -05002488 return;
2489}
2490
James Smarte59058c2008-08-24 21:49:00 -04002491/**
James Smart3621a712009-04-06 18:47:14 -04002492 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002493 * @vport: pointer to a virtual N_Port data structure.
2494 * @ndlp: pointer to a node-list data structure.
2495 * @retry: number of retries to the command IOCB.
2496 *
2497 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2498 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2499 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2500 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2501 *
2502 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2503 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2504 * will be stored into the context1 field of the IOCB for the completion
2505 * callback function to the LOGO ELS command.
2506 *
2507 * Return code
2508 * 0 - successfully issued logo
2509 * 1 - failed to issue logo
2510 **/
dea31012005-04-17 16:05:31 -05002511int
James Smart2e0fef82007-06-17 19:56:36 -05002512lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002513 uint8_t retry)
2514{
James Smart2e0fef82007-06-17 19:56:36 -05002515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2516 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002517 IOCB_t *icmd;
2518 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002519 uint8_t *pcmd;
2520 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002521 int rc;
dea31012005-04-17 16:05:31 -05002522
James Smart98c9ea52007-10-27 13:37:33 -04002523 spin_lock_irq(shost->host_lock);
2524 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2525 spin_unlock_irq(shost->host_lock);
2526 return 0;
2527 }
2528 spin_unlock_irq(shost->host_lock);
2529
James Smart92d7f7b2007-06-17 19:56:38 -05002530 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002531 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2532 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002533 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002534 return 1;
dea31012005-04-17 16:05:31 -05002535
2536 icmd = &elsiocb->iocb;
2537 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2538 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002539 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002540
2541 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002542 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002543 pcmd += sizeof(uint32_t);
2544 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002545
James Smart858c9f62007-06-17 19:56:39 -05002546 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2547 "Issue LOGO: did:x%x",
2548 ndlp->nlp_DID, 0, 0);
2549
James Smart086a3452012-08-14 14:25:21 -04002550 /*
2551 * If we are issuing a LOGO, we may try to recover the remote NPort
2552 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2553 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2554 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2555 * for that ELS cmd. To avoid this situation, lets get rid of the
2556 * RPI right now, before any ELS cmds are sent.
2557 */
2558 spin_lock_irq(shost->host_lock);
2559 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2560 spin_unlock_irq(shost->host_lock);
2561 if (lpfc_unreg_rpi(vport, ndlp)) {
2562 lpfc_els_free_iocb(phba, elsiocb);
2563 return 0;
2564 }
2565
dea31012005-04-17 16:05:31 -05002566 phba->fc_stat.elsXmitLOGO++;
2567 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002568 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002569 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002570 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002571 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002572 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002573
2574 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002575 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002576 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002577 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002578 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002579 return 1;
dea31012005-04-17 16:05:31 -05002580 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002581 return 0;
dea31012005-04-17 16:05:31 -05002582}
2583
James Smarte59058c2008-08-24 21:49:00 -04002584/**
James Smart3621a712009-04-06 18:47:14 -04002585 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002586 * @phba: pointer to lpfc hba data structure.
2587 * @cmdiocb: pointer to lpfc command iocb data structure.
2588 * @rspiocb: pointer to lpfc response iocb data structure.
2589 *
2590 * This routine is a generic completion callback function for ELS commands.
2591 * Specifically, it is the callback function which does not need to perform
2592 * any command specific operations. It is currently used by the ELS command
2593 * issuing routines for the ELS State Change Request (SCR),
2594 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2595 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2596 * certain debug loggings, this callback function simply invokes the
2597 * lpfc_els_chk_latt() routine to check whether link went down during the
2598 * discovery process.
2599 **/
dea31012005-04-17 16:05:31 -05002600static void
James Smart2e0fef82007-06-17 19:56:36 -05002601lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2602 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002603{
James Smart2e0fef82007-06-17 19:56:36 -05002604 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002605 IOCB_t *irsp;
2606
2607 irsp = &rspiocb->iocb;
2608
James Smart858c9f62007-06-17 19:56:39 -05002609 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2610 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2611 irsp->ulpStatus, irsp->un.ulpWord[4],
2612 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002613 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002614 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2615 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2616 irsp->ulpIoTag, irsp->ulpStatus,
2617 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002618 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002619 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002620 lpfc_els_free_iocb(phba, cmdiocb);
2621 return;
2622}
2623
James Smarte59058c2008-08-24 21:49:00 -04002624/**
James Smart3621a712009-04-06 18:47:14 -04002625 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002626 * @vport: pointer to a host virtual N_Port data structure.
2627 * @nportid: N_Port identifier to the remote node.
2628 * @retry: number of retries to the command IOCB.
2629 *
2630 * This routine issues a State Change Request (SCR) to a fabric node
2631 * on a @vport. The remote node @nportid is passed into the function. It
2632 * first search the @vport node list to find the matching ndlp. If no such
2633 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2634 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2635 * routine is invoked to send the SCR IOCB.
2636 *
2637 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2638 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2639 * will be stored into the context1 field of the IOCB for the completion
2640 * callback function to the SCR ELS command.
2641 *
2642 * Return code
2643 * 0 - Successfully issued scr command
2644 * 1 - Failed to issue scr command
2645 **/
dea31012005-04-17 16:05:31 -05002646int
James Smart2e0fef82007-06-17 19:56:36 -05002647lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002648{
James Smart2e0fef82007-06-17 19:56:36 -05002649 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002650 IOCB_t *icmd;
2651 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002652 struct lpfc_sli *psli;
2653 uint8_t *pcmd;
2654 uint16_t cmdsize;
2655 struct lpfc_nodelist *ndlp;
2656
2657 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002658 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002659
James Smarte47c9092008-02-08 18:49:26 -05002660 ndlp = lpfc_findnode_did(vport, nportid);
2661 if (!ndlp) {
2662 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2663 if (!ndlp)
2664 return 1;
2665 lpfc_nlp_init(vport, ndlp, nportid);
2666 lpfc_enqueue_node(vport, ndlp);
2667 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2668 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2669 if (!ndlp)
2670 return 1;
2671 }
dea31012005-04-17 16:05:31 -05002672
James Smart2e0fef82007-06-17 19:56:36 -05002673 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2674 ndlp->nlp_DID, ELS_CMD_SCR);
2675
James Smart488d1462006-03-07 15:02:37 -05002676 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002677 /* This will trigger the release of the node just
2678 * allocated
2679 */
James Smart329f9bc2007-04-25 09:53:01 -04002680 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002681 return 1;
dea31012005-04-17 16:05:31 -05002682 }
2683
2684 icmd = &elsiocb->iocb;
2685 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2686
2687 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002688 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002689
2690 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002691 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002692 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2693
James Smart858c9f62007-06-17 19:56:39 -05002694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2695 "Issue SCR: did:x%x",
2696 ndlp->nlp_DID, 0, 0);
2697
dea31012005-04-17 16:05:31 -05002698 phba->fc_stat.elsXmitSCR++;
2699 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002700 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2701 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002702 /* The additional lpfc_nlp_put will cause the following
2703 * lpfc_els_free_iocb routine to trigger the rlease of
2704 * the node.
2705 */
James Smart329f9bc2007-04-25 09:53:01 -04002706 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002707 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002708 return 1;
dea31012005-04-17 16:05:31 -05002709 }
James Smartfa4066b2008-01-11 01:53:27 -05002710 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2711 * trigger the release of node.
2712 */
James Smart329f9bc2007-04-25 09:53:01 -04002713 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002714 return 0;
dea31012005-04-17 16:05:31 -05002715}
2716
James Smarte59058c2008-08-24 21:49:00 -04002717/**
James Smart3621a712009-04-06 18:47:14 -04002718 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002719 * @vport: pointer to a host virtual N_Port data structure.
2720 * @nportid: N_Port identifier to the remote node.
2721 * @retry: number of retries to the command IOCB.
2722 *
2723 * This routine issues a Fibre Channel Address Resolution Response
2724 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2725 * is passed into the function. It first search the @vport node list to find
2726 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2727 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2728 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2729 *
2730 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2731 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2732 * will be stored into the context1 field of the IOCB for the completion
2733 * callback function to the PARPR ELS command.
2734 *
2735 * Return code
2736 * 0 - Successfully issued farpr command
2737 * 1 - Failed to issue farpr command
2738 **/
dea31012005-04-17 16:05:31 -05002739static int
James Smart2e0fef82007-06-17 19:56:36 -05002740lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002741{
James Smart2e0fef82007-06-17 19:56:36 -05002742 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002743 IOCB_t *icmd;
2744 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002745 struct lpfc_sli *psli;
2746 FARP *fp;
2747 uint8_t *pcmd;
2748 uint32_t *lp;
2749 uint16_t cmdsize;
2750 struct lpfc_nodelist *ondlp;
2751 struct lpfc_nodelist *ndlp;
2752
2753 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002754 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002755
James Smarte47c9092008-02-08 18:49:26 -05002756 ndlp = lpfc_findnode_did(vport, nportid);
2757 if (!ndlp) {
2758 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2759 if (!ndlp)
2760 return 1;
2761 lpfc_nlp_init(vport, ndlp, nportid);
2762 lpfc_enqueue_node(vport, ndlp);
2763 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2764 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2765 if (!ndlp)
2766 return 1;
2767 }
James Smart2e0fef82007-06-17 19:56:36 -05002768
2769 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2770 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002771 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002772 /* This will trigger the release of the node just
2773 * allocated
2774 */
James Smart329f9bc2007-04-25 09:53:01 -04002775 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002776 return 1;
dea31012005-04-17 16:05:31 -05002777 }
2778
2779 icmd = &elsiocb->iocb;
2780 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2781
2782 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002783 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002784
2785 /* Fill in FARPR payload */
2786 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002787 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002788 lp = (uint32_t *) pcmd;
2789 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002790 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002791 fp->Rflags = 0;
2792 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2793
James Smart92d7f7b2007-06-17 19:56:38 -05002794 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2795 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002796 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002797 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002798 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002799 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002800 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002801 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002802 }
2803
James Smart858c9f62007-06-17 19:56:39 -05002804 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2805 "Issue FARPR: did:x%x",
2806 ndlp->nlp_DID, 0, 0);
2807
dea31012005-04-17 16:05:31 -05002808 phba->fc_stat.elsXmitFARPR++;
2809 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002810 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2811 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002812 /* The additional lpfc_nlp_put will cause the following
2813 * lpfc_els_free_iocb routine to trigger the release of
2814 * the node.
2815 */
James Smart329f9bc2007-04-25 09:53:01 -04002816 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002817 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002818 return 1;
dea31012005-04-17 16:05:31 -05002819 }
James Smartfa4066b2008-01-11 01:53:27 -05002820 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2821 * trigger the release of the node.
2822 */
James Smart329f9bc2007-04-25 09:53:01 -04002823 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002824 return 0;
dea31012005-04-17 16:05:31 -05002825}
2826
James Smarte59058c2008-08-24 21:49:00 -04002827/**
James Smart3621a712009-04-06 18:47:14 -04002828 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002829 * @vport: pointer to a host virtual N_Port data structure.
2830 * @nlp: pointer to a node-list data structure.
2831 *
2832 * This routine cancels the timer with a delayed IOCB-command retry for
2833 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2834 * removes the ELS retry event if it presents. In addition, if the
2835 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2836 * commands are sent for the @vport's nodes that require issuing discovery
2837 * ADISC.
2838 **/
dea31012005-04-17 16:05:31 -05002839void
James Smart2e0fef82007-06-17 19:56:36 -05002840lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002841{
James Smart2e0fef82007-06-17 19:56:36 -05002842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002843 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002844
James Smart0d2b6b82008-06-14 22:52:47 -04002845 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2846 return;
James Smart2e0fef82007-06-17 19:56:36 -05002847 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002848 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002849 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002850 del_timer_sync(&nlp->nlp_delayfunc);
2851 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002852 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002853 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002854 /* Decrement nlp reference count held for the delayed retry */
2855 evtp = &nlp->els_retry_evt;
2856 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2857 }
James Smartfdcebe22006-03-07 15:04:01 -05002858 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002859 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002860 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002861 spin_unlock_irq(shost->host_lock);
2862 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002863 if (vport->port_state < LPFC_VPORT_READY) {
2864 /* Check if there are more ADISCs to be sent */
2865 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002866 } else {
2867 /* Check if there are more PLOGIs to be sent */
2868 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002869 if (vport->num_disc_nodes == 0) {
2870 spin_lock_irq(shost->host_lock);
2871 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2872 spin_unlock_irq(shost->host_lock);
2873 lpfc_can_disctmo(vport);
2874 lpfc_end_rscn(vport);
2875 }
James Smartfdcebe22006-03-07 15:04:01 -05002876 }
2877 }
2878 }
2879 return;
2880}
2881
James Smarte59058c2008-08-24 21:49:00 -04002882/**
James Smart3621a712009-04-06 18:47:14 -04002883 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002884 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2885 *
2886 * This routine is invoked by the ndlp delayed-function timer to check
2887 * whether there is any pending ELS retry event(s) with the node. If not, it
2888 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2889 * adds the delayed events to the HBA work list and invokes the
2890 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2891 * event. Note that lpfc_nlp_get() is called before posting the event to
2892 * the work list to hold reference count of ndlp so that it guarantees the
2893 * reference to ndlp will still be available when the worker thread gets
2894 * to the event associated with the ndlp.
2895 **/
James Smartfdcebe22006-03-07 15:04:01 -05002896void
dea31012005-04-17 16:05:31 -05002897lpfc_els_retry_delay(unsigned long ptr)
2898{
James Smart2e0fef82007-06-17 19:56:36 -05002899 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2900 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002901 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002902 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002903 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002904
James Smart92d7f7b2007-06-17 19:56:38 -05002905 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002906 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002907 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002908 return;
2909 }
2910
James Smartfa4066b2008-01-11 01:53:27 -05002911 /* We need to hold the node by incrementing the reference
2912 * count until the queued work is done
2913 */
2914 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002915 if (evtp->evt_arg1) {
2916 evtp->evt = LPFC_EVT_ELS_RETRY;
2917 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002918 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002919 }
James Smart92d7f7b2007-06-17 19:56:38 -05002920 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002921 return;
2922}
2923
James Smarte59058c2008-08-24 21:49:00 -04002924/**
James Smart3621a712009-04-06 18:47:14 -04002925 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002926 * @ndlp: pointer to a node-list data structure.
2927 *
2928 * This routine is the worker-thread handler for processing the @ndlp delayed
2929 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2930 * the last ELS command from the associated ndlp and invokes the proper ELS
2931 * function according to the delayed ELS command to retry the command.
2932 **/
dea31012005-04-17 16:05:31 -05002933void
2934lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2935{
James Smart2e0fef82007-06-17 19:56:36 -05002936 struct lpfc_vport *vport = ndlp->vport;
2937 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2938 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002939
James Smart2e0fef82007-06-17 19:56:36 -05002940 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002941 did = ndlp->nlp_DID;
2942 cmd = ndlp->nlp_last_elscmd;
2943 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002944
2945 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002946 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002947 return;
2948 }
2949
2950 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002951 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002952 /*
2953 * If a discovery event readded nlp_delayfunc after timer
2954 * firing and before processing the timer, cancel the
2955 * nlp_delayfunc.
2956 */
2957 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002958 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002959 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002960
2961 switch (cmd) {
2962 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002963 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002964 break;
2965 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002966 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002967 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002968 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002969 }
dea31012005-04-17 16:05:31 -05002970 break;
2971 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002972 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002973 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002974 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002975 }
dea31012005-04-17 16:05:31 -05002976 break;
2977 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002978 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002979 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002981 }
dea31012005-04-17 16:05:31 -05002982 break;
2983 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002984 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002985 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04002986 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002987 }
dea31012005-04-17 16:05:31 -05002988 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002989 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002990 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2991 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002992 break;
dea31012005-04-17 16:05:31 -05002993 }
2994 return;
2995}
2996
James Smarte59058c2008-08-24 21:49:00 -04002997/**
James Smart3621a712009-04-06 18:47:14 -04002998 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002999 * @phba: pointer to lpfc hba data structure.
3000 * @cmdiocb: pointer to lpfc command iocb data structure.
3001 * @rspiocb: pointer to lpfc response iocb data structure.
3002 *
3003 * This routine makes a retry decision on an ELS command IOCB, which has
3004 * failed. The following ELS IOCBs use this function for retrying the command
3005 * when previously issued command responsed with error status: FLOGI, PLOGI,
3006 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3007 * returned error status, it makes the decision whether a retry shall be
3008 * issued for the command, and whether a retry shall be made immediately or
3009 * delayed. In the former case, the corresponding ELS command issuing-function
3010 * is called to retry the command. In the later case, the ELS command shall
3011 * be posted to the ndlp delayed event and delayed function timer set to the
3012 * ndlp for the delayed command issusing.
3013 *
3014 * Return code
3015 * 0 - No retry of els command is made
3016 * 1 - Immediate or delayed retry of els command is made
3017 **/
dea31012005-04-17 16:05:31 -05003018static int
James Smart2e0fef82007-06-17 19:56:36 -05003019lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3020 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003021{
James Smart2e0fef82007-06-17 19:56:36 -05003022 struct lpfc_vport *vport = cmdiocb->vport;
3023 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3024 IOCB_t *irsp = &rspiocb->iocb;
3025 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3026 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003027 uint32_t *elscmd;
3028 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003029 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003030 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003031 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003032 uint32_t did;
dea31012005-04-17 16:05:31 -05003033
James Smart488d1462006-03-07 15:02:37 -05003034
dea31012005-04-17 16:05:31 -05003035 /* Note: context2 may be 0 for internal driver abort
3036 * of delays ELS command.
3037 */
3038
3039 if (pcmd && pcmd->virt) {
3040 elscmd = (uint32_t *) (pcmd->virt);
3041 cmd = *elscmd++;
3042 }
3043
James Smarte47c9092008-02-08 18:49:26 -05003044 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003045 did = ndlp->nlp_DID;
3046 else {
3047 /* We should only hit this case for retrying PLOGI */
3048 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003049 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003050 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3051 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003052 return 1;
3053 }
3054
James Smart858c9f62007-06-17 19:56:39 -05003055 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3056 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3057 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3058
dea31012005-04-17 16:05:31 -05003059 switch (irsp->ulpStatus) {
3060 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003061 break;
James Smart1151e3e2011-02-16 12:39:35 -05003062 case IOSTAT_REMOTE_STOP:
3063 if (phba->sli_rev == LPFC_SLI_REV4) {
3064 /* This IO was aborted by the target, we don't
3065 * know the rxid and because we did not send the
3066 * ABTS we cannot generate and RRQ.
3067 */
3068 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003069 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003070 }
3071 break;
dea31012005-04-17 16:05:31 -05003072 case IOSTAT_LOCAL_REJECT:
3073 switch ((irsp->un.ulpWord[4] & 0xff)) {
3074 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003075 if (cmd == ELS_CMD_FLOGI) {
3076 if (PCI_DEVICE_ID_HORNET ==
3077 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003078 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003079 phba->pport->fc_myDID = 0;
3080 phba->alpa_map[0] = 0;
3081 phba->alpa_map[1] = 0;
3082 }
3083 }
James Smart2e0fef82007-06-17 19:56:36 -05003084 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003085 delay = 1000;
dea31012005-04-17 16:05:31 -05003086 retry = 1;
3087 break;
3088
James Smart92d7f7b2007-06-17 19:56:38 -05003089 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003090 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3091 "0124 Retry illegal cmd x%x "
3092 "retry:x%x delay:x%x\n",
3093 cmd, cmdiocb->retry, delay);
3094 retry = 1;
3095 /* All command's retry policy */
3096 maxretry = 8;
3097 if (cmdiocb->retry > 2)
3098 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003099 break;
3100
dea31012005-04-17 16:05:31 -05003101 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003102 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003103 retry = 1;
3104 if (cmdiocb->retry > 100)
3105 delay = 100;
3106 maxretry = 250;
3107 break;
3108
3109 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003110 delay = 100;
dea31012005-04-17 16:05:31 -05003111 retry = 1;
3112 break;
3113
James Smart858c9f62007-06-17 19:56:39 -05003114 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003115 case IOERR_INVALID_RPI:
3116 retry = 1;
3117 break;
3118 }
3119 break;
3120
3121 case IOSTAT_NPORT_RJT:
3122 case IOSTAT_FABRIC_RJT:
3123 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3124 retry = 1;
3125 break;
3126 }
3127 break;
3128
3129 case IOSTAT_NPORT_BSY:
3130 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003131 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003132 retry = 1;
3133 break;
3134
3135 case IOSTAT_LS_RJT:
3136 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3137 /* Added for Vendor specifc support
3138 * Just keep retrying for these Rsn / Exp codes
3139 */
3140 switch (stat.un.b.lsRjtRsnCode) {
3141 case LSRJT_UNABLE_TPC:
3142 if (stat.un.b.lsRjtRsnCodeExp ==
3143 LSEXP_CMD_IN_PROGRESS) {
3144 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003145 delay = 1000;
dea31012005-04-17 16:05:31 -05003146 maxretry = 48;
3147 }
3148 retry = 1;
3149 break;
3150 }
James Smartffc95492010-06-07 15:23:17 -04003151 if (stat.un.b.lsRjtRsnCodeExp ==
3152 LSEXP_CANT_GIVE_DATA) {
3153 if (cmd == ELS_CMD_PLOGI) {
3154 delay = 1000;
3155 maxretry = 48;
3156 }
3157 retry = 1;
3158 break;
3159 }
dea31012005-04-17 16:05:31 -05003160 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003161 delay = 1000;
dea31012005-04-17 16:05:31 -05003162 maxretry = lpfc_max_els_tries + 1;
3163 retry = 1;
3164 break;
3165 }
James Smart92d7f7b2007-06-17 19:56:38 -05003166 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3167 (cmd == ELS_CMD_FDISC) &&
3168 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003169 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3170 "0125 FDISC Failed (x%x). "
3171 "Fabric out of resources\n",
3172 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003173 lpfc_vport_set_state(vport,
3174 FC_VPORT_NO_FABRIC_RSCS);
3175 }
dea31012005-04-17 16:05:31 -05003176 break;
3177
3178 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003179 if ((cmd == ELS_CMD_PLOGI) ||
3180 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003181 delay = 1000;
dea31012005-04-17 16:05:31 -05003182 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003183 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003184 /* FDISC retry policy */
3185 maxretry = 48;
3186 if (cmdiocb->retry >= 32)
3187 delay = 1000;
dea31012005-04-17 16:05:31 -05003188 }
3189 retry = 1;
3190 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003191
3192 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003193 /* There are some cases where switches return this
3194 * error when they are not ready and should be returning
3195 * Logical Busy. We should delay every time.
3196 */
3197 if (cmd == ELS_CMD_FDISC &&
3198 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3199 maxretry = 3;
3200 delay = 1000;
3201 retry = 1;
3202 break;
3203 }
James Smart92d7f7b2007-06-17 19:56:38 -05003204 case LSRJT_PROTOCOL_ERR:
3205 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3206 (cmd == ELS_CMD_FDISC) &&
3207 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3208 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3209 ) {
James Smarte8b62012007-08-02 11:10:09 -04003210 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003211 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003212 "Fabric Detected Bad WWN\n",
3213 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003214 lpfc_vport_set_state(vport,
3215 FC_VPORT_FABRIC_REJ_WWN);
3216 }
3217 break;
dea31012005-04-17 16:05:31 -05003218 }
3219 break;
3220
3221 case IOSTAT_INTERMED_RSP:
3222 case IOSTAT_BA_RJT:
3223 break;
3224
3225 default:
3226 break;
3227 }
3228
James Smart488d1462006-03-07 15:02:37 -05003229 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003230 retry = 1;
dea31012005-04-17 16:05:31 -05003231
James Smartdf9e1b52011-12-13 13:22:17 -05003232 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003233 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003234 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003235 /* FLOGI retry policy */
3236 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003237 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003238 maxretry = 0;
3239 if (cmdiocb->retry >= 100)
3240 delay = 5000;
3241 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003242 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003243 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3244 /* retry FDISCs every second up to devloss */
3245 retry = 1;
3246 maxretry = vport->cfg_devloss_tmo;
3247 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003248 }
3249
James Smart6669f9b2009-10-02 15:16:45 -04003250 cmdiocb->retry++;
3251 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003252 phba->fc_stat.elsRetryExceeded++;
3253 retry = 0;
3254 }
3255
James Smarted957682007-06-17 19:56:37 -05003256 if ((vport->load_flag & FC_UNLOADING) != 0)
3257 retry = 0;
3258
dea31012005-04-17 16:05:31 -05003259 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003260 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3261 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3262 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3263 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3264 "2849 Stop retry ELS command "
3265 "x%x to remote NPORT x%x, "
3266 "Data: x%x x%x\n", cmd, did,
3267 cmdiocb->retry, delay);
3268 return 0;
3269 }
3270 }
dea31012005-04-17 16:05:31 -05003271
3272 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003273 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3274 "0107 Retry ELS command x%x to remote "
3275 "NPORT x%x Data: x%x x%x\n",
3276 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003277
James Smart858c9f62007-06-17 19:56:39 -05003278 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3279 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3280 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3281 /* Don't reset timer for no resources */
3282
dea31012005-04-17 16:05:31 -05003283 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003284 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003285 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003286 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003287 }
3288
3289 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003290 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003291 phba->fc_stat.elsDelayRetry++;
3292 ndlp->nlp_retry = cmdiocb->retry;
3293
James Smart92d7f7b2007-06-17 19:56:38 -05003294 /* delay is specified in milliseconds */
3295 mod_timer(&ndlp->nlp_delayfunc,
3296 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003297 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003298 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003299 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003300
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003301 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003302 if (cmd == ELS_CMD_PRLI)
3303 lpfc_nlp_set_state(vport, ndlp,
3304 NLP_STE_REG_LOGIN_ISSUE);
3305 else
3306 lpfc_nlp_set_state(vport, ndlp,
3307 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003308 ndlp->nlp_last_elscmd = cmd;
3309
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003310 return 1;
dea31012005-04-17 16:05:31 -05003311 }
3312 switch (cmd) {
3313 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003314 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003315 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003316 case ELS_CMD_FDISC:
3317 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3318 return 1;
dea31012005-04-17 16:05:31 -05003319 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003320 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003321 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003322 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003323 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003324 }
James Smart2e0fef82007-06-17 19:56:36 -05003325 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003326 return 1;
dea31012005-04-17 16:05:31 -05003327 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003328 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003329 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3330 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003331 return 1;
dea31012005-04-17 16:05:31 -05003332 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003333 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003334 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3335 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003336 return 1;
dea31012005-04-17 16:05:31 -05003337 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003338 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003340 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003341 return 1;
dea31012005-04-17 16:05:31 -05003342 }
3343 }
dea31012005-04-17 16:05:31 -05003344 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003345 if (logerr) {
3346 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3347 "0137 No retry ELS command x%x to remote "
3348 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3349 cmd, did, irsp->ulpStatus,
3350 irsp->un.ulpWord[4]);
3351 }
3352 else {
3353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003354 "0108 No retry ELS command x%x to remote "
3355 "NPORT x%x Retried:%d Error:x%x/%x\n",
3356 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3357 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003358 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003359 return 0;
dea31012005-04-17 16:05:31 -05003360}
3361
James Smarte59058c2008-08-24 21:49:00 -04003362/**
James Smart3621a712009-04-06 18:47:14 -04003363 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003364 * @phba: pointer to lpfc hba data structure.
3365 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3366 *
3367 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3368 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3369 * checks to see whether there is a lpfc DMA buffer associated with the
3370 * response of the command IOCB. If so, it will be released before releasing
3371 * the lpfc DMA buffer associated with the IOCB itself.
3372 *
3373 * Return code
3374 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3375 **/
James Smart09372822008-01-11 01:52:54 -05003376static int
James Smart87af33f2007-10-27 13:37:43 -04003377lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3378{
3379 struct lpfc_dmabuf *buf_ptr;
3380
James Smarte59058c2008-08-24 21:49:00 -04003381 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003382 if (!list_empty(&buf_ptr1->list)) {
3383 list_remove_head(&buf_ptr1->list, buf_ptr,
3384 struct lpfc_dmabuf,
3385 list);
3386 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3387 kfree(buf_ptr);
3388 }
3389 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3390 kfree(buf_ptr1);
3391 return 0;
3392}
3393
James Smarte59058c2008-08-24 21:49:00 -04003394/**
James Smart3621a712009-04-06 18:47:14 -04003395 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003396 * @phba: pointer to lpfc hba data structure.
3397 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3398 *
3399 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3400 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3401 * pool.
3402 *
3403 * Return code
3404 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3405 **/
James Smart09372822008-01-11 01:52:54 -05003406static int
James Smart87af33f2007-10-27 13:37:43 -04003407lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3408{
3409 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3410 kfree(buf_ptr);
3411 return 0;
3412}
3413
James Smarte59058c2008-08-24 21:49:00 -04003414/**
James Smart3621a712009-04-06 18:47:14 -04003415 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003416 * @phba: pointer to lpfc hba data structure.
3417 * @elsiocb: pointer to lpfc els command iocb data structure.
3418 *
3419 * This routine frees a command IOCB and its associated resources. The
3420 * command IOCB data structure contains the reference to various associated
3421 * resources, these fields must be set to NULL if the associated reference
3422 * not present:
3423 * context1 - reference to ndlp
3424 * context2 - reference to cmd
3425 * context2->next - reference to rsp
3426 * context3 - reference to bpl
3427 *
3428 * It first properly decrements the reference count held on ndlp for the
3429 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3430 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3431 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3432 * adds the DMA buffer the @phba data structure for the delayed release.
3433 * If reference to the Buffer Pointer List (BPL) is present, the
3434 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3435 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3436 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3437 *
3438 * Return code
3439 * 0 - Success (currently, always return 0)
3440 **/
James Smart87af33f2007-10-27 13:37:43 -04003441int
James Smart329f9bc2007-04-25 09:53:01 -04003442lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003443{
3444 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003445 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003446
James Smarta8adb832007-10-27 13:37:53 -04003447 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3448 if (ndlp) {
3449 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3450 lpfc_nlp_put(ndlp);
3451
3452 /* If the ndlp is not being used by another discovery
3453 * thread, free it.
3454 */
3455 if (!lpfc_nlp_not_used(ndlp)) {
3456 /* If ndlp is being used by another discovery
3457 * thread, just clear NLP_DEFER_RM
3458 */
3459 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3460 }
3461 }
3462 else
3463 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003464 elsiocb->context1 = NULL;
3465 }
dea31012005-04-17 16:05:31 -05003466 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3467 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003468 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3469 /* Firmware could still be in progress of DMAing
3470 * payload, so don't free data buffer till after
3471 * a hbeat.
3472 */
3473 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3474 buf_ptr = elsiocb->context2;
3475 elsiocb->context2 = NULL;
3476 if (buf_ptr) {
3477 buf_ptr1 = NULL;
3478 spin_lock_irq(&phba->hbalock);
3479 if (!list_empty(&buf_ptr->list)) {
3480 list_remove_head(&buf_ptr->list,
3481 buf_ptr1, struct lpfc_dmabuf,
3482 list);
3483 INIT_LIST_HEAD(&buf_ptr1->list);
3484 list_add_tail(&buf_ptr1->list,
3485 &phba->elsbuf);
3486 phba->elsbuf_cnt++;
3487 }
3488 INIT_LIST_HEAD(&buf_ptr->list);
3489 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3490 phba->elsbuf_cnt++;
3491 spin_unlock_irq(&phba->hbalock);
3492 }
3493 } else {
3494 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3495 lpfc_els_free_data(phba, buf_ptr1);
3496 }
dea31012005-04-17 16:05:31 -05003497 }
3498
3499 if (elsiocb->context3) {
3500 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003501 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003502 }
James Bottomley604a3e32005-10-29 10:28:33 -05003503 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003504 return 0;
3505}
3506
James Smarte59058c2008-08-24 21:49:00 -04003507/**
James Smart3621a712009-04-06 18:47:14 -04003508 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003509 * @phba: pointer to lpfc hba data structure.
3510 * @cmdiocb: pointer to lpfc command iocb data structure.
3511 * @rspiocb: pointer to lpfc response iocb data structure.
3512 *
3513 * This routine is the completion callback function to the Logout (LOGO)
3514 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3515 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3516 * release the ndlp if it has the last reference remaining (reference count
3517 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3518 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3519 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3520 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3521 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3522 * IOCB data structure.
3523 **/
dea31012005-04-17 16:05:31 -05003524static void
James Smart2e0fef82007-06-17 19:56:36 -05003525lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3526 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003527{
James Smart2e0fef82007-06-17 19:56:36 -05003528 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3529 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003530 IOCB_t *irsp;
3531
3532 irsp = &rspiocb->iocb;
3533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3534 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3535 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003536 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003537 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3538 "0109 ACC to LOGO completes to NPort x%x "
3539 "Data: x%x x%x x%x\n",
3540 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3541 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003542
3543 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3544 /* NPort Recovery mode or node is just allocated */
3545 if (!lpfc_nlp_not_used(ndlp)) {
3546 /* If the ndlp is being used by another discovery
3547 * thread, just unregister the RPI.
3548 */
3549 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003550 } else {
3551 /* Indicate the node has already released, should
3552 * not reference to it from within lpfc_els_free_iocb.
3553 */
3554 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003555 }
dea31012005-04-17 16:05:31 -05003556 }
James Smart73d91e52011-10-10 21:32:10 -04003557
3558 /*
3559 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003560 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003561 */
dea31012005-04-17 16:05:31 -05003562 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003563
3564 /*
3565 * Remove the ndlp reference if it's a fabric node that has
3566 * sent us an unsolicted LOGO.
3567 */
3568 if (ndlp->nlp_type & NLP_FABRIC)
3569 lpfc_nlp_put(ndlp);
3570
dea31012005-04-17 16:05:31 -05003571 return;
3572}
3573
James Smarte59058c2008-08-24 21:49:00 -04003574/**
James Smart3621a712009-04-06 18:47:14 -04003575 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003576 * @phba: pointer to lpfc hba data structure.
3577 * @pmb: pointer to the driver internal queue element for mailbox command.
3578 *
3579 * This routine is the completion callback function for unregister default
3580 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3581 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3582 * decrements the ndlp reference count held for this completion callback
3583 * function. After that, it invokes the lpfc_nlp_not_used() to check
3584 * whether there is only one reference left on the ndlp. If so, it will
3585 * perform one more decrement and trigger the release of the ndlp.
3586 **/
James Smart858c9f62007-06-17 19:56:39 -05003587void
3588lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3589{
3590 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3591 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3592
3593 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003594 pmb->context2 = NULL;
3595
James Smart858c9f62007-06-17 19:56:39 -05003596 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3597 kfree(mp);
3598 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003599 if (ndlp) {
3600 if (NLP_CHK_NODE_ACT(ndlp)) {
3601 lpfc_nlp_put(ndlp);
3602 /* This is the end of the default RPI cleanup logic for
3603 * this ndlp. If no other discovery threads are using
3604 * this ndlp, free all resources associated with it.
3605 */
3606 lpfc_nlp_not_used(ndlp);
3607 } else {
3608 lpfc_drop_node(ndlp->vport, ndlp);
3609 }
James Smarta8adb832007-10-27 13:37:53 -04003610 }
James Smart3772a992009-05-22 14:50:54 -04003611
James Smart858c9f62007-06-17 19:56:39 -05003612 return;
3613}
3614
James Smarte59058c2008-08-24 21:49:00 -04003615/**
James Smart3621a712009-04-06 18:47:14 -04003616 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003617 * @phba: pointer to lpfc hba data structure.
3618 * @cmdiocb: pointer to lpfc command iocb data structure.
3619 * @rspiocb: pointer to lpfc response iocb data structure.
3620 *
3621 * This routine is the completion callback function for ELS Response IOCB
3622 * command. In normal case, this callback function just properly sets the
3623 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3624 * field in the command IOCB is not NULL, the referred mailbox command will
3625 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3626 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3627 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3628 * routine shall be invoked trying to release the ndlp if no other threads
3629 * are currently referring it.
3630 **/
dea31012005-04-17 16:05:31 -05003631static void
James Smart858c9f62007-06-17 19:56:39 -05003632lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003633 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003634{
James Smart2e0fef82007-06-17 19:56:36 -05003635 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3636 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3637 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003638 IOCB_t *irsp;
3639 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003640 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003641 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003642 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003643
James Smart33ccf8d2006-08-17 11:57:58 -04003644 irsp = &rspiocb->iocb;
3645
dea31012005-04-17 16:05:31 -05003646 if (cmdiocb->context_un.mbox)
3647 mbox = cmdiocb->context_un.mbox;
3648
James Smartfa4066b2008-01-11 01:53:27 -05003649 /* First determine if this is a LS_RJT cmpl. Note, this callback
3650 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3651 */
James Smart87af33f2007-10-27 13:37:43 -04003652 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003653 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3654 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003655 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003656 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003657 */
3658 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3659 ls_rjt = 1;
3660 }
3661
dea31012005-04-17 16:05:31 -05003662 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003663 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003664 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003665 mp = (struct lpfc_dmabuf *) mbox->context1;
3666 if (mp) {
3667 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3668 kfree(mp);
3669 }
James Smart329f9bc2007-04-25 09:53:01 -04003670 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003671 }
James Smart58da1ff2008-04-07 10:15:56 -04003672 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3673 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003674 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003675 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003676 /* Indicate the node has already released,
3677 * should not reference to it from within
3678 * the routine lpfc_els_free_iocb.
3679 */
3680 cmdiocb->context1 = NULL;
3681 }
dea31012005-04-17 16:05:31 -05003682 goto out;
3683 }
3684
James Smart858c9f62007-06-17 19:56:39 -05003685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003686 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003687 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003688 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003689 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3691 "0110 ELS response tag x%x completes "
3692 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3693 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3694 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3695 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3696 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003697 if (mbox) {
3698 if ((rspiocb->iocb.ulpStatus == 0)
3699 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003700 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003701 /* Increment reference count to ndlp to hold the
3702 * reference to ndlp for the callback function.
3703 */
James Smart329f9bc2007-04-25 09:53:01 -04003704 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003705 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003706 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3707 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3708 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3709 }
3710 else {
3711 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3712 ndlp->nlp_prev_state = ndlp->nlp_state;
3713 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003714 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003715 }
James Smart0b727fe2007-10-27 13:37:25 -04003716 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003717 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003718 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003719 else
3720 /* Decrement the ndlp reference count we
3721 * set for this failed mailbox command.
3722 */
3723 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003724
3725 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3726 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3727 "0138 ELS rsp: Cannot issue reg_login for x%x "
3728 "Data: x%x x%x x%x\n",
3729 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3730 ndlp->nlp_rpi);
3731
James Smartfa4066b2008-01-11 01:53:27 -05003732 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003733 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003734 /* Indicate node has already been released,
3735 * should not reference to it from within
3736 * the routine lpfc_els_free_iocb.
3737 */
3738 cmdiocb->context1 = NULL;
3739 }
dea31012005-04-17 16:05:31 -05003740 } else {
James Smart858c9f62007-06-17 19:56:39 -05003741 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3742 if (!lpfc_error_lost_link(irsp) &&
3743 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003744 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003745 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003746 /* Indicate node has already been
3747 * released, should not reference
3748 * to it from within the routine
3749 * lpfc_els_free_iocb.
3750 */
3751 cmdiocb->context1 = NULL;
3752 }
dea31012005-04-17 16:05:31 -05003753 }
3754 }
James Smart14691152006-12-02 13:34:28 -05003755 mp = (struct lpfc_dmabuf *) mbox->context1;
3756 if (mp) {
3757 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3758 kfree(mp);
3759 }
3760 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003761 }
3762out:
James Smart58da1ff2008-04-07 10:15:56 -04003763 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003764 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003765 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003766 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003767
3768 /* If the node is not being used by another discovery thread,
3769 * and we are sending a reject, we are done with it.
3770 * Release driver reference count here and free associated
3771 * resources.
3772 */
3773 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003774 if (lpfc_nlp_not_used(ndlp))
3775 /* Indicate node has already been released,
3776 * should not reference to it from within
3777 * the routine lpfc_els_free_iocb.
3778 */
3779 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003780 }
James Smart87af33f2007-10-27 13:37:43 -04003781
dea31012005-04-17 16:05:31 -05003782 lpfc_els_free_iocb(phba, cmdiocb);
3783 return;
3784}
3785
James Smarte59058c2008-08-24 21:49:00 -04003786/**
James Smart3621a712009-04-06 18:47:14 -04003787 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003788 * @vport: pointer to a host virtual N_Port data structure.
3789 * @flag: the els command code to be accepted.
3790 * @oldiocb: pointer to the original lpfc command iocb data structure.
3791 * @ndlp: pointer to a node-list data structure.
3792 * @mbox: pointer to the driver internal queue element for mailbox command.
3793 *
3794 * This routine prepares and issues an Accept (ACC) response IOCB
3795 * command. It uses the @flag to properly set up the IOCB field for the
3796 * specific ACC response command to be issued and invokes the
3797 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3798 * @mbox pointer is passed in, it will be put into the context_un.mbox
3799 * field of the IOCB for the completion callback function to issue the
3800 * mailbox command to the HBA later when callback is invoked.
3801 *
3802 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3803 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3804 * will be stored into the context1 field of the IOCB for the completion
3805 * callback function to the corresponding response ELS IOCB command.
3806 *
3807 * Return code
3808 * 0 - Successfully issued acc response
3809 * 1 - Failed to issue acc response
3810 **/
dea31012005-04-17 16:05:31 -05003811int
James Smart2e0fef82007-06-17 19:56:36 -05003812lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3813 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003814 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003815{
James Smart2e0fef82007-06-17 19:56:36 -05003816 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3817 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003818 IOCB_t *icmd;
3819 IOCB_t *oldcmd;
3820 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003821 struct lpfc_sli *psli;
3822 uint8_t *pcmd;
3823 uint16_t cmdsize;
3824 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003825 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003826
3827 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003828 oldcmd = &oldiocb->iocb;
3829
3830 switch (flag) {
3831 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003832 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003833 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3834 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003835 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003836 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003837 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003838 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003839 return 1;
dea31012005-04-17 16:05:31 -05003840 }
James Smart2e0fef82007-06-17 19:56:36 -05003841
dea31012005-04-17 16:05:31 -05003842 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003843 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3844 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003845 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3846 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003847 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003848
3849 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3850 "Issue ACC: did:x%x flg:x%x",
3851 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003852 break;
3853 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003854 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003855 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3856 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003857 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003858 return 1;
James Smart488d1462006-03-07 15:02:37 -05003859
dea31012005-04-17 16:05:31 -05003860 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003861 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3862 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003863 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3864
3865 if (mbox)
3866 elsiocb->context_un.mbox = mbox;
3867
3868 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003869 pcmd += sizeof(uint32_t);
3870 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003871
3872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3873 "Issue ACC PLOGI: did:x%x flg:x%x",
3874 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003875 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003876 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003877 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003878 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003879 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3880 if (!elsiocb)
3881 return 1;
3882
3883 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003884 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3885 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003886 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3887
3888 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003889 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003890 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3891 els_pkt_ptr = (ELS_PKT *) pcmd;
3892 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003893
3894 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3895 "Issue ACC PRLO: did:x%x flg:x%x",
3896 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003897 break;
dea31012005-04-17 16:05:31 -05003898 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003899 return 1;
dea31012005-04-17 16:05:31 -05003900 }
dea31012005-04-17 16:05:31 -05003901 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003902 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3903 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003904 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3905 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003906 elsiocb->iotag, elsiocb->iocb.ulpContext,
3907 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003908 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003909 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003910 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003911 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003912 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003913 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3914 } else {
James Smart858c9f62007-06-17 19:56:39 -05003915 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003916 }
3917
3918 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003919 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003920 if (rc == IOCB_ERROR) {
3921 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003922 return 1;
dea31012005-04-17 16:05:31 -05003923 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003924 return 0;
dea31012005-04-17 16:05:31 -05003925}
3926
James Smarte59058c2008-08-24 21:49:00 -04003927/**
James Smart3621a712009-04-06 18:47:14 -04003928 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003929 * @vport: pointer to a virtual N_Port data structure.
3930 * @rejectError:
3931 * @oldiocb: pointer to the original lpfc command iocb data structure.
3932 * @ndlp: pointer to a node-list data structure.
3933 * @mbox: pointer to the driver internal queue element for mailbox command.
3934 *
3935 * This routine prepares and issue an Reject (RJT) response IOCB
3936 * command. If a @mbox pointer is passed in, it will be put into the
3937 * context_un.mbox field of the IOCB for the completion callback function
3938 * to issue to the HBA later.
3939 *
3940 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3941 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3942 * will be stored into the context1 field of the IOCB for the completion
3943 * callback function to the reject response ELS IOCB command.
3944 *
3945 * Return code
3946 * 0 - Successfully issued reject response
3947 * 1 - Failed to issue reject response
3948 **/
dea31012005-04-17 16:05:31 -05003949int
James Smart2e0fef82007-06-17 19:56:36 -05003950lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003951 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3952 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003953{
James Smart2e0fef82007-06-17 19:56:36 -05003954 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003955 IOCB_t *icmd;
3956 IOCB_t *oldcmd;
3957 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003958 struct lpfc_sli *psli;
3959 uint8_t *pcmd;
3960 uint16_t cmdsize;
3961 int rc;
3962
3963 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003964 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003965 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3966 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003967 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003968 return 1;
dea31012005-04-17 16:05:31 -05003969
3970 icmd = &elsiocb->iocb;
3971 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003972 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3973 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003974 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3975
3976 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003977 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003978 *((uint32_t *) (pcmd)) = rejectError;
3979
James Smart51ef4c22007-08-02 11:10:31 -04003980 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003981 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003982
dea31012005-04-17 16:05:31 -05003983 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003984 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3985 "0129 Xmit ELS RJT x%x response tag x%x "
3986 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3987 "rpi x%x\n",
3988 rejectError, elsiocb->iotag,
3989 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3990 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3992 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3993 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3994
dea31012005-04-17 16:05:31 -05003995 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003996 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003997 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003998
dea31012005-04-17 16:05:31 -05003999 if (rc == IOCB_ERROR) {
4000 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004001 return 1;
dea31012005-04-17 16:05:31 -05004002 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004003 return 0;
dea31012005-04-17 16:05:31 -05004004}
4005
James Smarte59058c2008-08-24 21:49:00 -04004006/**
James Smart3621a712009-04-06 18:47:14 -04004007 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004008 * @vport: pointer to a virtual N_Port data structure.
4009 * @oldiocb: pointer to the original lpfc command iocb data structure.
4010 * @ndlp: pointer to a node-list data structure.
4011 *
4012 * This routine prepares and issues an Accept (ACC) response to Address
4013 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4014 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4015 *
4016 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4017 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4018 * will be stored into the context1 field of the IOCB for the completion
4019 * callback function to the ADISC Accept response ELS IOCB command.
4020 *
4021 * Return code
4022 * 0 - Successfully issued acc adisc response
4023 * 1 - Failed to issue adisc acc response
4024 **/
dea31012005-04-17 16:05:31 -05004025int
James Smart2e0fef82007-06-17 19:56:36 -05004026lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4027 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004028{
James Smart2e0fef82007-06-17 19:56:36 -05004029 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004030 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004031 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004032 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004033 uint8_t *pcmd;
4034 uint16_t cmdsize;
4035 int rc;
4036
James Smart92d7f7b2007-06-17 19:56:38 -05004037 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004038 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4039 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004040 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004041 return 1;
dea31012005-04-17 16:05:31 -05004042
dea31012005-04-17 16:05:31 -05004043 icmd = &elsiocb->iocb;
4044 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004045 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4046 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004047
4048 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004049 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4050 "0130 Xmit ADISC ACC response iotag x%x xri: "
4051 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4052 elsiocb->iotag, elsiocb->iocb.ulpContext,
4053 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4054 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004055 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4056
4057 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004058 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004059
4060 ap = (ADISC *) (pcmd);
4061 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004062 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4063 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004064 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004065
James Smart858c9f62007-06-17 19:56:39 -05004066 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4067 "Issue ACC ADISC: did:x%x flg:x%x",
4068 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4069
dea31012005-04-17 16:05:31 -05004070 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004071 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004072 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004073 if (rc == IOCB_ERROR) {
4074 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004075 return 1;
dea31012005-04-17 16:05:31 -05004076 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004077 return 0;
dea31012005-04-17 16:05:31 -05004078}
4079
James Smarte59058c2008-08-24 21:49:00 -04004080/**
James Smart3621a712009-04-06 18:47:14 -04004081 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004082 * @vport: pointer to a virtual N_Port data structure.
4083 * @oldiocb: pointer to the original lpfc command iocb data structure.
4084 * @ndlp: pointer to a node-list data structure.
4085 *
4086 * This routine prepares and issues an Accept (ACC) response to Process
4087 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4088 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4089 *
4090 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4091 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4092 * will be stored into the context1 field of the IOCB for the completion
4093 * callback function to the PRLI Accept response ELS IOCB command.
4094 *
4095 * Return code
4096 * 0 - Successfully issued acc prli response
4097 * 1 - Failed to issue acc prli response
4098 **/
dea31012005-04-17 16:05:31 -05004099int
James Smart2e0fef82007-06-17 19:56:36 -05004100lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004101 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004102{
James Smart2e0fef82007-06-17 19:56:36 -05004103 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004104 PRLI *npr;
4105 lpfc_vpd_t *vpd;
4106 IOCB_t *icmd;
4107 IOCB_t *oldcmd;
4108 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004109 struct lpfc_sli *psli;
4110 uint8_t *pcmd;
4111 uint16_t cmdsize;
4112 int rc;
4113
4114 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004115
James Smart92d7f7b2007-06-17 19:56:38 -05004116 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004117 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004118 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004119 if (!elsiocb)
4120 return 1;
dea31012005-04-17 16:05:31 -05004121
dea31012005-04-17 16:05:31 -05004122 icmd = &elsiocb->iocb;
4123 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004124 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4125 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4126
James Smart5b8bd0c2007-04-25 09:52:49 -04004127 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4129 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4130 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4131 elsiocb->iotag, elsiocb->iocb.ulpContext,
4132 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4133 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004134 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4135
4136 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004137 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004138
4139 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004140 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004141
4142 npr = (PRLI *) pcmd;
4143 vpd = &phba->vpd;
4144 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004145 * If the remote port is a target and our firmware version is 3.20 or
4146 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004147 */
James Smart0d2b6b82008-06-14 22:52:47 -04004148 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4149 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004150 npr->ConfmComplAllowed = 1;
4151 npr->Retry = 1;
4152 npr->TaskRetryIdReq = 1;
4153 }
4154
4155 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4156 npr->estabImagePair = 1;
4157 npr->readXferRdyDis = 1;
4158 npr->ConfmComplAllowed = 1;
4159
4160 npr->prliType = PRLI_FCP_TYPE;
4161 npr->initiatorFunc = 1;
4162
James Smart858c9f62007-06-17 19:56:39 -05004163 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4164 "Issue ACC PRLI: did:x%x flg:x%x",
4165 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4166
dea31012005-04-17 16:05:31 -05004167 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004168 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004169
James Smart3772a992009-05-22 14:50:54 -04004170 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004171 if (rc == IOCB_ERROR) {
4172 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004173 return 1;
dea31012005-04-17 16:05:31 -05004174 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004175 return 0;
dea31012005-04-17 16:05:31 -05004176}
4177
James Smarte59058c2008-08-24 21:49:00 -04004178/**
James Smart3621a712009-04-06 18:47:14 -04004179 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004180 * @vport: pointer to a virtual N_Port data structure.
4181 * @format: rnid command format.
4182 * @oldiocb: pointer to the original lpfc command iocb data structure.
4183 * @ndlp: pointer to a node-list data structure.
4184 *
4185 * This routine issues a Request Node Identification Data (RNID) Accept
4186 * (ACC) response. It constructs the RNID ACC response command according to
4187 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4188 * issue the response. Note that this command does not need to hold the ndlp
4189 * reference count for the callback. So, the ndlp reference count taken by
4190 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4191 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4192 * there is no ndlp reference available.
4193 *
4194 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4195 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4196 * will be stored into the context1 field of the IOCB for the completion
4197 * callback function. However, for the RNID Accept Response ELS command,
4198 * this is undone later by this routine after the IOCB is allocated.
4199 *
4200 * Return code
4201 * 0 - Successfully issued acc rnid response
4202 * 1 - Failed to issue acc rnid response
4203 **/
dea31012005-04-17 16:05:31 -05004204static int
James Smart2e0fef82007-06-17 19:56:36 -05004205lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004206 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004207{
James Smart2e0fef82007-06-17 19:56:36 -05004208 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004209 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004210 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004211 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004212 struct lpfc_sli *psli;
4213 uint8_t *pcmd;
4214 uint16_t cmdsize;
4215 int rc;
4216
4217 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004218 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4219 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004220 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004221 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004222
James Smart2e0fef82007-06-17 19:56:36 -05004223 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4224 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004225 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004226 return 1;
dea31012005-04-17 16:05:31 -05004227
dea31012005-04-17 16:05:31 -05004228 icmd = &elsiocb->iocb;
4229 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004230 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4231 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4232
James Smart5b8bd0c2007-04-25 09:52:49 -04004233 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004234 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4235 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4236 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004237 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004238 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004239 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004240
James Smart92d7f7b2007-06-17 19:56:38 -05004241 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004242 rn = (RNID *) (pcmd);
4243 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004244 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4245 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4246 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004247 switch (format) {
4248 case 0:
4249 rn->SpecificLen = 0;
4250 break;
4251 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004252 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004253 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004254 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004255 rn->un.topologyDisc.unitType = RNID_HBA;
4256 rn->un.topologyDisc.physPort = 0;
4257 rn->un.topologyDisc.attachedNodes = 0;
4258 break;
4259 default:
4260 rn->CommonLen = 0;
4261 rn->SpecificLen = 0;
4262 break;
4263 }
4264
James Smart858c9f62007-06-17 19:56:39 -05004265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4266 "Issue ACC RNID: did:x%x flg:x%x",
4267 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4268
dea31012005-04-17 16:05:31 -05004269 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004270 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004271
James Smart3772a992009-05-22 14:50:54 -04004272 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004273 if (rc == IOCB_ERROR) {
4274 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004275 return 1;
dea31012005-04-17 16:05:31 -05004276 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004277 return 0;
dea31012005-04-17 16:05:31 -05004278}
4279
James Smarte59058c2008-08-24 21:49:00 -04004280/**
James Smart19ca7602010-11-20 23:11:55 -05004281 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4282 * @vport: pointer to a virtual N_Port data structure.
4283 * @iocb: pointer to the lpfc command iocb data structure.
4284 * @ndlp: pointer to a node-list data structure.
4285 *
4286 * Return
4287 **/
4288static void
4289lpfc_els_clear_rrq(struct lpfc_vport *vport,
4290 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4291{
4292 struct lpfc_hba *phba = vport->phba;
4293 uint8_t *pcmd;
4294 struct RRQ *rrq;
4295 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004296 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004297 struct lpfc_node_rrq *prrq;
4298
4299
4300 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4301 pcmd += sizeof(uint32_t);
4302 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004303 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004304 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004305
4306 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4307 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4308 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004309 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004310 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004311 rxid,
4312 iocb->iotag, iocb->iocb.ulpContext);
4313
4314 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4315 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4316 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004317 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004318 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004319 else
4320 xri = rxid;
4321 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004322 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004323 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004324 return;
4325}
4326
4327/**
James Smart12265f62010-10-22 11:05:53 -04004328 * lpfc_els_rsp_echo_acc - Issue echo acc response
4329 * @vport: pointer to a virtual N_Port data structure.
4330 * @data: pointer to echo data to return in the accept.
4331 * @oldiocb: pointer to the original lpfc command iocb data structure.
4332 * @ndlp: pointer to a node-list data structure.
4333 *
4334 * Return code
4335 * 0 - Successfully issued acc echo response
4336 * 1 - Failed to issue acc echo response
4337 **/
4338static int
4339lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4340 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4341{
4342 struct lpfc_hba *phba = vport->phba;
4343 struct lpfc_iocbq *elsiocb;
4344 struct lpfc_sli *psli;
4345 uint8_t *pcmd;
4346 uint16_t cmdsize;
4347 int rc;
4348
4349 psli = &phba->sli;
4350 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4351
James Smartbf086112011-08-21 21:48:13 -04004352 /* The accumulated length can exceed the BPL_SIZE. For
4353 * now, use this as the limit
4354 */
4355 if (cmdsize > LPFC_BPL_SIZE)
4356 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004357 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4358 ndlp->nlp_DID, ELS_CMD_ACC);
4359 if (!elsiocb)
4360 return 1;
4361
James Smart7851fe22011-07-22 18:36:52 -04004362 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4363 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4364
James Smart12265f62010-10-22 11:05:53 -04004365 /* Xmit ECHO ACC response tag <ulpIoTag> */
4366 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4367 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4368 elsiocb->iotag, elsiocb->iocb.ulpContext);
4369 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4370 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4371 pcmd += sizeof(uint32_t);
4372 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4373
4374 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4375 "Issue ACC ECHO: did:x%x flg:x%x",
4376 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4377
4378 phba->fc_stat.elsXmitACC++;
4379 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004380
4381 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4382 if (rc == IOCB_ERROR) {
4383 lpfc_els_free_iocb(phba, elsiocb);
4384 return 1;
4385 }
4386 return 0;
4387}
4388
4389/**
James Smart3621a712009-04-06 18:47:14 -04004390 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004391 * @vport: pointer to a host virtual N_Port data structure.
4392 *
4393 * This routine issues Address Discover (ADISC) ELS commands to those
4394 * N_Ports which are in node port recovery state and ADISC has not been issued
4395 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4396 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4397 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4398 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4399 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4400 * IOCBs quit for later pick up. On the other hand, after walking through
4401 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4402 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4403 * no more ADISC need to be sent.
4404 *
4405 * Return code
4406 * The number of N_Ports with adisc issued.
4407 **/
dea31012005-04-17 16:05:31 -05004408int
James Smart2e0fef82007-06-17 19:56:36 -05004409lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004410{
James Smart2e0fef82007-06-17 19:56:36 -05004411 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004412 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004413 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004414
James Smart685f0bf2007-04-25 09:53:08 -04004415 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004416 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004417 if (!NLP_CHK_NODE_ACT(ndlp))
4418 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004419 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4420 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4421 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004422 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004423 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004424 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004425 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004426 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4427 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004428 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004429 vport->num_disc_nodes++;
4430 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004431 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004432 spin_lock_irq(shost->host_lock);
4433 vport->fc_flag |= FC_NLP_MORE;
4434 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004435 break;
dea31012005-04-17 16:05:31 -05004436 }
4437 }
4438 }
4439 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004440 spin_lock_irq(shost->host_lock);
4441 vport->fc_flag &= ~FC_NLP_MORE;
4442 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004443 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004444 return sentadisc;
dea31012005-04-17 16:05:31 -05004445}
4446
James Smarte59058c2008-08-24 21:49:00 -04004447/**
James Smart3621a712009-04-06 18:47:14 -04004448 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004449 * @vport: pointer to a host virtual N_Port data structure.
4450 *
4451 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4452 * which are in node port recovery state, with a @vport. Each time an ELS
4453 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4454 * the per @vport number of discover count (num_disc_nodes) shall be
4455 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4456 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4457 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4458 * later pick up. On the other hand, after walking through all the ndlps with
4459 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4460 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4461 * PLOGI need to be sent.
4462 *
4463 * Return code
4464 * The number of N_Ports with plogi issued.
4465 **/
dea31012005-04-17 16:05:31 -05004466int
James Smart2e0fef82007-06-17 19:56:36 -05004467lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004468{
James Smart2e0fef82007-06-17 19:56:36 -05004469 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004470 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004471 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004472
James Smart2e0fef82007-06-17 19:56:36 -05004473 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4474 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004475 if (!NLP_CHK_NODE_ACT(ndlp))
4476 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004477 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4478 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4479 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4480 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4481 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004482 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4483 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004484 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004485 vport->num_disc_nodes++;
4486 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004487 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004488 spin_lock_irq(shost->host_lock);
4489 vport->fc_flag |= FC_NLP_MORE;
4490 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004491 break;
dea31012005-04-17 16:05:31 -05004492 }
4493 }
4494 }
James Smart87af33f2007-10-27 13:37:43 -04004495 if (sentplogi) {
4496 lpfc_set_disctmo(vport);
4497 }
4498 else {
James Smart2e0fef82007-06-17 19:56:36 -05004499 spin_lock_irq(shost->host_lock);
4500 vport->fc_flag &= ~FC_NLP_MORE;
4501 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004502 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004503 return sentplogi;
dea31012005-04-17 16:05:31 -05004504}
4505
James Smarte59058c2008-08-24 21:49:00 -04004506/**
James Smart3621a712009-04-06 18:47:14 -04004507 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004508 * @vport: pointer to a host virtual N_Port data structure.
4509 *
4510 * This routine cleans up any Registration State Change Notification
4511 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4512 * @vport together with the host_lock is used to prevent multiple thread
4513 * trying to access the RSCN array on a same @vport at the same time.
4514 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004515void
James Smart2e0fef82007-06-17 19:56:36 -05004516lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004517{
James Smart2e0fef82007-06-17 19:56:36 -05004518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4519 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004520 int i;
4521
James Smart7f5f3d02008-02-08 18:50:14 -05004522 spin_lock_irq(shost->host_lock);
4523 if (vport->fc_rscn_flush) {
4524 /* Another thread is walking fc_rscn_id_list on this vport */
4525 spin_unlock_irq(shost->host_lock);
4526 return;
4527 }
4528 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4529 vport->fc_rscn_flush = 1;
4530 spin_unlock_irq(shost->host_lock);
4531
James Smart2e0fef82007-06-17 19:56:36 -05004532 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004533 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004534 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004535 }
James Smart2e0fef82007-06-17 19:56:36 -05004536 spin_lock_irq(shost->host_lock);
4537 vport->fc_rscn_id_cnt = 0;
4538 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4539 spin_unlock_irq(shost->host_lock);
4540 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004541 /* Indicate we are done walking this fc_rscn_id_list */
4542 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004543}
4544
James Smarte59058c2008-08-24 21:49:00 -04004545/**
James Smart3621a712009-04-06 18:47:14 -04004546 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004547 * @vport: pointer to a host virtual N_Port data structure.
4548 * @did: remote destination port identifier.
4549 *
4550 * This routine checks whether there is any pending Registration State
4551 * Configuration Notification (RSCN) to a @did on @vport.
4552 *
4553 * Return code
4554 * None zero - The @did matched with a pending rscn
4555 * 0 - not able to match @did with a pending rscn
4556 **/
dea31012005-04-17 16:05:31 -05004557int
James Smart2e0fef82007-06-17 19:56:36 -05004558lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004559{
4560 D_ID ns_did;
4561 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004562 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004563 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004565
4566 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004567
4568 /* Never match fabric nodes for RSCNs */
4569 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004570 return 0;
dea31012005-04-17 16:05:31 -05004571
4572 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004573 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004574 return did;
dea31012005-04-17 16:05:31 -05004575
James Smart7f5f3d02008-02-08 18:50:14 -05004576 spin_lock_irq(shost->host_lock);
4577 if (vport->fc_rscn_flush) {
4578 /* Another thread is walking fc_rscn_id_list on this vport */
4579 spin_unlock_irq(shost->host_lock);
4580 return 0;
4581 }
4582 /* Indicate we are walking fc_rscn_id_list on this vport */
4583 vport->fc_rscn_flush = 1;
4584 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004585 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004586 lp = vport->fc_rscn_id_list[i]->virt;
4587 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4588 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004589 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004590 rscn_did.un.word = be32_to_cpu(*lp++);
4591 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004592 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4593 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004594 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4595 && (ns_did.un.b.area == rscn_did.un.b.area)
4596 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004597 goto return_did_out;
dea31012005-04-17 16:05:31 -05004598 break;
James Smarteaf15d52008-12-04 22:39:29 -05004599 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004600 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4601 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004602 goto return_did_out;
dea31012005-04-17 16:05:31 -05004603 break;
James Smarteaf15d52008-12-04 22:39:29 -05004604 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004605 if (ns_did.un.b.domain == rscn_did.un.b.domain)
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_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004609 goto return_did_out;
dea31012005-04-17 16:05:31 -05004610 }
4611 }
James Smart92d7f7b2007-06-17 19:56:38 -05004612 }
James Smart7f5f3d02008-02-08 18:50:14 -05004613 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4614 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004615 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004616return_did_out:
4617 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4618 vport->fc_rscn_flush = 0;
4619 return did;
dea31012005-04-17 16:05:31 -05004620}
4621
James Smarte59058c2008-08-24 21:49:00 -04004622/**
James Smart3621a712009-04-06 18:47:14 -04004623 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004624 * @vport: pointer to a host virtual N_Port data structure.
4625 *
4626 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4627 * state machine for a @vport's nodes that are with pending RSCN (Registration
4628 * State Change Notification).
4629 *
4630 * Return code
4631 * 0 - Successful (currently alway return 0)
4632 **/
dea31012005-04-17 16:05:31 -05004633static int
James Smart2e0fef82007-06-17 19:56:36 -05004634lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004635{
James Smart685f0bf2007-04-25 09:53:08 -04004636 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004637
James Smart0d2b6b82008-06-14 22:52:47 -04004638 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004639 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004640 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004641 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4642 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004643 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004644 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004645 NLP_EVT_DEVICE_RECOVERY);
4646 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004647 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004648 return 0;
dea31012005-04-17 16:05:31 -05004649}
4650
James Smarte59058c2008-08-24 21:49:00 -04004651/**
James Smart3621a712009-04-06 18:47:14 -04004652 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004653 * @vport: pointer to a host virtual N_Port data structure.
4654 * @cmdiocb: pointer to lpfc command iocb data structure.
4655 *
4656 * lpfc_send_rscn_event sends an RSCN netlink event to management
4657 * applications.
4658 */
4659static void
4660lpfc_send_rscn_event(struct lpfc_vport *vport,
4661 struct lpfc_iocbq *cmdiocb)
4662{
4663 struct lpfc_dmabuf *pcmd;
4664 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4665 uint32_t *payload_ptr;
4666 uint32_t payload_len;
4667 struct lpfc_rscn_event_header *rscn_event_data;
4668
4669 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4670 payload_ptr = (uint32_t *) pcmd->virt;
4671 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4672
4673 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4674 payload_len, GFP_KERNEL);
4675 if (!rscn_event_data) {
4676 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4677 "0147 Failed to allocate memory for RSCN event\n");
4678 return;
4679 }
4680 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4681 rscn_event_data->payload_length = payload_len;
4682 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4683 payload_len);
4684
4685 fc_host_post_vendor_event(shost,
4686 fc_get_event_number(),
4687 sizeof(struct lpfc_els_event_header) + payload_len,
4688 (char *)rscn_event_data,
4689 LPFC_NL_VENDOR_ID);
4690
4691 kfree(rscn_event_data);
4692}
4693
4694/**
James Smart3621a712009-04-06 18:47:14 -04004695 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004696 * @vport: pointer to a host virtual N_Port data structure.
4697 * @cmdiocb: pointer to lpfc command iocb data structure.
4698 * @ndlp: pointer to a node-list data structure.
4699 *
4700 * This routine processes an unsolicited RSCN (Registration State Change
4701 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4702 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4703 * discover state machine is about to begin discovery, it just accepts the
4704 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4705 * contains N_Port IDs for other vports on this HBA, it just accepts the
4706 * RSCN and ignore processing it. If the state machine is in the recovery
4707 * state, the fc_rscn_id_list of this @vport is walked and the
4708 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4709 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4710 * routine is invoked to handle the RSCN event.
4711 *
4712 * Return code
4713 * 0 - Just sent the acc response
4714 * 1 - Sent the acc response and waited for name server completion
4715 **/
dea31012005-04-17 16:05:31 -05004716static int
James Smart2e0fef82007-06-17 19:56:36 -05004717lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004718 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004719{
James Smart2e0fef82007-06-17 19:56:36 -05004720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4721 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004722 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004723 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004724 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004725 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004726 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004727 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004728 int i;
dea31012005-04-17 16:05:31 -05004729
4730 icmd = &cmdiocb->iocb;
4731 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4732 lp = (uint32_t *) pcmd->virt;
4733
James Smart92d7f7b2007-06-17 19:56:38 -05004734 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4735 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004736 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004737 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4738 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004739 vport->fc_flag, payload_len, *lp,
4740 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004741
4742 /* Send an RSCN event to the management application */
4743 lpfc_send_rscn_event(vport, cmdiocb);
4744
James Smartd2873e42006-08-18 17:46:43 -04004745 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004746 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004747 FCH_EVT_RSCN, lp[i]);
4748
dea31012005-04-17 16:05:31 -05004749 /* If we are about to begin discovery, just ACC the RSCN.
4750 * Discovery processing will satisfy it.
4751 */
James Smart2e0fef82007-06-17 19:56:36 -05004752 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4754 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4755 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4756
James Smart51ef4c22007-08-02 11:10:31 -04004757 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004758 return 0;
dea31012005-04-17 16:05:31 -05004759 }
4760
James Smart92d7f7b2007-06-17 19:56:38 -05004761 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4762 * just ACC and ignore it.
4763 */
4764 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004765 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004766 i = payload_len;
4767 datap = lp;
4768 while (i > 0) {
4769 nportid = *datap++;
4770 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4771 i -= sizeof(uint32_t);
4772 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004773 if (lpfc_find_vport_by_did(phba, nportid))
4774 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004775 }
4776 if (rscn_id == hba_id) {
4777 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004778 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004779 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004780 "Data: x%x x%x x%x x%x\n",
4781 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004782 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4784 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4785 ndlp->nlp_DID, vport->port_state,
4786 ndlp->nlp_flag);
4787
James Smart92d7f7b2007-06-17 19:56:38 -05004788 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004789 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004790 return 0;
4791 }
4792 }
4793
James Smart7f5f3d02008-02-08 18:50:14 -05004794 spin_lock_irq(shost->host_lock);
4795 if (vport->fc_rscn_flush) {
4796 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004797 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004798 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004799 /* Send back ACC */
4800 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004801 return 0;
4802 }
4803 /* Indicate we are walking fc_rscn_id_list on this vport */
4804 vport->fc_rscn_flush = 1;
4805 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004806 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004807 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004808 /* If we are already processing an RSCN, save the received
4809 * RSCN payload buffer, cmdiocb->context2 to process later.
4810 */
James Smart2e0fef82007-06-17 19:56:36 -05004811 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4813 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4814 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4815
James Smart09372822008-01-11 01:52:54 -05004816 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004817 vport->fc_flag |= FC_RSCN_DEFERRED;
4818 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004819 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004820 vport->fc_flag |= FC_RSCN_MODE;
4821 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004822 if (rscn_cnt) {
4823 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4824 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4825 }
4826 if ((rscn_cnt) &&
4827 (payload_len + length <= LPFC_BPL_SIZE)) {
4828 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004829 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004830 memcpy(((uint8_t *)cmd) + length, lp,
4831 payload_len);
4832 } else {
4833 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4834 vport->fc_rscn_id_cnt++;
4835 /* If we zero, cmdiocb->context2, the calling
4836 * routine will not try to free it.
4837 */
4838 cmdiocb->context2 = NULL;
4839 }
dea31012005-04-17 16:05:31 -05004840 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004841 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4842 "0235 Deferred RSCN "
4843 "Data: x%x x%x x%x\n",
4844 vport->fc_rscn_id_cnt, vport->fc_flag,
4845 vport->port_state);
dea31012005-04-17 16:05:31 -05004846 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004847 vport->fc_flag |= FC_RSCN_DISCOVERY;
4848 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004849 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004850 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4851 "0234 ReDiscovery RSCN "
4852 "Data: x%x x%x x%x\n",
4853 vport->fc_rscn_id_cnt, vport->fc_flag,
4854 vport->port_state);
dea31012005-04-17 16:05:31 -05004855 }
James Smart7f5f3d02008-02-08 18:50:14 -05004856 /* Indicate we are done walking fc_rscn_id_list on this vport */
4857 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004858 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004859 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004860 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004861 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004862 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004863 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004864 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004865 return 0;
dea31012005-04-17 16:05:31 -05004866 }
James Smart858c9f62007-06-17 19:56:39 -05004867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4868 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4869 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4870
James Smart2e0fef82007-06-17 19:56:36 -05004871 spin_lock_irq(shost->host_lock);
4872 vport->fc_flag |= FC_RSCN_MODE;
4873 spin_unlock_irq(shost->host_lock);
4874 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004875 /* Indicate we are done walking fc_rscn_id_list on this vport */
4876 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004877 /*
4878 * If we zero, cmdiocb->context2, the calling routine will
4879 * not try to free it.
4880 */
4881 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004882 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004883 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004884 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004885 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004886 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004887 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004888}
4889
James Smarte59058c2008-08-24 21:49:00 -04004890/**
James Smart3621a712009-04-06 18:47:14 -04004891 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004892 * @vport: pointer to a host virtual N_Port data structure.
4893 *
4894 * This routine handles the Registration State Configuration Notification
4895 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4896 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4897 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4898 * NameServer shall be issued. If CT command to the NameServer fails to be
4899 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4900 * RSCN activities with the @vport.
4901 *
4902 * Return code
4903 * 0 - Cleaned up rscn on the @vport
4904 * 1 - Wait for plogi to name server before proceed
4905 **/
dea31012005-04-17 16:05:31 -05004906int
James Smart2e0fef82007-06-17 19:56:36 -05004907lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004908{
4909 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004910 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004911
James Smart92d7f7b2007-06-17 19:56:38 -05004912 /* Ignore RSCN if the port is being torn down. */
4913 if (vport->load_flag & FC_UNLOADING) {
4914 lpfc_els_flush_rscn(vport);
4915 return 0;
4916 }
4917
dea31012005-04-17 16:05:31 -05004918 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004919 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004920
4921 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004922 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4923 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4924 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4925 vport->port_state);
dea31012005-04-17 16:05:31 -05004926
4927 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004928 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004929 vport->num_disc_nodes = 0;
4930
James Smart2e0fef82007-06-17 19:56:36 -05004931 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004932 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4933 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004934 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004935 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004936 /* Wait for NameServer query cmpl before we can
4937 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004938 return 1;
dea31012005-04-17 16:05:31 -05004939 } else {
4940 /* If login to NameServer does not exist, issue one */
4941 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004942 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004943 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004944 /* Wait for NameServer login cmpl before we can
4945 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004946 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004947
James Smarte47c9092008-02-08 18:49:26 -05004948 if (ndlp) {
4949 ndlp = lpfc_enable_node(vport, ndlp,
4950 NLP_STE_PLOGI_ISSUE);
4951 if (!ndlp) {
4952 lpfc_els_flush_rscn(vport);
4953 return 0;
4954 }
4955 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004956 } else {
James Smarte47c9092008-02-08 18:49:26 -05004957 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4958 if (!ndlp) {
4959 lpfc_els_flush_rscn(vport);
4960 return 0;
4961 }
James Smart2e0fef82007-06-17 19:56:36 -05004962 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004963 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004964 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004965 }
James Smarte47c9092008-02-08 18:49:26 -05004966 ndlp->nlp_type |= NLP_FABRIC;
4967 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4968 /* Wait for NameServer login cmpl before we can
4969 * continue
4970 */
4971 return 1;
dea31012005-04-17 16:05:31 -05004972 }
4973
James Smart2e0fef82007-06-17 19:56:36 -05004974 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004975 return 0;
dea31012005-04-17 16:05:31 -05004976}
4977
James Smarte59058c2008-08-24 21:49:00 -04004978/**
James Smart3621a712009-04-06 18:47:14 -04004979 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004980 * @vport: pointer to a host virtual N_Port data structure.
4981 * @cmdiocb: pointer to lpfc command iocb data structure.
4982 * @ndlp: pointer to a node-list data structure.
4983 *
4984 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4985 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4986 * point topology. As an unsolicited FLOGI should not be received in a loop
4987 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4988 * lpfc_check_sparm() routine is invoked to check the parameters in the
4989 * unsolicited FLOGI. If parameters validation failed, the routine
4990 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4991 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4992 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4993 * will initiate PLOGI. The higher lexicographical value party shall has
4994 * higher priority (as the winning port) and will initiate PLOGI and
4995 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4996 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4997 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4998 *
4999 * Return code
5000 * 0 - Successfully processed the unsolicited flogi
5001 * 1 - Failed to process the unsolicited flogi
5002 **/
dea31012005-04-17 16:05:31 -05005003static int
James Smart2e0fef82007-06-17 19:56:36 -05005004lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005005 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005006{
James Smart2e0fef82007-06-17 19:56:36 -05005007 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5008 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005009 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5010 uint32_t *lp = (uint32_t *) pcmd->virt;
5011 IOCB_t *icmd = &cmdiocb->iocb;
5012 struct serv_parm *sp;
5013 LPFC_MBOXQ_t *mbox;
5014 struct ls_rjt stat;
5015 uint32_t cmd, did;
5016 int rc;
5017
5018 cmd = *lp++;
5019 sp = (struct serv_parm *) lp;
5020
5021 /* FLOGI received */
5022
James Smart2e0fef82007-06-17 19:56:36 -05005023 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005024
James Smart76a95d72010-11-20 23:11:48 -05005025 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005026 /* We should never receive a FLOGI in loop mode, ignore it */
5027 did = icmd->un.elsreq64.remoteID;
5028
5029 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5030 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005031 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5032 "0113 An FLOGI ELS command x%x was "
5033 "received from DID x%x in Loop Mode\n",
5034 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005035 return 1;
dea31012005-04-17 16:05:31 -05005036 }
5037
James Smart341af102010-01-26 23:07:37 -05005038 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005039 /* For a FLOGI we accept, then if our portname is greater
5040 * then the remote portname we initiate Nport login.
5041 */
5042
James Smart2e0fef82007-06-17 19:56:36 -05005043 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005044 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005045
5046 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005047 if (phba->sli_rev < LPFC_SLI_REV4) {
5048 mbox = mempool_alloc(phba->mbox_mem_pool,
5049 GFP_KERNEL);
5050 if (!mbox)
5051 return 1;
5052 lpfc_linkdown(phba);
5053 lpfc_init_link(phba, mbox,
5054 phba->cfg_topology,
5055 phba->cfg_link_speed);
5056 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5057 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5058 mbox->vport = vport;
5059 rc = lpfc_sli_issue_mbox(phba, mbox,
5060 MBX_NOWAIT);
5061 lpfc_set_loopback_flag(phba);
5062 if (rc == MBX_NOT_FINISHED)
5063 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005064 return 1;
James Smart1b511972011-12-13 13:23:09 -05005065 } else {
5066 /* abort the flogi coming back to ourselves
5067 * due to external loopback on the port.
5068 */
5069 lpfc_els_abort_flogi(phba);
5070 return 0;
dea31012005-04-17 16:05:31 -05005071 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005072 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005073 spin_lock_irq(shost->host_lock);
5074 vport->fc_flag |= FC_PT2PT_PLOGI;
5075 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005076
5077 /* If we have the high WWPN we can assign our own
5078 * myDID; otherwise, we have to WAIT for a PLOGI
5079 * from the remote NPort to find out what it
5080 * will be.
5081 */
James Smarte6446432012-05-09 21:16:42 -04005082 vport->fc_myDID = PT2PT_LocalID;
James Smart939723a2012-05-09 21:19:03 -04005083 }
5084
5085 /*
5086 * The vport state should go to LPFC_FLOGI only
5087 * AFTER we issue a FLOGI, not receive one.
5088 */
James Smart2e0fef82007-06-17 19:56:36 -05005089 spin_lock_irq(shost->host_lock);
5090 vport->fc_flag |= FC_PT2PT;
5091 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5092 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005093
5094 /*
5095 * We temporarily set fc_myDID to make it look like we are
5096 * a Fabric. This is done just so we end up with the right
5097 * did / sid on the FLOGI ACC rsp.
5098 */
5099 did = vport->fc_myDID;
5100 vport->fc_myDID = Fabric_DID;
5101
dea31012005-04-17 16:05:31 -05005102 } else {
5103 /* Reject this request because invalid parameters */
5104 stat.un.b.lsRjtRsvd0 = 0;
5105 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5106 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5107 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005108
5109 /*
5110 * We temporarily set fc_myDID to make it look like we are
5111 * a Fabric. This is done just so we end up with the right
5112 * did / sid on the FLOGI LS_RJT rsp.
5113 */
5114 did = vport->fc_myDID;
5115 vport->fc_myDID = Fabric_DID;
5116
James Smart858c9f62007-06-17 19:56:39 -05005117 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5118 NULL);
James Smart939723a2012-05-09 21:19:03 -04005119
5120 /* Now lets put fc_myDID back to what its supposed to be */
5121 vport->fc_myDID = did;
5122
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005123 return 1;
dea31012005-04-17 16:05:31 -05005124 }
5125
5126 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005127 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005128
James Smart939723a2012-05-09 21:19:03 -04005129 /* Now lets put fc_myDID back to what its supposed to be */
5130 vport->fc_myDID = did;
5131
James Smarte6446432012-05-09 21:16:42 -04005132 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005133
James Smarte6446432012-05-09 21:16:42 -04005134 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5135 if (!mbox)
5136 goto fail;
5137
5138 lpfc_config_link(phba, mbox);
5139
5140 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5141 mbox->vport = vport;
5142 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5143 if (rc == MBX_NOT_FINISHED) {
5144 mempool_free(mbox, phba->mbox_mem_pool);
5145 goto fail;
5146 }
5147 }
5148
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005149 return 0;
James Smarte6446432012-05-09 21:16:42 -04005150fail:
5151 return 1;
dea31012005-04-17 16:05:31 -05005152}
5153
James Smarte59058c2008-08-24 21:49:00 -04005154/**
James Smart3621a712009-04-06 18:47:14 -04005155 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005156 * @vport: pointer to a host virtual N_Port data structure.
5157 * @cmdiocb: pointer to lpfc command iocb data structure.
5158 * @ndlp: pointer to a node-list data structure.
5159 *
5160 * This routine processes Request Node Identification Data (RNID) IOCB
5161 * received as an ELS unsolicited event. Only when the RNID specified format
5162 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5163 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5164 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5165 * rejected by invoking the lpfc_els_rsp_reject() routine.
5166 *
5167 * Return code
5168 * 0 - Successfully processed rnid iocb (currently always return 0)
5169 **/
dea31012005-04-17 16:05:31 -05005170static int
James Smart2e0fef82007-06-17 19:56:36 -05005171lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5172 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005173{
5174 struct lpfc_dmabuf *pcmd;
5175 uint32_t *lp;
5176 IOCB_t *icmd;
5177 RNID *rn;
5178 struct ls_rjt stat;
5179 uint32_t cmd, did;
5180
5181 icmd = &cmdiocb->iocb;
5182 did = icmd->un.elsreq64.remoteID;
5183 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5184 lp = (uint32_t *) pcmd->virt;
5185
5186 cmd = *lp++;
5187 rn = (RNID *) lp;
5188
5189 /* RNID received */
5190
5191 switch (rn->Format) {
5192 case 0:
5193 case RNID_TOPOLOGY_DISC:
5194 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005195 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005196 break;
5197 default:
5198 /* Reject this request because format not supported */
5199 stat.un.b.lsRjtRsvd0 = 0;
5200 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5201 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5202 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005203 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5204 NULL);
dea31012005-04-17 16:05:31 -05005205 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005206 return 0;
dea31012005-04-17 16:05:31 -05005207}
5208
James Smarte59058c2008-08-24 21:49:00 -04005209/**
James Smart12265f62010-10-22 11:05:53 -04005210 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5211 * @vport: pointer to a host virtual N_Port data structure.
5212 * @cmdiocb: pointer to lpfc command iocb data structure.
5213 * @ndlp: pointer to a node-list data structure.
5214 *
5215 * Return code
5216 * 0 - Successfully processed echo iocb (currently always return 0)
5217 **/
5218static int
5219lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5220 struct lpfc_nodelist *ndlp)
5221{
5222 uint8_t *pcmd;
5223
5224 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5225
5226 /* skip over first word of echo command to find echo data */
5227 pcmd += sizeof(uint32_t);
5228
5229 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5230 return 0;
5231}
5232
5233/**
James Smart3621a712009-04-06 18:47:14 -04005234 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005235 * @vport: pointer to a host virtual N_Port data structure.
5236 * @cmdiocb: pointer to lpfc command iocb data structure.
5237 * @ndlp: pointer to a node-list data structure.
5238 *
5239 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5240 * received as an ELS unsolicited event. Currently, this function just invokes
5241 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5242 *
5243 * Return code
5244 * 0 - Successfully processed lirr iocb (currently always return 0)
5245 **/
dea31012005-04-17 16:05:31 -05005246static int
James Smart2e0fef82007-06-17 19:56:36 -05005247lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5248 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005249{
5250 struct ls_rjt stat;
5251
5252 /* For now, unconditionally reject this command */
5253 stat.un.b.lsRjtRsvd0 = 0;
5254 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5255 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5256 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005257 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005258 return 0;
5259}
5260
James Smarte59058c2008-08-24 21:49:00 -04005261/**
James Smart5ffc2662009-11-18 15:39:44 -05005262 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5263 * @vport: pointer to a host virtual N_Port data structure.
5264 * @cmdiocb: pointer to lpfc command iocb data structure.
5265 * @ndlp: pointer to a node-list data structure.
5266 *
5267 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5268 * received as an ELS unsolicited event. A request to RRQ shall only
5269 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5270 * Nx_Port N_Port_ID of the target Exchange is the same as the
5271 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5272 * not accepted, an LS_RJT with reason code "Unable to perform
5273 * command request" and reason code explanation "Invalid Originator
5274 * S_ID" shall be returned. For now, we just unconditionally accept
5275 * RRQ from the target.
5276 **/
5277static void
5278lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5279 struct lpfc_nodelist *ndlp)
5280{
5281 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005282 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5283 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005284}
5285
5286/**
James Smart12265f62010-10-22 11:05:53 -04005287 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5288 * @phba: pointer to lpfc hba data structure.
5289 * @pmb: pointer to the driver internal queue element for mailbox command.
5290 *
5291 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5292 * mailbox command. This callback function is to actually send the Accept
5293 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5294 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5295 * mailbox command, constructs the RPS response with the link statistics
5296 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5297 * response to the RPS.
5298 *
5299 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5300 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5301 * will be stored into the context1 field of the IOCB for the completion
5302 * callback function to the RPS Accept Response ELS IOCB command.
5303 *
5304 **/
5305static void
5306lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5307{
5308 MAILBOX_t *mb;
5309 IOCB_t *icmd;
5310 struct RLS_RSP *rls_rsp;
5311 uint8_t *pcmd;
5312 struct lpfc_iocbq *elsiocb;
5313 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005314 uint16_t oxid;
5315 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005316 uint32_t cmdsize;
5317
5318 mb = &pmb->u.mb;
5319
5320 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005321 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5322 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005323 pmb->context1 = NULL;
5324 pmb->context2 = NULL;
5325
5326 if (mb->mbxStatus) {
5327 mempool_free(pmb, phba->mbox_mem_pool);
5328 return;
5329 }
5330
5331 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005332 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5333 lpfc_max_els_tries, ndlp,
5334 ndlp->nlp_DID, ELS_CMD_ACC);
5335
5336 /* Decrement the ndlp reference count from previous mbox command */
5337 lpfc_nlp_put(ndlp);
5338
James Smart37db57e2012-05-09 21:17:16 -04005339 if (!elsiocb) {
5340 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005341 return;
James Smart37db57e2012-05-09 21:17:16 -04005342 }
James Smart12265f62010-10-22 11:05:53 -04005343
5344 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005345 icmd->ulpContext = rxid;
5346 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005347
5348 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5349 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5350 pcmd += sizeof(uint32_t); /* Skip past command */
5351 rls_rsp = (struct RLS_RSP *)pcmd;
5352
5353 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5354 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5355 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5356 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5357 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5358 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005359 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005360 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5361 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5362 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5363 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5364 elsiocb->iotag, elsiocb->iocb.ulpContext,
5365 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5366 ndlp->nlp_rpi);
5367 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5368 phba->fc_stat.elsXmitACC++;
5369 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5370 lpfc_els_free_iocb(phba, elsiocb);
5371}
5372
5373/**
James Smart3621a712009-04-06 18:47:14 -04005374 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005375 * @phba: pointer to lpfc hba data structure.
5376 * @pmb: pointer to the driver internal queue element for mailbox command.
5377 *
5378 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5379 * mailbox command. This callback function is to actually send the Accept
5380 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5381 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5382 * mailbox command, constructs the RPS response with the link statistics
5383 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5384 * response to the RPS.
5385 *
5386 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5387 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5388 * will be stored into the context1 field of the IOCB for the completion
5389 * callback function to the RPS Accept Response ELS IOCB command.
5390 *
5391 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005392static void
James Smart329f9bc2007-04-25 09:53:01 -04005393lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005394{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005395 MAILBOX_t *mb;
5396 IOCB_t *icmd;
5397 RPS_RSP *rps_rsp;
5398 uint8_t *pcmd;
5399 struct lpfc_iocbq *elsiocb;
5400 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005401 uint16_t status;
5402 uint16_t oxid;
5403 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005404 uint32_t cmdsize;
5405
James Smart04c68492009-05-22 14:52:52 -04005406 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005407
5408 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005409 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5410 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005411 pmb->context1 = NULL;
5412 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005413
5414 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005415 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005416 return;
5417 }
5418
5419 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005420 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005421 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5422 lpfc_max_els_tries, ndlp,
5423 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005424
5425 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005426 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005427
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005428 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005429 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005430
5431 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005432 icmd->ulpContext = rxid;
5433 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005434
5435 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5436 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005437 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005438 rps_rsp = (RPS_RSP *)pcmd;
5439
James Smart76a95d72010-11-20 23:11:48 -05005440 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005441 status = 0x10;
5442 else
5443 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005444 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005445 status |= 0x4;
5446
5447 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005448 rps_rsp->portStatus = cpu_to_be16(status);
5449 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5450 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5451 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5452 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5453 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5454 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005455 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005456 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5457 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5458 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5459 elsiocb->iotag, elsiocb->iocb.ulpContext,
5460 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5461 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005462 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005463 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005464 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005465 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005466 return;
5467}
5468
James Smarte59058c2008-08-24 21:49:00 -04005469/**
James Smart12265f62010-10-22 11:05:53 -04005470 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5471 * @vport: pointer to a host virtual N_Port data structure.
5472 * @cmdiocb: pointer to lpfc command iocb data structure.
5473 * @ndlp: pointer to a node-list data structure.
5474 *
5475 * This routine processes Read Port Status (RPL) IOCB received as an
5476 * ELS unsolicited event. It first checks the remote port state. If the
5477 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5478 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5479 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5480 * for reading the HBA link statistics. It is for the callback function,
5481 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5482 * to actually sending out RPL Accept (ACC) response.
5483 *
5484 * Return codes
5485 * 0 - Successfully processed rls iocb (currently always return 0)
5486 **/
5487static int
5488lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5489 struct lpfc_nodelist *ndlp)
5490{
5491 struct lpfc_hba *phba = vport->phba;
5492 LPFC_MBOXQ_t *mbox;
5493 struct lpfc_dmabuf *pcmd;
5494 struct ls_rjt stat;
5495
5496 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5497 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5498 /* reject the unsolicited RPS request and done with it */
5499 goto reject_out;
5500
5501 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5502
5503 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5504 if (mbox) {
5505 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005506 mbox->context1 = (void *)((unsigned long)
5507 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5508 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005509 mbox->context2 = lpfc_nlp_get(ndlp);
5510 mbox->vport = vport;
5511 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5512 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5513 != MBX_NOT_FINISHED)
5514 /* Mbox completion will send ELS Response */
5515 return 0;
5516 /* Decrement reference count used for the failed mbox
5517 * command.
5518 */
5519 lpfc_nlp_put(ndlp);
5520 mempool_free(mbox, phba->mbox_mem_pool);
5521 }
5522reject_out:
5523 /* issue rejection response */
5524 stat.un.b.lsRjtRsvd0 = 0;
5525 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5526 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5527 stat.un.b.vendorUnique = 0;
5528 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5529 return 0;
5530}
5531
5532/**
5533 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5534 * @vport: pointer to a host virtual N_Port data structure.
5535 * @cmdiocb: pointer to lpfc command iocb data structure.
5536 * @ndlp: pointer to a node-list data structure.
5537 *
5538 * This routine processes Read Timout Value (RTV) IOCB received as an
5539 * ELS unsolicited event. It first checks the remote port state. If the
5540 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5541 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5542 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5543 * Value (RTV) unsolicited IOCB event.
5544 *
5545 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5546 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5547 * will be stored into the context1 field of the IOCB for the completion
5548 * callback function to the RPS Accept Response ELS IOCB command.
5549 *
5550 * Return codes
5551 * 0 - Successfully processed rtv iocb (currently always return 0)
5552 **/
5553static int
5554lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5555 struct lpfc_nodelist *ndlp)
5556{
5557 struct lpfc_hba *phba = vport->phba;
5558 struct ls_rjt stat;
5559 struct RTV_RSP *rtv_rsp;
5560 uint8_t *pcmd;
5561 struct lpfc_iocbq *elsiocb;
5562 uint32_t cmdsize;
5563
5564
5565 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5566 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5567 /* reject the unsolicited RPS request and done with it */
5568 goto reject_out;
5569
5570 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5571 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5572 lpfc_max_els_tries, ndlp,
5573 ndlp->nlp_DID, ELS_CMD_ACC);
5574
5575 if (!elsiocb)
5576 return 1;
5577
5578 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5579 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5580 pcmd += sizeof(uint32_t); /* Skip past command */
5581
5582 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005583 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5584 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005585
5586 rtv_rsp = (struct RTV_RSP *)pcmd;
5587
5588 /* populate RTV payload */
5589 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5590 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5591 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5592 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5593 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5594
5595 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5596 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5597 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5598 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5599 "Data: x%x x%x x%x\n",
5600 elsiocb->iotag, elsiocb->iocb.ulpContext,
5601 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5602 ndlp->nlp_rpi,
5603 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5604 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5605 phba->fc_stat.elsXmitACC++;
5606 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5607 lpfc_els_free_iocb(phba, elsiocb);
5608 return 0;
5609
5610reject_out:
5611 /* issue rejection response */
5612 stat.un.b.lsRjtRsvd0 = 0;
5613 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5614 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5615 stat.un.b.vendorUnique = 0;
5616 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5617 return 0;
5618}
5619
5620/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005621 * @vport: pointer to a host virtual N_Port data structure.
5622 * @cmdiocb: pointer to lpfc command iocb data structure.
5623 * @ndlp: pointer to a node-list data structure.
5624 *
5625 * This routine processes Read Port Status (RPS) IOCB received as an
5626 * ELS unsolicited event. It first checks the remote port state. If the
5627 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5628 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5629 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5630 * for reading the HBA link statistics. It is for the callback function,
5631 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5632 * to actually sending out RPS Accept (ACC) response.
5633 *
5634 * Return codes
5635 * 0 - Successfully processed rps iocb (currently always return 0)
5636 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005637static int
James Smart2e0fef82007-06-17 19:56:36 -05005638lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5639 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005640{
James Smart2e0fef82007-06-17 19:56:36 -05005641 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005642 uint32_t *lp;
5643 uint8_t flag;
5644 LPFC_MBOXQ_t *mbox;
5645 struct lpfc_dmabuf *pcmd;
5646 RPS *rps;
5647 struct ls_rjt stat;
5648
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005649 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005650 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5651 /* reject the unsolicited RPS request and done with it */
5652 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005653
5654 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5655 lp = (uint32_t *) pcmd->virt;
5656 flag = (be32_to_cpu(*lp++) & 0xf);
5657 rps = (RPS *) lp;
5658
5659 if ((flag == 0) ||
5660 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005661 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005662 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005663
James Smart92d7f7b2007-06-17 19:56:38 -05005664 printk("Fix me....\n");
5665 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005666 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5667 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005668 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005669 mbox->context1 = (void *)((unsigned long)
5670 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5671 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005672 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005673 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005674 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005675 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005676 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005677 /* Mbox completion will send ELS Response */
5678 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005679 /* Decrement reference count used for the failed mbox
5680 * command.
5681 */
James Smart329f9bc2007-04-25 09:53:01 -04005682 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005683 mempool_free(mbox, phba->mbox_mem_pool);
5684 }
5685 }
James Smart90160e02008-08-24 21:49:45 -04005686
5687reject_out:
5688 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005689 stat.un.b.lsRjtRsvd0 = 0;
5690 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5691 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5692 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005693 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005694 return 0;
5695}
5696
James Smart19ca7602010-11-20 23:11:55 -05005697/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5698 * @vport: pointer to a host virtual N_Port data structure.
5699 * @ndlp: pointer to a node-list data structure.
5700 * @did: DID of the target.
5701 * @rrq: Pointer to the rrq struct.
5702 *
5703 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5704 * Successful the the completion handler will clear the RRQ.
5705 *
5706 * Return codes
5707 * 0 - Successfully sent rrq els iocb.
5708 * 1 - Failed to send rrq els iocb.
5709 **/
5710static int
5711lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5712 uint32_t did, struct lpfc_node_rrq *rrq)
5713{
5714 struct lpfc_hba *phba = vport->phba;
5715 struct RRQ *els_rrq;
5716 IOCB_t *icmd;
5717 struct lpfc_iocbq *elsiocb;
5718 uint8_t *pcmd;
5719 uint16_t cmdsize;
5720 int ret;
5721
5722
5723 if (ndlp != rrq->ndlp)
5724 ndlp = rrq->ndlp;
5725 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5726 return 1;
5727
5728 /* If ndlp is not NULL, we will bump the reference count on it */
5729 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5730 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5731 ELS_CMD_RRQ);
5732 if (!elsiocb)
5733 return 1;
5734
5735 icmd = &elsiocb->iocb;
5736 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5737
5738 /* For RRQ request, remainder of payload is Exchange IDs */
5739 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5740 pcmd += sizeof(uint32_t);
5741 els_rrq = (struct RRQ *) pcmd;
5742
James Smartee0f4fe2012-05-09 21:19:14 -04005743 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005744 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5745 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5746 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5747 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5748
5749
5750 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5751 "Issue RRQ: did:x%x",
5752 did, rrq->xritag, rrq->rxid);
5753 elsiocb->context_un.rrq = rrq;
5754 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5755 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5756
5757 if (ret == IOCB_ERROR) {
5758 lpfc_els_free_iocb(phba, elsiocb);
5759 return 1;
5760 }
5761 return 0;
5762}
5763
5764/**
5765 * lpfc_send_rrq - Sends ELS RRQ if needed.
5766 * @phba: pointer to lpfc hba data structure.
5767 * @rrq: pointer to the active rrq.
5768 *
5769 * This routine will call the lpfc_issue_els_rrq if the rrq is
5770 * still active for the xri. If this function returns a failure then
5771 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5772 *
5773 * Returns 0 Success.
5774 * 1 Failure.
5775 **/
5776int
5777lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5778{
5779 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5780 rrq->nlp_DID);
5781 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5782 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5783 rrq->nlp_DID, rrq);
5784 else
5785 return 1;
5786}
5787
James Smarte59058c2008-08-24 21:49:00 -04005788/**
James Smart3621a712009-04-06 18:47:14 -04005789 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005790 * @vport: pointer to a host virtual N_Port data structure.
5791 * @cmdsize: size of the ELS command.
5792 * @oldiocb: pointer to the original lpfc command iocb data structure.
5793 * @ndlp: pointer to a node-list data structure.
5794 *
5795 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5796 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5797 *
5798 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5799 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5800 * will be stored into the context1 field of the IOCB for the completion
5801 * callback function to the RPL Accept Response ELS command.
5802 *
5803 * Return code
5804 * 0 - Successfully issued ACC RPL ELS command
5805 * 1 - Failed to issue ACC RPL ELS command
5806 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005807static int
James Smart2e0fef82007-06-17 19:56:36 -05005808lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5809 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005810{
James Smart2e0fef82007-06-17 19:56:36 -05005811 struct lpfc_hba *phba = vport->phba;
5812 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005813 RPL_RSP rpl_rsp;
5814 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005815 uint8_t *pcmd;
5816
James Smart2e0fef82007-06-17 19:56:36 -05005817 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5818 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005819
James Smart488d1462006-03-07 15:02:37 -05005820 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005821 return 1;
James Smart488d1462006-03-07 15:02:37 -05005822
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005823 icmd = &elsiocb->iocb;
5824 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005825 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5826 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005827
5828 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5829 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005830 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005831 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5832 pcmd += sizeof(uint16_t);
5833
5834 /* Setup the RPL ACC payload */
5835 rpl_rsp.listLen = be32_to_cpu(1);
5836 rpl_rsp.index = 0;
5837 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005838 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5839 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005840 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005841 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005842 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005843 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5844 "0120 Xmit ELS RPL ACC response tag x%x "
5845 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5846 "rpi x%x\n",
5847 elsiocb->iotag, elsiocb->iocb.ulpContext,
5848 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5849 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005850 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005851 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005852 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5853 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005854 lpfc_els_free_iocb(phba, elsiocb);
5855 return 1;
5856 }
5857 return 0;
5858}
5859
James Smarte59058c2008-08-24 21:49:00 -04005860/**
James Smart3621a712009-04-06 18:47:14 -04005861 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005862 * @vport: pointer to a host virtual N_Port data structure.
5863 * @cmdiocb: pointer to lpfc command iocb data structure.
5864 * @ndlp: pointer to a node-list data structure.
5865 *
5866 * This routine processes Read Port List (RPL) IOCB received as an ELS
5867 * unsolicited event. It first checks the remote port state. If the remote
5868 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5869 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5870 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5871 * to accept the RPL.
5872 *
5873 * Return code
5874 * 0 - Successfully processed rpl iocb (currently always return 0)
5875 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005876static int
James Smart2e0fef82007-06-17 19:56:36 -05005877lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5878 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005879{
5880 struct lpfc_dmabuf *pcmd;
5881 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005882 uint32_t maxsize;
5883 uint16_t cmdsize;
5884 RPL *rpl;
5885 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005886
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005887 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5888 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005889 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005890 stat.un.b.lsRjtRsvd0 = 0;
5891 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5892 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5893 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005894 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5895 NULL);
James Smart90160e02008-08-24 21:49:45 -04005896 /* rejected the unsolicited RPL request and done with it */
5897 return 0;
dea31012005-04-17 16:05:31 -05005898 }
5899
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005900 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5901 lp = (uint32_t *) pcmd->virt;
5902 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005903 maxsize = be32_to_cpu(rpl->maxsize);
5904
5905 /* We support only one port */
5906 if ((rpl->index == 0) &&
5907 ((maxsize == 0) ||
5908 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5909 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005910 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005911 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5912 }
James Smart2e0fef82007-06-17 19:56:36 -05005913 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005914
5915 return 0;
5916}
5917
James Smarte59058c2008-08-24 21:49:00 -04005918/**
James Smart3621a712009-04-06 18:47:14 -04005919 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005920 * @vport: pointer to a virtual N_Port data structure.
5921 * @cmdiocb: pointer to lpfc command iocb data structure.
5922 * @ndlp: pointer to a node-list data structure.
5923 *
5924 * This routine processes Fibre Channel Address Resolution Protocol
5925 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5926 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5927 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5928 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5929 * remote PortName is compared against the FC PortName stored in the @vport
5930 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5931 * compared against the FC NodeName stored in the @vport data structure.
5932 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5933 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5934 * invoked to send out FARP Response to the remote node. Before sending the
5935 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5936 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5937 * routine is invoked to log into the remote port first.
5938 *
5939 * Return code
5940 * 0 - Either the FARP Match Mode not supported or successfully processed
5941 **/
dea31012005-04-17 16:05:31 -05005942static int
James Smart2e0fef82007-06-17 19:56:36 -05005943lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5944 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005945{
5946 struct lpfc_dmabuf *pcmd;
5947 uint32_t *lp;
5948 IOCB_t *icmd;
5949 FARP *fp;
5950 uint32_t cmd, cnt, did;
5951
5952 icmd = &cmdiocb->iocb;
5953 did = icmd->un.elsreq64.remoteID;
5954 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5955 lp = (uint32_t *) pcmd->virt;
5956
5957 cmd = *lp++;
5958 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005959 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005960 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5961 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005962 /* We will only support match on WWPN or WWNN */
5963 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005964 return 0;
dea31012005-04-17 16:05:31 -05005965 }
5966
5967 cnt = 0;
5968 /* If this FARP command is searching for my portname */
5969 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005970 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005971 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005972 cnt = 1;
5973 }
5974
5975 /* If this FARP command is searching for my nodename */
5976 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005977 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005978 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005979 cnt = 1;
5980 }
5981
5982 if (cnt) {
5983 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5984 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5985 /* Log back into the node before sending the FARP. */
5986 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005987 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005988 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005989 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005990 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005991 }
5992
5993 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005994 if (fp->Rflags & FARP_REQUEST_FARPR)
5995 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005996 }
5997 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005998 return 0;
dea31012005-04-17 16:05:31 -05005999}
6000
James Smarte59058c2008-08-24 21:49:00 -04006001/**
James Smart3621a712009-04-06 18:47:14 -04006002 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006003 * @vport: pointer to a host virtual N_Port data structure.
6004 * @cmdiocb: pointer to lpfc command iocb data structure.
6005 * @ndlp: pointer to a node-list data structure.
6006 *
6007 * This routine processes Fibre Channel Address Resolution Protocol
6008 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6009 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6010 * the FARP response request.
6011 *
6012 * Return code
6013 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6014 **/
dea31012005-04-17 16:05:31 -05006015static int
James Smart2e0fef82007-06-17 19:56:36 -05006016lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6017 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006018{
6019 struct lpfc_dmabuf *pcmd;
6020 uint32_t *lp;
6021 IOCB_t *icmd;
6022 uint32_t cmd, did;
6023
6024 icmd = &cmdiocb->iocb;
6025 did = icmd->un.elsreq64.remoteID;
6026 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6027 lp = (uint32_t *) pcmd->virt;
6028
6029 cmd = *lp++;
6030 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006031 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6032 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006033 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006034 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006035
6036 return 0;
6037}
6038
James Smarte59058c2008-08-24 21:49:00 -04006039/**
James Smart3621a712009-04-06 18:47:14 -04006040 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006041 * @vport: pointer to a host virtual N_Port data structure.
6042 * @cmdiocb: pointer to lpfc command iocb data structure.
6043 * @fan_ndlp: pointer to a node-list data structure.
6044 *
6045 * This routine processes a Fabric Address Notification (FAN) IOCB
6046 * command received as an ELS unsolicited event. The FAN ELS command will
6047 * only be processed on a physical port (i.e., the @vport represents the
6048 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6049 * compared against those in the phba data structure. If any of those is
6050 * different, the lpfc_initial_flogi() routine is invoked to initialize
6051 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6052 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6053 * is invoked to register login to the fabric.
6054 *
6055 * Return code
6056 * 0 - Successfully processed fan iocb (currently always return 0).
6057 **/
dea31012005-04-17 16:05:31 -05006058static int
James Smart2e0fef82007-06-17 19:56:36 -05006059lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6060 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006061{
James Smart2e0fef82007-06-17 19:56:36 -05006062 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006063 uint32_t *lp;
6064 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006065
James Smart0d2b6b82008-06-14 22:52:47 -04006066 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6067 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6068 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006069 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006070 if ((vport == phba->pport) &&
6071 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006072 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006073 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006074 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006075 sizeof(struct lpfc_name)))) {
6076 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006077 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006078 } else {
6079 /* FAN verified - skip FLOGI */
6080 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006081 if (phba->sli_rev < LPFC_SLI_REV4)
6082 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006083 else {
6084 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6085 "3138 Need register VFI: (x%x/%x)\n",
6086 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006087 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006088 }
dea31012005-04-17 16:05:31 -05006089 }
dea31012005-04-17 16:05:31 -05006090 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006091 return 0;
dea31012005-04-17 16:05:31 -05006092}
6093
James Smarte59058c2008-08-24 21:49:00 -04006094/**
James Smart3621a712009-04-06 18:47:14 -04006095 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006096 * @ptr: holder for the timer function associated data.
6097 *
6098 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6099 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6100 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6101 * up the worker thread. It is for the worker thread to invoke the routine
6102 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6103 **/
dea31012005-04-17 16:05:31 -05006104void
6105lpfc_els_timeout(unsigned long ptr)
6106{
James Smart2e0fef82007-06-17 19:56:36 -05006107 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6108 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006109 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006110 unsigned long iflag;
6111
James Smart2e0fef82007-06-17 19:56:36 -05006112 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006113 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6114 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006115 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006116 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006117
James Smart5e9d9b82008-06-14 22:52:53 -04006118 if (!tmo_posted)
6119 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006120 return;
6121}
6122
James Smart2a9bf3d2010-06-07 15:24:45 -04006123
James Smarte59058c2008-08-24 21:49:00 -04006124/**
James Smart3621a712009-04-06 18:47:14 -04006125 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006126 * @vport: pointer to a virtual N_Port data structure.
6127 *
6128 * This routine is the actual handler function that processes an ELS timeout
6129 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6130 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6131 * invoking the lpfc_sli_issue_abort_iotag() routine.
6132 **/
dea31012005-04-17 16:05:31 -05006133void
James Smart2e0fef82007-06-17 19:56:36 -05006134lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006135{
James Smart2e0fef82007-06-17 19:56:36 -05006136 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006137 struct lpfc_sli_ring *pring;
6138 struct lpfc_iocbq *tmp_iocb, *piocb;
6139 IOCB_t *cmd = NULL;
6140 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006141 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006142 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006143 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006144 LIST_HEAD(txcmplq_completions);
6145 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006146
James Smart2a9bf3d2010-06-07 15:24:45 -04006147
dea31012005-04-17 16:05:31 -05006148 timeout = (uint32_t)(phba->fc_ratov << 1);
6149
6150 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006151
James Smart2a9bf3d2010-06-07 15:24:45 -04006152 spin_lock_irq(&phba->hbalock);
6153 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6154 spin_unlock_irq(&phba->hbalock);
6155
6156 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006157 cmd = &piocb->iocb;
6158
James Smart2e0fef82007-06-17 19:56:36 -05006159 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6160 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6161 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006162 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006163
6164 if (piocb->vport != vport)
6165 continue;
6166
dea31012005-04-17 16:05:31 -05006167 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006168 if (pcmd)
6169 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006170
James Smart92d7f7b2007-06-17 19:56:38 -05006171 if (els_command == ELS_CMD_FARP ||
6172 els_command == ELS_CMD_FARPR ||
6173 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006174 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006175
dea31012005-04-17 16:05:31 -05006176 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006177 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006178 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006179 else
dea31012005-04-17 16:05:31 -05006180 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006181 continue;
6182 }
6183
James Smart2e0fef82007-06-17 19:56:36 -05006184 remote_ID = 0xffffffff;
6185 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006186 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006187 else {
6188 struct lpfc_nodelist *ndlp;
6189 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006190 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006191 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006192 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006193 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006194 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006195 spin_lock_irq(&phba->hbalock);
6196 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006197 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006198
James Smart2a9bf3d2010-06-07 15:24:45 -04006199 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6200 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6201 "0127 ELS timeout Data: x%x x%x x%x "
6202 "x%x\n", els_command,
6203 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6204 spin_lock_irq(&phba->hbalock);
6205 list_del_init(&piocb->dlist);
6206 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6207 spin_unlock_irq(&phba->hbalock);
6208 }
6209
James Smart2e0fef82007-06-17 19:56:36 -05006210 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6211 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006212}
6213
James Smarte59058c2008-08-24 21:49:00 -04006214/**
James Smart3621a712009-04-06 18:47:14 -04006215 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006216 * @vport: pointer to a host virtual N_Port data structure.
6217 *
6218 * This routine is used to clean up all the outstanding ELS commands on a
6219 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6220 * routine. After that, it walks the ELS transmit queue to remove all the
6221 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6222 * the IOCBs with a non-NULL completion callback function, the callback
6223 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6224 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6225 * callback function, the IOCB will simply be released. Finally, it walks
6226 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6227 * completion queue IOCB that is associated with the @vport and is not
6228 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6229 * part of the discovery state machine) out to HBA by invoking the
6230 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6231 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6232 * the IOCBs are aborted when this function returns.
6233 **/
dea31012005-04-17 16:05:31 -05006234void
James Smart2e0fef82007-06-17 19:56:36 -05006235lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006236{
James Smart2534ba72007-04-25 09:52:20 -04006237 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006238 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006239 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006240 struct lpfc_iocbq *tmp_iocb, *piocb;
6241 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006242
6243 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006244
James Smart2e0fef82007-06-17 19:56:36 -05006245 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006246 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6247 cmd = &piocb->iocb;
6248
6249 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6250 continue;
6251 }
6252
6253 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006254 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6255 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6256 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6257 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006258 continue;
dea31012005-04-17 16:05:31 -05006259
James Smart2e0fef82007-06-17 19:56:36 -05006260 if (piocb->vport != vport)
6261 continue;
6262
James Smart2534ba72007-04-25 09:52:20 -04006263 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006264 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006265 }
6266
6267 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006268 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6269 continue;
6270 }
dea31012005-04-17 16:05:31 -05006271
James Smart2e0fef82007-06-17 19:56:36 -05006272 if (piocb->vport != vport)
6273 continue;
6274
James Smart07951072007-04-25 09:51:38 -04006275 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006276 }
James Smart2e0fef82007-06-17 19:56:36 -05006277 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006278
James Smarta257bf92009-04-06 18:48:10 -04006279 /* Cancell all the IOCBs from the completions list */
6280 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6281 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006282
dea31012005-04-17 16:05:31 -05006283 return;
6284}
6285
James Smarte59058c2008-08-24 21:49:00 -04006286/**
James Smart3621a712009-04-06 18:47:14 -04006287 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006288 * @phba: pointer to lpfc hba data structure.
6289 *
6290 * This routine is used to clean up all the outstanding ELS commands on a
6291 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6292 * routine. After that, it walks the ELS transmit queue to remove all the
6293 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6294 * the IOCBs with the completion callback function associated, the callback
6295 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6296 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6297 * callback function associated, the IOCB will simply be released. Finally,
6298 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6299 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6300 * management plane IOCBs that are not part of the discovery state machine)
6301 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6302 **/
James Smart549e55c2007-08-02 11:09:51 -04006303void
6304lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6305{
6306 LIST_HEAD(completions);
6307 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6308 struct lpfc_iocbq *tmp_iocb, *piocb;
6309 IOCB_t *cmd = NULL;
6310
6311 lpfc_fabric_abort_hba(phba);
6312 spin_lock_irq(&phba->hbalock);
6313 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6314 cmd = &piocb->iocb;
6315 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6316 continue;
6317 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6318 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6319 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6320 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6321 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6322 continue;
6323 list_move_tail(&piocb->list, &completions);
6324 pring->txq_cnt--;
6325 }
6326 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6327 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6328 continue;
6329 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6330 }
6331 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006332
6333 /* Cancel all the IOCBs from the completions list */
6334 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6335 IOERR_SLI_ABORTED);
6336
James Smart549e55c2007-08-02 11:09:51 -04006337 return;
6338}
6339
James Smarte59058c2008-08-24 21:49:00 -04006340/**
James Smart3621a712009-04-06 18:47:14 -04006341 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006342 * @phba: Pointer to hba context object.
6343 * @cmdiocbp: Pointer to command iocb which reported error.
6344 * @rspiocbp: Pointer to response iocb which reported error.
6345 *
6346 * This function sends an event when there is an ELS command
6347 * failure.
6348 **/
6349void
6350lpfc_send_els_failure_event(struct lpfc_hba *phba,
6351 struct lpfc_iocbq *cmdiocbp,
6352 struct lpfc_iocbq *rspiocbp)
6353{
6354 struct lpfc_vport *vport = cmdiocbp->vport;
6355 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6356 struct lpfc_lsrjt_event lsrjt_event;
6357 struct lpfc_fabric_event_header fabric_event;
6358 struct ls_rjt stat;
6359 struct lpfc_nodelist *ndlp;
6360 uint32_t *pcmd;
6361
6362 ndlp = cmdiocbp->context1;
6363 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6364 return;
6365
6366 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6367 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6368 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6369 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6370 sizeof(struct lpfc_name));
6371 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6372 sizeof(struct lpfc_name));
6373 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6374 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006375 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006376 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6377 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6378 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6379 fc_host_post_vendor_event(shost,
6380 fc_get_event_number(),
6381 sizeof(lsrjt_event),
6382 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006383 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006384 return;
6385 }
6386 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6387 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6388 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6389 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6390 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6391 else
6392 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6393 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6394 sizeof(struct lpfc_name));
6395 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6396 sizeof(struct lpfc_name));
6397 fc_host_post_vendor_event(shost,
6398 fc_get_event_number(),
6399 sizeof(fabric_event),
6400 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006401 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006402 return;
6403 }
6404
6405}
6406
6407/**
James Smart3621a712009-04-06 18:47:14 -04006408 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006409 * @vport: Pointer to vport object.
6410 * @ndlp: Pointer FC node object.
6411 * @cmd: ELS command code.
6412 *
6413 * This function posts an event when there is an incoming
6414 * unsolicited ELS command.
6415 **/
6416static void
6417lpfc_send_els_event(struct lpfc_vport *vport,
6418 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006419 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006420{
James Smartddcc50f2008-12-04 22:38:46 -05006421 struct lpfc_els_event_header *els_data = NULL;
6422 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6424
James Smartddcc50f2008-12-04 22:38:46 -05006425 if (*payload == ELS_CMD_LOGO) {
6426 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6427 if (!logo_data) {
6428 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6429 "0148 Failed to allocate memory "
6430 "for LOGO event\n");
6431 return;
6432 }
6433 els_data = &logo_data->header;
6434 } else {
6435 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6436 GFP_KERNEL);
6437 if (!els_data) {
6438 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6439 "0149 Failed to allocate memory "
6440 "for ELS event\n");
6441 return;
6442 }
6443 }
6444 els_data->event_type = FC_REG_ELS_EVENT;
6445 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006446 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006447 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006448 break;
6449 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006450 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006451 break;
6452 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006453 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6454 break;
6455 case ELS_CMD_LOGO:
6456 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6457 /* Copy the WWPN in the LOGO payload */
6458 memcpy(logo_data->logo_wwpn, &payload[2],
6459 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006460 break;
6461 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006462 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006463 return;
6464 }
James Smartddcc50f2008-12-04 22:38:46 -05006465 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6466 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6467 if (*payload == ELS_CMD_LOGO) {
6468 fc_host_post_vendor_event(shost,
6469 fc_get_event_number(),
6470 sizeof(struct lpfc_logo_event),
6471 (char *)logo_data,
6472 LPFC_NL_VENDOR_ID);
6473 kfree(logo_data);
6474 } else {
6475 fc_host_post_vendor_event(shost,
6476 fc_get_event_number(),
6477 sizeof(struct lpfc_els_event_header),
6478 (char *)els_data,
6479 LPFC_NL_VENDOR_ID);
6480 kfree(els_data);
6481 }
James Smartea2151b2008-09-07 11:52:10 -04006482
6483 return;
6484}
6485
6486
6487/**
James Smart3621a712009-04-06 18:47:14 -04006488 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006489 * @phba: pointer to lpfc hba data structure.
6490 * @pring: pointer to a SLI ring.
6491 * @vport: pointer to a host virtual N_Port data structure.
6492 * @elsiocb: pointer to lpfc els command iocb data structure.
6493 *
6494 * This routine is used for processing the IOCB associated with a unsolicited
6495 * event. It first determines whether there is an existing ndlp that matches
6496 * the DID from the unsolicited IOCB. If not, it will create a new one with
6497 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6498 * IOCB is then used to invoke the proper routine and to set up proper state
6499 * of the discovery state machine.
6500 **/
James Smarted957682007-06-17 19:56:37 -05006501static void
6502lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006503 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006504{
James Smart87af33f2007-10-27 13:37:43 -04006505 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006506 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006507 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006508 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006509 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006510 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006511
James Smarte47c9092008-02-08 18:49:26 -05006512 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006513 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006514
dea31012005-04-17 16:05:31 -05006515 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006516 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6517 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006518 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006519 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006520
James Smart858c9f62007-06-17 19:56:39 -05006521 did = icmd->un.rcvels.remoteID;
6522 if (icmd->ulpStatus) {
6523 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6524 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6525 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006526 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006527 }
dea31012005-04-17 16:05:31 -05006528
6529 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006530 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006531 goto dropit;
dea31012005-04-17 16:05:31 -05006532
James Smartc8685952009-11-18 15:39:16 -05006533 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006534 if (vport->load_flag & FC_UNLOADING)
6535 goto dropit;
6536
James Smart92494142011-02-16 12:39:44 -05006537 /* If NPort discovery is delayed drop incoming ELS */
6538 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6539 (cmd != ELS_CMD_PLOGI))
6540 goto dropit;
6541
James Smart2e0fef82007-06-17 19:56:36 -05006542 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006543 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006544 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006545 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006546 if (!ndlp)
dea31012005-04-17 16:05:31 -05006547 goto dropit;
dea31012005-04-17 16:05:31 -05006548
James Smart2e0fef82007-06-17 19:56:36 -05006549 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006550 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006551 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006552 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006553 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006554 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6555 ndlp = lpfc_enable_node(vport, ndlp,
6556 NLP_STE_UNUSED_NODE);
6557 if (!ndlp)
6558 goto dropit;
6559 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6560 newnode = 1;
6561 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6562 ndlp->nlp_type |= NLP_FABRIC;
6563 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6564 /* This is similar to the new node path */
6565 ndlp = lpfc_nlp_get(ndlp);
6566 if (!ndlp)
6567 goto dropit;
6568 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6569 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006570 }
dea31012005-04-17 16:05:31 -05006571
6572 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006573
James Smart329f9bc2007-04-25 09:53:01 -04006574 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006575 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006576
6577 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6578 cmd &= ELS_CMD_MASK;
6579 }
6580 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006581 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6582 "0112 ELS command x%x received from NPORT x%x "
6583 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006584 switch (cmd) {
6585 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6587 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6588 did, vport->port_state, ndlp->nlp_flag);
6589
dea31012005-04-17 16:05:31 -05006590 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006591 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6592
James Smartddcc50f2008-12-04 22:38:46 -05006593 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006594
6595 /* If Nport discovery is delayed, reject PLOGIs */
6596 if (vport->fc_flag & FC_DISC_DELAYED) {
6597 rjt_err = LSRJT_UNABLE_TPC;
6598 break;
6599 }
James Smart858c9f62007-06-17 19:56:39 -05006600 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006601 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6602 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6603 rjt_err = LSRJT_UNABLE_TPC;
6604 break;
6605 }
6606 /* We get here, and drop thru, if we are PT2PT with
6607 * another NPort and the other side has initiated
6608 * the PLOGI before responding to our FLOGI.
6609 */
dea31012005-04-17 16:05:31 -05006610 }
James Smart87af33f2007-10-27 13:37:43 -04006611
6612 shost = lpfc_shost_from_vport(vport);
6613 spin_lock_irq(shost->host_lock);
6614 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6615 spin_unlock_irq(shost->host_lock);
6616
James Smart2e0fef82007-06-17 19:56:36 -05006617 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6618 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006619
dea31012005-04-17 16:05:31 -05006620 break;
6621 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6623 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6624 did, vport->port_state, ndlp->nlp_flag);
6625
dea31012005-04-17 16:05:31 -05006626 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006627 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006628 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006629 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006630 break;
6631 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6633 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6634 did, vport->port_state, ndlp->nlp_flag);
6635
dea31012005-04-17 16:05:31 -05006636 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006637 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006638 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006639 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006640 break;
6641 }
James Smart2e0fef82007-06-17 19:56:36 -05006642 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006643 break;
6644 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6646 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6647 did, vport->port_state, ndlp->nlp_flag);
6648
dea31012005-04-17 16:05:31 -05006649 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006650 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006651 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006652 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006653 break;
6654 }
James Smart2e0fef82007-06-17 19:56:36 -05006655 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006656 break;
6657 case ELS_CMD_RSCN:
6658 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006659 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006660 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006661 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006662 break;
6663 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006664 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6665 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6666 did, vport->port_state, ndlp->nlp_flag);
6667
James Smartddcc50f2008-12-04 22:38:46 -05006668 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006669 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006670 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006671 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006672 break;
6673 }
James Smart2e0fef82007-06-17 19:56:36 -05006674 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6675 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006676 break;
6677 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006678 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6679 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6680 did, vport->port_state, ndlp->nlp_flag);
6681
dea31012005-04-17 16:05:31 -05006682 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006683 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006684 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006685 break;
6686 }
James Smart2e0fef82007-06-17 19:56:36 -05006687 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6688 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006689 break;
6690 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006691 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6692 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6693 did, vport->port_state, ndlp->nlp_flag);
6694
dea31012005-04-17 16:05:31 -05006695 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006696 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006697 break;
6698 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006699 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6700 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6701 did, vport->port_state, ndlp->nlp_flag);
6702
dea31012005-04-17 16:05:31 -05006703 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006704 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006705 break;
6706 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6708 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6709 did, vport->port_state, ndlp->nlp_flag);
6710
dea31012005-04-17 16:05:31 -05006711 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006712 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006713 break;
dea31012005-04-17 16:05:31 -05006714 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006715 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6716 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6717 did, vport->port_state, ndlp->nlp_flag);
6718
dea31012005-04-17 16:05:31 -05006719 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006720 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006721 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006722 break;
6723 }
James Smart2e0fef82007-06-17 19:56:36 -05006724 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006725 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006726 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006727 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6728 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6729 did, vport->port_state, ndlp->nlp_flag);
6730
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006731 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006732 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006733 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006734 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006735 break;
James Smart12265f62010-10-22 11:05:53 -04006736 case ELS_CMD_RLS:
6737 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6738 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6739 did, vport->port_state, ndlp->nlp_flag);
6740
6741 phba->fc_stat.elsRcvRLS++;
6742 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6743 if (newnode)
6744 lpfc_nlp_put(ndlp);
6745 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006746 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006747 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6748 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6749 did, vport->port_state, ndlp->nlp_flag);
6750
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006751 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006752 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006753 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006754 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006755 break;
6756 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006757 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6758 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6759 did, vport->port_state, ndlp->nlp_flag);
6760
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006761 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006762 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006763 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006764 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006765 break;
dea31012005-04-17 16:05:31 -05006766 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006767 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6768 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6769 did, vport->port_state, ndlp->nlp_flag);
6770
dea31012005-04-17 16:05:31 -05006771 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006772 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006773 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006774 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006775 break;
James Smart12265f62010-10-22 11:05:53 -04006776 case ELS_CMD_RTV:
6777 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6778 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6779 did, vport->port_state, ndlp->nlp_flag);
6780 phba->fc_stat.elsRcvRTV++;
6781 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6782 if (newnode)
6783 lpfc_nlp_put(ndlp);
6784 break;
James Smart5ffc2662009-11-18 15:39:44 -05006785 case ELS_CMD_RRQ:
6786 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6787 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6788 did, vport->port_state, ndlp->nlp_flag);
6789
6790 phba->fc_stat.elsRcvRRQ++;
6791 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6792 if (newnode)
6793 lpfc_nlp_put(ndlp);
6794 break;
James Smart12265f62010-10-22 11:05:53 -04006795 case ELS_CMD_ECHO:
6796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6797 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6798 did, vport->port_state, ndlp->nlp_flag);
6799
6800 phba->fc_stat.elsRcvECHO++;
6801 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6802 if (newnode)
6803 lpfc_nlp_put(ndlp);
6804 break;
dea31012005-04-17 16:05:31 -05006805 default:
James Smart858c9f62007-06-17 19:56:39 -05006806 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6807 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6808 cmd, did, vport->port_state);
6809
dea31012005-04-17 16:05:31 -05006810 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006811 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006812
6813 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006814 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6815 "0115 Unknown ELS command x%x "
6816 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006817 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006818 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006819 break;
6820 }
6821
6822 /* check if need to LS_RJT received ELS cmd */
6823 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006824 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006825 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006826 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006827 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6828 NULL);
dea31012005-04-17 16:05:31 -05006829 }
6830
James Smartd7c255b2008-08-24 21:50:00 -04006831 lpfc_nlp_put(elsiocb->context1);
6832 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006833 return;
6834
6835dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006836 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006837 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6838 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006839 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006840 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006841 phba->fc_stat.elsRcvDrop++;
6842}
6843
James Smarte59058c2008-08-24 21:49:00 -04006844/**
James Smart3621a712009-04-06 18:47:14 -04006845 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006846 * @phba: pointer to lpfc hba data structure.
6847 * @pring: pointer to a SLI ring.
6848 * @elsiocb: pointer to lpfc els iocb data structure.
6849 *
6850 * This routine is used to process an unsolicited event received from a SLI
6851 * (Service Level Interface) ring. The actual processing of the data buffer
6852 * associated with the unsolicited event is done by invoking the routine
6853 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6854 * SLI ring on which the unsolicited event was received.
6855 **/
James Smarted957682007-06-17 19:56:37 -05006856void
6857lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6858 struct lpfc_iocbq *elsiocb)
6859{
6860 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006861 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006862 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006863 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6864 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006865
James Smartd7c255b2008-08-24 21:50:00 -04006866 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006867 elsiocb->context2 = NULL;
6868 elsiocb->context3 = NULL;
6869
6870 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6871 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6872 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6873 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006874 phba->fc_stat.NoRcvBuf++;
6875 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006876 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006877 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006878 return;
6879 }
6880
James Smart92d7f7b2007-06-17 19:56:38 -05006881 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6882 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6883 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6884 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6885 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006886 else
6887 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006888 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006889 }
James Smart6d368e52011-05-24 11:44:12 -04006890
James Smart7f5f3d02008-02-08 18:50:14 -05006891 /* If there are no BDEs associated
6892 * with this IOCB, there is nothing to do.
6893 */
James Smarted957682007-06-17 19:56:37 -05006894 if (icmd->ulpBdeCount == 0)
6895 return;
6896
James Smart7f5f3d02008-02-08 18:50:14 -05006897 /* type of ELS cmd is first 32bit word
6898 * in packet
6899 */
James Smarted957682007-06-17 19:56:37 -05006900 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006901 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006902 } else {
6903 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6904 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006905 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6906 paddr);
James Smarted957682007-06-17 19:56:37 -05006907 }
6908
James Smart92d7f7b2007-06-17 19:56:38 -05006909 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6910 /*
6911 * The different unsolicited event handlers would tell us
6912 * if they are done with "mp" by setting context2 to NULL.
6913 */
dea31012005-04-17 16:05:31 -05006914 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006915 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6916 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006917 }
James Smarted957682007-06-17 19:56:37 -05006918
6919 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006920 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006921 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006922 elsiocb->context2 = bdeBuf2;
6923 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006924 /* free mp if we are done with it */
6925 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006926 lpfc_in_buf_free(phba, elsiocb->context2);
6927 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006928 }
dea31012005-04-17 16:05:31 -05006929 }
dea31012005-04-17 16:05:31 -05006930}
James Smart92d7f7b2007-06-17 19:56:38 -05006931
James Smarte59058c2008-08-24 21:49:00 -04006932/**
James Smart3621a712009-04-06 18:47:14 -04006933 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006934 * @phba: pointer to lpfc hba data structure.
6935 * @vport: pointer to a virtual N_Port data structure.
6936 *
6937 * This routine issues a Port Login (PLOGI) to the Name Server with
6938 * State Change Request (SCR) for a @vport. This routine will create an
6939 * ndlp for the Name Server associated to the @vport if such node does
6940 * not already exist. The PLOGI to Name Server is issued by invoking the
6941 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6942 * (FDMI) is configured to the @vport, a FDMI node will be created and
6943 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6944 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006945void
6946lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6947{
6948 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6950
6951 /*
6952 * If lpfc_delay_discovery parameter is set and the clean address
6953 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6954 * discovery.
6955 */
6956 spin_lock_irq(shost->host_lock);
6957 if (vport->fc_flag & FC_DISC_DELAYED) {
6958 spin_unlock_irq(shost->host_lock);
6959 mod_timer(&vport->delayed_disc_tmo,
6960 jiffies + HZ * phba->fc_ratov);
6961 return;
6962 }
6963 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006964
6965 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6966 if (!ndlp) {
6967 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6968 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006969 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006970 lpfc_disc_start(vport);
6971 return;
6972 }
6973 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006974 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6975 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006976 return;
6977 }
6978 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006979 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6980 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6981 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006982 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006983 lpfc_disc_start(vport);
6984 return;
6985 }
6986 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6987 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6988 "0348 NameServer login: node freed\n");
6989 return;
6990 }
James Smart92d7f7b2007-06-17 19:56:38 -05006991 }
James Smart58da1ff2008-04-07 10:15:56 -04006992 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006993
6994 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6995
6996 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6997 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006998 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6999 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007000 return;
7001 }
7002
James Smart3de2a652007-08-02 11:09:59 -04007003 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05007004 /* If this is the first time, allocate an ndlp and initialize
7005 * it. Otherwise, make sure the node is enabled and then do the
7006 * login.
7007 */
7008 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7009 if (!ndlp_fdmi) {
7010 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7011 GFP_KERNEL);
7012 if (ndlp_fdmi) {
7013 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7014 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7015 } else
7016 return;
7017 }
7018 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7019 ndlp_fdmi = lpfc_enable_node(vport,
7020 ndlp_fdmi,
7021 NLP_STE_NPR_NODE);
7022
James Smart92d7f7b2007-06-17 19:56:38 -05007023 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007024 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007025 NLP_STE_PLOGI_ISSUE);
7026 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007027 }
7028 }
James Smart92d7f7b2007-06-17 19:56:38 -05007029}
7030
James Smarte59058c2008-08-24 21:49:00 -04007031/**
James Smart3621a712009-04-06 18:47:14 -04007032 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007033 * @phba: pointer to lpfc hba data structure.
7034 * @pmb: pointer to the driver internal queue element for mailbox command.
7035 *
7036 * This routine is the completion callback function to register new vport
7037 * mailbox command. If the new vport mailbox command completes successfully,
7038 * the fabric registration login shall be performed on physical port (the
7039 * new vport created is actually a physical port, with VPI 0) or the port
7040 * login to Name Server for State Change Request (SCR) will be performed
7041 * on virtual port (real virtual port, with VPI greater than 0).
7042 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007043static void
7044lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7045{
7046 struct lpfc_vport *vport = pmb->vport;
7047 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7048 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007049 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007050 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007051
James Smart09372822008-01-11 01:52:54 -05007052 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007053 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007054 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007055
7056 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007057 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007058 "0915 Register VPI failed : Status: x%x"
7059 " upd bit: x%x \n", mb->mbxStatus,
7060 mb->un.varRegVpi.upd);
7061 if (phba->sli_rev == LPFC_SLI_REV4 &&
7062 mb->un.varRegVpi.upd)
7063 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007064
7065 switch (mb->mbxStatus) {
7066 case 0x11: /* unsupported feature */
7067 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007068 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007069 /* giving up on vport registration */
7070 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7071 spin_lock_irq(shost->host_lock);
7072 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7073 spin_unlock_irq(shost->host_lock);
7074 lpfc_can_disctmo(vport);
7075 break;
James Smart695a8142010-01-26 23:08:03 -05007076 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7077 case 0x20:
7078 spin_lock_irq(shost->host_lock);
7079 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7080 spin_unlock_irq(shost->host_lock);
7081 lpfc_init_vpi(phba, pmb, vport->vpi);
7082 pmb->vport = vport;
7083 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7084 rc = lpfc_sli_issue_mbox(phba, pmb,
7085 MBX_NOWAIT);
7086 if (rc == MBX_NOT_FINISHED) {
7087 lpfc_printf_vlog(vport,
7088 KERN_ERR, LOG_MBOX,
7089 "2732 Failed to issue INIT_VPI"
7090 " mailbox command\n");
7091 } else {
7092 lpfc_nlp_put(ndlp);
7093 return;
7094 }
7095
James Smart92d7f7b2007-06-17 19:56:38 -05007096 default:
7097 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007098 if (phba->sli_rev == LPFC_SLI_REV4)
7099 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007100 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007101 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007102 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007103 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007104 if (vport->port_type == LPFC_PHYSICAL_PORT
7105 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007106 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007107 else
7108 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007109 break;
7110 }
James Smart92d7f7b2007-06-17 19:56:38 -05007111 } else {
James Smart695a8142010-01-26 23:08:03 -05007112 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007113 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007114 spin_unlock_irq(shost->host_lock);
7115 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007116 if (phba->sli_rev < LPFC_SLI_REV4)
7117 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007118 else {
James Smartfc2b9892010-02-26 14:15:29 -05007119 /*
7120 * If the physical port is instantiated using
7121 * FDISC, do not start vport discovery.
7122 */
7123 if (vport->port_state != LPFC_FDISC)
7124 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007125 lpfc_do_scr_ns_plogi(phba, vport);
7126 }
7127 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007128 lpfc_do_scr_ns_plogi(phba, vport);
7129 }
James Smart38b92ef2010-08-04 16:11:39 -04007130mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007131 /* Now, we decrement the ndlp reference count held for this
7132 * callback function
7133 */
7134 lpfc_nlp_put(ndlp);
7135
James Smart92d7f7b2007-06-17 19:56:38 -05007136 mempool_free(pmb, phba->mbox_mem_pool);
7137 return;
7138}
7139
James Smarte59058c2008-08-24 21:49:00 -04007140/**
James Smart3621a712009-04-06 18:47:14 -04007141 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007142 * @phba: pointer to lpfc hba data structure.
7143 * @vport: pointer to a host virtual N_Port data structure.
7144 * @ndlp: pointer to a node-list data structure.
7145 *
7146 * This routine registers the @vport as a new virtual port with a HBA.
7147 * It is done through a registering vpi mailbox command.
7148 **/
James Smart695a8142010-01-26 23:08:03 -05007149void
James Smart92d7f7b2007-06-17 19:56:38 -05007150lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7151 struct lpfc_nodelist *ndlp)
7152{
James Smart09372822008-01-11 01:52:54 -05007153 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007154 LPFC_MBOXQ_t *mbox;
7155
7156 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7157 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007158 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007159 mbox->vport = vport;
7160 mbox->context2 = lpfc_nlp_get(ndlp);
7161 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007162 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007163 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007164 /* mailbox command not success, decrement ndlp
7165 * reference count for this command
7166 */
7167 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007168 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007169
James Smarte8b62012007-08-02 11:10:09 -04007170 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7171 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007172 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007173 }
7174 } else {
James Smarte8b62012007-08-02 11:10:09 -04007175 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7176 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007177 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007178 }
James Smartfa4066b2008-01-11 01:53:27 -05007179 return;
7180
7181mbox_err_exit:
7182 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7183 spin_lock_irq(shost->host_lock);
7184 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7185 spin_unlock_irq(shost->host_lock);
7186 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007187}
7188
James Smarte59058c2008-08-24 21:49:00 -04007189/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007190 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007191 * @phba: pointer to lpfc hba data structure.
7192 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007193 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007194 **/
7195void
James Smart0c9ab6f2010-02-26 14:15:57 -05007196lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007197{
7198 struct lpfc_vport **vports;
7199 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007200 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007201 int i;
James Smart695a8142010-01-26 23:08:03 -05007202
7203 /* Treat this failure as linkdown for all vports */
7204 link_state = phba->link_state;
7205 lpfc_linkdown(phba);
7206 phba->link_state = link_state;
7207
7208 vports = lpfc_create_vport_work_array(phba);
7209
7210 if (vports) {
7211 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7212 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7213 if (ndlp)
7214 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7215 lpfc_els_flush_cmd(vports[i]);
7216 }
7217 lpfc_destroy_vport_work_array(phba, vports);
7218 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007219}
7220
7221/**
7222 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7223 * @phba: pointer to lpfc hba data structure.
7224 *
7225 * This routine abort all pending discovery commands and
7226 * start a timer to retry FLOGI for the physical port
7227 * discovery.
7228 **/
7229void
7230lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7231{
7232 struct lpfc_nodelist *ndlp;
7233 struct Scsi_Host *shost;
7234
7235 /* Cancel the all vports retry delay retry timers */
7236 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007237
7238 /* If fabric require FLOGI, then re-instantiate physical login */
7239 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7240 if (!ndlp)
7241 return;
7242
James Smart695a8142010-01-26 23:08:03 -05007243 shost = lpfc_shost_from_vport(phba->pport);
7244 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7245 spin_lock_irq(shost->host_lock);
7246 ndlp->nlp_flag |= NLP_DELAY_TMO;
7247 spin_unlock_irq(shost->host_lock);
7248 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7249 phba->pport->port_state = LPFC_FLOGI;
7250 return;
7251}
7252
7253/**
7254 * lpfc_fabric_login_reqd - Check if FLOGI required.
7255 * @phba: pointer to lpfc hba data structure.
7256 * @cmdiocb: pointer to FDISC command iocb.
7257 * @rspiocb: pointer to FDISC response iocb.
7258 *
7259 * This routine checks if a FLOGI is reguired for FDISC
7260 * to succeed.
7261 **/
7262static int
7263lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7264 struct lpfc_iocbq *cmdiocb,
7265 struct lpfc_iocbq *rspiocb)
7266{
7267
7268 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7269 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7270 return 0;
7271 else
7272 return 1;
7273}
7274
7275/**
James Smart3621a712009-04-06 18:47:14 -04007276 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007277 * @phba: pointer to lpfc hba data structure.
7278 * @cmdiocb: pointer to lpfc command iocb data structure.
7279 * @rspiocb: pointer to lpfc response iocb data structure.
7280 *
7281 * This routine is the completion callback function to a Fabric Discover
7282 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7283 * single threaded, each FDISC completion callback function will reset
7284 * the discovery timer for all vports such that the timers will not get
7285 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7286 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7287 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7288 * assigned to the vport has been changed with the completion of the FDISC
7289 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7290 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7291 * routine is invoked to register new vport with the HBA. Otherwise, the
7292 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7293 * Server for State Change Request (SCR).
7294 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007295static void
7296lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7297 struct lpfc_iocbq *rspiocb)
7298{
7299 struct lpfc_vport *vport = cmdiocb->vport;
7300 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7301 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7302 struct lpfc_nodelist *np;
7303 struct lpfc_nodelist *next_np;
7304 IOCB_t *irsp = &rspiocb->iocb;
7305 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007306 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7307 struct serv_parm *sp;
7308 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007309
James Smarte8b62012007-08-02 11:10:09 -04007310 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7311 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7312 irsp->ulpStatus, irsp->un.ulpWord[4],
7313 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007314 /* Since all FDISCs are being single threaded, we
7315 * must reset the discovery timer for ALL vports
7316 * waiting to send FDISC when one completes.
7317 */
7318 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7319 lpfc_set_disctmo(piocb->vport);
7320 }
7321
James Smart858c9f62007-06-17 19:56:39 -05007322 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7323 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7324 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7325
James Smart92d7f7b2007-06-17 19:56:38 -05007326 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007327
7328 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7329 lpfc_retry_pport_discovery(phba);
7330 goto out;
7331 }
7332
James Smart92d7f7b2007-06-17 19:56:38 -05007333 /* Check for retry */
7334 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7335 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007336 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007337 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007338 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007339 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007340 goto fdisc_failed;
7341 }
James Smartd7c255b2008-08-24 21:50:00 -04007342 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007343 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007344 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007345 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007346 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007347 vport->fc_flag |= FC_PUBLIC_LOOP;
7348 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007349
James Smartd7c255b2008-08-24 21:50:00 -04007350 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7351 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007352 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7353 sp = prsp->virt + sizeof(uint32_t);
7354 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7355 memcpy(&vport->fabric_portname, &sp->portName,
7356 sizeof(struct lpfc_name));
7357 memcpy(&vport->fabric_nodename, &sp->nodeName,
7358 sizeof(struct lpfc_name));
7359 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007360 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7361 /* If our NportID changed, we need to ensure all
7362 * remaining NPORTs get unreg_login'ed so we can
7363 * issue unreg_vpi.
7364 */
7365 list_for_each_entry_safe(np, next_np,
7366 &vport->fc_nodes, nlp_listp) {
7367 if (!NLP_CHK_NODE_ACT(ndlp) ||
7368 (np->nlp_state != NLP_STE_NPR_NODE) ||
7369 !(np->nlp_flag & NLP_NPR_ADISC))
7370 continue;
James Smart09372822008-01-11 01:52:54 -05007371 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007372 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007373 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007374 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007375 }
James Smart78730cf2010-04-06 15:06:30 -04007376 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007377
7378 if (phba->sli_rev == LPFC_SLI_REV4)
7379 lpfc_sli4_unreg_all_rpis(vport);
7380
James Smartd7c255b2008-08-24 21:50:00 -04007381 lpfc_mbx_unreg_vpi(vport);
7382 spin_lock_irq(shost->host_lock);
7383 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007384 if (phba->sli_rev == LPFC_SLI_REV4)
7385 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007386 else
7387 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007388 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007389 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7390 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7391 /*
7392 * Driver needs to re-reg VPI in order for f/w
7393 * to update the MAC address.
7394 */
7395 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007396 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007397 }
7398
James Smartecfd03c2010-02-12 14:41:27 -05007399 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7400 lpfc_issue_init_vpi(vport);
7401 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007402 lpfc_register_new_vport(phba, vport, ndlp);
7403 else
7404 lpfc_do_scr_ns_plogi(phba, vport);
7405 goto out;
7406fdisc_failed:
7407 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7408 /* Cancel discovery timer */
7409 lpfc_can_disctmo(vport);
7410 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007411out:
7412 lpfc_els_free_iocb(phba, cmdiocb);
7413}
7414
James Smarte59058c2008-08-24 21:49:00 -04007415/**
James Smart3621a712009-04-06 18:47:14 -04007416 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007417 * @vport: pointer to a virtual N_Port data structure.
7418 * @ndlp: pointer to a node-list data structure.
7419 * @retry: number of retries to the command IOCB.
7420 *
7421 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7422 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7423 * routine to issue the IOCB, which makes sure only one outstanding fabric
7424 * IOCB will be sent off HBA at any given time.
7425 *
7426 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7427 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7428 * will be stored into the context1 field of the IOCB for the completion
7429 * callback function to the FDISC ELS command.
7430 *
7431 * Return code
7432 * 0 - Successfully issued fdisc iocb command
7433 * 1 - Failed to issue fdisc iocb command
7434 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007435static int
James Smart92d7f7b2007-06-17 19:56:38 -05007436lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7437 uint8_t retry)
7438{
7439 struct lpfc_hba *phba = vport->phba;
7440 IOCB_t *icmd;
7441 struct lpfc_iocbq *elsiocb;
7442 struct serv_parm *sp;
7443 uint8_t *pcmd;
7444 uint16_t cmdsize;
7445 int did = ndlp->nlp_DID;
7446 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007447
James Smart5ffc2662009-11-18 15:39:44 -05007448 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007449 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007450 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7451 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7452 ELS_CMD_FDISC);
7453 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007454 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007455 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7456 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007457 return 1;
7458 }
7459
7460 icmd = &elsiocb->iocb;
7461 icmd->un.elsreq64.myID = 0;
7462 icmd->un.elsreq64.fl = 1;
7463
James Smart73d91e52011-10-10 21:32:10 -04007464 /*
7465 * SLI3 ports require a different context type value than SLI4.
7466 * Catch SLI3 ports here and override the prep.
7467 */
7468 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007469 icmd->ulpCt_h = 1;
7470 icmd->ulpCt_l = 0;
7471 }
James Smart92d7f7b2007-06-17 19:56:38 -05007472
7473 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7474 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7475 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7476 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7477 sp = (struct serv_parm *) pcmd;
7478 /* Setup CSPs accordingly for Fabric */
7479 sp->cmn.e_d_tov = 0;
7480 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007481 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007482 sp->cls1.classValid = 0;
7483 sp->cls2.seqDelivery = 1;
7484 sp->cls3.seqDelivery = 1;
7485
7486 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7487 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7488 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7489 pcmd += sizeof(uint32_t); /* Port Name */
7490 memcpy(pcmd, &vport->fc_portname, 8);
7491 pcmd += sizeof(uint32_t); /* Node Name */
7492 pcmd += sizeof(uint32_t); /* Node Name */
7493 memcpy(pcmd, &vport->fc_nodename, 8);
7494
7495 lpfc_set_disctmo(vport);
7496
7497 phba->fc_stat.elsXmitFDISC++;
7498 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7499
James Smart858c9f62007-06-17 19:56:39 -05007500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7501 "Issue FDISC: did:x%x",
7502 did, 0, 0);
7503
James Smart92d7f7b2007-06-17 19:56:38 -05007504 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7505 if (rc == IOCB_ERROR) {
7506 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007507 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007508 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7509 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007510 return 1;
7511 }
7512 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007513 return 0;
7514}
7515
James Smarte59058c2008-08-24 21:49:00 -04007516/**
James Smart3621a712009-04-06 18:47:14 -04007517 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007518 * @phba: pointer to lpfc hba data structure.
7519 * @cmdiocb: pointer to lpfc command iocb data structure.
7520 * @rspiocb: pointer to lpfc response iocb data structure.
7521 *
7522 * This routine is the completion callback function to the issuing of a LOGO
7523 * ELS command off a vport. It frees the command IOCB and then decrement the
7524 * reference count held on ndlp for this completion function, indicating that
7525 * the reference to the ndlp is no long needed. Note that the
7526 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7527 * callback function and an additional explicit ndlp reference decrementation
7528 * will trigger the actual release of the ndlp.
7529 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007530static void
7531lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7532 struct lpfc_iocbq *rspiocb)
7533{
7534 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007535 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007536 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007537 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007538
James Smart9589b062011-04-16 11:03:17 -04007539 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007540 irsp = &rspiocb->iocb;
7541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7542 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7543 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007544
7545 lpfc_els_free_iocb(phba, cmdiocb);
7546 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007547
7548 /* Trigger the release of the ndlp after logo */
7549 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007550
7551 /* NPIV LOGO completes to NPort <nlp_DID> */
7552 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7553 "2928 NPIV LOGO completes to NPort x%x "
7554 "Data: x%x x%x x%x x%x\n",
7555 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7556 irsp->ulpTimeout, vport->num_disc_nodes);
7557
7558 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7559 spin_lock_irq(shost->host_lock);
7560 vport->fc_flag &= ~FC_FABRIC;
7561 spin_unlock_irq(shost->host_lock);
7562 }
James Smart92d7f7b2007-06-17 19:56:38 -05007563}
7564
James Smarte59058c2008-08-24 21:49:00 -04007565/**
James Smart3621a712009-04-06 18:47:14 -04007566 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007567 * @vport: pointer to a virtual N_Port data structure.
7568 * @ndlp: pointer to a node-list data structure.
7569 *
7570 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7571 *
7572 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7573 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7574 * will be stored into the context1 field of the IOCB for the completion
7575 * callback function to the LOGO ELS command.
7576 *
7577 * Return codes
7578 * 0 - Successfully issued logo off the @vport
7579 * 1 - Failed to issue logo off the @vport
7580 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007581int
7582lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7583{
7584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7585 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007586 IOCB_t *icmd;
7587 struct lpfc_iocbq *elsiocb;
7588 uint8_t *pcmd;
7589 uint16_t cmdsize;
7590
7591 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7592 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7593 ELS_CMD_LOGO);
7594 if (!elsiocb)
7595 return 1;
7596
7597 icmd = &elsiocb->iocb;
7598 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7599 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7600 pcmd += sizeof(uint32_t);
7601
7602 /* Fill in LOGO payload */
7603 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7604 pcmd += sizeof(uint32_t);
7605 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7606
James Smart858c9f62007-06-17 19:56:39 -05007607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7608 "Issue LOGO npiv did:x%x flg:x%x",
7609 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7610
James Smart92d7f7b2007-06-17 19:56:38 -05007611 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7612 spin_lock_irq(shost->host_lock);
7613 ndlp->nlp_flag |= NLP_LOGO_SND;
7614 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007615 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7616 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007617 spin_lock_irq(shost->host_lock);
7618 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7619 spin_unlock_irq(shost->host_lock);
7620 lpfc_els_free_iocb(phba, elsiocb);
7621 return 1;
7622 }
7623 return 0;
7624}
7625
James Smarte59058c2008-08-24 21:49:00 -04007626/**
James Smart3621a712009-04-06 18:47:14 -04007627 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007628 * @ptr: holder for the timer function associated data.
7629 *
7630 * This routine is invoked by the fabric iocb block timer after
7631 * timeout. It posts the fabric iocb block timeout event by setting the
7632 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7633 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7634 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7635 * posted event WORKER_FABRIC_BLOCK_TMO.
7636 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007637void
7638lpfc_fabric_block_timeout(unsigned long ptr)
7639{
7640 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7641 unsigned long iflags;
7642 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007643
James Smart92d7f7b2007-06-17 19:56:38 -05007644 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7645 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7646 if (!tmo_posted)
7647 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7648 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7649
James Smart5e9d9b82008-06-14 22:52:53 -04007650 if (!tmo_posted)
7651 lpfc_worker_wake_up(phba);
7652 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007653}
7654
James Smarte59058c2008-08-24 21:49:00 -04007655/**
James Smart3621a712009-04-06 18:47:14 -04007656 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007657 * @phba: pointer to lpfc hba data structure.
7658 *
7659 * This routine issues one fabric iocb from the driver internal list to
7660 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7661 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7662 * remove one pending fabric iocb from the driver internal list and invokes
7663 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7664 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007665static void
7666lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7667{
7668 struct lpfc_iocbq *iocb;
7669 unsigned long iflags;
7670 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007671 IOCB_t *cmd;
7672
7673repeat:
7674 iocb = NULL;
7675 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007676 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007677 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7678 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7679 list);
7680 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007681 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007682 atomic_inc(&phba->fabric_iocb_count);
7683 }
7684 spin_unlock_irqrestore(&phba->hbalock, iflags);
7685 if (iocb) {
7686 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7687 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7688 iocb->iocb_flag |= LPFC_IO_FABRIC;
7689
James Smart858c9f62007-06-17 19:56:39 -05007690 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7691 "Fabric sched1: ste:x%x",
7692 iocb->vport->port_state, 0, 0);
7693
James Smart3772a992009-05-22 14:50:54 -04007694 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007695
7696 if (ret == IOCB_ERROR) {
7697 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7698 iocb->fabric_iocb_cmpl = NULL;
7699 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7700 cmd = &iocb->iocb;
7701 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7702 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7703 iocb->iocb_cmpl(phba, iocb, iocb);
7704
7705 atomic_dec(&phba->fabric_iocb_count);
7706 goto repeat;
7707 }
7708 }
7709
7710 return;
7711}
7712
James Smarte59058c2008-08-24 21:49:00 -04007713/**
James Smart3621a712009-04-06 18:47:14 -04007714 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007715 * @phba: pointer to lpfc hba data structure.
7716 *
7717 * This routine unblocks the issuing fabric iocb command. The function
7718 * will clear the fabric iocb block bit and then invoke the routine
7719 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7720 * from the driver internal fabric iocb list.
7721 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007722void
7723lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7724{
7725 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7726
7727 lpfc_resume_fabric_iocbs(phba);
7728 return;
7729}
7730
James Smarte59058c2008-08-24 21:49:00 -04007731/**
James Smart3621a712009-04-06 18:47:14 -04007732 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007733 * @phba: pointer to lpfc hba data structure.
7734 *
7735 * This routine blocks the issuing fabric iocb for a specified amount of
7736 * time (currently 100 ms). This is done by set the fabric iocb block bit
7737 * and set up a timeout timer for 100ms. When the block bit is set, no more
7738 * fabric iocb will be issued out of the HBA.
7739 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007740static void
7741lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7742{
7743 int blocked;
7744
7745 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007746 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007747 if (!blocked)
7748 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7749
7750 return;
7751}
7752
James Smarte59058c2008-08-24 21:49:00 -04007753/**
James Smart3621a712009-04-06 18:47:14 -04007754 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007755 * @phba: pointer to lpfc hba data structure.
7756 * @cmdiocb: pointer to lpfc command iocb data structure.
7757 * @rspiocb: pointer to lpfc response iocb data structure.
7758 *
7759 * This routine is the callback function that is put to the fabric iocb's
7760 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7761 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7762 * function first restores and invokes the original iocb's callback function
7763 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7764 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7765 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007766static void
7767lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7768 struct lpfc_iocbq *rspiocb)
7769{
7770 struct ls_rjt stat;
7771
7772 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7773 BUG();
7774
7775 switch (rspiocb->iocb.ulpStatus) {
7776 case IOSTAT_NPORT_RJT:
7777 case IOSTAT_FABRIC_RJT:
7778 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7779 lpfc_block_fabric_iocbs(phba);
7780 }
7781 break;
7782
7783 case IOSTAT_NPORT_BSY:
7784 case IOSTAT_FABRIC_BSY:
7785 lpfc_block_fabric_iocbs(phba);
7786 break;
7787
7788 case IOSTAT_LS_RJT:
7789 stat.un.lsRjtError =
7790 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7791 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7792 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7793 lpfc_block_fabric_iocbs(phba);
7794 break;
7795 }
7796
7797 if (atomic_read(&phba->fabric_iocb_count) == 0)
7798 BUG();
7799
7800 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7801 cmdiocb->fabric_iocb_cmpl = NULL;
7802 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7803 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7804
7805 atomic_dec(&phba->fabric_iocb_count);
7806 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007807 /* Post any pending iocbs to HBA */
7808 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007809 }
7810}
7811
James Smarte59058c2008-08-24 21:49:00 -04007812/**
James Smart3621a712009-04-06 18:47:14 -04007813 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007814 * @phba: pointer to lpfc hba data structure.
7815 * @iocb: pointer to lpfc command iocb data structure.
7816 *
7817 * This routine is used as the top-level API for issuing a fabric iocb command
7818 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7819 * function makes sure that only one fabric bound iocb will be outstanding at
7820 * any given time. As such, this function will first check to see whether there
7821 * is already an outstanding fabric iocb on the wire. If so, it will put the
7822 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7823 * issued later. Otherwise, it will issue the iocb on the wire and update the
7824 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7825 *
7826 * Note, this implementation has a potential sending out fabric IOCBs out of
7827 * order. The problem is caused by the construction of the "ready" boolen does
7828 * not include the condition that the internal fabric IOCB list is empty. As
7829 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7830 * ahead of the fabric IOCBs in the internal list.
7831 *
7832 * Return code
7833 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7834 * IOCB_ERROR - failed to issue fabric iocb
7835 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007836static int
James Smart92d7f7b2007-06-17 19:56:38 -05007837lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7838{
7839 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007840 int ready;
7841 int ret;
7842
7843 if (atomic_read(&phba->fabric_iocb_count) > 1)
7844 BUG();
7845
7846 spin_lock_irqsave(&phba->hbalock, iflags);
7847 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7848 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7849
James Smart7f5f3d02008-02-08 18:50:14 -05007850 if (ready)
7851 /* Increment fabric iocb count to hold the position */
7852 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007853 spin_unlock_irqrestore(&phba->hbalock, iflags);
7854 if (ready) {
7855 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7856 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7857 iocb->iocb_flag |= LPFC_IO_FABRIC;
7858
James Smart858c9f62007-06-17 19:56:39 -05007859 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7860 "Fabric sched2: ste:x%x",
7861 iocb->vport->port_state, 0, 0);
7862
James Smart3772a992009-05-22 14:50:54 -04007863 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007864
7865 if (ret == IOCB_ERROR) {
7866 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7867 iocb->fabric_iocb_cmpl = NULL;
7868 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7869 atomic_dec(&phba->fabric_iocb_count);
7870 }
7871 } else {
7872 spin_lock_irqsave(&phba->hbalock, iflags);
7873 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7874 spin_unlock_irqrestore(&phba->hbalock, iflags);
7875 ret = IOCB_SUCCESS;
7876 }
7877 return ret;
7878}
7879
James Smarte59058c2008-08-24 21:49:00 -04007880/**
James Smart3621a712009-04-06 18:47:14 -04007881 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007882 * @vport: pointer to a virtual N_Port data structure.
7883 *
7884 * This routine aborts all the IOCBs associated with a @vport from the
7885 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7886 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7887 * list, removes each IOCB associated with the @vport off the list, set the
7888 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7889 * associated with the IOCB.
7890 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007891static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007892{
7893 LIST_HEAD(completions);
7894 struct lpfc_hba *phba = vport->phba;
7895 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007896
7897 spin_lock_irq(&phba->hbalock);
7898 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7899 list) {
7900
7901 if (piocb->vport != vport)
7902 continue;
7903
7904 list_move_tail(&piocb->list, &completions);
7905 }
7906 spin_unlock_irq(&phba->hbalock);
7907
James Smarta257bf92009-04-06 18:48:10 -04007908 /* Cancel all the IOCBs from the completions list */
7909 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7910 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007911}
7912
James Smarte59058c2008-08-24 21:49:00 -04007913/**
James Smart3621a712009-04-06 18:47:14 -04007914 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007915 * @ndlp: pointer to a node-list data structure.
7916 *
7917 * This routine aborts all the IOCBs associated with an @ndlp from the
7918 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7919 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7920 * list, removes each IOCB associated with the @ndlp off the list, set the
7921 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7922 * associated with the IOCB.
7923 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007924void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7925{
7926 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007927 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007928 struct lpfc_iocbq *tmp_iocb, *piocb;
7929 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007930
7931 spin_lock_irq(&phba->hbalock);
7932 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7933 list) {
7934 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7935
7936 list_move_tail(&piocb->list, &completions);
7937 }
7938 }
7939 spin_unlock_irq(&phba->hbalock);
7940
James Smarta257bf92009-04-06 18:48:10 -04007941 /* Cancel all the IOCBs from the completions list */
7942 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7943 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007944}
7945
James Smarte59058c2008-08-24 21:49:00 -04007946/**
James Smart3621a712009-04-06 18:47:14 -04007947 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007948 * @phba: pointer to lpfc hba data structure.
7949 *
7950 * This routine aborts all the IOCBs currently on the driver internal
7951 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7952 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7953 * list, removes IOCBs off the list, set the status feild to
7954 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7955 * the IOCB.
7956 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007957void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7958{
7959 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007960
7961 spin_lock_irq(&phba->hbalock);
7962 list_splice_init(&phba->fabric_iocb_list, &completions);
7963 spin_unlock_irq(&phba->hbalock);
7964
James Smarta257bf92009-04-06 18:48:10 -04007965 /* Cancel all the IOCBs from the completions list */
7966 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7967 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007968}
James Smart6fb120a2009-05-22 14:52:59 -04007969
7970/**
James Smart1151e3e2011-02-16 12:39:35 -05007971 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7972 * @vport: pointer to lpfc vport data structure.
7973 *
7974 * This routine is invoked by the vport cleanup for deletions and the cleanup
7975 * for an ndlp on removal.
7976 **/
7977void
7978lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7979{
7980 struct lpfc_hba *phba = vport->phba;
7981 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7982 unsigned long iflag = 0;
7983
7984 spin_lock_irqsave(&phba->hbalock, iflag);
7985 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7986 list_for_each_entry_safe(sglq_entry, sglq_next,
7987 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7988 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7989 sglq_entry->ndlp = NULL;
7990 }
7991 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7992 spin_unlock_irqrestore(&phba->hbalock, iflag);
7993 return;
7994}
7995
7996/**
James Smart6fb120a2009-05-22 14:52:59 -04007997 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7998 * @phba: pointer to lpfc hba data structure.
7999 * @axri: pointer to the els xri abort wcqe structure.
8000 *
8001 * This routine is invoked by the worker thread to process a SLI4 slow-path
8002 * ELS aborted xri.
8003 **/
8004void
8005lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8006 struct sli4_wcqe_xri_aborted *axri)
8007{
8008 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008009 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008010 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008011
James Smart6fb120a2009-05-22 14:52:59 -04008012 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8013 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008014 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008015 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008016
James Smart0f65ff62010-02-26 14:14:23 -05008017 spin_lock_irqsave(&phba->hbalock, iflag);
8018 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008019 list_for_each_entry_safe(sglq_entry, sglq_next,
8020 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8021 if (sglq_entry->sli4_xritag == xri) {
8022 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008023 ndlp = sglq_entry->ndlp;
8024 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04008025 list_add_tail(&sglq_entry->list,
8026 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008027 sglq_entry->state = SGL_FREED;
8028 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008029 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008030 lpfc_set_rrq_active(phba, ndlp,
8031 sglq_entry->sli4_lxritag,
8032 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008033
8034 /* Check if TXQ queue needs to be serviced */
8035 if (pring->txq_cnt)
8036 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008037 return;
8038 }
8039 }
James Smart0f65ff62010-02-26 14:14:23 -05008040 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008041 lxri = lpfc_sli4_xri_inrange(phba, xri);
8042 if (lxri == NO_XRI) {
8043 spin_unlock_irqrestore(&phba->hbalock, iflag);
8044 return;
8045 }
8046 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008047 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8048 spin_unlock_irqrestore(&phba->hbalock, iflag);
8049 return;
8050 }
8051 sglq_entry->state = SGL_XRI_ABORTED;
8052 spin_unlock_irqrestore(&phba->hbalock, iflag);
8053 return;
James Smart6fb120a2009-05-22 14:52:59 -04008054}
James Smart086a3452012-08-14 14:25:21 -04008055
8056/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8057 * @vport: pointer to virtual port object.
8058 * @ndlp: nodelist pointer for the impacted node.
8059 *
8060 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8061 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8062 * the driver is required to send a LOGO to the remote node before it
8063 * attempts to recover its login to the remote node.
8064 */
8065void
8066lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8067 struct lpfc_nodelist *ndlp)
8068{
8069 struct Scsi_Host *shost;
8070 struct lpfc_hba *phba;
8071 unsigned long flags = 0;
8072
8073 shost = lpfc_shost_from_vport(vport);
8074 phba = vport->phba;
8075 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8076 lpfc_printf_log(phba, KERN_INFO,
8077 LOG_SLI, "3093 No rport recovery needed. "
8078 "rport in state 0x%x\n", ndlp->nlp_state);
8079 return;
8080 }
8081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8082 "3094 Start rport recovery on shost id 0x%x "
8083 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8084 "flags 0x%x\n",
8085 shost->host_no, ndlp->nlp_DID,
8086 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8087 ndlp->nlp_flag);
8088 /*
8089 * The rport is not responding. Remove the FCP-2 flag to prevent
8090 * an ADISC in the follow-up recovery code.
8091 */
8092 spin_lock_irqsave(shost->host_lock, flags);
8093 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8094 spin_unlock_irqrestore(shost->host_lock, flags);
8095 lpfc_issue_els_logo(vport, ndlp, 0);
8096 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8097}
8098