blob: c23f6415f76d0f2cb598905c446bcecb069cb6aa [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd4379ac2012-03-01 22:37:07 -05004 * Copyright (C) 2004-2012 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
James Smart9940b972011-03-11 16:06:12 -050092 if (lpfc_readl(phba->HAregaddr, &ha_copy))
93 return 1;
dea31012005-04-17 16:05:31 -050094
95 if (!(ha_copy & HA_LATT))
96 return 0;
97
98 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040099 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500103
104 /* CLEAR_LA should re-enable link attention events and
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300105 * we should then immediately take a LATT event. The
dea31012005-04-17 16:05:31 -0500106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
108 * events.
109 */
James Smart2e0fef82007-06-17 19:56:36 -0500110 spin_lock_irq(shost->host_lock);
111 vport->fc_flag |= FC_ABORT_DISCOVERY;
112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500113
James Smart92d7f7b2007-06-17 19:56:38 -0500114 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500115 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500116
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500117 return 1;
dea31012005-04-17 16:05:31 -0500118}
119
James Smarte59058c2008-08-24 21:49:00 -0400120/**
James Smart3621a712009-04-06 18:47:14 -0400121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
129 *
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
143 *
144 * Return code
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
147 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400148struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500149lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
150 uint16_t cmdSize, uint8_t retry,
151 struct lpfc_nodelist *ndlp, uint32_t did,
152 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500153{
James Smart2e0fef82007-06-17 19:56:36 -0500154 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400155 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500156 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
157 struct ulp_bde64 *bpl;
158 IOCB_t *icmd;
159
dea31012005-04-17 16:05:31 -0500160
James Smart2e0fef82007-06-17 19:56:36 -0500161 if (!lpfc_is_link_up(phba))
162 return NULL;
dea31012005-04-17 16:05:31 -0500163
dea31012005-04-17 16:05:31 -0500164 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400165 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500166
167 if (elsiocb == NULL)
168 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500169
James Smart0c287582009-06-10 17:22:56 -0400170 /*
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 */
174 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400175 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400176 ((elscmd == ELS_CMD_FLOGI) ||
177 (elscmd == ELS_CMD_FDISC) ||
178 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500179 switch (elscmd) {
180 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400181 elsiocb->iocb_flag |=
182 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500183 & LPFC_FIP_ELS_ID_MASK);
184 break;
185 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400186 elsiocb->iocb_flag |=
187 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400191 elsiocb->iocb_flag |=
192 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500193 & LPFC_FIP_ELS_ID_MASK);
194 break;
195 }
James Smart0c287582009-06-10 17:22:56 -0400196 else
James Smartc8685952009-11-18 15:39:16 -0500197 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400198
dea31012005-04-17 16:05:31 -0500199 icmd = &elsiocb->iocb;
200
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400203 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
204 if (pcmd)
205 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500206 if (!pcmd || !pcmd->virt)
207 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500208
209 INIT_LIST_HEAD(&pcmd->list);
210
211 /* Allocate buffer for response payload */
212 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500213 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500214 if (prsp)
215 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
216 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500217 if (!prsp || !prsp->virt)
218 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500219 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500220 } else
dea31012005-04-17 16:05:31 -0500221 prsp = NULL;
dea31012005-04-17 16:05:31 -0500222
223 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500224 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500225 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500226 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
227 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500228 if (!pbuflist || !pbuflist->virt)
229 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500230
231 INIT_LIST_HEAD(&pbuflist->list);
232
dea31012005-04-17 16:05:31 -0500233 if (expectRsp) {
James Smart939723a2012-05-09 21:19:03 -0400234 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
235 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
236 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart92d7f7b2007-06-17 19:56:38 -0500237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
James Smart939723a2012-05-09 21:19:03 -0400238
239 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500240 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400241 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500242 } else {
James Smart939723a2012-05-09 21:19:03 -0400243 icmd->un.xseq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
244 icmd->un.xseq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
245 icmd->un.xseq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
246 icmd->un.xseq64.bdl.bdeSize = sizeof(struct ulp_bde64);
247 icmd->un.xseq64.xmit_els_remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500248 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
249 }
dea31012005-04-17 16:05:31 -0500250 icmd->ulpBdeCount = 1;
251 icmd->ulpLe = 1;
252 icmd->ulpClass = CLASS3;
253
James Smart939723a2012-05-09 21:19:03 -0400254 /*
255 * If we have NPIV enabled, we want to send ELS traffic by VPI.
256 * For SLI4, since the driver controls VPIs we also want to include
257 * all ELS pt2pt protocol traffic as well.
258 */
259 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) ||
260 ((phba->sli_rev == LPFC_SLI_REV4) &&
261 (vport->fc_flag & FC_PT2PT))) {
James Smart92d7f7b2007-06-17 19:56:38 -0500262
James Smart939723a2012-05-09 21:19:03 -0400263 if (expectRsp) {
264 icmd->un.elsreq64.myID = vport->fc_myDID;
265
266 /* For ELS_REQUEST64_CR, use the VPI by default */
267 icmd->ulpContext = phba->vpi_ids[vport->vpi];
268 }
269
James Smart92d7f7b2007-06-17 19:56:38 -0500270 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500271 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
272 if (elscmd == ELS_CMD_ECHO)
273 icmd->ulpCt_l = 0; /* context = invalid RPI */
274 else
275 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500276 }
277
dea31012005-04-17 16:05:31 -0500278 bpl = (struct ulp_bde64 *) pbuflist->virt;
279 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
280 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
281 bpl->tus.f.bdeSize = cmdSize;
282 bpl->tus.f.bdeFlags = 0;
283 bpl->tus.w = le32_to_cpu(bpl->tus.w);
284
285 if (expectRsp) {
286 bpl++;
287 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
288 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
289 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400290 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500291 bpl->tus.w = le32_to_cpu(bpl->tus.w);
292 }
293
James Smartfa4066b2008-01-11 01:53:27 -0500294 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400295 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500296 if (!elsiocb->context1)
297 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400298 elsiocb->context2 = pcmd;
299 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500300 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500301 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500302 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
303
304 if (prsp) {
305 list_add(&prsp->list, &pcmd->list);
306 }
dea31012005-04-17 16:05:31 -0500307 if (expectRsp) {
308 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
310 "0116 Xmit ELS command x%x to remote "
311 "NPORT x%x I/O tag: x%x, port state: x%x\n",
312 elscmd, did, elsiocb->iotag,
313 vport->port_state);
dea31012005-04-17 16:05:31 -0500314 } else {
315 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0117 Xmit ELS response x%x to remote "
318 "NPORT x%x I/O tag: x%x, size: x%x\n",
319 elscmd, ndlp->nlp_DID, elsiocb->iotag,
320 cmdSize);
dea31012005-04-17 16:05:31 -0500321 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500322 return elsiocb;
dea31012005-04-17 16:05:31 -0500323
James Smartfa4066b2008-01-11 01:53:27 -0500324els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500325 if (expectRsp)
326 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500327 kfree(pbuflist);
328
329els_iocb_free_prsp_exit:
330 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
331 kfree(prsp);
332
333els_iocb_free_pcmb_exit:
334 kfree(pcmd);
335 lpfc_sli_release_iocbq(phba, elsiocb);
336 return NULL;
337}
dea31012005-04-17 16:05:31 -0500338
James Smarte59058c2008-08-24 21:49:00 -0400339/**
James Smart3621a712009-04-06 18:47:14 -0400340 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400341 * @vport: pointer to a host virtual N_Port data structure.
342 *
343 * This routine issues a fabric registration login for a @vport. An
344 * active ndlp node with Fabric_DID must already exist for this @vport.
345 * The routine invokes two mailbox commands to carry out fabric registration
346 * login through the HBA firmware: the first mailbox command requests the
347 * HBA to perform link configuration for the @vport; and the second mailbox
348 * command requests the HBA to perform the actual fabric registration login
349 * with the @vport.
350 *
351 * Return code
352 * 0 - successfully issued fabric registration login for @vport
353 * -ENXIO -- failed to issue fabric registration login for @vport
354 **/
James Smart3772a992009-05-22 14:50:54 -0400355int
James Smart92d7f7b2007-06-17 19:56:38 -0500356lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
357{
358 struct lpfc_hba *phba = vport->phba;
359 LPFC_MBOXQ_t *mbox;
360 struct lpfc_dmabuf *mp;
361 struct lpfc_nodelist *ndlp;
362 struct serv_parm *sp;
363 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400364 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500365
366 sp = &phba->fc_fabparam;
367 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500368 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400369 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500370 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400371 }
James Smart92d7f7b2007-06-17 19:56:38 -0500372
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400374 if (!mbox) {
375 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500376 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400377 }
James Smart92d7f7b2007-06-17 19:56:38 -0500378
379 vport->port_state = LPFC_FABRIC_CFG_LINK;
380 lpfc_config_link(phba, mbox);
381 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
382 mbox->vport = vport;
383
James Smart0b727fe2007-10-27 13:37:25 -0400384 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400385 if (rc == MBX_NOT_FINISHED) {
386 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500387 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400388 }
James Smart92d7f7b2007-06-17 19:56:38 -0500389
390 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400391 if (!mbox) {
392 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500393 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400394 }
James Smart40426292010-12-15 17:58:10 -0500395 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
396 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400397 if (rc) {
398 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500399 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400400 }
James Smart92d7f7b2007-06-17 19:56:38 -0500401
402 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
403 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500404 /* increment the reference count on ndlp to hold reference
405 * for the callback routine.
406 */
James Smart92d7f7b2007-06-17 19:56:38 -0500407 mbox->context2 = lpfc_nlp_get(ndlp);
408
James Smart0b727fe2007-10-27 13:37:25 -0400409 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400410 if (rc == MBX_NOT_FINISHED) {
411 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500412 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400413 }
James Smart92d7f7b2007-06-17 19:56:38 -0500414
415 return 0;
416
417fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500418 /* decrement the reference count on ndlp just incremented
419 * for the failed mbox command.
420 */
James Smart92d7f7b2007-06-17 19:56:38 -0500421 lpfc_nlp_put(ndlp);
422 mp = (struct lpfc_dmabuf *) mbox->context1;
423 lpfc_mbuf_free(phba, mp->virt, mp->phys);
424 kfree(mp);
425fail_free_mbox:
426 mempool_free(mbox, phba->mbox_mem_pool);
427
428fail:
429 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400431 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500432 return -ENXIO;
433}
434
James Smarte59058c2008-08-24 21:49:00 -0400435/**
James Smart6fb120a2009-05-22 14:52:59 -0400436 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
437 * @vport: pointer to a host virtual N_Port data structure.
438 *
439 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
James Smart1b511972011-12-13 13:23:09 -0500440 * the @vport. This mailbox command is necessary for SLI4 port only.
James Smart6fb120a2009-05-22 14:52:59 -0400441 *
442 * Return code
443 * 0 - successfully issued REG_VFI for @vport
444 * A failure code otherwise.
445 **/
James Smart1b511972011-12-13 13:23:09 -0500446int
James Smart6fb120a2009-05-22 14:52:59 -0400447lpfc_issue_reg_vfi(struct lpfc_vport *vport)
448{
449 struct lpfc_hba *phba = vport->phba;
450 LPFC_MBOXQ_t *mboxq;
451 struct lpfc_nodelist *ndlp;
452 struct serv_parm *sp;
453 struct lpfc_dmabuf *dmabuf;
454 int rc = 0;
455
456 sp = &phba->fc_fabparam;
James Smart939723a2012-05-09 21:19:03 -0400457 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
James Smart1b511972011-12-13 13:23:09 -0500458 if ((phba->sli_rev == LPFC_SLI_REV4) &&
James Smart939723a2012-05-09 21:19:03 -0400459 !(phba->link_flag & LS_LOOPBACK_MODE) &&
460 !(vport->fc_flag & FC_PT2PT)) {
James Smart1b511972011-12-13 13:23:09 -0500461 ndlp = lpfc_findnode_did(vport, Fabric_DID);
462 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
463 rc = -ENODEV;
464 goto fail;
465 }
James Smart6fb120a2009-05-22 14:52:59 -0400466 }
467
468 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
469 if (!dmabuf) {
470 rc = -ENOMEM;
471 goto fail;
472 }
473 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
474 if (!dmabuf->virt) {
475 rc = -ENOMEM;
476 goto fail_free_dmabuf;
477 }
James Smart6d368e52011-05-24 11:44:12 -0400478
James Smart6fb120a2009-05-22 14:52:59 -0400479 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
480 if (!mboxq) {
481 rc = -ENOMEM;
482 goto fail_free_coherent;
483 }
484 vport->port_state = LPFC_FABRIC_CFG_LINK;
485 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
486 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
487 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
488 mboxq->vport = vport;
489 mboxq->context1 = dmabuf;
490 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
491 if (rc == MBX_NOT_FINISHED) {
492 rc = -ENXIO;
493 goto fail_free_mbox;
494 }
495 return 0;
496
497fail_free_mbox:
498 mempool_free(mboxq, phba->mbox_mem_pool);
499fail_free_coherent:
500 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
501fail_free_dmabuf:
502 kfree(dmabuf);
503fail:
504 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
505 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
506 "0289 Issue Register VFI failed: Err %d\n", rc);
507 return rc;
508}
509
510/**
James Smart1b511972011-12-13 13:23:09 -0500511 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
512 * @vport: pointer to a host virtual N_Port data structure.
513 *
514 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
515 * the @vport. This mailbox command is necessary for SLI4 port only.
516 *
517 * Return code
518 * 0 - successfully issued REG_VFI for @vport
519 * A failure code otherwise.
520 **/
521int
522lpfc_issue_unreg_vfi(struct lpfc_vport *vport)
523{
524 struct lpfc_hba *phba = vport->phba;
525 struct Scsi_Host *shost;
526 LPFC_MBOXQ_t *mboxq;
527 int rc;
528
529 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
530 if (!mboxq) {
531 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
532 "2556 UNREG_VFI mbox allocation failed"
533 "HBA state x%x\n", phba->pport->port_state);
534 return -ENOMEM;
535 }
536
537 lpfc_unreg_vfi(mboxq, vport);
538 mboxq->vport = vport;
539 mboxq->mbox_cmpl = lpfc_unregister_vfi_cmpl;
540
541 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
542 if (rc == MBX_NOT_FINISHED) {
543 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
544 "2557 UNREG_VFI issue mbox failed rc x%x "
545 "HBA state x%x\n",
546 rc, phba->pport->port_state);
547 mempool_free(mboxq, phba->mbox_mem_pool);
548 return -EIO;
549 }
550
551 shost = lpfc_shost_from_vport(vport);
552 spin_lock_irq(shost->host_lock);
553 vport->fc_flag &= ~FC_VFI_REGISTERED;
554 spin_unlock_irq(shost->host_lock);
555 return 0;
556}
557
558/**
James Smart92494142011-02-16 12:39:44 -0500559 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
560 * @vport: pointer to a host virtual N_Port data structure.
561 * @sp: pointer to service parameter data structure.
562 *
563 * This routine is called from FLOGI/FDISC completion handler functions.
564 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
565 * node nodename is changed in the completion service parameter else return
566 * 0. This function also set flag in the vport data structure to delay
567 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
568 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
569 * node nodename is changed in the completion service parameter.
570 *
571 * Return code
572 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
573 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
574 *
575 **/
576static uint8_t
577lpfc_check_clean_addr_bit(struct lpfc_vport *vport,
578 struct serv_parm *sp)
579{
580 uint8_t fabric_param_changed = 0;
581 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
582
583 if ((vport->fc_prevDID != vport->fc_myDID) ||
584 memcmp(&vport->fabric_portname, &sp->portName,
585 sizeof(struct lpfc_name)) ||
586 memcmp(&vport->fabric_nodename, &sp->nodeName,
587 sizeof(struct lpfc_name)))
588 fabric_param_changed = 1;
589
590 /*
591 * Word 1 Bit 31 in common service parameter is overloaded.
592 * Word 1 Bit 31 in FLOGI request is multiple NPort request
593 * Word 1 Bit 31 in FLOGI response is clean address bit
594 *
595 * If fabric parameter is changed and clean address bit is
596 * cleared delay nport discovery if
597 * - vport->fc_prevDID != 0 (not initial discovery) OR
598 * - lpfc_delay_discovery module parameter is set.
599 */
600 if (fabric_param_changed && !sp->cmn.clean_address_bit &&
601 (vport->fc_prevDID || lpfc_delay_discovery)) {
602 spin_lock_irq(shost->host_lock);
603 vport->fc_flag |= FC_DISC_DELAYED;
604 spin_unlock_irq(shost->host_lock);
605 }
606
607 return fabric_param_changed;
608}
609
610
611/**
James Smart3621a712009-04-06 18:47:14 -0400612 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400613 * @vport: pointer to a host virtual N_Port data structure.
614 * @ndlp: pointer to a node-list data structure.
615 * @sp: pointer to service parameter data structure.
616 * @irsp: pointer to the IOCB within the lpfc response IOCB.
617 *
618 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
619 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
620 * port in a fabric topology. It properly sets up the parameters to the @ndlp
621 * from the IOCB response. It also check the newly assigned N_Port ID to the
622 * @vport against the previously assigned N_Port ID. If it is different from
623 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
624 * is invoked on all the remaining nodes with the @vport to unregister the
625 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
626 * is invoked to register login to the fabric.
627 *
628 * Return code
629 * 0 - Success (currently, always return 0)
630 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500631static int
James Smart2e0fef82007-06-17 19:56:36 -0500632lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
633 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500634{
James Smart2e0fef82007-06-17 19:56:36 -0500635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
636 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500637 struct lpfc_nodelist *np;
638 struct lpfc_nodelist *next_np;
James Smart92494142011-02-16 12:39:44 -0500639 uint8_t fabric_param_changed;
dea31012005-04-17 16:05:31 -0500640
James Smart2e0fef82007-06-17 19:56:36 -0500641 spin_lock_irq(shost->host_lock);
642 vport->fc_flag |= FC_FABRIC;
643 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500644
645 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
646 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
647 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
648
James Smart12265f62010-10-22 11:05:53 -0400649 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500650 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
651
James Smart76a95d72010-11-20 23:11:48 -0500652 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500653 spin_lock_irq(shost->host_lock);
654 vport->fc_flag |= FC_PUBLIC_LOOP;
655 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500656 }
657
James Smart2e0fef82007-06-17 19:56:36 -0500658 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500659 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500660 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500661 ndlp->nlp_class_sup = 0;
662 if (sp->cls1.classValid)
663 ndlp->nlp_class_sup |= FC_COS_CLASS1;
664 if (sp->cls2.classValid)
665 ndlp->nlp_class_sup |= FC_COS_CLASS2;
666 if (sp->cls3.classValid)
667 ndlp->nlp_class_sup |= FC_COS_CLASS3;
668 if (sp->cls4.classValid)
669 ndlp->nlp_class_sup |= FC_COS_CLASS4;
670 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
671 sp->cmn.bbRcvSizeLsb;
James Smart92494142011-02-16 12:39:44 -0500672
673 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
674 memcpy(&vport->fabric_portname, &sp->portName,
675 sizeof(struct lpfc_name));
676 memcpy(&vport->fabric_nodename, &sp->nodeName,
677 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500678 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
679
James Smart92d7f7b2007-06-17 19:56:38 -0500680 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
681 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400682 lpfc_printf_vlog(vport, KERN_WARNING,
683 LOG_ELS | LOG_VPORT,
684 "1816 FLOGI NPIV supported, "
685 "response data 0x%x\n",
686 sp->cmn.response_multiple_NPort);
James Smart1b511972011-12-13 13:23:09 -0500687 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500688 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500689 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500690 } else {
691 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400692 to call reg_vnpid atleast for the physcial host */
693 lpfc_printf_vlog(vport, KERN_WARNING,
694 LOG_ELS | LOG_VPORT,
695 "1817 Fabric does not support NPIV "
696 "- configuring single port mode.\n");
James Smart1b511972011-12-13 13:23:09 -0500697 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500698 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
James Smart1b511972011-12-13 13:23:09 -0500699 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500700 }
701 }
702
James Smart92494142011-02-16 12:39:44 -0500703 if (fabric_param_changed &&
James Smart92d7f7b2007-06-17 19:56:38 -0500704 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
705
706 /* If our NportID changed, we need to ensure all
707 * remaining NPORTs get unreg_login'ed.
708 */
709 list_for_each_entry_safe(np, next_np,
710 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400711 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500712 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500713 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
714 !(np->nlp_flag & NLP_NPR_ADISC))
715 continue;
716 spin_lock_irq(shost->host_lock);
717 np->nlp_flag &= ~NLP_NPR_ADISC;
718 spin_unlock_irq(shost->host_lock);
719 lpfc_unreg_rpi(vport, np);
720 }
James Smart78730cf2010-04-06 15:06:30 -0400721 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400722
James Smart5248a742011-07-22 18:37:06 -0400723 if (phba->sli_rev == LPFC_SLI_REV4) {
James Smart5af5eee2010-10-22 11:06:38 -0400724 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500725 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500726 spin_lock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -0500727 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
728 spin_unlock_irq(shost->host_lock);
729 }
James Smart27aa1b72012-05-09 21:18:49 -0400730
731 /*
732 * For SLI3 and SLI4, the VPI needs to be reregistered in
733 * response to this fabric parameter change event.
734 */
735 spin_lock_irq(shost->host_lock);
736 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
737 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -0400738 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
739 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
740 /*
741 * Driver needs to re-reg VPI in order for f/w
742 * to update the MAC address.
743 */
James Smart9589b062011-04-16 11:03:17 -0400744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart38b92ef2010-08-04 16:11:39 -0400745 lpfc_register_new_vport(phba, vport, ndlp);
746 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500747 }
748
James Smart6fb120a2009-05-22 14:52:59 -0400749 if (phba->sli_rev < LPFC_SLI_REV4) {
750 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
751 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
752 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
753 lpfc_register_new_vport(phba, vport, ndlp);
754 else
755 lpfc_issue_fabric_reglogin(vport);
756 } else {
757 ndlp->nlp_type |= NLP_FABRIC;
758 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500759 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
760 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400761 lpfc_start_fdiscs(phba);
762 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500763 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500764 lpfc_issue_init_vpi(vport);
James Smart1b511972011-12-13 13:23:09 -0500765 else {
766 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
767 "3135 Need register VFI: (x%x/%x)\n",
768 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -0400769 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -0500770 }
James Smart92d7f7b2007-06-17 19:56:38 -0500771 }
dea31012005-04-17 16:05:31 -0500772 return 0;
dea31012005-04-17 16:05:31 -0500773}
James Smart1b511972011-12-13 13:23:09 -0500774
James Smarte59058c2008-08-24 21:49:00 -0400775/**
James Smart3621a712009-04-06 18:47:14 -0400776 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400777 * @vport: pointer to a host virtual N_Port data structure.
778 * @ndlp: pointer to a node-list data structure.
779 * @sp: pointer to service parameter data structure.
780 *
781 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
782 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
783 * in a point-to-point topology. First, the @vport's N_Port Name is compared
784 * with the received N_Port Name: if the @vport's N_Port Name is greater than
785 * the received N_Port Name lexicographically, this node shall assign local
786 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
787 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
788 * this node shall just wait for the remote node to issue PLOGI and assign
789 * N_Port IDs.
790 *
791 * Return code
792 * 0 - Success
793 * -ENXIO - Fail
794 **/
dea31012005-04-17 16:05:31 -0500795static int
James Smart2e0fef82007-06-17 19:56:36 -0500796lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
797 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500798{
James Smart2e0fef82007-06-17 19:56:36 -0500799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
800 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500801 LPFC_MBOXQ_t *mbox;
802 int rc;
803
James Smart2e0fef82007-06-17 19:56:36 -0500804 spin_lock_irq(shost->host_lock);
805 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
806 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500807
808 phba->fc_edtov = FF_DEF_EDTOV;
809 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500810 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500811 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500812 if (rc >= 0) {
813 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500814 spin_lock_irq(shost->host_lock);
815 vport->fc_flag |= FC_PT2PT_PLOGI;
816 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500817
818 /*
819 * N_Port ID cannot be 0, set our to LocalID the other
820 * side will be RemoteID.
821 */
822
823 /* not equal */
824 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500825 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500826
827 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
828 if (!mbox)
829 goto fail;
830
831 lpfc_config_link(phba, mbox);
832
833 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500834 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400835 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500836 if (rc == MBX_NOT_FINISHED) {
837 mempool_free(mbox, phba->mbox_mem_pool);
838 goto fail;
839 }
James Smart939723a2012-05-09 21:19:03 -0400840
841 /*
842 * For SLI4, the VFI/VPI are registered AFTER the
843 * Nport with the higher WWPN sends the PLOGI with
844 * an assigned NPortId.
845 */
846
847 /* not equal */
848 if ((phba->sli_rev == LPFC_SLI_REV4) && rc)
849 lpfc_issue_reg_vfi(vport);
850
James Smarte47c9092008-02-08 18:49:26 -0500851 /* Decrement ndlp reference count indicating that ndlp can be
852 * safely released when other references to it are done.
853 */
James Smart329f9bc2007-04-25 09:53:01 -0400854 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500855
James Smart2e0fef82007-06-17 19:56:36 -0500856 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500857 if (!ndlp) {
858 /*
859 * Cannot find existing Fabric ndlp, so allocate a
860 * new one
861 */
862 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
863 if (!ndlp)
864 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500865 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500866 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
867 ndlp = lpfc_enable_node(vport, ndlp,
868 NLP_STE_UNUSED_NODE);
869 if(!ndlp)
870 goto fail;
dea31012005-04-17 16:05:31 -0500871 }
872
873 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500874 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500875 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500876 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500877 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500878 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
879 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500880 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500882 } else
883 /* This side will wait for the PLOGI, decrement ndlp reference
884 * count indicating that ndlp can be released when other
885 * references to it are done.
886 */
James Smart329f9bc2007-04-25 09:53:01 -0400887 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500888
James Smart09372822008-01-11 01:52:54 -0500889 /* If we are pt2pt with another NPort, force NPIV off! */
890 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
891
James Smart2e0fef82007-06-17 19:56:36 -0500892 spin_lock_irq(shost->host_lock);
893 vport->fc_flag |= FC_PT2PT;
894 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500895
896 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500897 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500898 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500899fail:
dea31012005-04-17 16:05:31 -0500900 return -ENXIO;
901}
902
James Smarte59058c2008-08-24 21:49:00 -0400903/**
James Smart3621a712009-04-06 18:47:14 -0400904 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400905 * @phba: pointer to lpfc hba data structure.
906 * @cmdiocb: pointer to lpfc command iocb data structure.
907 * @rspiocb: pointer to lpfc response iocb data structure.
908 *
909 * This routine is the top-level completion callback function for issuing
910 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
911 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
912 * retry has been made (either immediately or delayed with lpfc_els_retry()
913 * returning 1), the command IOCB will be released and function returned.
914 * If the retry attempt has been given up (possibly reach the maximum
915 * number of retries), one additional decrement of ndlp reference shall be
916 * invoked before going out after releasing the command IOCB. This will
917 * actually release the remote node (Note, lpfc_els_free_iocb() will also
918 * invoke one decrement of ndlp reference count). If no error reported in
919 * the IOCB status, the command Port ID field is used to determine whether
920 * this is a point-to-point topology or a fabric topology: if the Port ID
921 * field is assigned, it is a fabric topology; otherwise, it is a
922 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
923 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
924 * specific topology completion conditions.
925 **/
dea31012005-04-17 16:05:31 -0500926static void
James Smart329f9bc2007-04-25 09:53:01 -0400927lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
928 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500929{
James Smart2e0fef82007-06-17 19:56:36 -0500930 struct lpfc_vport *vport = cmdiocb->vport;
931 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500932 IOCB_t *irsp = &rspiocb->iocb;
933 struct lpfc_nodelist *ndlp = cmdiocb->context1;
934 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
935 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500936 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500937 int rc;
938
939 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500940 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500941 /* One additional decrement on node reference count to
942 * trigger the release of the node
943 */
James Smart329f9bc2007-04-25 09:53:01 -0400944 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500945 goto out;
946 }
947
James Smart858c9f62007-06-17 19:56:39 -0500948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
949 "FLOGI cmpl: status:x%x/x%x state:x%x",
950 irsp->ulpStatus, irsp->un.ulpWord[4],
951 vport->port_state);
952
dea31012005-04-17 16:05:31 -0500953 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500954 /*
James Smarta93ff372010-10-22 11:06:08 -0400955 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500956 * due to new FCF discovery
957 */
958 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart80c17842012-03-01 22:35:45 -0500959 (phba->fcf.fcf_flag & FCF_DISCOVERY)) {
960 if (phba->link_state < LPFC_LINK_UP)
961 goto stop_rr_fcf_flogi;
962 if ((phba->fcoe_cvl_eventtag_attn ==
963 phba->fcoe_cvl_eventtag) &&
964 (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
James Smarte3d2b802012-08-14 14:25:43 -0400965 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
966 IOERR_SLI_ABORTED))
James Smart80c17842012-03-01 22:35:45 -0500967 goto stop_rr_fcf_flogi;
968 else
969 phba->fcoe_cvl_eventtag_attn =
970 phba->fcoe_cvl_eventtag;
James Smart0c9ab6f2010-02-26 14:15:57 -0500971 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400972 "2611 FLOGI failed on FCF (x%x), "
973 "status:x%x/x%x, tmo:x%x, perform "
974 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400975 phba->fcf.current_rec.fcf_indx,
976 irsp->ulpStatus, irsp->un.ulpWord[4],
977 irsp->ulpTimeout);
James Smart7d791df2011-07-22 18:37:52 -0400978 lpfc_sli4_set_fcf_flogi_fail(phba,
979 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500980 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400981 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
982 if (rc)
983 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500984 }
985
James Smart80c17842012-03-01 22:35:45 -0500986stop_rr_fcf_flogi:
James Smart38b92ef2010-08-04 16:11:39 -0400987 /* FLOGI failure */
988 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
989 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
990 irsp->ulpStatus, irsp->un.ulpWord[4],
991 irsp->ulpTimeout);
992
dea31012005-04-17 16:05:31 -0500993 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500994 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500995 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500996
James Smart76a95d72010-11-20 23:11:48 -0500997 /* FLOGI failure */
998 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
999 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1000 irsp->ulpStatus, irsp->un.ulpWord[4],
1001 irsp->ulpTimeout);
1002
dea31012005-04-17 16:05:31 -05001003 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -05001004 spin_lock_irq(shost->host_lock);
1005 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1006 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001007
James Smart329f9bc2007-04-25 09:53:01 -04001008 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -05001009 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1010 * alpa map would take too long otherwise.
1011 */
James Smart1b511972011-12-13 13:23:09 -05001012 if (phba->alpa_map[0] == 0)
James Smart3de2a652007-08-02 11:09:59 -04001013 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smartff78d8f2011-12-13 13:21:35 -05001014 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1015 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
1016 (vport->fc_prevDID != vport->fc_myDID))) {
1017 if (vport->fc_flag & FC_VFI_REGISTERED)
1018 lpfc_sli4_unreg_all_rpis(vport);
1019 lpfc_issue_reg_vfi(vport);
1020 lpfc_nlp_put(ndlp);
1021 goto out;
dea31012005-04-17 16:05:31 -05001022 }
dea31012005-04-17 16:05:31 -05001023 goto flogifail;
1024 }
James Smart695a8142010-01-26 23:08:03 -05001025 spin_lock_irq(shost->host_lock);
1026 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04001027 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -05001028 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001029
1030 /*
1031 * The FLogI succeeded. Sync the data for the CPU before
1032 * accessing it.
1033 */
1034 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
1035
1036 sp = prsp->virt + sizeof(uint32_t);
1037
1038 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -04001039 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02001040 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -04001041 "Data: x%x x%x x%x x%x\n",
1042 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
1043 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -05001044
James Smart2e0fef82007-06-17 19:56:36 -05001045 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -05001046 /*
1047 * If Common Service Parameters indicate Nport
1048 * we are point to point, if Fport we are Fabric.
1049 */
1050 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -05001051 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -05001052 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001053 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -04001054 else {
1055 lpfc_printf_vlog(vport, KERN_ERR,
1056 LOG_FIP | LOG_ELS,
1057 "2831 FLOGI response with cleared Fabric "
1058 "bit fcf_index 0x%x "
1059 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1060 "Fabric Name "
1061 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1062 phba->fcf.current_rec.fcf_indx,
1063 phba->fcf.current_rec.switch_name[0],
1064 phba->fcf.current_rec.switch_name[1],
1065 phba->fcf.current_rec.switch_name[2],
1066 phba->fcf.current_rec.switch_name[3],
1067 phba->fcf.current_rec.switch_name[4],
1068 phba->fcf.current_rec.switch_name[5],
1069 phba->fcf.current_rec.switch_name[6],
1070 phba->fcf.current_rec.switch_name[7],
1071 phba->fcf.current_rec.fabric_name[0],
1072 phba->fcf.current_rec.fabric_name[1],
1073 phba->fcf.current_rec.fabric_name[2],
1074 phba->fcf.current_rec.fabric_name[3],
1075 phba->fcf.current_rec.fabric_name[4],
1076 phba->fcf.current_rec.fabric_name[5],
1077 phba->fcf.current_rec.fabric_name[6],
1078 phba->fcf.current_rec.fabric_name[7]);
1079 lpfc_nlp_put(ndlp);
1080 spin_lock_irq(&phba->hbalock);
1081 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001082 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -04001083 spin_unlock_irq(&phba->hbalock);
1084 goto out;
1085 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001086 if (!rc) {
1087 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -04001088 if (phba->hba_flag & HBA_FIP_SUPPORT)
1089 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
1090 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -04001091 "2769 FLOGI to FCF (x%x) "
1092 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -04001093 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -05001094 spin_lock_irq(&phba->hbalock);
1095 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04001096 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -05001097 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001098 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05001099 }
dea31012005-04-17 16:05:31 -05001100 }
1101
1102flogifail:
James Smart329f9bc2007-04-25 09:53:01 -04001103 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001104
James Smart858c9f62007-06-17 19:56:39 -05001105 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001106 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05001107 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001108
1109 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001110 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -04001111 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04001112 (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1113 IOERR_SLI_ABORTED) &&
1114 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
1115 IOERR_SLI_DOWN))) &&
James Smart87af33f2007-10-27 13:37:43 -04001116 (phba->link_state != LPFC_CLEAR_LA)) {
1117 /* If FLOGI failed enable link interrupt. */
1118 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001119 }
dea31012005-04-17 16:05:31 -05001120out:
1121 lpfc_els_free_iocb(phba, cmdiocb);
1122}
1123
James Smarte59058c2008-08-24 21:49:00 -04001124/**
James Smart3621a712009-04-06 18:47:14 -04001125 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001126 * @vport: pointer to a host virtual N_Port data structure.
1127 * @ndlp: pointer to a node-list data structure.
1128 * @retry: number of retries to the command IOCB.
1129 *
1130 * This routine issues a Fabric Login (FLOGI) Request ELS command
1131 * for a @vport. The initiator service parameters are put into the payload
1132 * of the FLOGI Request IOCB and the top-level callback function pointer
1133 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1134 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1135 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1136 *
1137 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1138 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1139 * will be stored into the context1 field of the IOCB for the completion
1140 * callback function to the FLOGI ELS command.
1141 *
1142 * Return code
1143 * 0 - successfully issued flogi iocb for @vport
1144 * 1 - failed to issue flogi iocb for @vport
1145 **/
dea31012005-04-17 16:05:31 -05001146static int
James Smart2e0fef82007-06-17 19:56:36 -05001147lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001148 uint8_t retry)
1149{
James Smart2e0fef82007-06-17 19:56:36 -05001150 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001151 struct serv_parm *sp;
1152 IOCB_t *icmd;
1153 struct lpfc_iocbq *elsiocb;
1154 struct lpfc_sli_ring *pring;
1155 uint8_t *pcmd;
1156 uint16_t cmdsize;
1157 uint32_t tmo;
1158 int rc;
1159
1160 pring = &phba->sli.ring[LPFC_ELS_RING];
1161
James Smart92d7f7b2007-06-17 19:56:38 -05001162 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001163 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1164 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001165
James Smart488d1462006-03-07 15:02:37 -05001166 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001167 return 1;
dea31012005-04-17 16:05:31 -05001168
1169 icmd = &elsiocb->iocb;
1170 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1171
1172 /* For FLOGI request, remainder of payload is service parameters */
1173 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001174 pcmd += sizeof(uint32_t);
1175 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001176 sp = (struct serv_parm *) pcmd;
1177
1178 /* Setup CSPs accordingly for Fabric */
1179 sp->cmn.e_d_tov = 0;
1180 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05001181 sp->cmn.virtual_fabric_support = 0;
dea31012005-04-17 16:05:31 -05001182 sp->cls1.classValid = 0;
1183 sp->cls2.seqDelivery = 1;
1184 sp->cls3.seqDelivery = 1;
1185 if (sp->cmn.fcphLow < FC_PH3)
1186 sp->cmn.fcphLow = FC_PH3;
1187 if (sp->cmn.fcphHigh < FC_PH3)
1188 sp->cmn.fcphHigh = FC_PH3;
1189
James Smartc31098c2011-04-16 11:03:33 -04001190 if (phba->sli_rev == LPFC_SLI_REV4) {
1191 if (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1192 LPFC_SLI_INTF_IF_TYPE_0) {
1193 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1194 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1195 /* FLOGI needs to be 3 for WQE FCFI */
1196 /* Set the fcfi to the fcfi we registered with */
1197 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1198 }
James Smart5248a742011-07-22 18:37:06 -04001199 } else {
1200 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1201 sp->cmn.request_multiple_Nport = 1;
1202 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1203 icmd->ulpCt_h = 1;
1204 icmd->ulpCt_l = 0;
1205 } else
1206 sp->cmn.request_multiple_Nport = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001207 }
1208
James Smart76a95d72010-11-20 23:11:48 -05001209 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001210 icmd->un.elsreq64.myID = 0;
1211 icmd->un.elsreq64.fl = 1;
1212 }
1213
dea31012005-04-17 16:05:31 -05001214 tmo = phba->fc_ratov;
1215 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001216 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001217 phba->fc_ratov = tmo;
1218
1219 phba->fc_stat.elsXmitFLOGI++;
1220 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001221
1222 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1223 "Issue FLOGI: opt:x%x",
1224 phba->sli3_options, 0, 0);
1225
James Smart92d7f7b2007-06-17 19:56:38 -05001226 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001227 if (rc == IOCB_ERROR) {
1228 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001229 return 1;
dea31012005-04-17 16:05:31 -05001230 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001231 return 0;
dea31012005-04-17 16:05:31 -05001232}
1233
James Smarte59058c2008-08-24 21:49:00 -04001234/**
James Smart3621a712009-04-06 18:47:14 -04001235 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001236 * @phba: pointer to lpfc hba data structure.
1237 *
1238 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1239 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1240 * list and issues an abort IOCB commond on each outstanding IOCB that
1241 * contains a active Fabric_DID ndlp. Note that this function is to issue
1242 * the abort IOCB command on all the outstanding IOCBs, thus when this
1243 * function returns, it does not guarantee all the IOCBs are actually aborted.
1244 *
1245 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001246 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001247 **/
dea31012005-04-17 16:05:31 -05001248int
James Smart2e0fef82007-06-17 19:56:36 -05001249lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001250{
1251 struct lpfc_sli_ring *pring;
1252 struct lpfc_iocbq *iocb, *next_iocb;
1253 struct lpfc_nodelist *ndlp;
1254 IOCB_t *icmd;
1255
1256 /* Abort outstanding I/O on NPort <nlp_DID> */
1257 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001258 "0201 Abort outstanding I/O on NPort x%x\n",
1259 Fabric_DID);
dea31012005-04-17 16:05:31 -05001260
1261 pring = &phba->sli.ring[LPFC_ELS_RING];
1262
1263 /*
1264 * Check the txcmplq for an iocb that matches the nport the driver is
1265 * searching for.
1266 */
James Smart2e0fef82007-06-17 19:56:36 -05001267 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001268 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1269 icmd = &iocb->iocb;
James Smart1b511972011-12-13 13:23:09 -05001270 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
dea31012005-04-17 16:05:31 -05001271 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001272 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1273 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001274 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001275 }
1276 }
James Smart2e0fef82007-06-17 19:56:36 -05001277 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001278
1279 return 0;
1280}
1281
James Smarte59058c2008-08-24 21:49:00 -04001282/**
James Smart3621a712009-04-06 18:47:14 -04001283 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001284 * @vport: pointer to a host virtual N_Port data structure.
1285 *
1286 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1287 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1288 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1289 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1290 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1291 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1292 * @vport.
1293 *
1294 * Return code
1295 * 0 - failed to issue initial flogi for @vport
1296 * 1 - successfully issued initial flogi for @vport
1297 **/
dea31012005-04-17 16:05:31 -05001298int
James Smart2e0fef82007-06-17 19:56:36 -05001299lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001300{
James Smart2e0fef82007-06-17 19:56:36 -05001301 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001302 struct lpfc_nodelist *ndlp;
1303
James Smart98c9ea52007-10-27 13:37:33 -04001304 vport->port_state = LPFC_FLOGI;
1305 lpfc_set_disctmo(vport);
1306
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001307 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001308 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001309 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001310 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001311 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1312 if (!ndlp)
1313 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001315 /* Set the node type */
1316 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001317 /* Put ndlp onto node list */
1318 lpfc_enqueue_node(vport, ndlp);
1319 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1320 /* re-setup ndlp without removing from node list */
1321 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1322 if (!ndlp)
1323 return 0;
dea31012005-04-17 16:05:31 -05001324 }
James Smart87af33f2007-10-27 13:37:43 -04001325
James Smart5ac6b302010-10-22 11:05:36 -04001326 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001327 /* This decrement of reference count to node shall kick off
1328 * the release of the node.
1329 */
James Smart329f9bc2007-04-25 09:53:01 -04001330 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001331 return 0;
1332 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001333 return 1;
dea31012005-04-17 16:05:31 -05001334}
1335
James Smarte59058c2008-08-24 21:49:00 -04001336/**
James Smart3621a712009-04-06 18:47:14 -04001337 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001338 * @vport: pointer to a host virtual N_Port data structure.
1339 *
1340 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1341 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1342 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1343 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1344 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1345 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1346 * @vport.
1347 *
1348 * Return code
1349 * 0 - failed to issue initial fdisc for @vport
1350 * 1 - successfully issued initial fdisc for @vport
1351 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001352int
1353lpfc_initial_fdisc(struct lpfc_vport *vport)
1354{
1355 struct lpfc_hba *phba = vport->phba;
1356 struct lpfc_nodelist *ndlp;
1357
1358 /* First look for the Fabric ndlp */
1359 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1360 if (!ndlp) {
1361 /* Cannot find existing Fabric ndlp, so allocate a new one */
1362 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1363 if (!ndlp)
1364 return 0;
1365 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001366 /* Put ndlp onto node list */
1367 lpfc_enqueue_node(vport, ndlp);
1368 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1369 /* re-setup ndlp without removing from node list */
1370 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1371 if (!ndlp)
1372 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001373 }
James Smarte47c9092008-02-08 18:49:26 -05001374
James Smart92d7f7b2007-06-17 19:56:38 -05001375 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001376 /* decrement node reference count to trigger the release of
1377 * the node.
1378 */
James Smart92d7f7b2007-06-17 19:56:38 -05001379 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001380 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001381 }
1382 return 1;
1383}
James Smart87af33f2007-10-27 13:37:43 -04001384
James Smarte59058c2008-08-24 21:49:00 -04001385/**
James Smart3621a712009-04-06 18:47:14 -04001386 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001387 * @vport: pointer to a host virtual N_Port data structure.
1388 *
1389 * This routine checks whether there are more remaining Port Logins
1390 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1391 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1392 * to issue ELS PLOGIs up to the configured discover threads with the
1393 * @vport (@vport->cfg_discovery_threads). The function also decrement
1394 * the @vport's num_disc_node by 1 if it is not already 0.
1395 **/
James Smart87af33f2007-10-27 13:37:43 -04001396void
James Smart2e0fef82007-06-17 19:56:36 -05001397lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001398{
1399 int sentplogi;
1400
James Smart2e0fef82007-06-17 19:56:36 -05001401 if (vport->num_disc_nodes)
1402 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001403
1404 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001405 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1406 "0232 Continue discovery with %d PLOGIs to go "
1407 "Data: x%x x%x x%x\n",
1408 vport->num_disc_nodes, vport->fc_plogi_cnt,
1409 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001410 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001411 if (vport->fc_flag & FC_NLP_MORE)
1412 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1413 sentplogi = lpfc_els_disc_plogi(vport);
1414
dea31012005-04-17 16:05:31 -05001415 return;
1416}
1417
James Smarte59058c2008-08-24 21:49:00 -04001418/**
James Smart3621a712009-04-06 18:47:14 -04001419 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001420 * @phba: pointer to lpfc hba data structure.
1421 * @prsp: pointer to response IOCB payload.
1422 * @ndlp: pointer to a node-list data structure.
1423 *
1424 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1425 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1426 * The following cases are considered N_Port confirmed:
1427 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1428 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1429 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1430 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1431 * 1) if there is a node on vport list other than the @ndlp with the same
1432 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1433 * on that node to release the RPI associated with the node; 2) if there is
1434 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1435 * into, a new node shall be allocated (or activated). In either case, the
1436 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1437 * be released and the new_ndlp shall be put on to the vport node list and
1438 * its pointer returned as the confirmed node.
1439 *
1440 * Note that before the @ndlp got "released", the keepDID from not-matching
1441 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1442 * of the @ndlp. This is because the release of @ndlp is actually to put it
1443 * into an inactive state on the vport node list and the vport node list
1444 * management algorithm does not allow two node with a same DID.
1445 *
1446 * Return code
1447 * pointer to the PLOGI N_Port @ndlp
1448 **/
James Smart488d1462006-03-07 15:02:37 -05001449static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001450lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001451 struct lpfc_nodelist *ndlp)
1452{
James Smart2e0fef82007-06-17 19:56:36 -05001453 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001454 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001455 struct lpfc_rport_data *rdata;
1456 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001457 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001458 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001459 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001460 int put_node;
1461 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001462 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001463
James Smart2fb9bd82006-12-02 13:33:57 -05001464 /* Fabric nodes can have the same WWPN so we don't bother searching
1465 * by WWPN. Just return the ndlp that was given to us.
1466 */
1467 if (ndlp->nlp_type & NLP_FABRIC)
1468 return ndlp;
1469
James Smart92d7f7b2007-06-17 19:56:38 -05001470 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001471 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001472
James Smart685f0bf2007-04-25 09:53:08 -04001473 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001474 * we have for that ndlp. If not, we have some work to do.
1475 */
James Smart2e0fef82007-06-17 19:56:36 -05001476 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001477
James Smarte47c9092008-02-08 18:49:26 -05001478 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001479 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001480 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001481
James Smart34f5ad82012-08-03 12:35:03 -04001482 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1483 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1484 ndlp, ndlp->nlp_DID, new_ndlp);
1485
James Smart488d1462006-03-07 15:02:37 -05001486 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001487 rc = memcmp(&ndlp->nlp_portname, name,
1488 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001489 if (!rc)
1490 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001491 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1492 if (!new_ndlp)
1493 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001494 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001495 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001496 rc = memcmp(&ndlp->nlp_portname, name,
1497 sizeof(struct lpfc_name));
1498 if (!rc)
1499 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001500 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1501 NLP_STE_UNUSED_NODE);
1502 if (!new_ndlp)
1503 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001504 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001505 if (phba->sli_rev == LPFC_SLI_REV4)
1506 memcpy(&rrq.xri_bitmap,
1507 &new_ndlp->active_rrqs.xri_bitmap,
1508 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1509 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001510 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001511 if (phba->sli_rev == LPFC_SLI_REV4)
1512 memcpy(&rrq.xri_bitmap,
1513 &new_ndlp->active_rrqs.xri_bitmap,
1514 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1515 }
James Smart488d1462006-03-07 15:02:37 -05001516
James Smart2e0fef82007-06-17 19:56:36 -05001517 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001518 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001519 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001520 if (phba->sli_rev == LPFC_SLI_REV4)
1521 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1522 &ndlp->active_rrqs.xri_bitmap,
1523 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001524
1525 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1526 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1527 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1528
James Smarte47c9092008-02-08 18:49:26 -05001529 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001530 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001531
James Smart2e0fef82007-06-17 19:56:36 -05001532 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001533 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1534 /* The new_ndlp is replacing ndlp totally, so we need
1535 * to put ndlp on UNUSED list and try to free it.
1536 */
James Smart34f5ad82012-08-03 12:35:03 -04001537 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1538 "3179 PLOGI confirm NEW: %x %x\n",
1539 new_ndlp->nlp_DID, keepDID);
James Smart0ff10d42008-01-11 01:52:36 -05001540
1541 /* Fix up the rport accordingly */
1542 rport = ndlp->rport;
1543 if (rport) {
1544 rdata = rport->dd_data;
1545 if (rdata->pnode == ndlp) {
1546 lpfc_nlp_put(ndlp);
1547 ndlp->rport = NULL;
1548 rdata->pnode = lpfc_nlp_get(new_ndlp);
1549 new_ndlp->rport = rport;
1550 }
1551 new_ndlp->nlp_type = ndlp->nlp_type;
1552 }
James Smart58da1ff2008-04-07 10:15:56 -04001553 /* We shall actually free the ndlp with both nlp_DID and
1554 * nlp_portname fields equals 0 to avoid any ndlp on the
1555 * nodelist never to be used.
1556 */
1557 if (ndlp->nlp_DID == 0) {
1558 spin_lock_irq(&phba->ndlp_lock);
1559 NLP_SET_FREE_REQ(ndlp);
1560 spin_unlock_irq(&phba->ndlp_lock);
1561 }
James Smart0ff10d42008-01-11 01:52:36 -05001562
James Smart58da1ff2008-04-07 10:15:56 -04001563 /* Two ndlps cannot have the same did on the nodelist */
1564 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001565 if (phba->sli_rev == LPFC_SLI_REV4)
1566 memcpy(&ndlp->active_rrqs.xri_bitmap,
1567 &rrq.xri_bitmap,
1568 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001569 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001570 }
James Smart92795652006-07-06 15:50:02 -04001571 else {
James Smart34f5ad82012-08-03 12:35:03 -04001572 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1573 "3180 PLOGI confirm SWAP: %x %x\n",
1574 new_ndlp->nlp_DID, keepDID);
1575
James Smart2e0fef82007-06-17 19:56:36 -05001576 lpfc_unreg_rpi(vport, ndlp);
James Smart34f5ad82012-08-03 12:35:03 -04001577
James Smart58da1ff2008-04-07 10:15:56 -04001578 /* Two ndlps cannot have the same did */
1579 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001580 if (phba->sli_rev == LPFC_SLI_REV4)
1581 memcpy(&ndlp->active_rrqs.xri_bitmap,
1582 &rrq.xri_bitmap,
1583 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart34f5ad82012-08-03 12:35:03 -04001584
James Smart38b92ef2010-08-04 16:11:39 -04001585 /* Since we are swapping the ndlp passed in with the new one
James Smart34f5ad82012-08-03 12:35:03 -04001586 * and the did has already been swapped, copy over state.
1587 * The new WWNs are already in new_ndlp since thats what
1588 * we looked it up by in the begining of this routine.
James Smart38b92ef2010-08-04 16:11:39 -04001589 */
James Smart38b92ef2010-08-04 16:11:39 -04001590 new_ndlp->nlp_state = ndlp->nlp_state;
James Smart34f5ad82012-08-03 12:35:03 -04001591
1592 /* Since we are switching over to the new_ndlp, the old
1593 * ndlp should be put in the NPR state, unless we have
1594 * already started re-discovery on it.
1595 */
1596 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
1597 (ndlp->nlp_state == NLP_STE_MAPPED_NODE))
1598 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1599
James Smart38b92ef2010-08-04 16:11:39 -04001600 /* Fix up the rport accordingly */
1601 rport = ndlp->rport;
1602 if (rport) {
1603 rdata = rport->dd_data;
1604 put_node = rdata->pnode != NULL;
1605 put_rport = ndlp->rport != NULL;
1606 rdata->pnode = NULL;
1607 ndlp->rport = NULL;
1608 if (put_node)
1609 lpfc_nlp_put(ndlp);
1610 if (put_rport)
1611 put_device(&rport->dev);
1612 }
James Smart92795652006-07-06 15:50:02 -04001613 }
James Smart488d1462006-03-07 15:02:37 -05001614 return new_ndlp;
1615}
1616
James Smarte59058c2008-08-24 21:49:00 -04001617/**
James Smart3621a712009-04-06 18:47:14 -04001618 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001619 * @vport: pointer to a host virtual N_Port data structure.
1620 *
1621 * This routine checks whether more Registration State Change
1622 * Notifications (RSCNs) came in while the discovery state machine was in
1623 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1624 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1625 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1626 * handling the RSCNs.
1627 **/
James Smart87af33f2007-10-27 13:37:43 -04001628void
1629lpfc_end_rscn(struct lpfc_vport *vport)
1630{
1631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1632
1633 if (vport->fc_flag & FC_RSCN_MODE) {
1634 /*
1635 * Check to see if more RSCNs came in while we were
1636 * processing this one.
1637 */
1638 if (vport->fc_rscn_id_cnt ||
1639 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1640 lpfc_els_handle_rscn(vport);
1641 else {
1642 spin_lock_irq(shost->host_lock);
1643 vport->fc_flag &= ~FC_RSCN_MODE;
1644 spin_unlock_irq(shost->host_lock);
1645 }
1646 }
1647}
1648
James Smarte59058c2008-08-24 21:49:00 -04001649/**
James Smart19ca7602010-11-20 23:11:55 -05001650 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1651 * @phba: pointer to lpfc hba data structure.
1652 * @cmdiocb: pointer to lpfc command iocb data structure.
1653 * @rspiocb: pointer to lpfc response iocb data structure.
1654 *
1655 * This routine will call the clear rrq function to free the rrq and
1656 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1657 * exist then the clear_rrq is still called because the rrq needs to
1658 * be freed.
1659 **/
1660
1661static void
1662lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1663 struct lpfc_iocbq *rspiocb)
1664{
1665 struct lpfc_vport *vport = cmdiocb->vport;
1666 IOCB_t *irsp;
1667 struct lpfc_nodelist *ndlp;
1668 struct lpfc_node_rrq *rrq;
1669
1670 /* we pass cmdiocb to state machine which needs rspiocb as well */
1671 rrq = cmdiocb->context_un.rrq;
1672 cmdiocb->context_un.rsp_iocb = rspiocb;
1673
1674 irsp = &rspiocb->iocb;
1675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1676 "RRQ cmpl: status:x%x/x%x did:x%x",
1677 irsp->ulpStatus, irsp->un.ulpWord[4],
1678 irsp->un.elsreq64.remoteID);
1679
1680 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1681 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1682 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1683 "2882 RRQ completes to NPort x%x "
1684 "with no ndlp. Data: x%x x%x x%x\n",
1685 irsp->un.elsreq64.remoteID,
1686 irsp->ulpStatus, irsp->un.ulpWord[4],
1687 irsp->ulpIoTag);
1688 goto out;
1689 }
1690
1691 /* rrq completes to NPort <nlp_DID> */
1692 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1693 "2880 RRQ completes to NPort x%x "
1694 "Data: x%x x%x x%x x%x x%x\n",
1695 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1696 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1697
1698 if (irsp->ulpStatus) {
1699 /* Check for retry */
1700 /* RRQ failed Don't print the vport to vport rjts */
1701 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1702 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1703 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1704 (phba)->pport->cfg_log_verbose & LOG_ELS)
1705 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1706 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1707 ndlp->nlp_DID, irsp->ulpStatus,
1708 irsp->un.ulpWord[4]);
1709 }
1710out:
1711 if (rrq)
1712 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1713 lpfc_els_free_iocb(phba, cmdiocb);
1714 return;
1715}
1716/**
James Smart3621a712009-04-06 18:47:14 -04001717 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001718 * @phba: pointer to lpfc hba data structure.
1719 * @cmdiocb: pointer to lpfc command iocb data structure.
1720 * @rspiocb: pointer to lpfc response iocb data structure.
1721 *
1722 * This routine is the completion callback function for issuing the Port
1723 * Login (PLOGI) command. For PLOGI completion, there must be an active
1724 * ndlp on the vport node list that matches the remote node ID from the
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001725 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
James Smarte59058c2008-08-24 21:49:00 -04001726 * ignored and command IOCB released. The PLOGI response IOCB status is
1727 * checked for error conditons. If there is error status reported, PLOGI
1728 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1729 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1730 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1731 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1732 * there are additional N_Port nodes with the vport that need to perform
1733 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1734 * PLOGIs.
1735 **/
dea31012005-04-17 16:05:31 -05001736static void
James Smart2e0fef82007-06-17 19:56:36 -05001737lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1738 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001739{
James Smart2e0fef82007-06-17 19:56:36 -05001740 struct lpfc_vport *vport = cmdiocb->vport;
1741 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001742 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001743 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001744 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001745 int disc, rc, did, type;
1746
dea31012005-04-17 16:05:31 -05001747 /* we pass cmdiocb to state machine which needs rspiocb as well */
1748 cmdiocb->context_un.rsp_iocb = rspiocb;
1749
1750 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001751 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1752 "PLOGI cmpl: status:x%x/x%x did:x%x",
1753 irsp->ulpStatus, irsp->un.ulpWord[4],
1754 irsp->un.elsreq64.remoteID);
1755
James Smart2e0fef82007-06-17 19:56:36 -05001756 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001757 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001758 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1759 "0136 PLOGI completes to NPort x%x "
1760 "with no ndlp. Data: x%x x%x x%x\n",
1761 irsp->un.elsreq64.remoteID,
1762 irsp->ulpStatus, irsp->un.ulpWord[4],
1763 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001764 goto out;
James Smarted957682007-06-17 19:56:37 -05001765 }
dea31012005-04-17 16:05:31 -05001766
1767 /* Since ndlp can be freed in the disc state machine, note if this node
1768 * is being used during discovery.
1769 */
James Smart2e0fef82007-06-17 19:56:36 -05001770 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001771 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001772 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001773 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001774 rc = 0;
1775
1776 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001777 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1778 "0102 PLOGI completes to NPort x%x "
1779 "Data: x%x x%x x%x x%x x%x\n",
1780 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1781 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001782 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001783 if (lpfc_els_chk_latt(vport)) {
1784 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001785 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001786 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001787 goto out;
1788 }
1789
1790 /* ndlp could be freed in DSM, save these values now */
1791 type = ndlp->nlp_type;
1792 did = ndlp->nlp_DID;
1793
1794 if (irsp->ulpStatus) {
1795 /* Check for retry */
1796 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1797 /* ELS command is being retried */
1798 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001799 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001800 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001801 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001802 }
1803 goto out;
1804 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001805 /* PLOGI failed Don't print the vport to vport rjts */
1806 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1807 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1808 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1809 (phba)->pport->cfg_log_verbose & LOG_ELS)
1810 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001811 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1812 ndlp->nlp_DID, irsp->ulpStatus,
1813 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001814 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001815 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001816 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001817 else
James Smart2e0fef82007-06-17 19:56:36 -05001818 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001819 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001820 } else {
1821 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001822 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001823 cmdiocb->context2)->list.next,
1824 struct lpfc_dmabuf, list);
1825 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001826 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001827 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001828 }
1829
James Smart2e0fef82007-06-17 19:56:36 -05001830 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001831 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001832 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001833
James Smart2e0fef82007-06-17 19:56:36 -05001834 if (vport->num_disc_nodes == 0) {
1835 spin_lock_irq(shost->host_lock);
1836 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1837 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001838
James Smart2e0fef82007-06-17 19:56:36 -05001839 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001840 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001841 }
1842 }
1843
1844out:
1845 lpfc_els_free_iocb(phba, cmdiocb);
1846 return;
1847}
1848
James Smarte59058c2008-08-24 21:49:00 -04001849/**
James Smart3621a712009-04-06 18:47:14 -04001850 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001851 * @vport: pointer to a host virtual N_Port data structure.
1852 * @did: destination port identifier.
1853 * @retry: number of retries to the command IOCB.
1854 *
1855 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1856 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1857 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1858 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1859 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1860 *
1861 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1862 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1863 * will be stored into the context1 field of the IOCB for the completion
1864 * callback function to the PLOGI ELS command.
1865 *
1866 * Return code
1867 * 0 - Successfully issued a plogi for @vport
1868 * 1 - failed to issue a plogi for @vport
1869 **/
dea31012005-04-17 16:05:31 -05001870int
James Smart2e0fef82007-06-17 19:56:36 -05001871lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001872{
James Smart2e0fef82007-06-17 19:56:36 -05001873 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001874 struct serv_parm *sp;
1875 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001876 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001877 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001878 struct lpfc_sli *psli;
1879 uint8_t *pcmd;
1880 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001881 int ret;
dea31012005-04-17 16:05:31 -05001882
1883 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001884
James Smart98c9ea52007-10-27 13:37:33 -04001885 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001886 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1887 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001888
James Smarte47c9092008-02-08 18:49:26 -05001889 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001890 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001891 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001892 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001893 if (!elsiocb)
1894 return 1;
dea31012005-04-17 16:05:31 -05001895
1896 icmd = &elsiocb->iocb;
1897 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1898
1899 /* For PLOGI request, remainder of payload is service parameters */
1900 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001901 pcmd += sizeof(uint32_t);
1902 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001903 sp = (struct serv_parm *) pcmd;
1904
James Smart5ac6b302010-10-22 11:05:36 -04001905 /*
1906 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1907 * to device on remote loops work.
1908 */
1909 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1910 sp->cmn.altBbCredit = 1;
1911
dea31012005-04-17 16:05:31 -05001912 if (sp->cmn.fcphLow < FC_PH_4_3)
1913 sp->cmn.fcphLow = FC_PH_4_3;
1914
1915 if (sp->cmn.fcphHigh < FC_PH3)
1916 sp->cmn.fcphHigh = FC_PH3;
1917
James Smart858c9f62007-06-17 19:56:39 -05001918 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1919 "Issue PLOGI: did:x%x",
1920 did, 0, 0);
1921
dea31012005-04-17 16:05:31 -05001922 phba->fc_stat.elsXmitPLOGI++;
1923 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001924 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001925
1926 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001927 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001928 return 1;
dea31012005-04-17 16:05:31 -05001929 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001930 return 0;
dea31012005-04-17 16:05:31 -05001931}
1932
James Smarte59058c2008-08-24 21:49:00 -04001933/**
James Smart3621a712009-04-06 18:47:14 -04001934 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001935 * @phba: pointer to lpfc hba data structure.
1936 * @cmdiocb: pointer to lpfc command iocb data structure.
1937 * @rspiocb: pointer to lpfc response iocb data structure.
1938 *
1939 * This routine is the completion callback function for a Process Login
1940 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1941 * status. If there is error status reported, PRLI retry shall be attempted
1942 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1943 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1944 * ndlp to mark the PRLI completion.
1945 **/
dea31012005-04-17 16:05:31 -05001946static void
James Smart2e0fef82007-06-17 19:56:36 -05001947lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1948 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001949{
James Smart2e0fef82007-06-17 19:56:36 -05001950 struct lpfc_vport *vport = cmdiocb->vport;
1951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001952 IOCB_t *irsp;
1953 struct lpfc_sli *psli;
1954 struct lpfc_nodelist *ndlp;
1955
1956 psli = &phba->sli;
1957 /* we pass cmdiocb to state machine which needs rspiocb as well */
1958 cmdiocb->context_un.rsp_iocb = rspiocb;
1959
1960 irsp = &(rspiocb->iocb);
1961 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001962 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001963 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001964 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001965
James Smart858c9f62007-06-17 19:56:39 -05001966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1967 "PRLI cmpl: status:x%x/x%x did:x%x",
1968 irsp->ulpStatus, irsp->un.ulpWord[4],
1969 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001970 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001971 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1972 "0103 PRLI completes to NPort x%x "
1973 "Data: x%x x%x x%x x%x\n",
1974 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1975 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001976
James Smart2e0fef82007-06-17 19:56:36 -05001977 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001978 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001979 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001980 goto out;
1981
1982 if (irsp->ulpStatus) {
1983 /* Check for retry */
1984 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1985 /* ELS command is being retried */
1986 goto out;
1987 }
1988 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001989 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1990 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1991 ndlp->nlp_DID, irsp->ulpStatus,
1992 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001993 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001994 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001995 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001996 else
James Smart2e0fef82007-06-17 19:56:36 -05001997 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001998 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001999 } else
dea31012005-04-17 16:05:31 -05002000 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002002 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05002003out:
2004 lpfc_els_free_iocb(phba, cmdiocb);
2005 return;
2006}
2007
James Smarte59058c2008-08-24 21:49:00 -04002008/**
James Smart3621a712009-04-06 18:47:14 -04002009 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04002010 * @vport: pointer to a host virtual N_Port data structure.
2011 * @ndlp: pointer to a node-list data structure.
2012 * @retry: number of retries to the command IOCB.
2013 *
2014 * This routine issues a Process Login (PRLI) ELS command for the
2015 * @vport. The PRLI service parameters are set up in the payload of the
2016 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2017 * is put to the IOCB completion callback func field before invoking the
2018 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2019 *
2020 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2021 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2022 * will be stored into the context1 field of the IOCB for the completion
2023 * callback function to the PRLI ELS command.
2024 *
2025 * Return code
2026 * 0 - successfully issued prli iocb command for @vport
2027 * 1 - failed to issue prli iocb command for @vport
2028 **/
dea31012005-04-17 16:05:31 -05002029int
James Smart2e0fef82007-06-17 19:56:36 -05002030lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002031 uint8_t retry)
2032{
James Smart2e0fef82007-06-17 19:56:36 -05002033 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2034 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002035 PRLI *npr;
2036 IOCB_t *icmd;
2037 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002038 uint8_t *pcmd;
2039 uint16_t cmdsize;
2040
James Smart92d7f7b2007-06-17 19:56:38 -05002041 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05002042 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2043 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05002044 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002045 return 1;
dea31012005-04-17 16:05:31 -05002046
2047 icmd = &elsiocb->iocb;
2048 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2049
2050 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05002051 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05002052 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05002053 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002054
2055 /* For PRLI, remainder of payload is PRLI parameter page */
2056 npr = (PRLI *) pcmd;
2057 /*
2058 * If our firmware version is 3.20 or later,
2059 * set the following bits for FC-TAPE support.
2060 */
2061 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
2062 npr->ConfmComplAllowed = 1;
2063 npr->Retry = 1;
2064 npr->TaskRetryIdReq = 1;
2065 }
2066 npr->estabImagePair = 1;
2067 npr->readXferRdyDis = 1;
2068
2069 /* For FCP support */
2070 npr->prliType = PRLI_FCP_TYPE;
2071 npr->initiatorFunc = 1;
2072
James Smart858c9f62007-06-17 19:56:39 -05002073 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2074 "Issue PRLI: did:x%x",
2075 ndlp->nlp_DID, 0, 0);
2076
dea31012005-04-17 16:05:31 -05002077 phba->fc_stat.elsXmitPRLI++;
2078 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05002079 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002080 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002081 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002082 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2083 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002084 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002085 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002086 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002087 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002088 return 1;
dea31012005-04-17 16:05:31 -05002089 }
James Smart2e0fef82007-06-17 19:56:36 -05002090 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002091 return 0;
dea31012005-04-17 16:05:31 -05002092}
2093
James Smarte59058c2008-08-24 21:49:00 -04002094/**
James Smart3621a712009-04-06 18:47:14 -04002095 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04002096 * @vport: pointer to a host virtual N_Port data structure.
2097 *
2098 * This routine performs Registration State Change Notification (RSCN)
2099 * discovery for a @vport. If the @vport's node port recovery count is not
2100 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2101 * the nodes that need recovery. If none of the PLOGI were needed through
2102 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2103 * invoked to check and handle possible more RSCN came in during the period
2104 * of processing the current ones.
2105 **/
2106static void
2107lpfc_rscn_disc(struct lpfc_vport *vport)
2108{
2109 lpfc_can_disctmo(vport);
2110
2111 /* RSCN discovery */
2112 /* go thru NPR nodes and issue ELS PLOGIs */
2113 if (vport->fc_npr_cnt)
2114 if (lpfc_els_disc_plogi(vport))
2115 return;
2116
2117 lpfc_end_rscn(vport);
2118}
2119
2120/**
James Smart3621a712009-04-06 18:47:14 -04002121 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04002122 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2123 *
2124 * This function is called when the final ADISC is completed during discovery.
2125 * This function handles clearing link attention or issuing reg_vpi depending
2126 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2127 * discovery.
2128 * This function is called with no locks held.
2129 **/
2130static void
2131lpfc_adisc_done(struct lpfc_vport *vport)
2132{
2133 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2134 struct lpfc_hba *phba = vport->phba;
2135
2136 /*
2137 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2138 * and continue discovery.
2139 */
2140 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04002141 !(vport->fc_flag & FC_RSCN_MODE) &&
2142 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04002143 lpfc_issue_reg_vpi(phba, vport);
2144 return;
2145 }
2146 /*
2147 * For SLI2, we need to set port_state to READY
2148 * and continue discovery.
2149 */
2150 if (vport->port_state < LPFC_VPORT_READY) {
2151 /* If we get here, there is nothing to ADISC */
2152 if (vport->port_type == LPFC_PHYSICAL_PORT)
2153 lpfc_issue_clear_la(phba, vport);
2154 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
2155 vport->num_disc_nodes = 0;
2156 /* go thru NPR list, issue ELS PLOGIs */
2157 if (vport->fc_npr_cnt)
2158 lpfc_els_disc_plogi(vport);
2159 if (!vport->num_disc_nodes) {
2160 spin_lock_irq(shost->host_lock);
2161 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2162 spin_unlock_irq(shost->host_lock);
2163 lpfc_can_disctmo(vport);
2164 lpfc_end_rscn(vport);
2165 }
2166 }
2167 vport->port_state = LPFC_VPORT_READY;
2168 } else
2169 lpfc_rscn_disc(vport);
2170}
2171
2172/**
James Smart3621a712009-04-06 18:47:14 -04002173 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04002174 * @vport: pointer to a host virtual N_Port data structure.
2175 *
2176 * This routine determines whether there are more ndlps on a @vport
2177 * node list need to have Address Discover (ADISC) issued. If so, it will
2178 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2179 * remaining nodes which need to have ADISC sent.
2180 **/
James Smart0ff10d42008-01-11 01:52:36 -05002181void
James Smart2e0fef82007-06-17 19:56:36 -05002182lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002183{
2184 int sentadisc;
2185
James Smart2e0fef82007-06-17 19:56:36 -05002186 if (vport->num_disc_nodes)
2187 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002188 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002189 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2190 "0210 Continue discovery with %d ADISCs to go "
2191 "Data: x%x x%x x%x\n",
2192 vport->num_disc_nodes, vport->fc_adisc_cnt,
2193 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002194 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002195 if (vport->fc_flag & FC_NLP_MORE) {
2196 lpfc_set_disctmo(vport);
2197 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2198 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002199 }
James Smart90160e02008-08-24 21:49:45 -04002200 if (!vport->num_disc_nodes)
2201 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002202 return;
2203}
2204
James Smarte59058c2008-08-24 21:49:00 -04002205/**
James Smart3621a712009-04-06 18:47:14 -04002206 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002207 * @phba: pointer to lpfc hba data structure.
2208 * @cmdiocb: pointer to lpfc command iocb data structure.
2209 * @rspiocb: pointer to lpfc response iocb data structure.
2210 *
2211 * This routine is the completion function for issuing the Address Discover
2212 * (ADISC) command. It first checks to see whether link went down during
2213 * the discovery process. If so, the node will be marked as node port
2214 * recovery for issuing discover IOCB by the link attention handler and
2215 * exit. Otherwise, the response status is checked. If error was reported
2216 * in the response status, the ADISC command shall be retried by invoking
2217 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2218 * the response status, the state machine is invoked to set transition
2219 * with respect to NLP_EVT_CMPL_ADISC event.
2220 **/
dea31012005-04-17 16:05:31 -05002221static void
James Smart2e0fef82007-06-17 19:56:36 -05002222lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2223 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002224{
James Smart2e0fef82007-06-17 19:56:36 -05002225 struct lpfc_vport *vport = cmdiocb->vport;
2226 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002227 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002228 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002229 int disc;
dea31012005-04-17 16:05:31 -05002230
2231 /* we pass cmdiocb to state machine which needs rspiocb as well */
2232 cmdiocb->context_un.rsp_iocb = rspiocb;
2233
2234 irsp = &(rspiocb->iocb);
2235 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002236
James Smart858c9f62007-06-17 19:56:39 -05002237 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2238 "ADISC cmpl: status:x%x/x%x did:x%x",
2239 irsp->ulpStatus, irsp->un.ulpWord[4],
2240 ndlp->nlp_DID);
2241
dea31012005-04-17 16:05:31 -05002242 /* Since ndlp can be freed in the disc state machine, note if this node
2243 * is being used during discovery.
2244 */
James Smart2e0fef82007-06-17 19:56:36 -05002245 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002246 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002247 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002248 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002249 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002250 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2251 "0104 ADISC completes to NPort x%x "
2252 "Data: x%x x%x x%x x%x x%x\n",
2253 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2254 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002255 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002256 if (lpfc_els_chk_latt(vport)) {
2257 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002258 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002259 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002260 goto out;
2261 }
2262
2263 if (irsp->ulpStatus) {
2264 /* Check for retry */
2265 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2266 /* ELS command is being retried */
2267 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002268 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002269 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002270 spin_unlock_irq(shost->host_lock);
2271 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002272 }
2273 goto out;
2274 }
2275 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002276 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2277 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2278 ndlp->nlp_DID, irsp->ulpStatus,
2279 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002280 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002281 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002282 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002283 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002284 } else
dea31012005-04-17 16:05:31 -05002285 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002286 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002287 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002288
James Smart90160e02008-08-24 21:49:45 -04002289 /* Check to see if there are more ADISCs to be sent */
2290 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002291 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002292out:
2293 lpfc_els_free_iocb(phba, cmdiocb);
2294 return;
2295}
2296
James Smarte59058c2008-08-24 21:49:00 -04002297/**
James Smart3621a712009-04-06 18:47:14 -04002298 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002299 * @vport: pointer to a virtual N_Port data structure.
2300 * @ndlp: pointer to a node-list data structure.
2301 * @retry: number of retries to the command IOCB.
2302 *
2303 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2304 * @vport. It prepares the payload of the ADISC ELS command, updates the
2305 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2306 * to issue the ADISC ELS command.
2307 *
2308 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2309 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2310 * will be stored into the context1 field of the IOCB for the completion
2311 * callback function to the ADISC ELS command.
2312 *
2313 * Return code
2314 * 0 - successfully issued adisc
2315 * 1 - failed to issue adisc
2316 **/
dea31012005-04-17 16:05:31 -05002317int
James Smart2e0fef82007-06-17 19:56:36 -05002318lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002319 uint8_t retry)
2320{
James Smart2e0fef82007-06-17 19:56:36 -05002321 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2322 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002323 ADISC *ap;
2324 IOCB_t *icmd;
2325 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002326 uint8_t *pcmd;
2327 uint16_t cmdsize;
2328
James Smart92d7f7b2007-06-17 19:56:38 -05002329 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002330 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2331 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002332 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002333 return 1;
dea31012005-04-17 16:05:31 -05002334
2335 icmd = &elsiocb->iocb;
2336 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2337
2338 /* For ADISC request, remainder of payload is service parameters */
2339 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002340 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002341
2342 /* Fill in ADISC payload */
2343 ap = (ADISC *) pcmd;
2344 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002345 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2346 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002347 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002348
James Smart858c9f62007-06-17 19:56:39 -05002349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2350 "Issue ADISC: did:x%x",
2351 ndlp->nlp_DID, 0, 0);
2352
dea31012005-04-17 16:05:31 -05002353 phba->fc_stat.elsXmitADISC++;
2354 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002355 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002356 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002358 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2359 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002360 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002361 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002363 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002364 return 1;
dea31012005-04-17 16:05:31 -05002365 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002366 return 0;
dea31012005-04-17 16:05:31 -05002367}
2368
James Smarte59058c2008-08-24 21:49:00 -04002369/**
James Smart3621a712009-04-06 18:47:14 -04002370 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002371 * @phba: pointer to lpfc hba data structure.
2372 * @cmdiocb: pointer to lpfc command iocb data structure.
2373 * @rspiocb: pointer to lpfc response iocb data structure.
2374 *
2375 * This routine is the completion function for issuing the ELS Logout (LOGO)
2376 * command. If no error status was reported from the LOGO response, the
2377 * state machine of the associated ndlp shall be invoked for transition with
2378 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2379 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2380 **/
dea31012005-04-17 16:05:31 -05002381static void
James Smart2e0fef82007-06-17 19:56:36 -05002382lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2383 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002384{
James Smart2e0fef82007-06-17 19:56:36 -05002385 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2386 struct lpfc_vport *vport = ndlp->vport;
2387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002388 IOCB_t *irsp;
2389 struct lpfc_sli *psli;
James Smart92494142011-02-16 12:39:44 -05002390 struct lpfcMboxq *mbox;
James Smart086a3452012-08-14 14:25:21 -04002391 unsigned long flags;
2392 uint32_t skip_recovery = 0;
dea31012005-04-17 16:05:31 -05002393
2394 psli = &phba->sli;
2395 /* we pass cmdiocb to state machine which needs rspiocb as well */
2396 cmdiocb->context_un.rsp_iocb = rspiocb;
2397
2398 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002399 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002400 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002401 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002402
James Smart858c9f62007-06-17 19:56:39 -05002403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2404 "LOGO cmpl: status:x%x/x%x did:x%x",
2405 irsp->ulpStatus, irsp->un.ulpWord[4],
2406 ndlp->nlp_DID);
James Smart086a3452012-08-14 14:25:21 -04002407
dea31012005-04-17 16:05:31 -05002408 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002409 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2410 "0105 LOGO completes to NPort x%x "
2411 "Data: x%x x%x x%x x%x\n",
2412 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2413 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002414
James Smart086a3452012-08-14 14:25:21 -04002415 if (lpfc_els_chk_latt(vport)) {
2416 skip_recovery = 1;
2417 goto out;
2418 }
2419
2420 /* Check to see if link went down during discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05002421 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2422 /* NLP_EVT_DEVICE_RM should unregister the RPI
2423 * which should abort all outstanding IOs.
2424 */
2425 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2426 NLP_EVT_DEVICE_RM);
James Smart086a3452012-08-14 14:25:21 -04002427 skip_recovery = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002428 goto out;
2429 }
2430
dea31012005-04-17 16:05:31 -05002431 if (irsp->ulpStatus) {
2432 /* Check for retry */
James Smart086a3452012-08-14 14:25:21 -04002433 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
dea31012005-04-17 16:05:31 -05002434 /* ELS command is being retried */
James Smart086a3452012-08-14 14:25:21 -04002435 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002436 goto out;
James Smart086a3452012-08-14 14:25:21 -04002437 }
dea31012005-04-17 16:05:31 -05002438 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002439 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2440 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2441 ndlp->nlp_DID, irsp->ulpStatus,
2442 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002443 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart086a3452012-08-14 14:25:21 -04002444 if (lpfc_error_lost_link(irsp)) {
2445 skip_recovery = 1;
dea31012005-04-17 16:05:31 -05002446 goto out;
James Smart086a3452012-08-14 14:25:21 -04002447 }
2448 }
2449
2450 /* Call state machine. This will unregister the rpi if needed. */
2451 lpfc_disc_state_machine(vport, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
2452
dea31012005-04-17 16:05:31 -05002453out:
2454 lpfc_els_free_iocb(phba, cmdiocb);
James Smart92494142011-02-16 12:39:44 -05002455 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2456 if ((vport->fc_flag & FC_PT2PT) &&
2457 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
2458 phba->pport->fc_myDID = 0;
2459 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2460 if (mbox) {
2461 lpfc_config_link(phba, mbox);
2462 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2463 mbox->vport = vport;
2464 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT) ==
2465 MBX_NOT_FINISHED) {
2466 mempool_free(mbox, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04002467 skip_recovery = 1;
James Smart92494142011-02-16 12:39:44 -05002468 }
2469 }
2470 }
James Smart086a3452012-08-14 14:25:21 -04002471
2472 /*
2473 * If the node is a target, the handling attempts to recover the port.
2474 * For any other port type, the rpi is unregistered as an implicit
2475 * LOGO.
2476 */
2477 if ((ndlp->nlp_type & NLP_FCP_TARGET) && (skip_recovery == 0)) {
2478 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2479 spin_lock_irqsave(shost->host_lock, flags);
2480 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2481 spin_unlock_irqrestore(shost->host_lock, flags);
2482
2483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2484 "3187 LOGO completes to NPort x%x: Start "
2485 "Recovery Data: x%x x%x x%x x%x\n",
2486 ndlp->nlp_DID, irsp->ulpStatus,
2487 irsp->un.ulpWord[4], irsp->ulpTimeout,
2488 vport->num_disc_nodes);
2489 lpfc_disc_start(vport);
2490 }
dea31012005-04-17 16:05:31 -05002491 return;
2492}
2493
James Smarte59058c2008-08-24 21:49:00 -04002494/**
James Smart3621a712009-04-06 18:47:14 -04002495 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002496 * @vport: pointer to a virtual N_Port data structure.
2497 * @ndlp: pointer to a node-list data structure.
2498 * @retry: number of retries to the command IOCB.
2499 *
2500 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2501 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2502 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2503 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2504 *
2505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2507 * will be stored into the context1 field of the IOCB for the completion
2508 * callback function to the LOGO ELS command.
2509 *
2510 * Return code
2511 * 0 - successfully issued logo
2512 * 1 - failed to issue logo
2513 **/
dea31012005-04-17 16:05:31 -05002514int
James Smart2e0fef82007-06-17 19:56:36 -05002515lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002516 uint8_t retry)
2517{
James Smart2e0fef82007-06-17 19:56:36 -05002518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2519 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002520 IOCB_t *icmd;
2521 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002522 uint8_t *pcmd;
2523 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002524 int rc;
dea31012005-04-17 16:05:31 -05002525
James Smart98c9ea52007-10-27 13:37:33 -04002526 spin_lock_irq(shost->host_lock);
2527 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2528 spin_unlock_irq(shost->host_lock);
2529 return 0;
2530 }
2531 spin_unlock_irq(shost->host_lock);
2532
James Smart92d7f7b2007-06-17 19:56:38 -05002533 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002534 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2535 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002536 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002537 return 1;
dea31012005-04-17 16:05:31 -05002538
2539 icmd = &elsiocb->iocb;
2540 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2541 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002542 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002543
2544 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002545 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002546 pcmd += sizeof(uint32_t);
2547 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002548
James Smart858c9f62007-06-17 19:56:39 -05002549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2550 "Issue LOGO: did:x%x",
2551 ndlp->nlp_DID, 0, 0);
2552
James Smart086a3452012-08-14 14:25:21 -04002553 /*
2554 * If we are issuing a LOGO, we may try to recover the remote NPort
2555 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2556 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2557 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2558 * for that ELS cmd. To avoid this situation, lets get rid of the
2559 * RPI right now, before any ELS cmds are sent.
2560 */
2561 spin_lock_irq(shost->host_lock);
2562 ndlp->nlp_flag |= NLP_ISSUE_LOGO;
2563 spin_unlock_irq(shost->host_lock);
2564 if (lpfc_unreg_rpi(vport, ndlp)) {
2565 lpfc_els_free_iocb(phba, elsiocb);
2566 return 0;
2567 }
2568
dea31012005-04-17 16:05:31 -05002569 phba->fc_stat.elsXmitLOGO++;
2570 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002571 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002572 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart086a3452012-08-14 14:25:21 -04002573 ndlp->nlp_flag &= ~NLP_ISSUE_LOGO;
James Smart2e0fef82007-06-17 19:56:36 -05002574 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002575 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002576
2577 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002578 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002579 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002580 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002581 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002582 return 1;
dea31012005-04-17 16:05:31 -05002583 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002584 return 0;
dea31012005-04-17 16:05:31 -05002585}
2586
James Smarte59058c2008-08-24 21:49:00 -04002587/**
James Smart3621a712009-04-06 18:47:14 -04002588 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002589 * @phba: pointer to lpfc hba data structure.
2590 * @cmdiocb: pointer to lpfc command iocb data structure.
2591 * @rspiocb: pointer to lpfc response iocb data structure.
2592 *
2593 * This routine is a generic completion callback function for ELS commands.
2594 * Specifically, it is the callback function which does not need to perform
2595 * any command specific operations. It is currently used by the ELS command
2596 * issuing routines for the ELS State Change Request (SCR),
2597 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2598 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2599 * certain debug loggings, this callback function simply invokes the
2600 * lpfc_els_chk_latt() routine to check whether link went down during the
2601 * discovery process.
2602 **/
dea31012005-04-17 16:05:31 -05002603static void
James Smart2e0fef82007-06-17 19:56:36 -05002604lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2605 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002606{
James Smart2e0fef82007-06-17 19:56:36 -05002607 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002608 IOCB_t *irsp;
2609
2610 irsp = &rspiocb->iocb;
2611
James Smart858c9f62007-06-17 19:56:39 -05002612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2613 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2614 irsp->ulpStatus, irsp->un.ulpWord[4],
2615 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002616 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002617 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2618 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2619 irsp->ulpIoTag, irsp->ulpStatus,
2620 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002621 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002622 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002623 lpfc_els_free_iocb(phba, cmdiocb);
2624 return;
2625}
2626
James Smarte59058c2008-08-24 21:49:00 -04002627/**
James Smart3621a712009-04-06 18:47:14 -04002628 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002629 * @vport: pointer to a host virtual N_Port data structure.
2630 * @nportid: N_Port identifier to the remote node.
2631 * @retry: number of retries to the command IOCB.
2632 *
2633 * This routine issues a State Change Request (SCR) to a fabric node
2634 * on a @vport. The remote node @nportid is passed into the function. It
2635 * first search the @vport node list to find the matching ndlp. If no such
2636 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2637 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2638 * routine is invoked to send the SCR IOCB.
2639 *
2640 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2641 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2642 * will be stored into the context1 field of the IOCB for the completion
2643 * callback function to the SCR ELS command.
2644 *
2645 * Return code
2646 * 0 - Successfully issued scr command
2647 * 1 - Failed to issue scr command
2648 **/
dea31012005-04-17 16:05:31 -05002649int
James Smart2e0fef82007-06-17 19:56:36 -05002650lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002651{
James Smart2e0fef82007-06-17 19:56:36 -05002652 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002653 IOCB_t *icmd;
2654 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002655 struct lpfc_sli *psli;
2656 uint8_t *pcmd;
2657 uint16_t cmdsize;
2658 struct lpfc_nodelist *ndlp;
2659
2660 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002661 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002662
James Smarte47c9092008-02-08 18:49:26 -05002663 ndlp = lpfc_findnode_did(vport, nportid);
2664 if (!ndlp) {
2665 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2666 if (!ndlp)
2667 return 1;
2668 lpfc_nlp_init(vport, ndlp, nportid);
2669 lpfc_enqueue_node(vport, ndlp);
2670 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2671 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2672 if (!ndlp)
2673 return 1;
2674 }
dea31012005-04-17 16:05:31 -05002675
James Smart2e0fef82007-06-17 19:56:36 -05002676 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2677 ndlp->nlp_DID, ELS_CMD_SCR);
2678
James Smart488d1462006-03-07 15:02:37 -05002679 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002680 /* This will trigger the release of the node just
2681 * allocated
2682 */
James Smart329f9bc2007-04-25 09:53:01 -04002683 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002684 return 1;
dea31012005-04-17 16:05:31 -05002685 }
2686
2687 icmd = &elsiocb->iocb;
2688 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2689
2690 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002691 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002692
2693 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002694 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002695 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2696
James Smart858c9f62007-06-17 19:56:39 -05002697 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2698 "Issue SCR: did:x%x",
2699 ndlp->nlp_DID, 0, 0);
2700
dea31012005-04-17 16:05:31 -05002701 phba->fc_stat.elsXmitSCR++;
2702 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002703 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2704 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002705 /* The additional lpfc_nlp_put will cause the following
2706 * lpfc_els_free_iocb routine to trigger the rlease of
2707 * the node.
2708 */
James Smart329f9bc2007-04-25 09:53:01 -04002709 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002710 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002711 return 1;
dea31012005-04-17 16:05:31 -05002712 }
James Smartfa4066b2008-01-11 01:53:27 -05002713 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2714 * trigger the release of node.
2715 */
James Smart329f9bc2007-04-25 09:53:01 -04002716 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002717 return 0;
dea31012005-04-17 16:05:31 -05002718}
2719
James Smarte59058c2008-08-24 21:49:00 -04002720/**
James Smart3621a712009-04-06 18:47:14 -04002721 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002722 * @vport: pointer to a host virtual N_Port data structure.
2723 * @nportid: N_Port identifier to the remote node.
2724 * @retry: number of retries to the command IOCB.
2725 *
2726 * This routine issues a Fibre Channel Address Resolution Response
2727 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2728 * is passed into the function. It first search the @vport node list to find
2729 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2730 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2731 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2732 *
2733 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2734 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2735 * will be stored into the context1 field of the IOCB for the completion
2736 * callback function to the PARPR ELS command.
2737 *
2738 * Return code
2739 * 0 - Successfully issued farpr command
2740 * 1 - Failed to issue farpr command
2741 **/
dea31012005-04-17 16:05:31 -05002742static int
James Smart2e0fef82007-06-17 19:56:36 -05002743lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002744{
James Smart2e0fef82007-06-17 19:56:36 -05002745 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002746 IOCB_t *icmd;
2747 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002748 struct lpfc_sli *psli;
2749 FARP *fp;
2750 uint8_t *pcmd;
2751 uint32_t *lp;
2752 uint16_t cmdsize;
2753 struct lpfc_nodelist *ondlp;
2754 struct lpfc_nodelist *ndlp;
2755
2756 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002757 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002758
James Smarte47c9092008-02-08 18:49:26 -05002759 ndlp = lpfc_findnode_did(vport, nportid);
2760 if (!ndlp) {
2761 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2762 if (!ndlp)
2763 return 1;
2764 lpfc_nlp_init(vport, ndlp, nportid);
2765 lpfc_enqueue_node(vport, ndlp);
2766 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2767 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2768 if (!ndlp)
2769 return 1;
2770 }
James Smart2e0fef82007-06-17 19:56:36 -05002771
2772 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2773 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002774 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002775 /* This will trigger the release of the node just
2776 * allocated
2777 */
James Smart329f9bc2007-04-25 09:53:01 -04002778 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002779 return 1;
dea31012005-04-17 16:05:31 -05002780 }
2781
2782 icmd = &elsiocb->iocb;
2783 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2784
2785 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002786 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002787
2788 /* Fill in FARPR payload */
2789 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002790 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002791 lp = (uint32_t *) pcmd;
2792 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002793 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002794 fp->Rflags = 0;
2795 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2796
James Smart92d7f7b2007-06-17 19:56:38 -05002797 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2798 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002799 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002800 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002801 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002802 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002803 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002804 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002805 }
2806
James Smart858c9f62007-06-17 19:56:39 -05002807 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2808 "Issue FARPR: did:x%x",
2809 ndlp->nlp_DID, 0, 0);
2810
dea31012005-04-17 16:05:31 -05002811 phba->fc_stat.elsXmitFARPR++;
2812 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002813 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2814 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002815 /* The additional lpfc_nlp_put will cause the following
2816 * lpfc_els_free_iocb routine to trigger the release of
2817 * the node.
2818 */
James Smart329f9bc2007-04-25 09:53:01 -04002819 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002820 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002821 return 1;
dea31012005-04-17 16:05:31 -05002822 }
James Smartfa4066b2008-01-11 01:53:27 -05002823 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2824 * trigger the release of the node.
2825 */
James Smart329f9bc2007-04-25 09:53:01 -04002826 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002827 return 0;
dea31012005-04-17 16:05:31 -05002828}
2829
James Smarte59058c2008-08-24 21:49:00 -04002830/**
James Smart3621a712009-04-06 18:47:14 -04002831 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002832 * @vport: pointer to a host virtual N_Port data structure.
2833 * @nlp: pointer to a node-list data structure.
2834 *
2835 * This routine cancels the timer with a delayed IOCB-command retry for
2836 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2837 * removes the ELS retry event if it presents. In addition, if the
2838 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2839 * commands are sent for the @vport's nodes that require issuing discovery
2840 * ADISC.
2841 **/
dea31012005-04-17 16:05:31 -05002842void
James Smart2e0fef82007-06-17 19:56:36 -05002843lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002844{
James Smart2e0fef82007-06-17 19:56:36 -05002845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002846 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002847
James Smart0d2b6b82008-06-14 22:52:47 -04002848 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2849 return;
James Smart2e0fef82007-06-17 19:56:36 -05002850 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002851 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002852 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002853 del_timer_sync(&nlp->nlp_delayfunc);
2854 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002855 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002856 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002857 /* Decrement nlp reference count held for the delayed retry */
2858 evtp = &nlp->els_retry_evt;
2859 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2860 }
James Smartfdcebe22006-03-07 15:04:01 -05002861 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002862 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002863 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_unlock_irq(shost->host_lock);
2865 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002866 if (vport->port_state < LPFC_VPORT_READY) {
2867 /* Check if there are more ADISCs to be sent */
2868 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002869 } else {
2870 /* Check if there are more PLOGIs to be sent */
2871 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002872 if (vport->num_disc_nodes == 0) {
2873 spin_lock_irq(shost->host_lock);
2874 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2875 spin_unlock_irq(shost->host_lock);
2876 lpfc_can_disctmo(vport);
2877 lpfc_end_rscn(vport);
2878 }
James Smartfdcebe22006-03-07 15:04:01 -05002879 }
2880 }
2881 }
2882 return;
2883}
2884
James Smarte59058c2008-08-24 21:49:00 -04002885/**
James Smart3621a712009-04-06 18:47:14 -04002886 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002887 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2888 *
2889 * This routine is invoked by the ndlp delayed-function timer to check
2890 * whether there is any pending ELS retry event(s) with the node. If not, it
2891 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2892 * adds the delayed events to the HBA work list and invokes the
2893 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2894 * event. Note that lpfc_nlp_get() is called before posting the event to
2895 * the work list to hold reference count of ndlp so that it guarantees the
2896 * reference to ndlp will still be available when the worker thread gets
2897 * to the event associated with the ndlp.
2898 **/
James Smartfdcebe22006-03-07 15:04:01 -05002899void
dea31012005-04-17 16:05:31 -05002900lpfc_els_retry_delay(unsigned long ptr)
2901{
James Smart2e0fef82007-06-17 19:56:36 -05002902 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2903 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002904 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002905 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002906 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002907
James Smart92d7f7b2007-06-17 19:56:38 -05002908 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002909 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002910 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002911 return;
2912 }
2913
James Smartfa4066b2008-01-11 01:53:27 -05002914 /* We need to hold the node by incrementing the reference
2915 * count until the queued work is done
2916 */
2917 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002918 if (evtp->evt_arg1) {
2919 evtp->evt = LPFC_EVT_ELS_RETRY;
2920 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002921 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002922 }
James Smart92d7f7b2007-06-17 19:56:38 -05002923 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002924 return;
2925}
2926
James Smarte59058c2008-08-24 21:49:00 -04002927/**
James Smart3621a712009-04-06 18:47:14 -04002928 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002929 * @ndlp: pointer to a node-list data structure.
2930 *
2931 * This routine is the worker-thread handler for processing the @ndlp delayed
2932 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2933 * the last ELS command from the associated ndlp and invokes the proper ELS
2934 * function according to the delayed ELS command to retry the command.
2935 **/
dea31012005-04-17 16:05:31 -05002936void
2937lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2938{
James Smart2e0fef82007-06-17 19:56:36 -05002939 struct lpfc_vport *vport = ndlp->vport;
2940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2941 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002942
James Smart2e0fef82007-06-17 19:56:36 -05002943 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002944 did = ndlp->nlp_DID;
2945 cmd = ndlp->nlp_last_elscmd;
2946 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002947
2948 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002949 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002950 return;
2951 }
2952
2953 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002954 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002955 /*
2956 * If a discovery event readded nlp_delayfunc after timer
2957 * firing and before processing the timer, cancel the
2958 * nlp_delayfunc.
2959 */
2960 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002961 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002962 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002963
2964 switch (cmd) {
2965 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002966 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002967 break;
2968 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002969 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002970 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002972 }
dea31012005-04-17 16:05:31 -05002973 break;
2974 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002975 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002976 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002977 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002978 }
dea31012005-04-17 16:05:31 -05002979 break;
2980 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002981 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002982 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002983 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002984 }
dea31012005-04-17 16:05:31 -05002985 break;
2986 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002987 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002988 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04002989 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002990 }
dea31012005-04-17 16:05:31 -05002991 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002992 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002993 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2994 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002995 break;
dea31012005-04-17 16:05:31 -05002996 }
2997 return;
2998}
2999
James Smarte59058c2008-08-24 21:49:00 -04003000/**
James Smart3621a712009-04-06 18:47:14 -04003001 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04003002 * @phba: pointer to lpfc hba data structure.
3003 * @cmdiocb: pointer to lpfc command iocb data structure.
3004 * @rspiocb: pointer to lpfc response iocb data structure.
3005 *
3006 * This routine makes a retry decision on an ELS command IOCB, which has
3007 * failed. The following ELS IOCBs use this function for retrying the command
3008 * when previously issued command responsed with error status: FLOGI, PLOGI,
3009 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3010 * returned error status, it makes the decision whether a retry shall be
3011 * issued for the command, and whether a retry shall be made immediately or
3012 * delayed. In the former case, the corresponding ELS command issuing-function
3013 * is called to retry the command. In the later case, the ELS command shall
3014 * be posted to the ndlp delayed event and delayed function timer set to the
3015 * ndlp for the delayed command issusing.
3016 *
3017 * Return code
3018 * 0 - No retry of els command is made
3019 * 1 - Immediate or delayed retry of els command is made
3020 **/
dea31012005-04-17 16:05:31 -05003021static int
James Smart2e0fef82007-06-17 19:56:36 -05003022lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3023 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003024{
James Smart2e0fef82007-06-17 19:56:36 -05003025 struct lpfc_vport *vport = cmdiocb->vport;
3026 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3027 IOCB_t *irsp = &rspiocb->iocb;
3028 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3029 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05003030 uint32_t *elscmd;
3031 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003032 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04003033 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003034 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05003035 uint32_t did;
dea31012005-04-17 16:05:31 -05003036
James Smart488d1462006-03-07 15:02:37 -05003037
dea31012005-04-17 16:05:31 -05003038 /* Note: context2 may be 0 for internal driver abort
3039 * of delays ELS command.
3040 */
3041
3042 if (pcmd && pcmd->virt) {
3043 elscmd = (uint32_t *) (pcmd->virt);
3044 cmd = *elscmd++;
3045 }
3046
James Smarte47c9092008-02-08 18:49:26 -05003047 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05003048 did = ndlp->nlp_DID;
3049 else {
3050 /* We should only hit this case for retrying PLOGI */
3051 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003052 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05003053 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
3054 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05003055 return 1;
3056 }
3057
James Smart858c9f62007-06-17 19:56:39 -05003058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3059 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3060 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
3061
dea31012005-04-17 16:05:31 -05003062 switch (irsp->ulpStatus) {
3063 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05003064 break;
James Smart1151e3e2011-02-16 12:39:35 -05003065 case IOSTAT_REMOTE_STOP:
3066 if (phba->sli_rev == LPFC_SLI_REV4) {
3067 /* This IO was aborted by the target, we don't
3068 * know the rxid and because we did not send the
3069 * ABTS we cannot generate and RRQ.
3070 */
3071 lpfc_set_rrq_active(phba, ndlp,
James Smartee0f4fe2012-05-09 21:19:14 -04003072 cmdiocb->sli4_lxritag, 0, 0);
James Smart1151e3e2011-02-16 12:39:35 -05003073 }
3074 break;
dea31012005-04-17 16:05:31 -05003075 case IOSTAT_LOCAL_REJECT:
James Smarte3d2b802012-08-14 14:25:43 -04003076 switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
dea31012005-04-17 16:05:31 -05003077 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05003078 if (cmd == ELS_CMD_FLOGI) {
3079 if (PCI_DEVICE_ID_HORNET ==
3080 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05003081 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05003082 phba->pport->fc_myDID = 0;
3083 phba->alpa_map[0] = 0;
3084 phba->alpa_map[1] = 0;
3085 }
3086 }
James Smart2e0fef82007-06-17 19:56:36 -05003087 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05003088 delay = 1000;
dea31012005-04-17 16:05:31 -05003089 retry = 1;
3090 break;
3091
James Smart92d7f7b2007-06-17 19:56:38 -05003092 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05003093 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3094 "0124 Retry illegal cmd x%x "
3095 "retry:x%x delay:x%x\n",
3096 cmd, cmdiocb->retry, delay);
3097 retry = 1;
3098 /* All command's retry policy */
3099 maxretry = 8;
3100 if (cmdiocb->retry > 2)
3101 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05003102 break;
3103
dea31012005-04-17 16:05:31 -05003104 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04003105 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05003106 retry = 1;
3107 if (cmdiocb->retry > 100)
3108 delay = 100;
3109 maxretry = 250;
3110 break;
3111
3112 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05003113 delay = 100;
dea31012005-04-17 16:05:31 -05003114 retry = 1;
3115 break;
3116
James Smart858c9f62007-06-17 19:56:39 -05003117 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05003118 case IOERR_INVALID_RPI:
3119 retry = 1;
3120 break;
3121 }
3122 break;
3123
3124 case IOSTAT_NPORT_RJT:
3125 case IOSTAT_FABRIC_RJT:
3126 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
3127 retry = 1;
3128 break;
3129 }
3130 break;
3131
3132 case IOSTAT_NPORT_BSY:
3133 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04003134 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05003135 retry = 1;
3136 break;
3137
3138 case IOSTAT_LS_RJT:
3139 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
3140 /* Added for Vendor specifc support
3141 * Just keep retrying for these Rsn / Exp codes
3142 */
3143 switch (stat.un.b.lsRjtRsnCode) {
3144 case LSRJT_UNABLE_TPC:
3145 if (stat.un.b.lsRjtRsnCodeExp ==
3146 LSEXP_CMD_IN_PROGRESS) {
3147 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05003148 delay = 1000;
dea31012005-04-17 16:05:31 -05003149 maxretry = 48;
3150 }
3151 retry = 1;
3152 break;
3153 }
James Smartffc95492010-06-07 15:23:17 -04003154 if (stat.un.b.lsRjtRsnCodeExp ==
3155 LSEXP_CANT_GIVE_DATA) {
3156 if (cmd == ELS_CMD_PLOGI) {
3157 delay = 1000;
3158 maxretry = 48;
3159 }
3160 retry = 1;
3161 break;
3162 }
James Smart4c1b64b2012-09-29 11:31:11 -04003163 if ((cmd == ELS_CMD_PLOGI) ||
3164 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003165 delay = 1000;
dea31012005-04-17 16:05:31 -05003166 maxretry = lpfc_max_els_tries + 1;
3167 retry = 1;
3168 break;
3169 }
James Smart92d7f7b2007-06-17 19:56:38 -05003170 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3171 (cmd == ELS_CMD_FDISC) &&
3172 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04003173 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3174 "0125 FDISC Failed (x%x). "
3175 "Fabric out of resources\n",
3176 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003177 lpfc_vport_set_state(vport,
3178 FC_VPORT_NO_FABRIC_RSCS);
3179 }
dea31012005-04-17 16:05:31 -05003180 break;
3181
3182 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05003183 if ((cmd == ELS_CMD_PLOGI) ||
3184 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003185 delay = 1000;
dea31012005-04-17 16:05:31 -05003186 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05003187 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04003188 /* FDISC retry policy */
3189 maxretry = 48;
3190 if (cmdiocb->retry >= 32)
3191 delay = 1000;
dea31012005-04-17 16:05:31 -05003192 }
3193 retry = 1;
3194 break;
James Smart92d7f7b2007-06-17 19:56:38 -05003195
3196 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05003197 /* There are some cases where switches return this
3198 * error when they are not ready and should be returning
3199 * Logical Busy. We should delay every time.
3200 */
3201 if (cmd == ELS_CMD_FDISC &&
3202 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
3203 maxretry = 3;
3204 delay = 1000;
3205 retry = 1;
3206 break;
3207 }
James Smart92d7f7b2007-06-17 19:56:38 -05003208 case LSRJT_PROTOCOL_ERR:
3209 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
3210 (cmd == ELS_CMD_FDISC) &&
3211 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
3212 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
3213 ) {
James Smarte8b62012007-08-02 11:10:09 -04003214 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04003215 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04003216 "Fabric Detected Bad WWN\n",
3217 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05003218 lpfc_vport_set_state(vport,
3219 FC_VPORT_FABRIC_REJ_WWN);
3220 }
3221 break;
dea31012005-04-17 16:05:31 -05003222 }
3223 break;
3224
3225 case IOSTAT_INTERMED_RSP:
3226 case IOSTAT_BA_RJT:
3227 break;
3228
3229 default:
3230 break;
3231 }
3232
James Smart488d1462006-03-07 15:02:37 -05003233 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05003234 retry = 1;
dea31012005-04-17 16:05:31 -05003235
James Smartdf9e1b52011-12-13 13:22:17 -05003236 if ((cmd == ELS_CMD_FLOGI) &&
James Smart76a95d72010-11-20 23:11:48 -05003237 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05003238 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003239 /* FLOGI retry policy */
3240 retry = 1;
James Smartdf9e1b52011-12-13 13:22:17 -05003241 /* retry FLOGI forever */
James Smart6669f9b2009-10-02 15:16:45 -04003242 maxretry = 0;
3243 if (cmdiocb->retry >= 100)
3244 delay = 5000;
3245 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003246 delay = 1000;
James Smartdf9e1b52011-12-13 13:22:17 -05003247 } else if ((cmd == ELS_CMD_FDISC) && !lpfc_error_lost_link(irsp)) {
3248 /* retry FDISCs every second up to devloss */
3249 retry = 1;
3250 maxretry = vport->cfg_devloss_tmo;
3251 delay = 1000;
James Smart98c9ea52007-10-27 13:37:33 -04003252 }
3253
James Smart6669f9b2009-10-02 15:16:45 -04003254 cmdiocb->retry++;
3255 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003256 phba->fc_stat.elsRetryExceeded++;
3257 retry = 0;
3258 }
3259
James Smarted957682007-06-17 19:56:37 -05003260 if ((vport->load_flag & FC_UNLOADING) != 0)
3261 retry = 0;
3262
dea31012005-04-17 16:05:31 -05003263 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003264 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3265 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3266 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3267 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3268 "2849 Stop retry ELS command "
3269 "x%x to remote NPORT x%x, "
3270 "Data: x%x x%x\n", cmd, did,
3271 cmdiocb->retry, delay);
3272 return 0;
3273 }
3274 }
dea31012005-04-17 16:05:31 -05003275
3276 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003277 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3278 "0107 Retry ELS command x%x to remote "
3279 "NPORT x%x Data: x%x x%x\n",
3280 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003281
James Smart858c9f62007-06-17 19:56:39 -05003282 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3283 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
James Smarte3d2b802012-08-14 14:25:43 -04003284 ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
3285 IOERR_NO_RESOURCES))) {
James Smart858c9f62007-06-17 19:56:39 -05003286 /* Don't reset timer for no resources */
3287
dea31012005-04-17 16:05:31 -05003288 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003289 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003290 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003291 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003292 }
3293
3294 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003295 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003296 phba->fc_stat.elsDelayRetry++;
3297 ndlp->nlp_retry = cmdiocb->retry;
3298
James Smart92d7f7b2007-06-17 19:56:38 -05003299 /* delay is specified in milliseconds */
3300 mod_timer(&ndlp->nlp_delayfunc,
3301 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003302 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003303 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003304 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003305
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003306 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003307 if (cmd == ELS_CMD_PRLI)
3308 lpfc_nlp_set_state(vport, ndlp,
James Smart4c1b64b2012-09-29 11:31:11 -04003309 NLP_STE_PRLI_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003310 else
3311 lpfc_nlp_set_state(vport, ndlp,
3312 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003313 ndlp->nlp_last_elscmd = cmd;
3314
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003315 return 1;
dea31012005-04-17 16:05:31 -05003316 }
3317 switch (cmd) {
3318 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003319 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003320 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003321 case ELS_CMD_FDISC:
3322 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3323 return 1;
dea31012005-04-17 16:05:31 -05003324 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003325 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003326 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003327 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003328 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003329 }
James Smart2e0fef82007-06-17 19:56:36 -05003330 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003331 return 1;
dea31012005-04-17 16:05:31 -05003332 case ELS_CMD_ADISC:
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_ADISC_ISSUE);
3335 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003336 return 1;
dea31012005-04-17 16:05:31 -05003337 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003338 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003339 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3340 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003341 return 1;
dea31012005-04-17 16:05:31 -05003342 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003343 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart086a3452012-08-14 14:25:21 -04003344 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003345 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003346 return 1;
dea31012005-04-17 16:05:31 -05003347 }
3348 }
dea31012005-04-17 16:05:31 -05003349 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003350 if (logerr) {
3351 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3352 "0137 No retry ELS command x%x to remote "
3353 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3354 cmd, did, irsp->ulpStatus,
3355 irsp->un.ulpWord[4]);
3356 }
3357 else {
3358 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003359 "0108 No retry ELS command x%x to remote "
3360 "NPORT x%x Retried:%d Error:x%x/%x\n",
3361 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3362 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003363 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003364 return 0;
dea31012005-04-17 16:05:31 -05003365}
3366
James Smarte59058c2008-08-24 21:49:00 -04003367/**
James Smart3621a712009-04-06 18:47:14 -04003368 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003369 * @phba: pointer to lpfc hba data structure.
3370 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3371 *
3372 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3373 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3374 * checks to see whether there is a lpfc DMA buffer associated with the
3375 * response of the command IOCB. If so, it will be released before releasing
3376 * the lpfc DMA buffer associated with the IOCB itself.
3377 *
3378 * Return code
3379 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3380 **/
James Smart09372822008-01-11 01:52:54 -05003381static int
James Smart87af33f2007-10-27 13:37:43 -04003382lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3383{
3384 struct lpfc_dmabuf *buf_ptr;
3385
James Smarte59058c2008-08-24 21:49:00 -04003386 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003387 if (!list_empty(&buf_ptr1->list)) {
3388 list_remove_head(&buf_ptr1->list, buf_ptr,
3389 struct lpfc_dmabuf,
3390 list);
3391 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3392 kfree(buf_ptr);
3393 }
3394 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3395 kfree(buf_ptr1);
3396 return 0;
3397}
3398
James Smarte59058c2008-08-24 21:49:00 -04003399/**
James Smart3621a712009-04-06 18:47:14 -04003400 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003401 * @phba: pointer to lpfc hba data structure.
3402 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3403 *
3404 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3405 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3406 * pool.
3407 *
3408 * Return code
3409 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3410 **/
James Smart09372822008-01-11 01:52:54 -05003411static int
James Smart87af33f2007-10-27 13:37:43 -04003412lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3413{
3414 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3415 kfree(buf_ptr);
3416 return 0;
3417}
3418
James Smarte59058c2008-08-24 21:49:00 -04003419/**
James Smart3621a712009-04-06 18:47:14 -04003420 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003421 * @phba: pointer to lpfc hba data structure.
3422 * @elsiocb: pointer to lpfc els command iocb data structure.
3423 *
3424 * This routine frees a command IOCB and its associated resources. The
3425 * command IOCB data structure contains the reference to various associated
3426 * resources, these fields must be set to NULL if the associated reference
3427 * not present:
3428 * context1 - reference to ndlp
3429 * context2 - reference to cmd
3430 * context2->next - reference to rsp
3431 * context3 - reference to bpl
3432 *
3433 * It first properly decrements the reference count held on ndlp for the
3434 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3435 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3436 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3437 * adds the DMA buffer the @phba data structure for the delayed release.
3438 * If reference to the Buffer Pointer List (BPL) is present, the
3439 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3440 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3441 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3442 *
3443 * Return code
3444 * 0 - Success (currently, always return 0)
3445 **/
James Smart87af33f2007-10-27 13:37:43 -04003446int
James Smart329f9bc2007-04-25 09:53:01 -04003447lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003448{
3449 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003450 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003451
James Smarta8adb832007-10-27 13:37:53 -04003452 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3453 if (ndlp) {
3454 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3455 lpfc_nlp_put(ndlp);
3456
3457 /* If the ndlp is not being used by another discovery
3458 * thread, free it.
3459 */
3460 if (!lpfc_nlp_not_used(ndlp)) {
3461 /* If ndlp is being used by another discovery
3462 * thread, just clear NLP_DEFER_RM
3463 */
3464 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3465 }
3466 }
3467 else
3468 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003469 elsiocb->context1 = NULL;
3470 }
dea31012005-04-17 16:05:31 -05003471 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3472 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003473 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3474 /* Firmware could still be in progress of DMAing
3475 * payload, so don't free data buffer till after
3476 * a hbeat.
3477 */
3478 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3479 buf_ptr = elsiocb->context2;
3480 elsiocb->context2 = NULL;
3481 if (buf_ptr) {
3482 buf_ptr1 = NULL;
3483 spin_lock_irq(&phba->hbalock);
3484 if (!list_empty(&buf_ptr->list)) {
3485 list_remove_head(&buf_ptr->list,
3486 buf_ptr1, struct lpfc_dmabuf,
3487 list);
3488 INIT_LIST_HEAD(&buf_ptr1->list);
3489 list_add_tail(&buf_ptr1->list,
3490 &phba->elsbuf);
3491 phba->elsbuf_cnt++;
3492 }
3493 INIT_LIST_HEAD(&buf_ptr->list);
3494 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3495 phba->elsbuf_cnt++;
3496 spin_unlock_irq(&phba->hbalock);
3497 }
3498 } else {
3499 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3500 lpfc_els_free_data(phba, buf_ptr1);
3501 }
dea31012005-04-17 16:05:31 -05003502 }
3503
3504 if (elsiocb->context3) {
3505 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003506 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003507 }
James Bottomley604a3e32005-10-29 10:28:33 -05003508 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003509 return 0;
3510}
3511
James Smarte59058c2008-08-24 21:49:00 -04003512/**
James Smart3621a712009-04-06 18:47:14 -04003513 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003514 * @phba: pointer to lpfc hba data structure.
3515 * @cmdiocb: pointer to lpfc command iocb data structure.
3516 * @rspiocb: pointer to lpfc response iocb data structure.
3517 *
3518 * This routine is the completion callback function to the Logout (LOGO)
3519 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3520 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3521 * release the ndlp if it has the last reference remaining (reference count
3522 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3523 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3524 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3525 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3526 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3527 * IOCB data structure.
3528 **/
dea31012005-04-17 16:05:31 -05003529static void
James Smart2e0fef82007-06-17 19:56:36 -05003530lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3531 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003532{
James Smart2e0fef82007-06-17 19:56:36 -05003533 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3534 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003535 IOCB_t *irsp;
3536
3537 irsp = &rspiocb->iocb;
3538 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3539 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3540 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003541 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003542 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3543 "0109 ACC to LOGO completes to NPort x%x "
3544 "Data: x%x x%x x%x\n",
3545 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3546 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003547
3548 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3549 /* NPort Recovery mode or node is just allocated */
3550 if (!lpfc_nlp_not_used(ndlp)) {
3551 /* If the ndlp is being used by another discovery
3552 * thread, just unregister the RPI.
3553 */
3554 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003555 } else {
3556 /* Indicate the node has already released, should
3557 * not reference to it from within lpfc_els_free_iocb.
3558 */
3559 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003560 }
dea31012005-04-17 16:05:31 -05003561 }
James Smart73d91e52011-10-10 21:32:10 -04003562
3563 /*
3564 * The driver received a LOGO from the rport and has ACK'd it.
James Smartdf9e1b52011-12-13 13:22:17 -05003565 * At this point, the driver is done so release the IOCB
James Smart73d91e52011-10-10 21:32:10 -04003566 */
dea31012005-04-17 16:05:31 -05003567 lpfc_els_free_iocb(phba, cmdiocb);
James Smartdf9e1b52011-12-13 13:22:17 -05003568
3569 /*
3570 * Remove the ndlp reference if it's a fabric node that has
3571 * sent us an unsolicted LOGO.
3572 */
3573 if (ndlp->nlp_type & NLP_FABRIC)
3574 lpfc_nlp_put(ndlp);
3575
dea31012005-04-17 16:05:31 -05003576 return;
3577}
3578
James Smarte59058c2008-08-24 21:49:00 -04003579/**
James Smart3621a712009-04-06 18:47:14 -04003580 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003581 * @phba: pointer to lpfc hba data structure.
3582 * @pmb: pointer to the driver internal queue element for mailbox command.
3583 *
3584 * This routine is the completion callback function for unregister default
3585 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3586 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3587 * decrements the ndlp reference count held for this completion callback
3588 * function. After that, it invokes the lpfc_nlp_not_used() to check
3589 * whether there is only one reference left on the ndlp. If so, it will
3590 * perform one more decrement and trigger the release of the ndlp.
3591 **/
James Smart858c9f62007-06-17 19:56:39 -05003592void
3593lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3594{
3595 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3596 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3597
3598 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003599 pmb->context2 = NULL;
3600
James Smart858c9f62007-06-17 19:56:39 -05003601 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3602 kfree(mp);
3603 mempool_free(pmb, phba->mbox_mem_pool);
James Smart086a3452012-08-14 14:25:21 -04003604 if (ndlp) {
3605 if (NLP_CHK_NODE_ACT(ndlp)) {
3606 lpfc_nlp_put(ndlp);
3607 /* This is the end of the default RPI cleanup logic for
3608 * this ndlp. If no other discovery threads are using
3609 * this ndlp, free all resources associated with it.
3610 */
3611 lpfc_nlp_not_used(ndlp);
3612 } else {
3613 lpfc_drop_node(ndlp->vport, ndlp);
3614 }
James Smarta8adb832007-10-27 13:37:53 -04003615 }
James Smart3772a992009-05-22 14:50:54 -04003616
James Smart858c9f62007-06-17 19:56:39 -05003617 return;
3618}
3619
James Smarte59058c2008-08-24 21:49:00 -04003620/**
James Smart3621a712009-04-06 18:47:14 -04003621 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003622 * @phba: pointer to lpfc hba data structure.
3623 * @cmdiocb: pointer to lpfc command iocb data structure.
3624 * @rspiocb: pointer to lpfc response iocb data structure.
3625 *
3626 * This routine is the completion callback function for ELS Response IOCB
3627 * command. In normal case, this callback function just properly sets the
3628 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3629 * field in the command IOCB is not NULL, the referred mailbox command will
3630 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3631 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3632 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3633 * routine shall be invoked trying to release the ndlp if no other threads
3634 * are currently referring it.
3635 **/
dea31012005-04-17 16:05:31 -05003636static void
James Smart858c9f62007-06-17 19:56:39 -05003637lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003638 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003639{
James Smart2e0fef82007-06-17 19:56:36 -05003640 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3641 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3642 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003643 IOCB_t *irsp;
3644 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003645 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003646 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003647 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003648
James Smart33ccf8d2006-08-17 11:57:58 -04003649 irsp = &rspiocb->iocb;
3650
dea31012005-04-17 16:05:31 -05003651 if (cmdiocb->context_un.mbox)
3652 mbox = cmdiocb->context_un.mbox;
3653
James Smartfa4066b2008-01-11 01:53:27 -05003654 /* First determine if this is a LS_RJT cmpl. Note, this callback
3655 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3656 */
James Smart87af33f2007-10-27 13:37:43 -04003657 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003658 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3659 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003660 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003661 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003662 */
3663 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3664 ls_rjt = 1;
3665 }
3666
dea31012005-04-17 16:05:31 -05003667 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003668 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003669 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003670 mp = (struct lpfc_dmabuf *) mbox->context1;
3671 if (mp) {
3672 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3673 kfree(mp);
3674 }
James Smart329f9bc2007-04-25 09:53:01 -04003675 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003676 }
James Smart58da1ff2008-04-07 10:15:56 -04003677 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3678 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003679 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003680 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003681 /* Indicate the node has already released,
3682 * should not reference to it from within
3683 * the routine lpfc_els_free_iocb.
3684 */
3685 cmdiocb->context1 = NULL;
3686 }
dea31012005-04-17 16:05:31 -05003687 goto out;
3688 }
3689
James Smart858c9f62007-06-17 19:56:39 -05003690 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003691 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003692 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003693 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003694 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003695 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3696 "0110 ELS response tag x%x completes "
3697 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3698 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3699 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3700 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3701 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003702 if (mbox) {
3703 if ((rspiocb->iocb.ulpStatus == 0)
3704 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003705 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003706 /* Increment reference count to ndlp to hold the
3707 * reference to ndlp for the callback function.
3708 */
James Smart329f9bc2007-04-25 09:53:01 -04003709 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003710 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003711 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3712 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3713 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3714 }
3715 else {
3716 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3717 ndlp->nlp_prev_state = ndlp->nlp_state;
3718 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003719 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003720 }
James Smart0b727fe2007-10-27 13:37:25 -04003721 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003722 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003723 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003724 else
3725 /* Decrement the ndlp reference count we
3726 * set for this failed mailbox command.
3727 */
3728 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003729
3730 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3731 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3732 "0138 ELS rsp: Cannot issue reg_login for x%x "
3733 "Data: x%x x%x x%x\n",
3734 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3735 ndlp->nlp_rpi);
3736
James Smartfa4066b2008-01-11 01:53:27 -05003737 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003738 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003739 /* Indicate node has already been released,
3740 * should not reference to it from within
3741 * the routine lpfc_els_free_iocb.
3742 */
3743 cmdiocb->context1 = NULL;
3744 }
dea31012005-04-17 16:05:31 -05003745 } else {
James Smart858c9f62007-06-17 19:56:39 -05003746 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3747 if (!lpfc_error_lost_link(irsp) &&
3748 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003749 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003750 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003751 /* Indicate node has already been
3752 * released, should not reference
3753 * to it from within the routine
3754 * lpfc_els_free_iocb.
3755 */
3756 cmdiocb->context1 = NULL;
3757 }
dea31012005-04-17 16:05:31 -05003758 }
3759 }
James Smart14691152006-12-02 13:34:28 -05003760 mp = (struct lpfc_dmabuf *) mbox->context1;
3761 if (mp) {
3762 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3763 kfree(mp);
3764 }
3765 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003766 }
3767out:
James Smart58da1ff2008-04-07 10:15:56 -04003768 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003769 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003770 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003771 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003772
3773 /* If the node is not being used by another discovery thread,
3774 * and we are sending a reject, we are done with it.
3775 * Release driver reference count here and free associated
3776 * resources.
3777 */
3778 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003779 if (lpfc_nlp_not_used(ndlp))
3780 /* Indicate node has already been released,
3781 * should not reference to it from within
3782 * the routine lpfc_els_free_iocb.
3783 */
3784 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003785 }
James Smart87af33f2007-10-27 13:37:43 -04003786
dea31012005-04-17 16:05:31 -05003787 lpfc_els_free_iocb(phba, cmdiocb);
3788 return;
3789}
3790
James Smarte59058c2008-08-24 21:49:00 -04003791/**
James Smart3621a712009-04-06 18:47:14 -04003792 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003793 * @vport: pointer to a host virtual N_Port data structure.
3794 * @flag: the els command code to be accepted.
3795 * @oldiocb: pointer to the original lpfc command iocb data structure.
3796 * @ndlp: pointer to a node-list data structure.
3797 * @mbox: pointer to the driver internal queue element for mailbox command.
3798 *
3799 * This routine prepares and issues an Accept (ACC) response IOCB
3800 * command. It uses the @flag to properly set up the IOCB field for the
3801 * specific ACC response command to be issued and invokes the
3802 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3803 * @mbox pointer is passed in, it will be put into the context_un.mbox
3804 * field of the IOCB for the completion callback function to issue the
3805 * mailbox command to the HBA later when callback is invoked.
3806 *
3807 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3808 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3809 * will be stored into the context1 field of the IOCB for the completion
3810 * callback function to the corresponding response ELS IOCB command.
3811 *
3812 * Return code
3813 * 0 - Successfully issued acc response
3814 * 1 - Failed to issue acc response
3815 **/
dea31012005-04-17 16:05:31 -05003816int
James Smart2e0fef82007-06-17 19:56:36 -05003817lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3818 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003819 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003820{
James Smart2e0fef82007-06-17 19:56:36 -05003821 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3822 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003823 IOCB_t *icmd;
3824 IOCB_t *oldcmd;
3825 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003826 struct lpfc_sli *psli;
3827 uint8_t *pcmd;
3828 uint16_t cmdsize;
3829 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003830 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003831
3832 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003833 oldcmd = &oldiocb->iocb;
3834
3835 switch (flag) {
3836 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003837 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003838 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3839 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003840 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003841 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003842 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003843 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003844 return 1;
dea31012005-04-17 16:05:31 -05003845 }
James Smart2e0fef82007-06-17 19:56:36 -05003846
dea31012005-04-17 16:05:31 -05003847 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003848 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3849 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003850 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3851 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003852 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003853
3854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3855 "Issue ACC: did:x%x flg:x%x",
3856 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003857 break;
3858 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003859 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003860 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3861 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003862 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003863 return 1;
James Smart488d1462006-03-07 15:02:37 -05003864
dea31012005-04-17 16:05:31 -05003865 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003866 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3867 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003868 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3869
3870 if (mbox)
3871 elsiocb->context_un.mbox = mbox;
3872
3873 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003874 pcmd += sizeof(uint32_t);
3875 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003876
3877 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3878 "Issue ACC PLOGI: did:x%x flg:x%x",
3879 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003880 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003881 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003882 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003883 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003884 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3885 if (!elsiocb)
3886 return 1;
3887
3888 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003889 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3890 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart82d9a2a2006-04-15 11:53:05 -04003891 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3892
3893 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003894 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003895 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3896 els_pkt_ptr = (ELS_PKT *) pcmd;
3897 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003898
3899 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3900 "Issue ACC PRLO: did:x%x flg:x%x",
3901 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003902 break;
dea31012005-04-17 16:05:31 -05003903 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003904 return 1;
dea31012005-04-17 16:05:31 -05003905 }
dea31012005-04-17 16:05:31 -05003906 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003907 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3908 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smarte6446432012-05-09 21:16:42 -04003909 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3910 "fc_flag x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003911 elsiocb->iotag, elsiocb->iocb.ulpContext,
3912 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
James Smarte6446432012-05-09 21:16:42 -04003913 ndlp->nlp_rpi, vport->fc_flag);
dea31012005-04-17 16:05:31 -05003914 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003915 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003916 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003917 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003918 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3919 } else {
James Smart858c9f62007-06-17 19:56:39 -05003920 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003921 }
3922
3923 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003924 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003925 if (rc == IOCB_ERROR) {
3926 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003927 return 1;
dea31012005-04-17 16:05:31 -05003928 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003929 return 0;
dea31012005-04-17 16:05:31 -05003930}
3931
James Smarte59058c2008-08-24 21:49:00 -04003932/**
James Smart3621a712009-04-06 18:47:14 -04003933 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003934 * @vport: pointer to a virtual N_Port data structure.
3935 * @rejectError:
3936 * @oldiocb: pointer to the original lpfc command iocb data structure.
3937 * @ndlp: pointer to a node-list data structure.
3938 * @mbox: pointer to the driver internal queue element for mailbox command.
3939 *
3940 * This routine prepares and issue an Reject (RJT) response IOCB
3941 * command. If a @mbox pointer is passed in, it will be put into the
3942 * context_un.mbox field of the IOCB for the completion callback function
3943 * to issue to the HBA later.
3944 *
3945 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3946 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3947 * will be stored into the context1 field of the IOCB for the completion
3948 * callback function to the reject response ELS IOCB command.
3949 *
3950 * Return code
3951 * 0 - Successfully issued reject response
3952 * 1 - Failed to issue reject response
3953 **/
dea31012005-04-17 16:05:31 -05003954int
James Smart2e0fef82007-06-17 19:56:36 -05003955lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003956 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3957 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003958{
James Smart2e0fef82007-06-17 19:56:36 -05003959 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003960 IOCB_t *icmd;
3961 IOCB_t *oldcmd;
3962 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003963 struct lpfc_sli *psli;
3964 uint8_t *pcmd;
3965 uint16_t cmdsize;
3966 int rc;
3967
3968 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003969 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003970 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3971 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003972 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003973 return 1;
dea31012005-04-17 16:05:31 -05003974
3975 icmd = &elsiocb->iocb;
3976 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04003977 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
3978 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
dea31012005-04-17 16:05:31 -05003979 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3980
3981 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003982 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003983 *((uint32_t *) (pcmd)) = rejectError;
3984
James Smart51ef4c22007-08-02 11:10:31 -04003985 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003986 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003987
dea31012005-04-17 16:05:31 -05003988 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003989 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3990 "0129 Xmit ELS RJT x%x response tag x%x "
3991 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3992 "rpi x%x\n",
3993 rejectError, elsiocb->iotag,
3994 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3995 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3997 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3998 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3999
dea31012005-04-17 16:05:31 -05004000 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05004001 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004002 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04004003
dea31012005-04-17 16:05:31 -05004004 if (rc == IOCB_ERROR) {
4005 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004006 return 1;
dea31012005-04-17 16:05:31 -05004007 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004008 return 0;
dea31012005-04-17 16:05:31 -05004009}
4010
James Smarte59058c2008-08-24 21:49:00 -04004011/**
James Smart3621a712009-04-06 18:47:14 -04004012 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004013 * @vport: pointer to a virtual N_Port data structure.
4014 * @oldiocb: pointer to the original lpfc command iocb data structure.
4015 * @ndlp: pointer to a node-list data structure.
4016 *
4017 * This routine prepares and issues an Accept (ACC) response to Address
4018 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4019 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4020 *
4021 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4022 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4023 * will be stored into the context1 field of the IOCB for the completion
4024 * callback function to the ADISC Accept response ELS IOCB command.
4025 *
4026 * Return code
4027 * 0 - Successfully issued acc adisc response
4028 * 1 - Failed to issue adisc acc response
4029 **/
dea31012005-04-17 16:05:31 -05004030int
James Smart2e0fef82007-06-17 19:56:36 -05004031lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
4032 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004033{
James Smart2e0fef82007-06-17 19:56:36 -05004034 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004035 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05004036 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004037 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004038 uint8_t *pcmd;
4039 uint16_t cmdsize;
4040 int rc;
4041
James Smart92d7f7b2007-06-17 19:56:38 -05004042 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05004043 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4044 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004045 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004046 return 1;
dea31012005-04-17 16:05:31 -05004047
dea31012005-04-17 16:05:31 -05004048 icmd = &elsiocb->iocb;
4049 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004050 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4051 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
James Smart5b8bd0c2007-04-25 09:52:49 -04004052
4053 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004054 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4055 "0130 Xmit ADISC ACC response iotag x%x xri: "
4056 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4057 elsiocb->iotag, elsiocb->iocb.ulpContext,
4058 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4059 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004060 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4061
4062 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004063 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004064
4065 ap = (ADISC *) (pcmd);
4066 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05004067 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4068 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05004069 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05004070
James Smart858c9f62007-06-17 19:56:39 -05004071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4072 "Issue ACC ADISC: did:x%x flg:x%x",
4073 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4074
dea31012005-04-17 16:05:31 -05004075 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004076 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04004077 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004078 if (rc == IOCB_ERROR) {
4079 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004080 return 1;
dea31012005-04-17 16:05:31 -05004081 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004082 return 0;
dea31012005-04-17 16:05:31 -05004083}
4084
James Smarte59058c2008-08-24 21:49:00 -04004085/**
James Smart3621a712009-04-06 18:47:14 -04004086 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04004087 * @vport: pointer to a virtual N_Port data structure.
4088 * @oldiocb: pointer to the original lpfc command iocb data structure.
4089 * @ndlp: pointer to a node-list data structure.
4090 *
4091 * This routine prepares and issues an Accept (ACC) response to Process
4092 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4093 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4094 *
4095 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4096 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4097 * will be stored into the context1 field of the IOCB for the completion
4098 * callback function to the PRLI Accept response ELS IOCB command.
4099 *
4100 * Return code
4101 * 0 - Successfully issued acc prli response
4102 * 1 - Failed to issue acc prli response
4103 **/
dea31012005-04-17 16:05:31 -05004104int
James Smart2e0fef82007-06-17 19:56:36 -05004105lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04004106 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004107{
James Smart2e0fef82007-06-17 19:56:36 -05004108 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004109 PRLI *npr;
4110 lpfc_vpd_t *vpd;
4111 IOCB_t *icmd;
4112 IOCB_t *oldcmd;
4113 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004114 struct lpfc_sli *psli;
4115 uint8_t *pcmd;
4116 uint16_t cmdsize;
4117 int rc;
4118
4119 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05004120
James Smart92d7f7b2007-06-17 19:56:38 -05004121 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05004122 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05004123 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004124 if (!elsiocb)
4125 return 1;
dea31012005-04-17 16:05:31 -05004126
dea31012005-04-17 16:05:31 -05004127 icmd = &elsiocb->iocb;
4128 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004129 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4130 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4131
James Smart5b8bd0c2007-04-25 09:52:49 -04004132 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004133 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4134 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4135 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4136 elsiocb->iotag, elsiocb->iocb.ulpContext,
4137 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4138 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05004139 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4140
4141 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05004142 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004143
4144 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05004145 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05004146
4147 npr = (PRLI *) pcmd;
4148 vpd = &phba->vpd;
4149 /*
James Smart0d2b6b82008-06-14 22:52:47 -04004150 * If the remote port is a target and our firmware version is 3.20 or
4151 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05004152 */
James Smart0d2b6b82008-06-14 22:52:47 -04004153 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
4154 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05004155 npr->ConfmComplAllowed = 1;
4156 npr->Retry = 1;
4157 npr->TaskRetryIdReq = 1;
4158 }
4159
4160 npr->acceptRspCode = PRLI_REQ_EXECUTED;
4161 npr->estabImagePair = 1;
4162 npr->readXferRdyDis = 1;
4163 npr->ConfmComplAllowed = 1;
4164
4165 npr->prliType = PRLI_FCP_TYPE;
4166 npr->initiatorFunc = 1;
4167
James Smart858c9f62007-06-17 19:56:39 -05004168 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4169 "Issue ACC PRLI: did:x%x flg:x%x",
4170 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4171
dea31012005-04-17 16:05:31 -05004172 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004173 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004174
James Smart3772a992009-05-22 14:50:54 -04004175 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004176 if (rc == IOCB_ERROR) {
4177 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004178 return 1;
dea31012005-04-17 16:05:31 -05004179 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004180 return 0;
dea31012005-04-17 16:05:31 -05004181}
4182
James Smarte59058c2008-08-24 21:49:00 -04004183/**
James Smart3621a712009-04-06 18:47:14 -04004184 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04004185 * @vport: pointer to a virtual N_Port data structure.
4186 * @format: rnid command format.
4187 * @oldiocb: pointer to the original lpfc command iocb data structure.
4188 * @ndlp: pointer to a node-list data structure.
4189 *
4190 * This routine issues a Request Node Identification Data (RNID) Accept
4191 * (ACC) response. It constructs the RNID ACC response command according to
4192 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4193 * issue the response. Note that this command does not need to hold the ndlp
4194 * reference count for the callback. So, the ndlp reference count taken by
4195 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4196 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4197 * there is no ndlp reference available.
4198 *
4199 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4200 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4201 * will be stored into the context1 field of the IOCB for the completion
4202 * callback function. However, for the RNID Accept Response ELS command,
4203 * this is undone later by this routine after the IOCB is allocated.
4204 *
4205 * Return code
4206 * 0 - Successfully issued acc rnid response
4207 * 1 - Failed to issue acc rnid response
4208 **/
dea31012005-04-17 16:05:31 -05004209static int
James Smart2e0fef82007-06-17 19:56:36 -05004210lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04004211 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004212{
James Smart2e0fef82007-06-17 19:56:36 -05004213 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004214 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05004215 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05004216 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05004217 struct lpfc_sli *psli;
4218 uint8_t *pcmd;
4219 uint16_t cmdsize;
4220 int rc;
4221
4222 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05004223 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
4224 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004225 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05004226 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004227
James Smart2e0fef82007-06-17 19:56:36 -05004228 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4229 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05004230 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004231 return 1;
dea31012005-04-17 16:05:31 -05004232
dea31012005-04-17 16:05:31 -05004233 icmd = &elsiocb->iocb;
4234 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04004235 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
4236 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
4237
James Smart5b8bd0c2007-04-25 09:52:49 -04004238 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004239 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4240 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4241 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05004242 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05004243 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004244 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05004245
James Smart92d7f7b2007-06-17 19:56:38 -05004246 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05004247 rn = (RNID *) (pcmd);
4248 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05004249 rn->CommonLen = (2 * sizeof(struct lpfc_name));
4250 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
4251 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004252 switch (format) {
4253 case 0:
4254 rn->SpecificLen = 0;
4255 break;
4256 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05004257 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05004258 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004259 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004260 rn->un.topologyDisc.unitType = RNID_HBA;
4261 rn->un.topologyDisc.physPort = 0;
4262 rn->un.topologyDisc.attachedNodes = 0;
4263 break;
4264 default:
4265 rn->CommonLen = 0;
4266 rn->SpecificLen = 0;
4267 break;
4268 }
4269
James Smart858c9f62007-06-17 19:56:39 -05004270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4271 "Issue ACC RNID: did:x%x flg:x%x",
4272 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4273
dea31012005-04-17 16:05:31 -05004274 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05004275 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05004276
James Smart3772a992009-05-22 14:50:54 -04004277 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004278 if (rc == IOCB_ERROR) {
4279 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004280 return 1;
dea31012005-04-17 16:05:31 -05004281 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004282 return 0;
dea31012005-04-17 16:05:31 -05004283}
4284
James Smarte59058c2008-08-24 21:49:00 -04004285/**
James Smart19ca7602010-11-20 23:11:55 -05004286 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4287 * @vport: pointer to a virtual N_Port data structure.
4288 * @iocb: pointer to the lpfc command iocb data structure.
4289 * @ndlp: pointer to a node-list data structure.
4290 *
4291 * Return
4292 **/
4293static void
4294lpfc_els_clear_rrq(struct lpfc_vport *vport,
4295 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4296{
4297 struct lpfc_hba *phba = vport->phba;
4298 uint8_t *pcmd;
4299 struct RRQ *rrq;
4300 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004301 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004302 struct lpfc_node_rrq *prrq;
4303
4304
4305 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4306 pcmd += sizeof(uint32_t);
4307 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004308 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
James Smart9589b062011-04-16 11:03:17 -04004309 rxid = bf_get(rrq_rxid, rrq);
James Smart19ca7602010-11-20 23:11:55 -05004310
4311 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4312 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4313 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004314 be32_to_cpu(bf_get(rrq_did, rrq)),
James Smart9589b062011-04-16 11:03:17 -04004315 bf_get(rrq_oxid, rrq),
James Smart19ca7602010-11-20 23:11:55 -05004316 rxid,
4317 iocb->iotag, iocb->iocb.ulpContext);
4318
4319 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4320 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4321 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004322 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
James Smart9589b062011-04-16 11:03:17 -04004323 xri = bf_get(rrq_oxid, rrq);
James Smart1151e3e2011-02-16 12:39:35 -05004324 else
4325 xri = rxid;
4326 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004327 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004328 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004329 return;
4330}
4331
4332/**
James Smart12265f62010-10-22 11:05:53 -04004333 * lpfc_els_rsp_echo_acc - Issue echo acc response
4334 * @vport: pointer to a virtual N_Port data structure.
4335 * @data: pointer to echo data to return in the accept.
4336 * @oldiocb: pointer to the original lpfc command iocb data structure.
4337 * @ndlp: pointer to a node-list data structure.
4338 *
4339 * Return code
4340 * 0 - Successfully issued acc echo response
4341 * 1 - Failed to issue acc echo response
4342 **/
4343static int
4344lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4345 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4346{
4347 struct lpfc_hba *phba = vport->phba;
4348 struct lpfc_iocbq *elsiocb;
4349 struct lpfc_sli *psli;
4350 uint8_t *pcmd;
4351 uint16_t cmdsize;
4352 int rc;
4353
4354 psli = &phba->sli;
4355 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4356
James Smartbf086112011-08-21 21:48:13 -04004357 /* The accumulated length can exceed the BPL_SIZE. For
4358 * now, use this as the limit
4359 */
4360 if (cmdsize > LPFC_BPL_SIZE)
4361 cmdsize = LPFC_BPL_SIZE;
James Smart12265f62010-10-22 11:05:53 -04004362 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4363 ndlp->nlp_DID, ELS_CMD_ACC);
4364 if (!elsiocb)
4365 return 1;
4366
James Smart7851fe22011-07-22 18:36:52 -04004367 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri / rx_id */
4368 elsiocb->iocb.unsli3.rcvsli3.ox_id = oldiocb->iocb.unsli3.rcvsli3.ox_id;
4369
James Smart12265f62010-10-22 11:05:53 -04004370 /* Xmit ECHO ACC response tag <ulpIoTag> */
4371 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4372 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4373 elsiocb->iotag, elsiocb->iocb.ulpContext);
4374 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4375 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4376 pcmd += sizeof(uint32_t);
4377 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4378
4379 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4380 "Issue ACC ECHO: did:x%x flg:x%x",
4381 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4382
4383 phba->fc_stat.elsXmitACC++;
4384 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart12265f62010-10-22 11:05:53 -04004385
4386 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4387 if (rc == IOCB_ERROR) {
4388 lpfc_els_free_iocb(phba, elsiocb);
4389 return 1;
4390 }
4391 return 0;
4392}
4393
4394/**
James Smart3621a712009-04-06 18:47:14 -04004395 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004396 * @vport: pointer to a host virtual N_Port data structure.
4397 *
4398 * This routine issues Address Discover (ADISC) ELS commands to those
4399 * N_Ports which are in node port recovery state and ADISC has not been issued
4400 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4401 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4402 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4403 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4404 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4405 * IOCBs quit for later pick up. On the other hand, after walking through
4406 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4407 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4408 * no more ADISC need to be sent.
4409 *
4410 * Return code
4411 * The number of N_Ports with adisc issued.
4412 **/
dea31012005-04-17 16:05:31 -05004413int
James Smart2e0fef82007-06-17 19:56:36 -05004414lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004415{
James Smart2e0fef82007-06-17 19:56:36 -05004416 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004417 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004418 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004419
James Smart685f0bf2007-04-25 09:53:08 -04004420 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004421 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004422 if (!NLP_CHK_NODE_ACT(ndlp))
4423 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004424 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4425 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4426 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004427 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004428 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004429 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004430 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4432 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004433 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004434 vport->num_disc_nodes++;
4435 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004436 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004437 spin_lock_irq(shost->host_lock);
4438 vport->fc_flag |= FC_NLP_MORE;
4439 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004440 break;
dea31012005-04-17 16:05:31 -05004441 }
4442 }
4443 }
4444 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004445 spin_lock_irq(shost->host_lock);
4446 vport->fc_flag &= ~FC_NLP_MORE;
4447 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004448 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004449 return sentadisc;
dea31012005-04-17 16:05:31 -05004450}
4451
James Smarte59058c2008-08-24 21:49:00 -04004452/**
James Smart3621a712009-04-06 18:47:14 -04004453 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004454 * @vport: pointer to a host virtual N_Port data structure.
4455 *
4456 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4457 * which are in node port recovery state, with a @vport. Each time an ELS
4458 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4459 * the per @vport number of discover count (num_disc_nodes) shall be
4460 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4461 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4462 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4463 * later pick up. On the other hand, after walking through all the ndlps with
4464 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4465 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4466 * PLOGI need to be sent.
4467 *
4468 * Return code
4469 * The number of N_Ports with plogi issued.
4470 **/
dea31012005-04-17 16:05:31 -05004471int
James Smart2e0fef82007-06-17 19:56:36 -05004472lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004473{
James Smart2e0fef82007-06-17 19:56:36 -05004474 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004475 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004476 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004477
James Smart2e0fef82007-06-17 19:56:36 -05004478 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4479 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004480 if (!NLP_CHK_NODE_ACT(ndlp))
4481 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004482 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4483 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4484 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4485 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4486 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004487 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4488 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004489 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004490 vport->num_disc_nodes++;
4491 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004492 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004493 spin_lock_irq(shost->host_lock);
4494 vport->fc_flag |= FC_NLP_MORE;
4495 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004496 break;
dea31012005-04-17 16:05:31 -05004497 }
4498 }
4499 }
James Smart87af33f2007-10-27 13:37:43 -04004500 if (sentplogi) {
4501 lpfc_set_disctmo(vport);
4502 }
4503 else {
James Smart2e0fef82007-06-17 19:56:36 -05004504 spin_lock_irq(shost->host_lock);
4505 vport->fc_flag &= ~FC_NLP_MORE;
4506 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004507 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004508 return sentplogi;
dea31012005-04-17 16:05:31 -05004509}
4510
James Smarte59058c2008-08-24 21:49:00 -04004511/**
James Smart3621a712009-04-06 18:47:14 -04004512 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004513 * @vport: pointer to a host virtual N_Port data structure.
4514 *
4515 * This routine cleans up any Registration State Change Notification
4516 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4517 * @vport together with the host_lock is used to prevent multiple thread
4518 * trying to access the RSCN array on a same @vport at the same time.
4519 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004520void
James Smart2e0fef82007-06-17 19:56:36 -05004521lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004522{
James Smart2e0fef82007-06-17 19:56:36 -05004523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4524 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004525 int i;
4526
James Smart7f5f3d02008-02-08 18:50:14 -05004527 spin_lock_irq(shost->host_lock);
4528 if (vport->fc_rscn_flush) {
4529 /* Another thread is walking fc_rscn_id_list on this vport */
4530 spin_unlock_irq(shost->host_lock);
4531 return;
4532 }
4533 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4534 vport->fc_rscn_flush = 1;
4535 spin_unlock_irq(shost->host_lock);
4536
James Smart2e0fef82007-06-17 19:56:36 -05004537 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004538 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004539 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004540 }
James Smart2e0fef82007-06-17 19:56:36 -05004541 spin_lock_irq(shost->host_lock);
4542 vport->fc_rscn_id_cnt = 0;
4543 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4544 spin_unlock_irq(shost->host_lock);
4545 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004546 /* Indicate we are done walking this fc_rscn_id_list */
4547 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004548}
4549
James Smarte59058c2008-08-24 21:49:00 -04004550/**
James Smart3621a712009-04-06 18:47:14 -04004551 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004552 * @vport: pointer to a host virtual N_Port data structure.
4553 * @did: remote destination port identifier.
4554 *
4555 * This routine checks whether there is any pending Registration State
4556 * Configuration Notification (RSCN) to a @did on @vport.
4557 *
4558 * Return code
4559 * None zero - The @did matched with a pending rscn
4560 * 0 - not able to match @did with a pending rscn
4561 **/
dea31012005-04-17 16:05:31 -05004562int
James Smart2e0fef82007-06-17 19:56:36 -05004563lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004564{
4565 D_ID ns_did;
4566 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004567 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004568 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004569 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004570
4571 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004572
4573 /* Never match fabric nodes for RSCNs */
4574 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004575 return 0;
dea31012005-04-17 16:05:31 -05004576
4577 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004578 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004579 return did;
dea31012005-04-17 16:05:31 -05004580
James Smart7f5f3d02008-02-08 18:50:14 -05004581 spin_lock_irq(shost->host_lock);
4582 if (vport->fc_rscn_flush) {
4583 /* Another thread is walking fc_rscn_id_list on this vport */
4584 spin_unlock_irq(shost->host_lock);
4585 return 0;
4586 }
4587 /* Indicate we are walking fc_rscn_id_list on this vport */
4588 vport->fc_rscn_flush = 1;
4589 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004590 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004591 lp = vport->fc_rscn_id_list[i]->virt;
4592 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4593 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004594 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004595 rscn_did.un.word = be32_to_cpu(*lp++);
4596 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004597 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4598 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004599 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4600 && (ns_did.un.b.area == rscn_did.un.b.area)
4601 && (ns_did.un.b.id == rscn_did.un.b.id))
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_AREA:
dea31012005-04-17 16:05:31 -05004605 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4606 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004607 goto return_did_out;
dea31012005-04-17 16:05:31 -05004608 break;
James Smarteaf15d52008-12-04 22:39:29 -05004609 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004610 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004611 goto return_did_out;
dea31012005-04-17 16:05:31 -05004612 break;
James Smarteaf15d52008-12-04 22:39:29 -05004613 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004614 goto return_did_out;
dea31012005-04-17 16:05:31 -05004615 }
4616 }
James Smart92d7f7b2007-06-17 19:56:38 -05004617 }
James Smart7f5f3d02008-02-08 18:50:14 -05004618 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4619 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004620 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004621return_did_out:
4622 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4623 vport->fc_rscn_flush = 0;
4624 return did;
dea31012005-04-17 16:05:31 -05004625}
4626
James Smarte59058c2008-08-24 21:49:00 -04004627/**
James Smart3621a712009-04-06 18:47:14 -04004628 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004629 * @vport: pointer to a host virtual N_Port data structure.
4630 *
4631 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4632 * state machine for a @vport's nodes that are with pending RSCN (Registration
4633 * State Change Notification).
4634 *
4635 * Return code
4636 * 0 - Successful (currently alway return 0)
4637 **/
dea31012005-04-17 16:05:31 -05004638static int
James Smart2e0fef82007-06-17 19:56:36 -05004639lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004640{
James Smart685f0bf2007-04-25 09:53:08 -04004641 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004642
James Smart0d2b6b82008-06-14 22:52:47 -04004643 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004644 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004645 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004646 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4647 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004648 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004649 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004650 NLP_EVT_DEVICE_RECOVERY);
4651 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004652 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004653 return 0;
dea31012005-04-17 16:05:31 -05004654}
4655
James Smarte59058c2008-08-24 21:49:00 -04004656/**
James Smart3621a712009-04-06 18:47:14 -04004657 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004658 * @vport: pointer to a host virtual N_Port data structure.
4659 * @cmdiocb: pointer to lpfc command iocb data structure.
4660 *
4661 * lpfc_send_rscn_event sends an RSCN netlink event to management
4662 * applications.
4663 */
4664static void
4665lpfc_send_rscn_event(struct lpfc_vport *vport,
4666 struct lpfc_iocbq *cmdiocb)
4667{
4668 struct lpfc_dmabuf *pcmd;
4669 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4670 uint32_t *payload_ptr;
4671 uint32_t payload_len;
4672 struct lpfc_rscn_event_header *rscn_event_data;
4673
4674 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4675 payload_ptr = (uint32_t *) pcmd->virt;
4676 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4677
4678 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4679 payload_len, GFP_KERNEL);
4680 if (!rscn_event_data) {
4681 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4682 "0147 Failed to allocate memory for RSCN event\n");
4683 return;
4684 }
4685 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4686 rscn_event_data->payload_length = payload_len;
4687 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4688 payload_len);
4689
4690 fc_host_post_vendor_event(shost,
4691 fc_get_event_number(),
4692 sizeof(struct lpfc_els_event_header) + payload_len,
4693 (char *)rscn_event_data,
4694 LPFC_NL_VENDOR_ID);
4695
4696 kfree(rscn_event_data);
4697}
4698
4699/**
James Smart3621a712009-04-06 18:47:14 -04004700 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004701 * @vport: pointer to a host virtual N_Port data structure.
4702 * @cmdiocb: pointer to lpfc command iocb data structure.
4703 * @ndlp: pointer to a node-list data structure.
4704 *
4705 * This routine processes an unsolicited RSCN (Registration State Change
4706 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4707 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4708 * discover state machine is about to begin discovery, it just accepts the
4709 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4710 * contains N_Port IDs for other vports on this HBA, it just accepts the
4711 * RSCN and ignore processing it. If the state machine is in the recovery
4712 * state, the fc_rscn_id_list of this @vport is walked and the
4713 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4714 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4715 * routine is invoked to handle the RSCN event.
4716 *
4717 * Return code
4718 * 0 - Just sent the acc response
4719 * 1 - Sent the acc response and waited for name server completion
4720 **/
dea31012005-04-17 16:05:31 -05004721static int
James Smart2e0fef82007-06-17 19:56:36 -05004722lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004723 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004724{
James Smart2e0fef82007-06-17 19:56:36 -05004725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4726 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004727 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004728 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004729 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004730 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004731 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004732 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004733 int i;
dea31012005-04-17 16:05:31 -05004734
4735 icmd = &cmdiocb->iocb;
4736 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4737 lp = (uint32_t *) pcmd->virt;
4738
James Smart92d7f7b2007-06-17 19:56:38 -05004739 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4740 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004741 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004742 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4743 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004744 vport->fc_flag, payload_len, *lp,
4745 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004746
4747 /* Send an RSCN event to the management application */
4748 lpfc_send_rscn_event(vport, cmdiocb);
4749
James Smartd2873e42006-08-18 17:46:43 -04004750 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004751 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004752 FCH_EVT_RSCN, lp[i]);
4753
dea31012005-04-17 16:05:31 -05004754 /* If we are about to begin discovery, just ACC the RSCN.
4755 * Discovery processing will satisfy it.
4756 */
James Smart2e0fef82007-06-17 19:56:36 -05004757 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004758 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4759 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4760 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4761
James Smart51ef4c22007-08-02 11:10:31 -04004762 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004763 return 0;
dea31012005-04-17 16:05:31 -05004764 }
4765
James Smart92d7f7b2007-06-17 19:56:38 -05004766 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4767 * just ACC and ignore it.
4768 */
4769 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004770 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004771 i = payload_len;
4772 datap = lp;
4773 while (i > 0) {
4774 nportid = *datap++;
4775 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4776 i -= sizeof(uint32_t);
4777 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004778 if (lpfc_find_vport_by_did(phba, nportid))
4779 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004780 }
4781 if (rscn_id == hba_id) {
4782 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004783 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004784 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004785 "Data: x%x x%x x%x x%x\n",
4786 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004787 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4789 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4790 ndlp->nlp_DID, vport->port_state,
4791 ndlp->nlp_flag);
4792
James Smart92d7f7b2007-06-17 19:56:38 -05004793 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004794 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004795 return 0;
4796 }
4797 }
4798
James Smart7f5f3d02008-02-08 18:50:14 -05004799 spin_lock_irq(shost->host_lock);
4800 if (vport->fc_rscn_flush) {
4801 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004802 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004803 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004804 /* Send back ACC */
4805 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004806 return 0;
4807 }
4808 /* Indicate we are walking fc_rscn_id_list on this vport */
4809 vport->fc_rscn_flush = 1;
4810 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004811 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004812 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004813 /* If we are already processing an RSCN, save the received
4814 * RSCN payload buffer, cmdiocb->context2 to process later.
4815 */
James Smart2e0fef82007-06-17 19:56:36 -05004816 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004817 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4818 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4819 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4820
James Smart09372822008-01-11 01:52:54 -05004821 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004822 vport->fc_flag |= FC_RSCN_DEFERRED;
4823 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004824 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004825 vport->fc_flag |= FC_RSCN_MODE;
4826 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004827 if (rscn_cnt) {
4828 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4829 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4830 }
4831 if ((rscn_cnt) &&
4832 (payload_len + length <= LPFC_BPL_SIZE)) {
4833 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004834 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004835 memcpy(((uint8_t *)cmd) + length, lp,
4836 payload_len);
4837 } else {
4838 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4839 vport->fc_rscn_id_cnt++;
4840 /* If we zero, cmdiocb->context2, the calling
4841 * routine will not try to free it.
4842 */
4843 cmdiocb->context2 = NULL;
4844 }
dea31012005-04-17 16:05:31 -05004845 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004846 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4847 "0235 Deferred RSCN "
4848 "Data: x%x x%x x%x\n",
4849 vport->fc_rscn_id_cnt, vport->fc_flag,
4850 vport->port_state);
dea31012005-04-17 16:05:31 -05004851 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004852 vport->fc_flag |= FC_RSCN_DISCOVERY;
4853 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004854 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004855 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4856 "0234 ReDiscovery RSCN "
4857 "Data: x%x x%x x%x\n",
4858 vport->fc_rscn_id_cnt, vport->fc_flag,
4859 vport->port_state);
dea31012005-04-17 16:05:31 -05004860 }
James Smart7f5f3d02008-02-08 18:50:14 -05004861 /* Indicate we are done walking fc_rscn_id_list on this vport */
4862 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004863 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004864 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004865 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004866 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004867 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004868 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004869 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004870 return 0;
dea31012005-04-17 16:05:31 -05004871 }
James Smart858c9f62007-06-17 19:56:39 -05004872 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4873 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4874 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4875
James Smart2e0fef82007-06-17 19:56:36 -05004876 spin_lock_irq(shost->host_lock);
4877 vport->fc_flag |= FC_RSCN_MODE;
4878 spin_unlock_irq(shost->host_lock);
4879 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004880 /* Indicate we are done walking fc_rscn_id_list on this vport */
4881 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004882 /*
4883 * If we zero, cmdiocb->context2, the calling routine will
4884 * not try to free it.
4885 */
4886 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004887 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004888 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004889 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004890 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004891 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004892 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004893}
4894
James Smarte59058c2008-08-24 21:49:00 -04004895/**
James Smart3621a712009-04-06 18:47:14 -04004896 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004897 * @vport: pointer to a host virtual N_Port data structure.
4898 *
4899 * This routine handles the Registration State Configuration Notification
4900 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4901 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4902 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4903 * NameServer shall be issued. If CT command to the NameServer fails to be
4904 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4905 * RSCN activities with the @vport.
4906 *
4907 * Return code
4908 * 0 - Cleaned up rscn on the @vport
4909 * 1 - Wait for plogi to name server before proceed
4910 **/
dea31012005-04-17 16:05:31 -05004911int
James Smart2e0fef82007-06-17 19:56:36 -05004912lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004913{
4914 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004915 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004916
James Smart92d7f7b2007-06-17 19:56:38 -05004917 /* Ignore RSCN if the port is being torn down. */
4918 if (vport->load_flag & FC_UNLOADING) {
4919 lpfc_els_flush_rscn(vport);
4920 return 0;
4921 }
4922
dea31012005-04-17 16:05:31 -05004923 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004924 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004925
4926 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004927 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4928 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4929 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4930 vport->port_state);
dea31012005-04-17 16:05:31 -05004931
4932 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004933 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004934 vport->num_disc_nodes = 0;
4935
James Smart2e0fef82007-06-17 19:56:36 -05004936 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004937 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4938 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004939 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004940 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004941 /* Wait for NameServer query cmpl before we can
4942 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004943 return 1;
dea31012005-04-17 16:05:31 -05004944 } else {
4945 /* If login to NameServer does not exist, issue one */
4946 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004947 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004948 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004949 /* Wait for NameServer login cmpl before we can
4950 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004951 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004952
James Smarte47c9092008-02-08 18:49:26 -05004953 if (ndlp) {
4954 ndlp = lpfc_enable_node(vport, ndlp,
4955 NLP_STE_PLOGI_ISSUE);
4956 if (!ndlp) {
4957 lpfc_els_flush_rscn(vport);
4958 return 0;
4959 }
4960 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004961 } else {
James Smarte47c9092008-02-08 18:49:26 -05004962 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4963 if (!ndlp) {
4964 lpfc_els_flush_rscn(vport);
4965 return 0;
4966 }
James Smart2e0fef82007-06-17 19:56:36 -05004967 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004968 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004969 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004970 }
James Smarte47c9092008-02-08 18:49:26 -05004971 ndlp->nlp_type |= NLP_FABRIC;
4972 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4973 /* Wait for NameServer login cmpl before we can
4974 * continue
4975 */
4976 return 1;
dea31012005-04-17 16:05:31 -05004977 }
4978
James Smart2e0fef82007-06-17 19:56:36 -05004979 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004980 return 0;
dea31012005-04-17 16:05:31 -05004981}
4982
James Smarte59058c2008-08-24 21:49:00 -04004983/**
James Smart3621a712009-04-06 18:47:14 -04004984 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004985 * @vport: pointer to a host virtual N_Port data structure.
4986 * @cmdiocb: pointer to lpfc command iocb data structure.
4987 * @ndlp: pointer to a node-list data structure.
4988 *
4989 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4990 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4991 * point topology. As an unsolicited FLOGI should not be received in a loop
4992 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4993 * lpfc_check_sparm() routine is invoked to check the parameters in the
4994 * unsolicited FLOGI. If parameters validation failed, the routine
4995 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4996 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4997 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4998 * will initiate PLOGI. The higher lexicographical value party shall has
4999 * higher priority (as the winning port) and will initiate PLOGI and
5000 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5001 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5002 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5003 *
5004 * Return code
5005 * 0 - Successfully processed the unsolicited flogi
5006 * 1 - Failed to process the unsolicited flogi
5007 **/
dea31012005-04-17 16:05:31 -05005008static int
James Smart2e0fef82007-06-17 19:56:36 -05005009lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04005010 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005011{
James Smart2e0fef82007-06-17 19:56:36 -05005012 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5013 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005014 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5015 uint32_t *lp = (uint32_t *) pcmd->virt;
5016 IOCB_t *icmd = &cmdiocb->iocb;
5017 struct serv_parm *sp;
5018 LPFC_MBOXQ_t *mbox;
5019 struct ls_rjt stat;
5020 uint32_t cmd, did;
5021 int rc;
5022
5023 cmd = *lp++;
5024 sp = (struct serv_parm *) lp;
5025
5026 /* FLOGI received */
5027
James Smart2e0fef82007-06-17 19:56:36 -05005028 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05005029
James Smart76a95d72010-11-20 23:11:48 -05005030 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05005031 /* We should never receive a FLOGI in loop mode, ignore it */
5032 did = icmd->un.elsreq64.remoteID;
5033
5034 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5035 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04005036 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5037 "0113 An FLOGI ELS command x%x was "
5038 "received from DID x%x in Loop Mode\n",
5039 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005040 return 1;
dea31012005-04-17 16:05:31 -05005041 }
5042
James Smart341af102010-01-26 23:07:37 -05005043 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05005044 /* For a FLOGI we accept, then if our portname is greater
5045 * then the remote portname we initiate Nport login.
5046 */
5047
James Smart2e0fef82007-06-17 19:56:36 -05005048 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05005049 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05005050
5051 if (!rc) {
James Smart1b511972011-12-13 13:23:09 -05005052 if (phba->sli_rev < LPFC_SLI_REV4) {
5053 mbox = mempool_alloc(phba->mbox_mem_pool,
5054 GFP_KERNEL);
5055 if (!mbox)
5056 return 1;
5057 lpfc_linkdown(phba);
5058 lpfc_init_link(phba, mbox,
5059 phba->cfg_topology,
5060 phba->cfg_link_speed);
5061 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
5062 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5063 mbox->vport = vport;
5064 rc = lpfc_sli_issue_mbox(phba, mbox,
5065 MBX_NOWAIT);
5066 lpfc_set_loopback_flag(phba);
5067 if (rc == MBX_NOT_FINISHED)
5068 mempool_free(mbox, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005069 return 1;
James Smart1b511972011-12-13 13:23:09 -05005070 } else {
5071 /* abort the flogi coming back to ourselves
5072 * due to external loopback on the port.
5073 */
5074 lpfc_els_abort_flogi(phba);
5075 return 0;
dea31012005-04-17 16:05:31 -05005076 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005077 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05005078 spin_lock_irq(shost->host_lock);
5079 vport->fc_flag |= FC_PT2PT_PLOGI;
5080 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005081
5082 /* If we have the high WWPN we can assign our own
5083 * myDID; otherwise, we have to WAIT for a PLOGI
5084 * from the remote NPort to find out what it
5085 * will be.
5086 */
James Smarte6446432012-05-09 21:16:42 -04005087 vport->fc_myDID = PT2PT_LocalID;
James Smart939723a2012-05-09 21:19:03 -04005088 }
5089
5090 /*
5091 * The vport state should go to LPFC_FLOGI only
5092 * AFTER we issue a FLOGI, not receive one.
5093 */
James Smart2e0fef82007-06-17 19:56:36 -05005094 spin_lock_irq(shost->host_lock);
5095 vport->fc_flag |= FC_PT2PT;
5096 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5097 spin_unlock_irq(shost->host_lock);
James Smart939723a2012-05-09 21:19:03 -04005098
5099 /*
5100 * We temporarily set fc_myDID to make it look like we are
5101 * a Fabric. This is done just so we end up with the right
5102 * did / sid on the FLOGI ACC rsp.
5103 */
5104 did = vport->fc_myDID;
5105 vport->fc_myDID = Fabric_DID;
5106
dea31012005-04-17 16:05:31 -05005107 } else {
5108 /* Reject this request because invalid parameters */
5109 stat.un.b.lsRjtRsvd0 = 0;
5110 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5111 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
5112 stat.un.b.vendorUnique = 0;
James Smart939723a2012-05-09 21:19:03 -04005113
5114 /*
5115 * We temporarily set fc_myDID to make it look like we are
5116 * a Fabric. This is done just so we end up with the right
5117 * did / sid on the FLOGI LS_RJT rsp.
5118 */
5119 did = vport->fc_myDID;
5120 vport->fc_myDID = Fabric_DID;
5121
James Smart858c9f62007-06-17 19:56:39 -05005122 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5123 NULL);
James Smart939723a2012-05-09 21:19:03 -04005124
5125 /* Now lets put fc_myDID back to what its supposed to be */
5126 vport->fc_myDID = did;
5127
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005128 return 1;
dea31012005-04-17 16:05:31 -05005129 }
5130
5131 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04005132 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005133
James Smart939723a2012-05-09 21:19:03 -04005134 /* Now lets put fc_myDID back to what its supposed to be */
5135 vport->fc_myDID = did;
5136
James Smarte6446432012-05-09 21:16:42 -04005137 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
James Smart939723a2012-05-09 21:19:03 -04005138
James Smarte6446432012-05-09 21:16:42 -04005139 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5140 if (!mbox)
5141 goto fail;
5142
5143 lpfc_config_link(phba, mbox);
5144
5145 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
5146 mbox->vport = vport;
5147 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5148 if (rc == MBX_NOT_FINISHED) {
5149 mempool_free(mbox, phba->mbox_mem_pool);
5150 goto fail;
5151 }
5152 }
5153
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005154 return 0;
James Smarte6446432012-05-09 21:16:42 -04005155fail:
5156 return 1;
dea31012005-04-17 16:05:31 -05005157}
5158
James Smarte59058c2008-08-24 21:49:00 -04005159/**
James Smart3621a712009-04-06 18:47:14 -04005160 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04005161 * @vport: pointer to a host virtual N_Port data structure.
5162 * @cmdiocb: pointer to lpfc command iocb data structure.
5163 * @ndlp: pointer to a node-list data structure.
5164 *
5165 * This routine processes Request Node Identification Data (RNID) IOCB
5166 * received as an ELS unsolicited event. Only when the RNID specified format
5167 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5168 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5169 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5170 * rejected by invoking the lpfc_els_rsp_reject() routine.
5171 *
5172 * Return code
5173 * 0 - Successfully processed rnid iocb (currently always return 0)
5174 **/
dea31012005-04-17 16:05:31 -05005175static int
James Smart2e0fef82007-06-17 19:56:36 -05005176lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5177 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005178{
5179 struct lpfc_dmabuf *pcmd;
5180 uint32_t *lp;
5181 IOCB_t *icmd;
5182 RNID *rn;
5183 struct ls_rjt stat;
5184 uint32_t cmd, did;
5185
5186 icmd = &cmdiocb->iocb;
5187 did = icmd->un.elsreq64.remoteID;
5188 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5189 lp = (uint32_t *) pcmd->virt;
5190
5191 cmd = *lp++;
5192 rn = (RNID *) lp;
5193
5194 /* RNID received */
5195
5196 switch (rn->Format) {
5197 case 0:
5198 case RNID_TOPOLOGY_DISC:
5199 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05005200 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005201 break;
5202 default:
5203 /* Reject this request because format not supported */
5204 stat.un.b.lsRjtRsvd0 = 0;
5205 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5206 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5207 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005208 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5209 NULL);
dea31012005-04-17 16:05:31 -05005210 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005211 return 0;
dea31012005-04-17 16:05:31 -05005212}
5213
James Smarte59058c2008-08-24 21:49:00 -04005214/**
James Smart12265f62010-10-22 11:05:53 -04005215 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5216 * @vport: pointer to a host virtual N_Port data structure.
5217 * @cmdiocb: pointer to lpfc command iocb data structure.
5218 * @ndlp: pointer to a node-list data structure.
5219 *
5220 * Return code
5221 * 0 - Successfully processed echo iocb (currently always return 0)
5222 **/
5223static int
5224lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5225 struct lpfc_nodelist *ndlp)
5226{
5227 uint8_t *pcmd;
5228
5229 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
5230
5231 /* skip over first word of echo command to find echo data */
5232 pcmd += sizeof(uint32_t);
5233
5234 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
5235 return 0;
5236}
5237
5238/**
James Smart3621a712009-04-06 18:47:14 -04005239 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04005240 * @vport: pointer to a host virtual N_Port data structure.
5241 * @cmdiocb: pointer to lpfc command iocb data structure.
5242 * @ndlp: pointer to a node-list data structure.
5243 *
5244 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5245 * received as an ELS unsolicited event. Currently, this function just invokes
5246 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5247 *
5248 * Return code
5249 * 0 - Successfully processed lirr iocb (currently always return 0)
5250 **/
dea31012005-04-17 16:05:31 -05005251static int
James Smart2e0fef82007-06-17 19:56:36 -05005252lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5253 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005254{
5255 struct ls_rjt stat;
5256
5257 /* For now, unconditionally reject this command */
5258 stat.un.b.lsRjtRsvd0 = 0;
5259 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5260 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5261 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005262 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005263 return 0;
5264}
5265
James Smarte59058c2008-08-24 21:49:00 -04005266/**
James Smart5ffc2662009-11-18 15:39:44 -05005267 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5268 * @vport: pointer to a host virtual N_Port data structure.
5269 * @cmdiocb: pointer to lpfc command iocb data structure.
5270 * @ndlp: pointer to a node-list data structure.
5271 *
5272 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5273 * received as an ELS unsolicited event. A request to RRQ shall only
5274 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5275 * Nx_Port N_Port_ID of the target Exchange is the same as the
5276 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5277 * not accepted, an LS_RJT with reason code "Unable to perform
5278 * command request" and reason code explanation "Invalid Originator
5279 * S_ID" shall be returned. For now, we just unconditionally accept
5280 * RRQ from the target.
5281 **/
5282static void
5283lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5284 struct lpfc_nodelist *ndlp)
5285{
5286 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05005287 if (vport->phba->sli_rev == LPFC_SLI_REV4)
5288 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05005289}
5290
5291/**
James Smart12265f62010-10-22 11:05:53 -04005292 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5293 * @phba: pointer to lpfc hba data structure.
5294 * @pmb: pointer to the driver internal queue element for mailbox command.
5295 *
5296 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5297 * mailbox command. This callback function is to actually send the Accept
5298 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5299 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5300 * mailbox command, constructs the RPS response with the link statistics
5301 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5302 * response to the RPS.
5303 *
5304 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5305 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5306 * will be stored into the context1 field of the IOCB for the completion
5307 * callback function to the RPS Accept Response ELS IOCB command.
5308 *
5309 **/
5310static void
5311lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5312{
5313 MAILBOX_t *mb;
5314 IOCB_t *icmd;
5315 struct RLS_RSP *rls_rsp;
5316 uint8_t *pcmd;
5317 struct lpfc_iocbq *elsiocb;
5318 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005319 uint16_t oxid;
5320 uint16_t rxid;
James Smart12265f62010-10-22 11:05:53 -04005321 uint32_t cmdsize;
5322
5323 mb = &pmb->u.mb;
5324
5325 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005326 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5327 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
James Smart12265f62010-10-22 11:05:53 -04005328 pmb->context1 = NULL;
5329 pmb->context2 = NULL;
5330
5331 if (mb->mbxStatus) {
5332 mempool_free(pmb, phba->mbox_mem_pool);
5333 return;
5334 }
5335
5336 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
James Smart12265f62010-10-22 11:05:53 -04005337 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5338 lpfc_max_els_tries, ndlp,
5339 ndlp->nlp_DID, ELS_CMD_ACC);
5340
5341 /* Decrement the ndlp reference count from previous mbox command */
5342 lpfc_nlp_put(ndlp);
5343
James Smart37db57e2012-05-09 21:17:16 -04005344 if (!elsiocb) {
5345 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005346 return;
James Smart37db57e2012-05-09 21:17:16 -04005347 }
James Smart12265f62010-10-22 11:05:53 -04005348
5349 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005350 icmd->ulpContext = rxid;
5351 icmd->unsli3.rcvsli3.ox_id = oxid;
James Smart12265f62010-10-22 11:05:53 -04005352
5353 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5354 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5355 pcmd += sizeof(uint32_t); /* Skip past command */
5356 rls_rsp = (struct RLS_RSP *)pcmd;
5357
5358 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5359 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5360 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5361 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5362 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5363 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
James Smart37db57e2012-05-09 21:17:16 -04005364 mempool_free(pmb, phba->mbox_mem_pool);
James Smart12265f62010-10-22 11:05:53 -04005365 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5366 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5367 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5368 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5369 elsiocb->iotag, elsiocb->iocb.ulpContext,
5370 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5371 ndlp->nlp_rpi);
5372 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5373 phba->fc_stat.elsXmitACC++;
5374 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5375 lpfc_els_free_iocb(phba, elsiocb);
5376}
5377
5378/**
James Smart3621a712009-04-06 18:47:14 -04005379 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005380 * @phba: pointer to lpfc hba data structure.
5381 * @pmb: pointer to the driver internal queue element for mailbox command.
5382 *
5383 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5384 * mailbox command. This callback function is to actually send the Accept
5385 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5386 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5387 * mailbox command, constructs the RPS response with the link statistics
5388 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5389 * response to the RPS.
5390 *
5391 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5392 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5393 * will be stored into the context1 field of the IOCB for the completion
5394 * callback function to the RPS Accept Response ELS IOCB command.
5395 *
5396 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005397static void
James Smart329f9bc2007-04-25 09:53:01 -04005398lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005399{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005400 MAILBOX_t *mb;
5401 IOCB_t *icmd;
5402 RPS_RSP *rps_rsp;
5403 uint8_t *pcmd;
5404 struct lpfc_iocbq *elsiocb;
5405 struct lpfc_nodelist *ndlp;
James Smart7851fe22011-07-22 18:36:52 -04005406 uint16_t status;
5407 uint16_t oxid;
5408 uint16_t rxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005409 uint32_t cmdsize;
5410
James Smart04c68492009-05-22 14:52:52 -04005411 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005412
5413 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart7851fe22011-07-22 18:36:52 -04005414 rxid = (uint16_t) ((unsigned long)(pmb->context1) & 0xffff);
5415 oxid = (uint16_t) (((unsigned long)(pmb->context1) >> 16) & 0xffff);
Randy Dunlap041976f2006-06-25 01:58:51 -07005416 pmb->context1 = NULL;
5417 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005418
5419 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005420 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005421 return;
5422 }
5423
5424 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005425 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005426 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5427 lpfc_max_els_tries, ndlp,
5428 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005429
5430 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005431 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005432
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005433 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005434 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005435
5436 icmd = &elsiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005437 icmd->ulpContext = rxid;
5438 icmd->unsli3.rcvsli3.ox_id = oxid;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005439
5440 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5441 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005442 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005443 rps_rsp = (RPS_RSP *)pcmd;
5444
James Smart76a95d72010-11-20 23:11:48 -05005445 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005446 status = 0x10;
5447 else
5448 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005449 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005450 status |= 0x4;
5451
5452 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005453 rps_rsp->portStatus = cpu_to_be16(status);
5454 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5455 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5456 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5457 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5458 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5459 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005460 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005461 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5462 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5463 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5464 elsiocb->iotag, elsiocb->iocb.ulpContext,
5465 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5466 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005467 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005468 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005469 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005470 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005471 return;
5472}
5473
James Smarte59058c2008-08-24 21:49:00 -04005474/**
James Smart12265f62010-10-22 11:05:53 -04005475 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5476 * @vport: pointer to a host virtual N_Port data structure.
5477 * @cmdiocb: pointer to lpfc command iocb data structure.
5478 * @ndlp: pointer to a node-list data structure.
5479 *
5480 * This routine processes Read Port Status (RPL) IOCB received as an
5481 * ELS unsolicited event. It first checks the remote port state. If the
5482 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5483 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5484 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5485 * for reading the HBA link statistics. It is for the callback function,
5486 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5487 * to actually sending out RPL Accept (ACC) response.
5488 *
5489 * Return codes
5490 * 0 - Successfully processed rls iocb (currently always return 0)
5491 **/
5492static int
5493lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5494 struct lpfc_nodelist *ndlp)
5495{
5496 struct lpfc_hba *phba = vport->phba;
5497 LPFC_MBOXQ_t *mbox;
5498 struct lpfc_dmabuf *pcmd;
5499 struct ls_rjt stat;
5500
5501 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5502 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5503 /* reject the unsolicited RPS request and done with it */
5504 goto reject_out;
5505
5506 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5507
5508 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5509 if (mbox) {
5510 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005511 mbox->context1 = (void *)((unsigned long)
5512 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5513 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart12265f62010-10-22 11:05:53 -04005514 mbox->context2 = lpfc_nlp_get(ndlp);
5515 mbox->vport = vport;
5516 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5517 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5518 != MBX_NOT_FINISHED)
5519 /* Mbox completion will send ELS Response */
5520 return 0;
5521 /* Decrement reference count used for the failed mbox
5522 * command.
5523 */
5524 lpfc_nlp_put(ndlp);
5525 mempool_free(mbox, phba->mbox_mem_pool);
5526 }
5527reject_out:
5528 /* issue rejection response */
5529 stat.un.b.lsRjtRsvd0 = 0;
5530 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5531 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5532 stat.un.b.vendorUnique = 0;
5533 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5534 return 0;
5535}
5536
5537/**
5538 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5539 * @vport: pointer to a host virtual N_Port data structure.
5540 * @cmdiocb: pointer to lpfc command iocb data structure.
5541 * @ndlp: pointer to a node-list data structure.
5542 *
5543 * This routine processes Read Timout Value (RTV) IOCB received as an
5544 * ELS unsolicited event. It first checks the remote port state. If the
5545 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5546 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5547 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5548 * Value (RTV) unsolicited IOCB event.
5549 *
5550 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5551 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5552 * will be stored into the context1 field of the IOCB for the completion
5553 * callback function to the RPS Accept Response ELS IOCB command.
5554 *
5555 * Return codes
5556 * 0 - Successfully processed rtv iocb (currently always return 0)
5557 **/
5558static int
5559lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5560 struct lpfc_nodelist *ndlp)
5561{
5562 struct lpfc_hba *phba = vport->phba;
5563 struct ls_rjt stat;
5564 struct RTV_RSP *rtv_rsp;
5565 uint8_t *pcmd;
5566 struct lpfc_iocbq *elsiocb;
5567 uint32_t cmdsize;
5568
5569
5570 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5571 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5572 /* reject the unsolicited RPS request and done with it */
5573 goto reject_out;
5574
5575 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5576 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5577 lpfc_max_els_tries, ndlp,
5578 ndlp->nlp_DID, ELS_CMD_ACC);
5579
5580 if (!elsiocb)
5581 return 1;
5582
5583 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5584 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5585 pcmd += sizeof(uint32_t); /* Skip past command */
5586
5587 /* use the command's xri in the response */
James Smart7851fe22011-07-22 18:36:52 -04005588 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext; /* Xri / rx_id */
5589 elsiocb->iocb.unsli3.rcvsli3.ox_id = cmdiocb->iocb.unsli3.rcvsli3.ox_id;
James Smart12265f62010-10-22 11:05:53 -04005590
5591 rtv_rsp = (struct RTV_RSP *)pcmd;
5592
5593 /* populate RTV payload */
5594 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5595 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5596 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5597 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5598 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5599
5600 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5601 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5602 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5603 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5604 "Data: x%x x%x x%x\n",
5605 elsiocb->iotag, elsiocb->iocb.ulpContext,
5606 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5607 ndlp->nlp_rpi,
5608 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5609 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5610 phba->fc_stat.elsXmitACC++;
5611 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5612 lpfc_els_free_iocb(phba, elsiocb);
5613 return 0;
5614
5615reject_out:
5616 /* issue rejection response */
5617 stat.un.b.lsRjtRsvd0 = 0;
5618 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5619 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5620 stat.un.b.vendorUnique = 0;
5621 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5622 return 0;
5623}
5624
5625/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005626 * @vport: pointer to a host virtual N_Port data structure.
5627 * @cmdiocb: pointer to lpfc command iocb data structure.
5628 * @ndlp: pointer to a node-list data structure.
5629 *
5630 * This routine processes Read Port Status (RPS) IOCB received as an
5631 * ELS unsolicited event. It first checks the remote port state. If the
5632 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5633 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5634 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5635 * for reading the HBA link statistics. It is for the callback function,
5636 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5637 * to actually sending out RPS Accept (ACC) response.
5638 *
5639 * Return codes
5640 * 0 - Successfully processed rps iocb (currently always return 0)
5641 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005642static int
James Smart2e0fef82007-06-17 19:56:36 -05005643lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5644 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005645{
James Smart2e0fef82007-06-17 19:56:36 -05005646 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005647 uint32_t *lp;
5648 uint8_t flag;
5649 LPFC_MBOXQ_t *mbox;
5650 struct lpfc_dmabuf *pcmd;
5651 RPS *rps;
5652 struct ls_rjt stat;
5653
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005654 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005655 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5656 /* reject the unsolicited RPS request and done with it */
5657 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005658
5659 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5660 lp = (uint32_t *) pcmd->virt;
5661 flag = (be32_to_cpu(*lp++) & 0xf);
5662 rps = (RPS *) lp;
5663
5664 if ((flag == 0) ||
5665 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005666 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005667 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005668
James Smart92d7f7b2007-06-17 19:56:38 -05005669 printk("Fix me....\n");
5670 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005671 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5672 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005673 lpfc_read_lnk_stat(phba, mbox);
James Smart7851fe22011-07-22 18:36:52 -04005674 mbox->context1 = (void *)((unsigned long)
5675 ((cmdiocb->iocb.unsli3.rcvsli3.ox_id << 16) |
5676 cmdiocb->iocb.ulpContext)); /* rx_id */
James Smart329f9bc2007-04-25 09:53:01 -04005677 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005678 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005679 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005680 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005681 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005682 /* Mbox completion will send ELS Response */
5683 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005684 /* Decrement reference count used for the failed mbox
5685 * command.
5686 */
James Smart329f9bc2007-04-25 09:53:01 -04005687 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005688 mempool_free(mbox, phba->mbox_mem_pool);
5689 }
5690 }
James Smart90160e02008-08-24 21:49:45 -04005691
5692reject_out:
5693 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005694 stat.un.b.lsRjtRsvd0 = 0;
5695 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5696 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5697 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005698 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005699 return 0;
5700}
5701
James Smart19ca7602010-11-20 23:11:55 -05005702/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5703 * @vport: pointer to a host virtual N_Port data structure.
5704 * @ndlp: pointer to a node-list data structure.
5705 * @did: DID of the target.
5706 * @rrq: Pointer to the rrq struct.
5707 *
5708 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5709 * Successful the the completion handler will clear the RRQ.
5710 *
5711 * Return codes
5712 * 0 - Successfully sent rrq els iocb.
5713 * 1 - Failed to send rrq els iocb.
5714 **/
5715static int
5716lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5717 uint32_t did, struct lpfc_node_rrq *rrq)
5718{
5719 struct lpfc_hba *phba = vport->phba;
5720 struct RRQ *els_rrq;
5721 IOCB_t *icmd;
5722 struct lpfc_iocbq *elsiocb;
5723 uint8_t *pcmd;
5724 uint16_t cmdsize;
5725 int ret;
5726
5727
5728 if (ndlp != rrq->ndlp)
5729 ndlp = rrq->ndlp;
5730 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5731 return 1;
5732
5733 /* If ndlp is not NULL, we will bump the reference count on it */
5734 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5735 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5736 ELS_CMD_RRQ);
5737 if (!elsiocb)
5738 return 1;
5739
5740 icmd = &elsiocb->iocb;
5741 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5742
5743 /* For RRQ request, remainder of payload is Exchange IDs */
5744 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5745 pcmd += sizeof(uint32_t);
5746 els_rrq = (struct RRQ *) pcmd;
5747
James Smartee0f4fe2012-05-09 21:19:14 -04005748 bf_set(rrq_oxid, els_rrq, phba->sli4_hba.xri_ids[rrq->xritag]);
James Smart19ca7602010-11-20 23:11:55 -05005749 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5750 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5751 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5752 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5753
5754
5755 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5756 "Issue RRQ: did:x%x",
5757 did, rrq->xritag, rrq->rxid);
5758 elsiocb->context_un.rrq = rrq;
5759 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5760 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5761
5762 if (ret == IOCB_ERROR) {
5763 lpfc_els_free_iocb(phba, elsiocb);
5764 return 1;
5765 }
5766 return 0;
5767}
5768
5769/**
5770 * lpfc_send_rrq - Sends ELS RRQ if needed.
5771 * @phba: pointer to lpfc hba data structure.
5772 * @rrq: pointer to the active rrq.
5773 *
5774 * This routine will call the lpfc_issue_els_rrq if the rrq is
5775 * still active for the xri. If this function returns a failure then
5776 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5777 *
5778 * Returns 0 Success.
5779 * 1 Failure.
5780 **/
5781int
5782lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5783{
5784 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5785 rrq->nlp_DID);
5786 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5787 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5788 rrq->nlp_DID, rrq);
5789 else
5790 return 1;
5791}
5792
James Smarte59058c2008-08-24 21:49:00 -04005793/**
James Smart3621a712009-04-06 18:47:14 -04005794 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005795 * @vport: pointer to a host virtual N_Port data structure.
5796 * @cmdsize: size of the ELS command.
5797 * @oldiocb: pointer to the original lpfc command iocb data structure.
5798 * @ndlp: pointer to a node-list data structure.
5799 *
5800 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5801 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5802 *
5803 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5804 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5805 * will be stored into the context1 field of the IOCB for the completion
5806 * callback function to the RPL Accept Response ELS command.
5807 *
5808 * Return code
5809 * 0 - Successfully issued ACC RPL ELS command
5810 * 1 - Failed to issue ACC RPL ELS command
5811 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005812static int
James Smart2e0fef82007-06-17 19:56:36 -05005813lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5814 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005815{
James Smart2e0fef82007-06-17 19:56:36 -05005816 struct lpfc_hba *phba = vport->phba;
5817 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005818 RPL_RSP rpl_rsp;
5819 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005820 uint8_t *pcmd;
5821
James Smart2e0fef82007-06-17 19:56:36 -05005822 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5823 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005824
James Smart488d1462006-03-07 15:02:37 -05005825 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005826 return 1;
James Smart488d1462006-03-07 15:02:37 -05005827
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005828 icmd = &elsiocb->iocb;
5829 oldcmd = &oldiocb->iocb;
James Smart7851fe22011-07-22 18:36:52 -04005830 icmd->ulpContext = oldcmd->ulpContext; /* Xri / rx_id */
5831 icmd->unsli3.rcvsli3.ox_id = oldcmd->unsli3.rcvsli3.ox_id;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005832
5833 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5834 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005835 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005836 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5837 pcmd += sizeof(uint16_t);
5838
5839 /* Setup the RPL ACC payload */
5840 rpl_rsp.listLen = be32_to_cpu(1);
5841 rpl_rsp.index = 0;
5842 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005843 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5844 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005845 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005846 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005847 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005848 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5849 "0120 Xmit ELS RPL ACC response tag x%x "
5850 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5851 "rpi x%x\n",
5852 elsiocb->iotag, elsiocb->iocb.ulpContext,
5853 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5854 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005855 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005856 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005857 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5858 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005859 lpfc_els_free_iocb(phba, elsiocb);
5860 return 1;
5861 }
5862 return 0;
5863}
5864
James Smarte59058c2008-08-24 21:49:00 -04005865/**
James Smart3621a712009-04-06 18:47:14 -04005866 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005867 * @vport: pointer to a host virtual N_Port data structure.
5868 * @cmdiocb: pointer to lpfc command iocb data structure.
5869 * @ndlp: pointer to a node-list data structure.
5870 *
5871 * This routine processes Read Port List (RPL) IOCB received as an ELS
5872 * unsolicited event. It first checks the remote port state. If the remote
5873 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5874 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5875 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5876 * to accept the RPL.
5877 *
5878 * Return code
5879 * 0 - Successfully processed rpl iocb (currently always return 0)
5880 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005881static int
James Smart2e0fef82007-06-17 19:56:36 -05005882lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5883 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005884{
5885 struct lpfc_dmabuf *pcmd;
5886 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005887 uint32_t maxsize;
5888 uint16_t cmdsize;
5889 RPL *rpl;
5890 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005891
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005892 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5893 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005894 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005895 stat.un.b.lsRjtRsvd0 = 0;
5896 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5897 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5898 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005899 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5900 NULL);
James Smart90160e02008-08-24 21:49:45 -04005901 /* rejected the unsolicited RPL request and done with it */
5902 return 0;
dea31012005-04-17 16:05:31 -05005903 }
5904
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005905 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5906 lp = (uint32_t *) pcmd->virt;
5907 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005908 maxsize = be32_to_cpu(rpl->maxsize);
5909
5910 /* We support only one port */
5911 if ((rpl->index == 0) &&
5912 ((maxsize == 0) ||
5913 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5914 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005915 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005916 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5917 }
James Smart2e0fef82007-06-17 19:56:36 -05005918 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005919
5920 return 0;
5921}
5922
James Smarte59058c2008-08-24 21:49:00 -04005923/**
James Smart3621a712009-04-06 18:47:14 -04005924 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005925 * @vport: pointer to a virtual N_Port data structure.
5926 * @cmdiocb: pointer to lpfc command iocb data structure.
5927 * @ndlp: pointer to a node-list data structure.
5928 *
5929 * This routine processes Fibre Channel Address Resolution Protocol
5930 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5931 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5932 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5933 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5934 * remote PortName is compared against the FC PortName stored in the @vport
5935 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5936 * compared against the FC NodeName stored in the @vport data structure.
5937 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5938 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5939 * invoked to send out FARP Response to the remote node. Before sending the
5940 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5941 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5942 * routine is invoked to log into the remote port first.
5943 *
5944 * Return code
5945 * 0 - Either the FARP Match Mode not supported or successfully processed
5946 **/
dea31012005-04-17 16:05:31 -05005947static int
James Smart2e0fef82007-06-17 19:56:36 -05005948lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5949 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005950{
5951 struct lpfc_dmabuf *pcmd;
5952 uint32_t *lp;
5953 IOCB_t *icmd;
5954 FARP *fp;
5955 uint32_t cmd, cnt, did;
5956
5957 icmd = &cmdiocb->iocb;
5958 did = icmd->un.elsreq64.remoteID;
5959 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5960 lp = (uint32_t *) pcmd->virt;
5961
5962 cmd = *lp++;
5963 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005964 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005965 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5966 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005967 /* We will only support match on WWPN or WWNN */
5968 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005969 return 0;
dea31012005-04-17 16:05:31 -05005970 }
5971
5972 cnt = 0;
5973 /* If this FARP command is searching for my portname */
5974 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005975 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005976 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005977 cnt = 1;
5978 }
5979
5980 /* If this FARP command is searching for my nodename */
5981 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005982 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005983 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005984 cnt = 1;
5985 }
5986
5987 if (cnt) {
5988 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5989 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5990 /* Log back into the node before sending the FARP. */
5991 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005992 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005993 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005994 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005995 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005996 }
5997
5998 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005999 if (fp->Rflags & FARP_REQUEST_FARPR)
6000 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05006001 }
6002 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006003 return 0;
dea31012005-04-17 16:05:31 -05006004}
6005
James Smarte59058c2008-08-24 21:49:00 -04006006/**
James Smart3621a712009-04-06 18:47:14 -04006007 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04006008 * @vport: pointer to a host virtual N_Port data structure.
6009 * @cmdiocb: pointer to lpfc command iocb data structure.
6010 * @ndlp: pointer to a node-list data structure.
6011 *
6012 * This routine processes Fibre Channel Address Resolution Protocol
6013 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6014 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6015 * the FARP response request.
6016 *
6017 * Return code
6018 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6019 **/
dea31012005-04-17 16:05:31 -05006020static int
James Smart2e0fef82007-06-17 19:56:36 -05006021lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6022 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05006023{
6024 struct lpfc_dmabuf *pcmd;
6025 uint32_t *lp;
6026 IOCB_t *icmd;
6027 uint32_t cmd, did;
6028
6029 icmd = &cmdiocb->iocb;
6030 did = icmd->un.elsreq64.remoteID;
6031 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
6032 lp = (uint32_t *) pcmd->virt;
6033
6034 cmd = *lp++;
6035 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04006036 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6037 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05006038 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04006039 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05006040
6041 return 0;
6042}
6043
James Smarte59058c2008-08-24 21:49:00 -04006044/**
James Smart3621a712009-04-06 18:47:14 -04006045 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04006046 * @vport: pointer to a host virtual N_Port data structure.
6047 * @cmdiocb: pointer to lpfc command iocb data structure.
6048 * @fan_ndlp: pointer to a node-list data structure.
6049 *
6050 * This routine processes a Fabric Address Notification (FAN) IOCB
6051 * command received as an ELS unsolicited event. The FAN ELS command will
6052 * only be processed on a physical port (i.e., the @vport represents the
6053 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6054 * compared against those in the phba data structure. If any of those is
6055 * different, the lpfc_initial_flogi() routine is invoked to initialize
6056 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6057 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6058 * is invoked to register login to the fabric.
6059 *
6060 * Return code
6061 * 0 - Successfully processed fan iocb (currently always return 0).
6062 **/
dea31012005-04-17 16:05:31 -05006063static int
James Smart2e0fef82007-06-17 19:56:36 -05006064lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
6065 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05006066{
James Smart2e0fef82007-06-17 19:56:36 -05006067 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04006068 uint32_t *lp;
6069 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006070
James Smart0d2b6b82008-06-14 22:52:47 -04006071 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
6072 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
6073 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006074 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04006075 if ((vport == phba->pport) &&
6076 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006077 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04006078 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05006079 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04006080 sizeof(struct lpfc_name)))) {
6081 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05006082 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04006083 } else {
6084 /* FAN verified - skip FLOGI */
6085 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04006086 if (phba->sli_rev < LPFC_SLI_REV4)
6087 lpfc_issue_fabric_reglogin(vport);
James Smart1b511972011-12-13 13:23:09 -05006088 else {
6089 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6090 "3138 Need register VFI: (x%x/%x)\n",
6091 vport->fc_prevDID, vport->fc_myDID);
James Smart6fb120a2009-05-22 14:52:59 -04006092 lpfc_issue_reg_vfi(vport);
James Smart1b511972011-12-13 13:23:09 -05006093 }
dea31012005-04-17 16:05:31 -05006094 }
dea31012005-04-17 16:05:31 -05006095 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006096 return 0;
dea31012005-04-17 16:05:31 -05006097}
6098
James Smarte59058c2008-08-24 21:49:00 -04006099/**
James Smart3621a712009-04-06 18:47:14 -04006100 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04006101 * @ptr: holder for the timer function associated data.
6102 *
6103 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6104 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6105 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6106 * up the worker thread. It is for the worker thread to invoke the routine
6107 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6108 **/
dea31012005-04-17 16:05:31 -05006109void
6110lpfc_els_timeout(unsigned long ptr)
6111{
James Smart2e0fef82007-06-17 19:56:36 -05006112 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
6113 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04006114 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05006115 unsigned long iflag;
6116
James Smart2e0fef82007-06-17 19:56:36 -05006117 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04006118 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
6119 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05006120 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04006121 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05006122
James Smart5e9d9b82008-06-14 22:52:53 -04006123 if (!tmo_posted)
6124 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05006125 return;
6126}
6127
James Smart2a9bf3d2010-06-07 15:24:45 -04006128
James Smarte59058c2008-08-24 21:49:00 -04006129/**
James Smart3621a712009-04-06 18:47:14 -04006130 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04006131 * @vport: pointer to a virtual N_Port data structure.
6132 *
6133 * This routine is the actual handler function that processes an ELS timeout
6134 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6135 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6136 * invoking the lpfc_sli_issue_abort_iotag() routine.
6137 **/
dea31012005-04-17 16:05:31 -05006138void
James Smart2e0fef82007-06-17 19:56:36 -05006139lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006140{
James Smart2e0fef82007-06-17 19:56:36 -05006141 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05006142 struct lpfc_sli_ring *pring;
6143 struct lpfc_iocbq *tmp_iocb, *piocb;
6144 IOCB_t *cmd = NULL;
6145 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05006146 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05006147 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05006148 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04006149 LIST_HEAD(txcmplq_completions);
6150 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05006151
James Smart2a9bf3d2010-06-07 15:24:45 -04006152
dea31012005-04-17 16:05:31 -05006153 timeout = (uint32_t)(phba->fc_ratov << 1);
6154
6155 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006156
James Smart2a9bf3d2010-06-07 15:24:45 -04006157 spin_lock_irq(&phba->hbalock);
6158 list_splice_init(&pring->txcmplq, &txcmplq_completions);
6159 spin_unlock_irq(&phba->hbalock);
6160
6161 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05006162 cmd = &piocb->iocb;
6163
James Smart2e0fef82007-06-17 19:56:36 -05006164 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
6165 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
6166 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05006167 continue;
James Smart2e0fef82007-06-17 19:56:36 -05006168
6169 if (piocb->vport != vport)
6170 continue;
6171
dea31012005-04-17 16:05:31 -05006172 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05006173 if (pcmd)
6174 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05006175
James Smart92d7f7b2007-06-17 19:56:38 -05006176 if (els_command == ELS_CMD_FARP ||
6177 els_command == ELS_CMD_FARPR ||
6178 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05006179 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05006180
dea31012005-04-17 16:05:31 -05006181 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05006182 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05006183 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05006184 else
dea31012005-04-17 16:05:31 -05006185 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05006186 continue;
6187 }
6188
James Smart2e0fef82007-06-17 19:56:36 -05006189 remote_ID = 0xffffffff;
6190 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05006191 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05006192 else {
6193 struct lpfc_nodelist *ndlp;
6194 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04006195 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05006196 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05006197 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006198 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05006199 }
James Smart2a9bf3d2010-06-07 15:24:45 -04006200 spin_lock_irq(&phba->hbalock);
6201 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05006202 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04006203
James Smart2a9bf3d2010-06-07 15:24:45 -04006204 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
6205 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6206 "0127 ELS timeout Data: x%x x%x x%x "
6207 "x%x\n", els_command,
6208 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
6209 spin_lock_irq(&phba->hbalock);
6210 list_del_init(&piocb->dlist);
6211 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6212 spin_unlock_irq(&phba->hbalock);
6213 }
6214
James Smart2e0fef82007-06-17 19:56:36 -05006215 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
6216 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05006217}
6218
James Smarte59058c2008-08-24 21:49:00 -04006219/**
James Smart3621a712009-04-06 18:47:14 -04006220 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04006221 * @vport: pointer to a host virtual N_Port data structure.
6222 *
6223 * This routine is used to clean up all the outstanding ELS commands on a
6224 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6225 * routine. After that, it walks the ELS transmit queue to remove all the
6226 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6227 * the IOCBs with a non-NULL completion callback function, the callback
6228 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6229 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6230 * callback function, the IOCB will simply be released. Finally, it walks
6231 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6232 * completion queue IOCB that is associated with the @vport and is not
6233 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6234 * part of the discovery state machine) out to HBA by invoking the
6235 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6236 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6237 * the IOCBs are aborted when this function returns.
6238 **/
dea31012005-04-17 16:05:31 -05006239void
James Smart2e0fef82007-06-17 19:56:36 -05006240lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05006241{
James Smart2534ba72007-04-25 09:52:20 -04006242 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05006243 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04006244 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05006245 struct lpfc_iocbq *tmp_iocb, *piocb;
6246 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006247
6248 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05006249
James Smart2e0fef82007-06-17 19:56:36 -05006250 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05006251 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6252 cmd = &piocb->iocb;
6253
6254 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6255 continue;
6256 }
6257
6258 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04006259 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6260 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6261 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6262 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05006263 continue;
dea31012005-04-17 16:05:31 -05006264
James Smart2e0fef82007-06-17 19:56:36 -05006265 if (piocb->vport != vport)
6266 continue;
6267
James Smart2534ba72007-04-25 09:52:20 -04006268 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04006269 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05006270 }
6271
6272 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05006273 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
6274 continue;
6275 }
dea31012005-04-17 16:05:31 -05006276
James Smart2e0fef82007-06-17 19:56:36 -05006277 if (piocb->vport != vport)
6278 continue;
6279
James Smart07951072007-04-25 09:51:38 -04006280 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05006281 }
James Smart2e0fef82007-06-17 19:56:36 -05006282 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04006283
James Smarta257bf92009-04-06 18:48:10 -04006284 /* Cancell all the IOCBs from the completions list */
6285 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6286 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04006287
dea31012005-04-17 16:05:31 -05006288 return;
6289}
6290
James Smarte59058c2008-08-24 21:49:00 -04006291/**
James Smart3621a712009-04-06 18:47:14 -04006292 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04006293 * @phba: pointer to lpfc hba data structure.
6294 *
6295 * This routine is used to clean up all the outstanding ELS commands on a
6296 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6297 * routine. After that, it walks the ELS transmit queue to remove all the
6298 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6299 * the IOCBs with the completion callback function associated, the callback
6300 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6301 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6302 * callback function associated, the IOCB will simply be released. Finally,
6303 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6304 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6305 * management plane IOCBs that are not part of the discovery state machine)
6306 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6307 **/
James Smart549e55c2007-08-02 11:09:51 -04006308void
6309lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
6310{
6311 LIST_HEAD(completions);
6312 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6313 struct lpfc_iocbq *tmp_iocb, *piocb;
6314 IOCB_t *cmd = NULL;
6315
6316 lpfc_fabric_abort_hba(phba);
6317 spin_lock_irq(&phba->hbalock);
6318 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
6319 cmd = &piocb->iocb;
6320 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6321 continue;
6322 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6323 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
6324 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
6325 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
6326 cmd->ulpCommand == CMD_ABORT_XRI_CN)
6327 continue;
6328 list_move_tail(&piocb->list, &completions);
6329 pring->txq_cnt--;
6330 }
6331 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
6332 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
6333 continue;
6334 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
6335 }
6336 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04006337
6338 /* Cancel all the IOCBs from the completions list */
6339 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6340 IOERR_SLI_ABORTED);
6341
James Smart549e55c2007-08-02 11:09:51 -04006342 return;
6343}
6344
James Smarte59058c2008-08-24 21:49:00 -04006345/**
James Smart3621a712009-04-06 18:47:14 -04006346 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04006347 * @phba: Pointer to hba context object.
6348 * @cmdiocbp: Pointer to command iocb which reported error.
6349 * @rspiocbp: Pointer to response iocb which reported error.
6350 *
6351 * This function sends an event when there is an ELS command
6352 * failure.
6353 **/
6354void
6355lpfc_send_els_failure_event(struct lpfc_hba *phba,
6356 struct lpfc_iocbq *cmdiocbp,
6357 struct lpfc_iocbq *rspiocbp)
6358{
6359 struct lpfc_vport *vport = cmdiocbp->vport;
6360 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6361 struct lpfc_lsrjt_event lsrjt_event;
6362 struct lpfc_fabric_event_header fabric_event;
6363 struct ls_rjt stat;
6364 struct lpfc_nodelist *ndlp;
6365 uint32_t *pcmd;
6366
6367 ndlp = cmdiocbp->context1;
6368 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6369 return;
6370
6371 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6372 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6373 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6374 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6375 sizeof(struct lpfc_name));
6376 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6377 sizeof(struct lpfc_name));
6378 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6379 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006380 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006381 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6382 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6383 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6384 fc_host_post_vendor_event(shost,
6385 fc_get_event_number(),
6386 sizeof(lsrjt_event),
6387 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006388 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006389 return;
6390 }
6391 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6392 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6393 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6394 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6395 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6396 else
6397 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6398 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6399 sizeof(struct lpfc_name));
6400 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6401 sizeof(struct lpfc_name));
6402 fc_host_post_vendor_event(shost,
6403 fc_get_event_number(),
6404 sizeof(fabric_event),
6405 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006406 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006407 return;
6408 }
6409
6410}
6411
6412/**
James Smart3621a712009-04-06 18:47:14 -04006413 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006414 * @vport: Pointer to vport object.
6415 * @ndlp: Pointer FC node object.
6416 * @cmd: ELS command code.
6417 *
6418 * This function posts an event when there is an incoming
6419 * unsolicited ELS command.
6420 **/
6421static void
6422lpfc_send_els_event(struct lpfc_vport *vport,
6423 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006424 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006425{
James Smartddcc50f2008-12-04 22:38:46 -05006426 struct lpfc_els_event_header *els_data = NULL;
6427 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6429
James Smartddcc50f2008-12-04 22:38:46 -05006430 if (*payload == ELS_CMD_LOGO) {
6431 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6432 if (!logo_data) {
6433 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6434 "0148 Failed to allocate memory "
6435 "for LOGO event\n");
6436 return;
6437 }
6438 els_data = &logo_data->header;
6439 } else {
6440 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6441 GFP_KERNEL);
6442 if (!els_data) {
6443 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6444 "0149 Failed to allocate memory "
6445 "for ELS event\n");
6446 return;
6447 }
6448 }
6449 els_data->event_type = FC_REG_ELS_EVENT;
6450 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006451 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006452 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006453 break;
6454 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006455 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006456 break;
6457 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006458 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6459 break;
6460 case ELS_CMD_LOGO:
6461 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6462 /* Copy the WWPN in the LOGO payload */
6463 memcpy(logo_data->logo_wwpn, &payload[2],
6464 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006465 break;
6466 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006467 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006468 return;
6469 }
James Smartddcc50f2008-12-04 22:38:46 -05006470 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6471 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6472 if (*payload == ELS_CMD_LOGO) {
6473 fc_host_post_vendor_event(shost,
6474 fc_get_event_number(),
6475 sizeof(struct lpfc_logo_event),
6476 (char *)logo_data,
6477 LPFC_NL_VENDOR_ID);
6478 kfree(logo_data);
6479 } else {
6480 fc_host_post_vendor_event(shost,
6481 fc_get_event_number(),
6482 sizeof(struct lpfc_els_event_header),
6483 (char *)els_data,
6484 LPFC_NL_VENDOR_ID);
6485 kfree(els_data);
6486 }
James Smartea2151b2008-09-07 11:52:10 -04006487
6488 return;
6489}
6490
6491
6492/**
James Smart3621a712009-04-06 18:47:14 -04006493 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006494 * @phba: pointer to lpfc hba data structure.
6495 * @pring: pointer to a SLI ring.
6496 * @vport: pointer to a host virtual N_Port data structure.
6497 * @elsiocb: pointer to lpfc els command iocb data structure.
6498 *
6499 * This routine is used for processing the IOCB associated with a unsolicited
6500 * event. It first determines whether there is an existing ndlp that matches
6501 * the DID from the unsolicited IOCB. If not, it will create a new one with
6502 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6503 * IOCB is then used to invoke the proper routine and to set up proper state
6504 * of the discovery state machine.
6505 **/
James Smarted957682007-06-17 19:56:37 -05006506static void
6507lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006508 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006509{
James Smart87af33f2007-10-27 13:37:43 -04006510 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006511 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006512 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006513 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006514 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006515 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006516
James Smarte47c9092008-02-08 18:49:26 -05006517 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006518 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006519
dea31012005-04-17 16:05:31 -05006520 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006521 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6522 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006523 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006524 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006525
James Smart858c9f62007-06-17 19:56:39 -05006526 did = icmd->un.rcvels.remoteID;
6527 if (icmd->ulpStatus) {
6528 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6529 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6530 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006531 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006532 }
dea31012005-04-17 16:05:31 -05006533
6534 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006535 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006536 goto dropit;
dea31012005-04-17 16:05:31 -05006537
James Smartc8685952009-11-18 15:39:16 -05006538 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006539 if (vport->load_flag & FC_UNLOADING)
6540 goto dropit;
6541
James Smart92494142011-02-16 12:39:44 -05006542 /* If NPort discovery is delayed drop incoming ELS */
6543 if ((vport->fc_flag & FC_DISC_DELAYED) &&
6544 (cmd != ELS_CMD_PLOGI))
6545 goto dropit;
6546
James Smart2e0fef82007-06-17 19:56:36 -05006547 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006548 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006549 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006550 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006551 if (!ndlp)
dea31012005-04-17 16:05:31 -05006552 goto dropit;
dea31012005-04-17 16:05:31 -05006553
James Smart2e0fef82007-06-17 19:56:36 -05006554 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006555 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006556 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006557 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006558 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006559 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6560 ndlp = lpfc_enable_node(vport, ndlp,
6561 NLP_STE_UNUSED_NODE);
6562 if (!ndlp)
6563 goto dropit;
6564 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6565 newnode = 1;
6566 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6567 ndlp->nlp_type |= NLP_FABRIC;
6568 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6569 /* This is similar to the new node path */
6570 ndlp = lpfc_nlp_get(ndlp);
6571 if (!ndlp)
6572 goto dropit;
6573 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6574 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006575 }
dea31012005-04-17 16:05:31 -05006576
6577 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006578
James Smart329f9bc2007-04-25 09:53:01 -04006579 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006580 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006581
6582 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6583 cmd &= ELS_CMD_MASK;
6584 }
6585 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006586 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6587 "0112 ELS command x%x received from NPORT x%x "
6588 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006589 switch (cmd) {
6590 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006591 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6592 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6593 did, vport->port_state, ndlp->nlp_flag);
6594
dea31012005-04-17 16:05:31 -05006595 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006596 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6597
James Smartddcc50f2008-12-04 22:38:46 -05006598 lpfc_send_els_event(vport, ndlp, payload);
James Smart92494142011-02-16 12:39:44 -05006599
6600 /* If Nport discovery is delayed, reject PLOGIs */
6601 if (vport->fc_flag & FC_DISC_DELAYED) {
6602 rjt_err = LSRJT_UNABLE_TPC;
6603 break;
6604 }
James Smart858c9f62007-06-17 19:56:39 -05006605 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006606 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6607 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6608 rjt_err = LSRJT_UNABLE_TPC;
6609 break;
6610 }
6611 /* We get here, and drop thru, if we are PT2PT with
6612 * another NPort and the other side has initiated
6613 * the PLOGI before responding to our FLOGI.
6614 */
dea31012005-04-17 16:05:31 -05006615 }
James Smart87af33f2007-10-27 13:37:43 -04006616
6617 shost = lpfc_shost_from_vport(vport);
6618 spin_lock_irq(shost->host_lock);
6619 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6620 spin_unlock_irq(shost->host_lock);
6621
James Smart2e0fef82007-06-17 19:56:36 -05006622 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6623 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006624
dea31012005-04-17 16:05:31 -05006625 break;
6626 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6628 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6629 did, vport->port_state, ndlp->nlp_flag);
6630
dea31012005-04-17 16:05:31 -05006631 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006632 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006633 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006634 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006635 break;
6636 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006637 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6638 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6639 did, vport->port_state, ndlp->nlp_flag);
6640
dea31012005-04-17 16:05:31 -05006641 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006642 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006643 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006644 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006645 break;
6646 }
James Smart2e0fef82007-06-17 19:56:36 -05006647 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006648 break;
6649 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006650 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6651 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6652 did, vport->port_state, ndlp->nlp_flag);
6653
dea31012005-04-17 16:05:31 -05006654 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006655 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006656 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006657 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006658 break;
6659 }
James Smart2e0fef82007-06-17 19:56:36 -05006660 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006661 break;
6662 case ELS_CMD_RSCN:
6663 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006664 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006665 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006666 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006667 break;
6668 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006669 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6670 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6671 did, vport->port_state, ndlp->nlp_flag);
6672
James Smartddcc50f2008-12-04 22:38:46 -05006673 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006674 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006675 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006676 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006677 break;
6678 }
James Smart2e0fef82007-06-17 19:56:36 -05006679 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6680 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006681 break;
6682 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6684 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6685 did, vport->port_state, ndlp->nlp_flag);
6686
dea31012005-04-17 16:05:31 -05006687 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006688 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006689 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006690 break;
6691 }
James Smart2e0fef82007-06-17 19:56:36 -05006692 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6693 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006694 break;
6695 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006696 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6697 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6698 did, vport->port_state, ndlp->nlp_flag);
6699
dea31012005-04-17 16:05:31 -05006700 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006701 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006702 break;
6703 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006704 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6705 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6706 did, vport->port_state, ndlp->nlp_flag);
6707
dea31012005-04-17 16:05:31 -05006708 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006709 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006710 break;
6711 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006712 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6713 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6714 did, vport->port_state, ndlp->nlp_flag);
6715
dea31012005-04-17 16:05:31 -05006716 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006717 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006718 break;
dea31012005-04-17 16:05:31 -05006719 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006720 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6721 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6722 did, vport->port_state, ndlp->nlp_flag);
6723
dea31012005-04-17 16:05:31 -05006724 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006725 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006726 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006727 break;
6728 }
James Smart2e0fef82007-06-17 19:56:36 -05006729 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006730 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006731 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006732 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6733 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6734 did, vport->port_state, ndlp->nlp_flag);
6735
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006736 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006737 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006738 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006739 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006740 break;
James Smart12265f62010-10-22 11:05:53 -04006741 case ELS_CMD_RLS:
6742 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6743 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6744 did, vport->port_state, ndlp->nlp_flag);
6745
6746 phba->fc_stat.elsRcvRLS++;
6747 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6748 if (newnode)
6749 lpfc_nlp_put(ndlp);
6750 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006751 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006752 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6753 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6754 did, vport->port_state, ndlp->nlp_flag);
6755
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006756 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006757 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006758 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006759 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006760 break;
6761 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6763 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6764 did, vport->port_state, ndlp->nlp_flag);
6765
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006766 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006767 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006768 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006769 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006770 break;
dea31012005-04-17 16:05:31 -05006771 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6773 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6774 did, vport->port_state, ndlp->nlp_flag);
6775
dea31012005-04-17 16:05:31 -05006776 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006777 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006778 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006779 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006780 break;
James Smart12265f62010-10-22 11:05:53 -04006781 case ELS_CMD_RTV:
6782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6783 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6784 did, vport->port_state, ndlp->nlp_flag);
6785 phba->fc_stat.elsRcvRTV++;
6786 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6787 if (newnode)
6788 lpfc_nlp_put(ndlp);
6789 break;
James Smart5ffc2662009-11-18 15:39:44 -05006790 case ELS_CMD_RRQ:
6791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6792 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6793 did, vport->port_state, ndlp->nlp_flag);
6794
6795 phba->fc_stat.elsRcvRRQ++;
6796 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6797 if (newnode)
6798 lpfc_nlp_put(ndlp);
6799 break;
James Smart12265f62010-10-22 11:05:53 -04006800 case ELS_CMD_ECHO:
6801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6802 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6803 did, vport->port_state, ndlp->nlp_flag);
6804
6805 phba->fc_stat.elsRcvECHO++;
6806 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6807 if (newnode)
6808 lpfc_nlp_put(ndlp);
6809 break;
dea31012005-04-17 16:05:31 -05006810 default:
James Smart858c9f62007-06-17 19:56:39 -05006811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6812 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6813 cmd, did, vport->port_state);
6814
dea31012005-04-17 16:05:31 -05006815 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006816 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006817
6818 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006819 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6820 "0115 Unknown ELS command x%x "
6821 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006822 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006823 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006824 break;
6825 }
6826
6827 /* check if need to LS_RJT received ELS cmd */
6828 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006829 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006830 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006831 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006832 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6833 NULL);
dea31012005-04-17 16:05:31 -05006834 }
6835
James Smartd7c255b2008-08-24 21:50:00 -04006836 lpfc_nlp_put(elsiocb->context1);
6837 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006838 return;
6839
6840dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006841 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006842 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6843 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006844 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006845 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006846 phba->fc_stat.elsRcvDrop++;
6847}
6848
James Smarte59058c2008-08-24 21:49:00 -04006849/**
James Smart3621a712009-04-06 18:47:14 -04006850 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006851 * @phba: pointer to lpfc hba data structure.
6852 * @pring: pointer to a SLI ring.
6853 * @elsiocb: pointer to lpfc els iocb data structure.
6854 *
6855 * This routine is used to process an unsolicited event received from a SLI
6856 * (Service Level Interface) ring. The actual processing of the data buffer
6857 * associated with the unsolicited event is done by invoking the routine
6858 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6859 * SLI ring on which the unsolicited event was received.
6860 **/
James Smarted957682007-06-17 19:56:37 -05006861void
6862lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6863 struct lpfc_iocbq *elsiocb)
6864{
6865 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006866 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006867 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006868 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6869 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006870
James Smartd7c255b2008-08-24 21:50:00 -04006871 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006872 elsiocb->context2 = NULL;
6873 elsiocb->context3 = NULL;
6874
6875 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6876 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6877 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
James Smarte3d2b802012-08-14 14:25:43 -04006878 (icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
6879 IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006880 phba->fc_stat.NoRcvBuf++;
6881 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006882 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006883 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006884 return;
6885 }
6886
James Smart92d7f7b2007-06-17 19:56:38 -05006887 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6888 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6889 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6890 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6891 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006892 else
6893 vport = lpfc_find_vport_by_vpid(phba,
James Smart6d368e52011-05-24 11:44:12 -04006894 icmd->unsli3.rcvsli3.vpi);
James Smart92d7f7b2007-06-17 19:56:38 -05006895 }
James Smart6d368e52011-05-24 11:44:12 -04006896
James Smart7f5f3d02008-02-08 18:50:14 -05006897 /* If there are no BDEs associated
6898 * with this IOCB, there is nothing to do.
6899 */
James Smarted957682007-06-17 19:56:37 -05006900 if (icmd->ulpBdeCount == 0)
6901 return;
6902
James Smart7f5f3d02008-02-08 18:50:14 -05006903 /* type of ELS cmd is first 32bit word
6904 * in packet
6905 */
James Smarted957682007-06-17 19:56:37 -05006906 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006907 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006908 } else {
6909 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6910 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006911 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6912 paddr);
James Smarted957682007-06-17 19:56:37 -05006913 }
6914
James Smart92d7f7b2007-06-17 19:56:38 -05006915 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6916 /*
6917 * The different unsolicited event handlers would tell us
6918 * if they are done with "mp" by setting context2 to NULL.
6919 */
dea31012005-04-17 16:05:31 -05006920 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006921 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6922 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006923 }
James Smarted957682007-06-17 19:56:37 -05006924
6925 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006926 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006927 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006928 elsiocb->context2 = bdeBuf2;
6929 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006930 /* free mp if we are done with it */
6931 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006932 lpfc_in_buf_free(phba, elsiocb->context2);
6933 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006934 }
dea31012005-04-17 16:05:31 -05006935 }
dea31012005-04-17 16:05:31 -05006936}
James Smart92d7f7b2007-06-17 19:56:38 -05006937
James Smarte59058c2008-08-24 21:49:00 -04006938/**
James Smart3621a712009-04-06 18:47:14 -04006939 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006940 * @phba: pointer to lpfc hba data structure.
6941 * @vport: pointer to a virtual N_Port data structure.
6942 *
6943 * This routine issues a Port Login (PLOGI) to the Name Server with
6944 * State Change Request (SCR) for a @vport. This routine will create an
6945 * ndlp for the Name Server associated to the @vport if such node does
6946 * not already exist. The PLOGI to Name Server is issued by invoking the
6947 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6948 * (FDMI) is configured to the @vport, a FDMI node will be created and
6949 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6950 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006951void
6952lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6953{
6954 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
James Smart92494142011-02-16 12:39:44 -05006955 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6956
6957 /*
6958 * If lpfc_delay_discovery parameter is set and the clean address
6959 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6960 * discovery.
6961 */
6962 spin_lock_irq(shost->host_lock);
6963 if (vport->fc_flag & FC_DISC_DELAYED) {
6964 spin_unlock_irq(shost->host_lock);
6965 mod_timer(&vport->delayed_disc_tmo,
6966 jiffies + HZ * phba->fc_ratov);
6967 return;
6968 }
6969 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006970
6971 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6972 if (!ndlp) {
6973 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6974 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006975 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006976 lpfc_disc_start(vport);
6977 return;
6978 }
6979 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006980 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6981 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006982 return;
6983 }
6984 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006985 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6986 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6987 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006988 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006989 lpfc_disc_start(vport);
6990 return;
6991 }
6992 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6993 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6994 "0348 NameServer login: node freed\n");
6995 return;
6996 }
James Smart92d7f7b2007-06-17 19:56:38 -05006997 }
James Smart58da1ff2008-04-07 10:15:56 -04006998 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006999
7000 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
7001
7002 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
7003 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007004 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7005 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007006 return;
7007 }
7008
James Smart3de2a652007-08-02 11:09:59 -04007009 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05007010 /* If this is the first time, allocate an ndlp and initialize
7011 * it. Otherwise, make sure the node is enabled and then do the
7012 * login.
7013 */
7014 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
7015 if (!ndlp_fdmi) {
7016 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
7017 GFP_KERNEL);
7018 if (ndlp_fdmi) {
7019 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
7020 ndlp_fdmi->nlp_type |= NLP_FABRIC;
7021 } else
7022 return;
7023 }
7024 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
7025 ndlp_fdmi = lpfc_enable_node(vport,
7026 ndlp_fdmi,
7027 NLP_STE_NPR_NODE);
7028
James Smart92d7f7b2007-06-17 19:56:38 -05007029 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04007030 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05007031 NLP_STE_PLOGI_ISSUE);
7032 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007033 }
7034 }
James Smart92d7f7b2007-06-17 19:56:38 -05007035}
7036
James Smarte59058c2008-08-24 21:49:00 -04007037/**
James Smart3621a712009-04-06 18:47:14 -04007038 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04007039 * @phba: pointer to lpfc hba data structure.
7040 * @pmb: pointer to the driver internal queue element for mailbox command.
7041 *
7042 * This routine is the completion callback function to register new vport
7043 * mailbox command. If the new vport mailbox command completes successfully,
7044 * the fabric registration login shall be performed on physical port (the
7045 * new vport created is actually a physical port, with VPI 0) or the port
7046 * login to Name Server for State Change Request (SCR) will be performed
7047 * on virtual port (real virtual port, with VPI greater than 0).
7048 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007049static void
7050lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
7051{
7052 struct lpfc_vport *vport = pmb->vport;
7053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7054 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04007055 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05007056 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007057
James Smart09372822008-01-11 01:52:54 -05007058 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007059 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007060 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007061
7062 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04007063 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04007064 "0915 Register VPI failed : Status: x%x"
7065 " upd bit: x%x \n", mb->mbxStatus,
7066 mb->un.varRegVpi.upd);
7067 if (phba->sli_rev == LPFC_SLI_REV4 &&
7068 mb->un.varRegVpi.upd)
7069 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05007070
7071 switch (mb->mbxStatus) {
7072 case 0x11: /* unsupported feature */
7073 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05007074 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05007075 /* giving up on vport registration */
7076 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7077 spin_lock_irq(shost->host_lock);
7078 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
7079 spin_unlock_irq(shost->host_lock);
7080 lpfc_can_disctmo(vport);
7081 break;
James Smart695a8142010-01-26 23:08:03 -05007082 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7083 case 0x20:
7084 spin_lock_irq(shost->host_lock);
7085 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7086 spin_unlock_irq(shost->host_lock);
7087 lpfc_init_vpi(phba, pmb, vport->vpi);
7088 pmb->vport = vport;
7089 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
7090 rc = lpfc_sli_issue_mbox(phba, pmb,
7091 MBX_NOWAIT);
7092 if (rc == MBX_NOT_FINISHED) {
7093 lpfc_printf_vlog(vport,
7094 KERN_ERR, LOG_MBOX,
7095 "2732 Failed to issue INIT_VPI"
7096 " mailbox command\n");
7097 } else {
7098 lpfc_nlp_put(ndlp);
7099 return;
7100 }
7101
James Smart92d7f7b2007-06-17 19:56:38 -05007102 default:
7103 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04007104 if (phba->sli_rev == LPFC_SLI_REV4)
7105 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007106 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05007107 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007108 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05007109 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04007110 if (vport->port_type == LPFC_PHYSICAL_PORT
7111 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05007112 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05007113 else
7114 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007115 break;
7116 }
James Smart92d7f7b2007-06-17 19:56:38 -05007117 } else {
James Smart695a8142010-01-26 23:08:03 -05007118 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05007119 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05007120 spin_unlock_irq(shost->host_lock);
7121 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04007122 if (phba->sli_rev < LPFC_SLI_REV4)
7123 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05007124 else {
James Smartfc2b9892010-02-26 14:15:29 -05007125 /*
7126 * If the physical port is instantiated using
7127 * FDISC, do not start vport discovery.
7128 */
7129 if (vport->port_state != LPFC_FDISC)
7130 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05007131 lpfc_do_scr_ns_plogi(phba, vport);
7132 }
7133 } else
James Smart92d7f7b2007-06-17 19:56:38 -05007134 lpfc_do_scr_ns_plogi(phba, vport);
7135 }
James Smart38b92ef2010-08-04 16:11:39 -04007136mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05007137 /* Now, we decrement the ndlp reference count held for this
7138 * callback function
7139 */
7140 lpfc_nlp_put(ndlp);
7141
James Smart92d7f7b2007-06-17 19:56:38 -05007142 mempool_free(pmb, phba->mbox_mem_pool);
7143 return;
7144}
7145
James Smarte59058c2008-08-24 21:49:00 -04007146/**
James Smart3621a712009-04-06 18:47:14 -04007147 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04007148 * @phba: pointer to lpfc hba data structure.
7149 * @vport: pointer to a host virtual N_Port data structure.
7150 * @ndlp: pointer to a node-list data structure.
7151 *
7152 * This routine registers the @vport as a new virtual port with a HBA.
7153 * It is done through a registering vpi mailbox command.
7154 **/
James Smart695a8142010-01-26 23:08:03 -05007155void
James Smart92d7f7b2007-06-17 19:56:38 -05007156lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
7157 struct lpfc_nodelist *ndlp)
7158{
James Smart09372822008-01-11 01:52:54 -05007159 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05007160 LPFC_MBOXQ_t *mbox;
7161
7162 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
7163 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04007164 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05007165 mbox->vport = vport;
7166 mbox->context2 = lpfc_nlp_get(ndlp);
7167 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04007168 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05007169 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05007170 /* mailbox command not success, decrement ndlp
7171 * reference count for this command
7172 */
7173 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007174 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05007175
James Smarte8b62012007-08-02 11:10:09 -04007176 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7177 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05007178 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007179 }
7180 } else {
James Smarte8b62012007-08-02 11:10:09 -04007181 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
7182 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05007183 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05007184 }
James Smartfa4066b2008-01-11 01:53:27 -05007185 return;
7186
7187mbox_err_exit:
7188 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7189 spin_lock_irq(shost->host_lock);
7190 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
7191 spin_unlock_irq(shost->host_lock);
7192 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007193}
7194
James Smarte59058c2008-08-24 21:49:00 -04007195/**
James Smart0c9ab6f2010-02-26 14:15:57 -05007196 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05007197 * @phba: pointer to lpfc hba data structure.
7198 *
James Smart0c9ab6f2010-02-26 14:15:57 -05007199 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05007200 **/
7201void
James Smart0c9ab6f2010-02-26 14:15:57 -05007202lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05007203{
7204 struct lpfc_vport **vports;
7205 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05007206 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05007207 int i;
James Smart695a8142010-01-26 23:08:03 -05007208
7209 /* Treat this failure as linkdown for all vports */
7210 link_state = phba->link_state;
7211 lpfc_linkdown(phba);
7212 phba->link_state = link_state;
7213
7214 vports = lpfc_create_vport_work_array(phba);
7215
7216 if (vports) {
7217 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
7218 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
7219 if (ndlp)
7220 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
7221 lpfc_els_flush_cmd(vports[i]);
7222 }
7223 lpfc_destroy_vport_work_array(phba, vports);
7224 }
James Smart0c9ab6f2010-02-26 14:15:57 -05007225}
7226
7227/**
7228 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7229 * @phba: pointer to lpfc hba data structure.
7230 *
7231 * This routine abort all pending discovery commands and
7232 * start a timer to retry FLOGI for the physical port
7233 * discovery.
7234 **/
7235void
7236lpfc_retry_pport_discovery(struct lpfc_hba *phba)
7237{
7238 struct lpfc_nodelist *ndlp;
7239 struct Scsi_Host *shost;
7240
7241 /* Cancel the all vports retry delay retry timers */
7242 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05007243
7244 /* If fabric require FLOGI, then re-instantiate physical login */
7245 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
7246 if (!ndlp)
7247 return;
7248
James Smart695a8142010-01-26 23:08:03 -05007249 shost = lpfc_shost_from_vport(phba->pport);
7250 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
7251 spin_lock_irq(shost->host_lock);
7252 ndlp->nlp_flag |= NLP_DELAY_TMO;
7253 spin_unlock_irq(shost->host_lock);
7254 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
7255 phba->pport->port_state = LPFC_FLOGI;
7256 return;
7257}
7258
7259/**
7260 * lpfc_fabric_login_reqd - Check if FLOGI required.
7261 * @phba: pointer to lpfc hba data structure.
7262 * @cmdiocb: pointer to FDISC command iocb.
7263 * @rspiocb: pointer to FDISC response iocb.
7264 *
7265 * This routine checks if a FLOGI is reguired for FDISC
7266 * to succeed.
7267 **/
7268static int
7269lpfc_fabric_login_reqd(struct lpfc_hba *phba,
7270 struct lpfc_iocbq *cmdiocb,
7271 struct lpfc_iocbq *rspiocb)
7272{
7273
7274 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
7275 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
7276 return 0;
7277 else
7278 return 1;
7279}
7280
7281/**
James Smart3621a712009-04-06 18:47:14 -04007282 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007283 * @phba: pointer to lpfc hba data structure.
7284 * @cmdiocb: pointer to lpfc command iocb data structure.
7285 * @rspiocb: pointer to lpfc response iocb data structure.
7286 *
7287 * This routine is the completion callback function to a Fabric Discover
7288 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7289 * single threaded, each FDISC completion callback function will reset
7290 * the discovery timer for all vports such that the timers will not get
7291 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7292 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7293 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7294 * assigned to the vport has been changed with the completion of the FDISC
7295 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7296 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7297 * routine is invoked to register new vport with the HBA. Otherwise, the
7298 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7299 * Server for State Change Request (SCR).
7300 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007301static void
7302lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7303 struct lpfc_iocbq *rspiocb)
7304{
7305 struct lpfc_vport *vport = cmdiocb->vport;
7306 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7307 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
7308 struct lpfc_nodelist *np;
7309 struct lpfc_nodelist *next_np;
7310 IOCB_t *irsp = &rspiocb->iocb;
7311 struct lpfc_iocbq *piocb;
James Smart92494142011-02-16 12:39:44 -05007312 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
7313 struct serv_parm *sp;
7314 uint8_t fabric_param_changed;
James Smart92d7f7b2007-06-17 19:56:38 -05007315
James Smarte8b62012007-08-02 11:10:09 -04007316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7317 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7318 irsp->ulpStatus, irsp->un.ulpWord[4],
7319 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05007320 /* Since all FDISCs are being single threaded, we
7321 * must reset the discovery timer for ALL vports
7322 * waiting to send FDISC when one completes.
7323 */
7324 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
7325 lpfc_set_disctmo(piocb->vport);
7326 }
7327
James Smart858c9f62007-06-17 19:56:39 -05007328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7329 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7330 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
7331
James Smart92d7f7b2007-06-17 19:56:38 -05007332 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05007333
7334 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
7335 lpfc_retry_pport_discovery(phba);
7336 goto out;
7337 }
7338
James Smart92d7f7b2007-06-17 19:56:38 -05007339 /* Check for retry */
7340 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
7341 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007342 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04007343 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart6b5151f2012-01-18 16:24:06 -05007344 "0126 FDISC failed. (x%x/x%x)\n",
James Smarte8b62012007-08-02 11:10:09 -04007345 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04007346 goto fdisc_failed;
7347 }
James Smartd7c255b2008-08-24 21:50:00 -04007348 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05007349 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04007350 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04007351 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05007352 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04007353 vport->fc_flag |= FC_PUBLIC_LOOP;
7354 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05007355
James Smartd7c255b2008-08-24 21:50:00 -04007356 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
7357 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
James Smart92494142011-02-16 12:39:44 -05007358 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
7359 sp = prsp->virt + sizeof(uint32_t);
7360 fabric_param_changed = lpfc_check_clean_addr_bit(vport, sp);
7361 memcpy(&vport->fabric_portname, &sp->portName,
7362 sizeof(struct lpfc_name));
7363 memcpy(&vport->fabric_nodename, &sp->nodeName,
7364 sizeof(struct lpfc_name));
7365 if (fabric_param_changed &&
James Smartd7c255b2008-08-24 21:50:00 -04007366 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7367 /* If our NportID changed, we need to ensure all
7368 * remaining NPORTs get unreg_login'ed so we can
7369 * issue unreg_vpi.
7370 */
7371 list_for_each_entry_safe(np, next_np,
7372 &vport->fc_nodes, nlp_listp) {
7373 if (!NLP_CHK_NODE_ACT(ndlp) ||
7374 (np->nlp_state != NLP_STE_NPR_NODE) ||
7375 !(np->nlp_flag & NLP_NPR_ADISC))
7376 continue;
James Smart09372822008-01-11 01:52:54 -05007377 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007378 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007379 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007380 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007381 }
James Smart78730cf2010-04-06 15:06:30 -04007382 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007383
7384 if (phba->sli_rev == LPFC_SLI_REV4)
7385 lpfc_sli4_unreg_all_rpis(vport);
7386
James Smartd7c255b2008-08-24 21:50:00 -04007387 lpfc_mbx_unreg_vpi(vport);
7388 spin_lock_irq(shost->host_lock);
7389 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007390 if (phba->sli_rev == LPFC_SLI_REV4)
7391 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007392 else
7393 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007394 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007395 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7396 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7397 /*
7398 * Driver needs to re-reg VPI in order for f/w
7399 * to update the MAC address.
7400 */
7401 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007402 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007403 }
7404
James Smartecfd03c2010-02-12 14:41:27 -05007405 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7406 lpfc_issue_init_vpi(vport);
7407 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007408 lpfc_register_new_vport(phba, vport, ndlp);
7409 else
7410 lpfc_do_scr_ns_plogi(phba, vport);
7411 goto out;
7412fdisc_failed:
7413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7414 /* Cancel discovery timer */
7415 lpfc_can_disctmo(vport);
7416 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007417out:
7418 lpfc_els_free_iocb(phba, cmdiocb);
7419}
7420
James Smarte59058c2008-08-24 21:49:00 -04007421/**
James Smart3621a712009-04-06 18:47:14 -04007422 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007423 * @vport: pointer to a virtual N_Port data structure.
7424 * @ndlp: pointer to a node-list data structure.
7425 * @retry: number of retries to the command IOCB.
7426 *
7427 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7428 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7429 * routine to issue the IOCB, which makes sure only one outstanding fabric
7430 * IOCB will be sent off HBA at any given time.
7431 *
7432 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7433 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7434 * will be stored into the context1 field of the IOCB for the completion
7435 * callback function to the FDISC ELS command.
7436 *
7437 * Return code
7438 * 0 - Successfully issued fdisc iocb command
7439 * 1 - Failed to issue fdisc iocb command
7440 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007441static int
James Smart92d7f7b2007-06-17 19:56:38 -05007442lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7443 uint8_t retry)
7444{
7445 struct lpfc_hba *phba = vport->phba;
7446 IOCB_t *icmd;
7447 struct lpfc_iocbq *elsiocb;
7448 struct serv_parm *sp;
7449 uint8_t *pcmd;
7450 uint16_t cmdsize;
7451 int did = ndlp->nlp_DID;
7452 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007453
James Smart5ffc2662009-11-18 15:39:44 -05007454 vport->port_state = LPFC_FDISC;
James Smart6b5151f2012-01-18 16:24:06 -05007455 vport->fc_myDID = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007456 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7457 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7458 ELS_CMD_FDISC);
7459 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007460 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007461 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7462 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007463 return 1;
7464 }
7465
7466 icmd = &elsiocb->iocb;
7467 icmd->un.elsreq64.myID = 0;
7468 icmd->un.elsreq64.fl = 1;
7469
James Smart73d91e52011-10-10 21:32:10 -04007470 /*
7471 * SLI3 ports require a different context type value than SLI4.
7472 * Catch SLI3 ports here and override the prep.
7473 */
7474 if (phba->sli_rev == LPFC_SLI_REV3) {
James Smartf1126682009-06-10 17:22:44 -04007475 icmd->ulpCt_h = 1;
7476 icmd->ulpCt_l = 0;
7477 }
James Smart92d7f7b2007-06-17 19:56:38 -05007478
7479 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7480 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7481 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7482 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7483 sp = (struct serv_parm *) pcmd;
7484 /* Setup CSPs accordingly for Fabric */
7485 sp->cmn.e_d_tov = 0;
7486 sp->cmn.w2.r_a_tov = 0;
James Smartdf9e1b52011-12-13 13:22:17 -05007487 sp->cmn.virtual_fabric_support = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05007488 sp->cls1.classValid = 0;
7489 sp->cls2.seqDelivery = 1;
7490 sp->cls3.seqDelivery = 1;
7491
7492 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7493 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7494 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7495 pcmd += sizeof(uint32_t); /* Port Name */
7496 memcpy(pcmd, &vport->fc_portname, 8);
7497 pcmd += sizeof(uint32_t); /* Node Name */
7498 pcmd += sizeof(uint32_t); /* Node Name */
7499 memcpy(pcmd, &vport->fc_nodename, 8);
7500
7501 lpfc_set_disctmo(vport);
7502
7503 phba->fc_stat.elsXmitFDISC++;
7504 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7505
James Smart858c9f62007-06-17 19:56:39 -05007506 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7507 "Issue FDISC: did:x%x",
7508 did, 0, 0);
7509
James Smart92d7f7b2007-06-17 19:56:38 -05007510 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7511 if (rc == IOCB_ERROR) {
7512 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007513 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007514 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7515 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007516 return 1;
7517 }
7518 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007519 return 0;
7520}
7521
James Smarte59058c2008-08-24 21:49:00 -04007522/**
James Smart3621a712009-04-06 18:47:14 -04007523 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007524 * @phba: pointer to lpfc hba data structure.
7525 * @cmdiocb: pointer to lpfc command iocb data structure.
7526 * @rspiocb: pointer to lpfc response iocb data structure.
7527 *
7528 * This routine is the completion callback function to the issuing of a LOGO
7529 * ELS command off a vport. It frees the command IOCB and then decrement the
7530 * reference count held on ndlp for this completion function, indicating that
7531 * the reference to the ndlp is no long needed. Note that the
7532 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7533 * callback function and an additional explicit ndlp reference decrementation
7534 * will trigger the actual release of the ndlp.
7535 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007536static void
7537lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7538 struct lpfc_iocbq *rspiocb)
7539{
7540 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007541 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007542 struct lpfc_nodelist *ndlp;
James Smart9589b062011-04-16 11:03:17 -04007543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart858c9f62007-06-17 19:56:39 -05007544
James Smart9589b062011-04-16 11:03:17 -04007545 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007546 irsp = &rspiocb->iocb;
7547 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7548 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7549 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007550
7551 lpfc_els_free_iocb(phba, cmdiocb);
7552 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007553
7554 /* Trigger the release of the ndlp after logo */
7555 lpfc_nlp_put(ndlp);
James Smart9589b062011-04-16 11:03:17 -04007556
7557 /* NPIV LOGO completes to NPort <nlp_DID> */
7558 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
7559 "2928 NPIV LOGO completes to NPort x%x "
7560 "Data: x%x x%x x%x x%x\n",
7561 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
7562 irsp->ulpTimeout, vport->num_disc_nodes);
7563
7564 if (irsp->ulpStatus == IOSTAT_SUCCESS) {
7565 spin_lock_irq(shost->host_lock);
7566 vport->fc_flag &= ~FC_FABRIC;
7567 spin_unlock_irq(shost->host_lock);
7568 }
James Smart92d7f7b2007-06-17 19:56:38 -05007569}
7570
James Smarte59058c2008-08-24 21:49:00 -04007571/**
James Smart3621a712009-04-06 18:47:14 -04007572 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007573 * @vport: pointer to a virtual N_Port data structure.
7574 * @ndlp: pointer to a node-list data structure.
7575 *
7576 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7577 *
7578 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7579 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7580 * will be stored into the context1 field of the IOCB for the completion
7581 * callback function to the LOGO ELS command.
7582 *
7583 * Return codes
7584 * 0 - Successfully issued logo off the @vport
7585 * 1 - Failed to issue logo off the @vport
7586 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007587int
7588lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7589{
7590 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7591 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007592 IOCB_t *icmd;
7593 struct lpfc_iocbq *elsiocb;
7594 uint8_t *pcmd;
7595 uint16_t cmdsize;
7596
7597 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7598 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7599 ELS_CMD_LOGO);
7600 if (!elsiocb)
7601 return 1;
7602
7603 icmd = &elsiocb->iocb;
7604 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7605 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7606 pcmd += sizeof(uint32_t);
7607
7608 /* Fill in LOGO payload */
7609 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7610 pcmd += sizeof(uint32_t);
7611 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7612
James Smart858c9f62007-06-17 19:56:39 -05007613 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7614 "Issue LOGO npiv did:x%x flg:x%x",
7615 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7616
James Smart92d7f7b2007-06-17 19:56:38 -05007617 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7618 spin_lock_irq(shost->host_lock);
7619 ndlp->nlp_flag |= NLP_LOGO_SND;
7620 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007621 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7622 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007623 spin_lock_irq(shost->host_lock);
7624 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7625 spin_unlock_irq(shost->host_lock);
7626 lpfc_els_free_iocb(phba, elsiocb);
7627 return 1;
7628 }
7629 return 0;
7630}
7631
James Smarte59058c2008-08-24 21:49:00 -04007632/**
James Smart3621a712009-04-06 18:47:14 -04007633 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007634 * @ptr: holder for the timer function associated data.
7635 *
7636 * This routine is invoked by the fabric iocb block timer after
7637 * timeout. It posts the fabric iocb block timeout event by setting the
7638 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7639 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7640 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7641 * posted event WORKER_FABRIC_BLOCK_TMO.
7642 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007643void
7644lpfc_fabric_block_timeout(unsigned long ptr)
7645{
7646 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7647 unsigned long iflags;
7648 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007649
James Smart92d7f7b2007-06-17 19:56:38 -05007650 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7651 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7652 if (!tmo_posted)
7653 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7654 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7655
James Smart5e9d9b82008-06-14 22:52:53 -04007656 if (!tmo_posted)
7657 lpfc_worker_wake_up(phba);
7658 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007659}
7660
James Smarte59058c2008-08-24 21:49:00 -04007661/**
James Smart3621a712009-04-06 18:47:14 -04007662 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007663 * @phba: pointer to lpfc hba data structure.
7664 *
7665 * This routine issues one fabric iocb from the driver internal list to
7666 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7667 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7668 * remove one pending fabric iocb from the driver internal list and invokes
7669 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7670 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007671static void
7672lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7673{
7674 struct lpfc_iocbq *iocb;
7675 unsigned long iflags;
7676 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007677 IOCB_t *cmd;
7678
7679repeat:
7680 iocb = NULL;
7681 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007682 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007683 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7684 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7685 list);
7686 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007687 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007688 atomic_inc(&phba->fabric_iocb_count);
7689 }
7690 spin_unlock_irqrestore(&phba->hbalock, iflags);
7691 if (iocb) {
7692 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7693 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7694 iocb->iocb_flag |= LPFC_IO_FABRIC;
7695
James Smart858c9f62007-06-17 19:56:39 -05007696 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7697 "Fabric sched1: ste:x%x",
7698 iocb->vport->port_state, 0, 0);
7699
James Smart3772a992009-05-22 14:50:54 -04007700 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007701
7702 if (ret == IOCB_ERROR) {
7703 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7704 iocb->fabric_iocb_cmpl = NULL;
7705 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7706 cmd = &iocb->iocb;
7707 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7708 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7709 iocb->iocb_cmpl(phba, iocb, iocb);
7710
7711 atomic_dec(&phba->fabric_iocb_count);
7712 goto repeat;
7713 }
7714 }
7715
7716 return;
7717}
7718
James Smarte59058c2008-08-24 21:49:00 -04007719/**
James Smart3621a712009-04-06 18:47:14 -04007720 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007721 * @phba: pointer to lpfc hba data structure.
7722 *
7723 * This routine unblocks the issuing fabric iocb command. The function
7724 * will clear the fabric iocb block bit and then invoke the routine
7725 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7726 * from the driver internal fabric iocb list.
7727 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007728void
7729lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7730{
7731 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7732
7733 lpfc_resume_fabric_iocbs(phba);
7734 return;
7735}
7736
James Smarte59058c2008-08-24 21:49:00 -04007737/**
James Smart3621a712009-04-06 18:47:14 -04007738 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007739 * @phba: pointer to lpfc hba data structure.
7740 *
7741 * This routine blocks the issuing fabric iocb for a specified amount of
7742 * time (currently 100 ms). This is done by set the fabric iocb block bit
7743 * and set up a timeout timer for 100ms. When the block bit is set, no more
7744 * fabric iocb will be issued out of the HBA.
7745 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007746static void
7747lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7748{
7749 int blocked;
7750
7751 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007752 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007753 if (!blocked)
7754 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7755
7756 return;
7757}
7758
James Smarte59058c2008-08-24 21:49:00 -04007759/**
James Smart3621a712009-04-06 18:47:14 -04007760 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007761 * @phba: pointer to lpfc hba data structure.
7762 * @cmdiocb: pointer to lpfc command iocb data structure.
7763 * @rspiocb: pointer to lpfc response iocb data structure.
7764 *
7765 * This routine is the callback function that is put to the fabric iocb's
7766 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7767 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7768 * function first restores and invokes the original iocb's callback function
7769 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7770 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7771 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007772static void
7773lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7774 struct lpfc_iocbq *rspiocb)
7775{
7776 struct ls_rjt stat;
7777
7778 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7779 BUG();
7780
7781 switch (rspiocb->iocb.ulpStatus) {
7782 case IOSTAT_NPORT_RJT:
7783 case IOSTAT_FABRIC_RJT:
7784 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7785 lpfc_block_fabric_iocbs(phba);
7786 }
7787 break;
7788
7789 case IOSTAT_NPORT_BSY:
7790 case IOSTAT_FABRIC_BSY:
7791 lpfc_block_fabric_iocbs(phba);
7792 break;
7793
7794 case IOSTAT_LS_RJT:
7795 stat.un.lsRjtError =
7796 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7797 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7798 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7799 lpfc_block_fabric_iocbs(phba);
7800 break;
7801 }
7802
7803 if (atomic_read(&phba->fabric_iocb_count) == 0)
7804 BUG();
7805
7806 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7807 cmdiocb->fabric_iocb_cmpl = NULL;
7808 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7809 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7810
7811 atomic_dec(&phba->fabric_iocb_count);
7812 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007813 /* Post any pending iocbs to HBA */
7814 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007815 }
7816}
7817
James Smarte59058c2008-08-24 21:49:00 -04007818/**
James Smart3621a712009-04-06 18:47:14 -04007819 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007820 * @phba: pointer to lpfc hba data structure.
7821 * @iocb: pointer to lpfc command iocb data structure.
7822 *
7823 * This routine is used as the top-level API for issuing a fabric iocb command
7824 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7825 * function makes sure that only one fabric bound iocb will be outstanding at
7826 * any given time. As such, this function will first check to see whether there
7827 * is already an outstanding fabric iocb on the wire. If so, it will put the
7828 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7829 * issued later. Otherwise, it will issue the iocb on the wire and update the
7830 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7831 *
7832 * Note, this implementation has a potential sending out fabric IOCBs out of
7833 * order. The problem is caused by the construction of the "ready" boolen does
7834 * not include the condition that the internal fabric IOCB list is empty. As
7835 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7836 * ahead of the fabric IOCBs in the internal list.
7837 *
7838 * Return code
7839 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7840 * IOCB_ERROR - failed to issue fabric iocb
7841 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007842static int
James Smart92d7f7b2007-06-17 19:56:38 -05007843lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7844{
7845 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007846 int ready;
7847 int ret;
7848
7849 if (atomic_read(&phba->fabric_iocb_count) > 1)
7850 BUG();
7851
7852 spin_lock_irqsave(&phba->hbalock, iflags);
7853 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7854 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7855
James Smart7f5f3d02008-02-08 18:50:14 -05007856 if (ready)
7857 /* Increment fabric iocb count to hold the position */
7858 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007859 spin_unlock_irqrestore(&phba->hbalock, iflags);
7860 if (ready) {
7861 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7862 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7863 iocb->iocb_flag |= LPFC_IO_FABRIC;
7864
James Smart858c9f62007-06-17 19:56:39 -05007865 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7866 "Fabric sched2: ste:x%x",
7867 iocb->vport->port_state, 0, 0);
7868
James Smart3772a992009-05-22 14:50:54 -04007869 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007870
7871 if (ret == IOCB_ERROR) {
7872 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7873 iocb->fabric_iocb_cmpl = NULL;
7874 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7875 atomic_dec(&phba->fabric_iocb_count);
7876 }
7877 } else {
7878 spin_lock_irqsave(&phba->hbalock, iflags);
7879 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7880 spin_unlock_irqrestore(&phba->hbalock, iflags);
7881 ret = IOCB_SUCCESS;
7882 }
7883 return ret;
7884}
7885
James Smarte59058c2008-08-24 21:49:00 -04007886/**
James Smart3621a712009-04-06 18:47:14 -04007887 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007888 * @vport: pointer to a virtual N_Port data structure.
7889 *
7890 * This routine aborts all the IOCBs associated with a @vport from the
7891 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7892 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7893 * list, removes each IOCB associated with the @vport off the list, set the
7894 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7895 * associated with the IOCB.
7896 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007897static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007898{
7899 LIST_HEAD(completions);
7900 struct lpfc_hba *phba = vport->phba;
7901 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007902
7903 spin_lock_irq(&phba->hbalock);
7904 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7905 list) {
7906
7907 if (piocb->vport != vport)
7908 continue;
7909
7910 list_move_tail(&piocb->list, &completions);
7911 }
7912 spin_unlock_irq(&phba->hbalock);
7913
James Smarta257bf92009-04-06 18:48:10 -04007914 /* Cancel all the IOCBs from the completions list */
7915 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7916 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007917}
7918
James Smarte59058c2008-08-24 21:49:00 -04007919/**
James Smart3621a712009-04-06 18:47:14 -04007920 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007921 * @ndlp: pointer to a node-list data structure.
7922 *
7923 * This routine aborts all the IOCBs associated with an @ndlp from the
7924 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7925 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7926 * list, removes each IOCB associated with the @ndlp off the list, set the
7927 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7928 * associated with the IOCB.
7929 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007930void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7931{
7932 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007933 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007934 struct lpfc_iocbq *tmp_iocb, *piocb;
7935 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007936
7937 spin_lock_irq(&phba->hbalock);
7938 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7939 list) {
7940 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7941
7942 list_move_tail(&piocb->list, &completions);
7943 }
7944 }
7945 spin_unlock_irq(&phba->hbalock);
7946
James Smarta257bf92009-04-06 18:48:10 -04007947 /* Cancel all the IOCBs from the completions list */
7948 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7949 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007950}
7951
James Smarte59058c2008-08-24 21:49:00 -04007952/**
James Smart3621a712009-04-06 18:47:14 -04007953 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007954 * @phba: pointer to lpfc hba data structure.
7955 *
7956 * This routine aborts all the IOCBs currently on the driver internal
7957 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7958 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7959 * list, removes IOCBs off the list, set the status feild to
7960 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7961 * the IOCB.
7962 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007963void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7964{
7965 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007966
7967 spin_lock_irq(&phba->hbalock);
7968 list_splice_init(&phba->fabric_iocb_list, &completions);
7969 spin_unlock_irq(&phba->hbalock);
7970
James Smarta257bf92009-04-06 18:48:10 -04007971 /* Cancel all the IOCBs from the completions list */
7972 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7973 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007974}
James Smart6fb120a2009-05-22 14:52:59 -04007975
7976/**
James Smart1151e3e2011-02-16 12:39:35 -05007977 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7978 * @vport: pointer to lpfc vport data structure.
7979 *
7980 * This routine is invoked by the vport cleanup for deletions and the cleanup
7981 * for an ndlp on removal.
7982 **/
7983void
7984lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7985{
7986 struct lpfc_hba *phba = vport->phba;
7987 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7988 unsigned long iflag = 0;
7989
7990 spin_lock_irqsave(&phba->hbalock, iflag);
7991 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7992 list_for_each_entry_safe(sglq_entry, sglq_next,
7993 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7994 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7995 sglq_entry->ndlp = NULL;
7996 }
7997 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7998 spin_unlock_irqrestore(&phba->hbalock, iflag);
7999 return;
8000}
8001
8002/**
James Smart6fb120a2009-05-22 14:52:59 -04008003 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8004 * @phba: pointer to lpfc hba data structure.
8005 * @axri: pointer to the els xri abort wcqe structure.
8006 *
8007 * This routine is invoked by the worker thread to process a SLI4 slow-path
8008 * ELS aborted xri.
8009 **/
8010void
8011lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
8012 struct sli4_wcqe_xri_aborted *axri)
8013{
8014 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05008015 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
James Smart7851fe22011-07-22 18:36:52 -04008016 uint16_t lxri = 0;
James Smart19ca7602010-11-20 23:11:55 -05008017
James Smart6fb120a2009-05-22 14:52:59 -04008018 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
8019 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05008020 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04008021 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04008022
James Smart0f65ff62010-02-26 14:14:23 -05008023 spin_lock_irqsave(&phba->hbalock, iflag);
8024 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008025 list_for_each_entry_safe(sglq_entry, sglq_next,
8026 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
8027 if (sglq_entry->sli4_xritag == xri) {
8028 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05008029 ndlp = sglq_entry->ndlp;
8030 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04008031 list_add_tail(&sglq_entry->list,
8032 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05008033 sglq_entry->state = SGL_FREED;
8034 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04008035 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smartee0f4fe2012-05-09 21:19:14 -04008036 lpfc_set_rrq_active(phba, ndlp,
8037 sglq_entry->sli4_lxritag,
8038 rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04008039
8040 /* Check if TXQ queue needs to be serviced */
8041 if (pring->txq_cnt)
8042 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04008043 return;
8044 }
8045 }
James Smart0f65ff62010-02-26 14:14:23 -05008046 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart7851fe22011-07-22 18:36:52 -04008047 lxri = lpfc_sli4_xri_inrange(phba, xri);
8048 if (lxri == NO_XRI) {
8049 spin_unlock_irqrestore(&phba->hbalock, iflag);
8050 return;
8051 }
8052 sglq_entry = __lpfc_get_active_sglq(phba, lxri);
James Smart0f65ff62010-02-26 14:14:23 -05008053 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
8054 spin_unlock_irqrestore(&phba->hbalock, iflag);
8055 return;
8056 }
8057 sglq_entry->state = SGL_XRI_ABORTED;
8058 spin_unlock_irqrestore(&phba->hbalock, iflag);
8059 return;
James Smart6fb120a2009-05-22 14:52:59 -04008060}
James Smart086a3452012-08-14 14:25:21 -04008061
8062/* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8063 * @vport: pointer to virtual port object.
8064 * @ndlp: nodelist pointer for the impacted node.
8065 *
8066 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8067 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8068 * the driver is required to send a LOGO to the remote node before it
8069 * attempts to recover its login to the remote node.
8070 */
8071void
8072lpfc_sli_abts_recover_port(struct lpfc_vport *vport,
8073 struct lpfc_nodelist *ndlp)
8074{
8075 struct Scsi_Host *shost;
8076 struct lpfc_hba *phba;
8077 unsigned long flags = 0;
8078
8079 shost = lpfc_shost_from_vport(vport);
8080 phba = vport->phba;
8081 if (ndlp->nlp_state != NLP_STE_MAPPED_NODE) {
8082 lpfc_printf_log(phba, KERN_INFO,
8083 LOG_SLI, "3093 No rport recovery needed. "
8084 "rport in state 0x%x\n", ndlp->nlp_state);
8085 return;
8086 }
8087 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
8088 "3094 Start rport recovery on shost id 0x%x "
8089 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8090 "flags 0x%x\n",
8091 shost->host_no, ndlp->nlp_DID,
8092 vport->vpi, ndlp->nlp_rpi, ndlp->nlp_state,
8093 ndlp->nlp_flag);
8094 /*
8095 * The rport is not responding. Remove the FCP-2 flag to prevent
8096 * an ADISC in the follow-up recovery code.
8097 */
8098 spin_lock_irqsave(shost->host_lock, flags);
8099 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
8100 spin_unlock_irqrestore(shost->host_lock, flags);
8101 lpfc_issue_els_logo(vport, ndlp, 0);
8102 lpfc_nlp_set_state(vport, ndlp, NLP_STE_LOGO_ISSUE);
8103}
8104