blob: 04072ce9c9053a2ddfdb4098d3f5ea8616214233 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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 */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400180 elsiocb->iocb_flag |=
181 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500182 & LPFC_FIP_ELS_ID_MASK);
183 break;
184 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500192 & LPFC_FIP_ELS_ID_MASK);
193 break;
194 }
James Smart0c287582009-06-10 17:22:56 -0400195 else
James Smartc8685952009-11-18 15:39:16 -0500196 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400197
dea31012005-04-17 16:05:31 -0500198 icmd = &elsiocb->iocb;
199
200 /* fill in BDEs for command */
201 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400202 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
203 if (pcmd)
204 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500205 if (!pcmd || !pcmd->virt)
206 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500207
208 INIT_LIST_HEAD(&pcmd->list);
209
210 /* Allocate buffer for response payload */
211 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500212 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500213 if (prsp)
214 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
215 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500216 if (!prsp || !prsp->virt)
217 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500218 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500219 } else
dea31012005-04-17 16:05:31 -0500220 prsp = NULL;
dea31012005-04-17 16:05:31 -0500221
222 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500223 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500224 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500225 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
226 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500227 if (!pbuflist || !pbuflist->virt)
228 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500229
230 INIT_LIST_HEAD(&pbuflist->list);
231
232 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
233 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400234 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500235 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500236 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500238 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400239 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500240 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500241 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500242 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
243 }
dea31012005-04-17 16:05:31 -0500244 icmd->ulpBdeCount = 1;
245 icmd->ulpLe = 1;
246 icmd->ulpClass = CLASS3;
247
James Smart92d7f7b2007-06-17 19:56:38 -0500248 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
249 icmd->un.elsreq64.myID = vport->fc_myDID;
250
251 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400252 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500253 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500254 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
255 if (elscmd == ELS_CMD_ECHO)
256 icmd->ulpCt_l = 0; /* context = invalid RPI */
257 else
258 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500259 }
260
dea31012005-04-17 16:05:31 -0500261 bpl = (struct ulp_bde64 *) pbuflist->virt;
262 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
263 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
264 bpl->tus.f.bdeSize = cmdSize;
265 bpl->tus.f.bdeFlags = 0;
266 bpl->tus.w = le32_to_cpu(bpl->tus.w);
267
268 if (expectRsp) {
269 bpl++;
270 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
271 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
272 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400273 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500274 bpl->tus.w = le32_to_cpu(bpl->tus.w);
275 }
276
James Smartfa4066b2008-01-11 01:53:27 -0500277 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400278 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500279 if (!elsiocb->context1)
280 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400281 elsiocb->context2 = pcmd;
282 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500283 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500284 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500285 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
286
287 if (prsp) {
288 list_add(&prsp->list, &pcmd->list);
289 }
dea31012005-04-17 16:05:31 -0500290 if (expectRsp) {
291 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
293 "0116 Xmit ELS command x%x to remote "
294 "NPORT x%x I/O tag: x%x, port state: x%x\n",
295 elscmd, did, elsiocb->iotag,
296 vport->port_state);
dea31012005-04-17 16:05:31 -0500297 } else {
298 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400299 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
300 "0117 Xmit ELS response x%x to remote "
301 "NPORT x%x I/O tag: x%x, size: x%x\n",
302 elscmd, ndlp->nlp_DID, elsiocb->iotag,
303 cmdSize);
dea31012005-04-17 16:05:31 -0500304 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500305 return elsiocb;
dea31012005-04-17 16:05:31 -0500306
James Smartfa4066b2008-01-11 01:53:27 -0500307els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500308 if (expectRsp)
309 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500310 kfree(pbuflist);
311
312els_iocb_free_prsp_exit:
313 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
314 kfree(prsp);
315
316els_iocb_free_pcmb_exit:
317 kfree(pcmd);
318 lpfc_sli_release_iocbq(phba, elsiocb);
319 return NULL;
320}
dea31012005-04-17 16:05:31 -0500321
James Smarte59058c2008-08-24 21:49:00 -0400322/**
James Smart3621a712009-04-06 18:47:14 -0400323 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400324 * @vport: pointer to a host virtual N_Port data structure.
325 *
326 * This routine issues a fabric registration login for a @vport. An
327 * active ndlp node with Fabric_DID must already exist for this @vport.
328 * The routine invokes two mailbox commands to carry out fabric registration
329 * login through the HBA firmware: the first mailbox command requests the
330 * HBA to perform link configuration for the @vport; and the second mailbox
331 * command requests the HBA to perform the actual fabric registration login
332 * with the @vport.
333 *
334 * Return code
335 * 0 - successfully issued fabric registration login for @vport
336 * -ENXIO -- failed to issue fabric registration login for @vport
337 **/
James Smart3772a992009-05-22 14:50:54 -0400338int
James Smart92d7f7b2007-06-17 19:56:38 -0500339lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
340{
341 struct lpfc_hba *phba = vport->phba;
342 LPFC_MBOXQ_t *mbox;
343 struct lpfc_dmabuf *mp;
344 struct lpfc_nodelist *ndlp;
345 struct serv_parm *sp;
346 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400347 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500348
349 sp = &phba->fc_fabparam;
350 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500351 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400352 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500353 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400354 }
James Smart92d7f7b2007-06-17 19:56:38 -0500355
356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400357 if (!mbox) {
358 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500359 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400360 }
James Smart92d7f7b2007-06-17 19:56:38 -0500361
362 vport->port_state = LPFC_FABRIC_CFG_LINK;
363 lpfc_config_link(phba, mbox);
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 mbox->vport = vport;
366
James Smart0b727fe2007-10-27 13:37:25 -0400367 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400368 if (rc == MBX_NOT_FINISHED) {
369 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500370 goto fail_free_mbox;
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 = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500376 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400377 }
James Smart3772a992009-05-22 14:50:54 -0400378 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400379 if (rc) {
380 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500381 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400382 }
James Smart92d7f7b2007-06-17 19:56:38 -0500383
384 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
385 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500386 /* increment the reference count on ndlp to hold reference
387 * for the callback routine.
388 */
James Smart92d7f7b2007-06-17 19:56:38 -0500389 mbox->context2 = lpfc_nlp_get(ndlp);
390
James Smart0b727fe2007-10-27 13:37:25 -0400391 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400392 if (rc == MBX_NOT_FINISHED) {
393 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500394 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400395 }
James Smart92d7f7b2007-06-17 19:56:38 -0500396
397 return 0;
398
399fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500400 /* decrement the reference count on ndlp just incremented
401 * for the failed mbox command.
402 */
James Smart92d7f7b2007-06-17 19:56:38 -0500403 lpfc_nlp_put(ndlp);
404 mp = (struct lpfc_dmabuf *) mbox->context1;
405 lpfc_mbuf_free(phba, mp->virt, mp->phys);
406 kfree(mp);
407fail_free_mbox:
408 mempool_free(mbox, phba->mbox_mem_pool);
409
410fail:
411 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400412 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400413 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500414 return -ENXIO;
415}
416
James Smarte59058c2008-08-24 21:49:00 -0400417/**
James Smart6fb120a2009-05-22 14:52:59 -0400418 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
419 * @vport: pointer to a host virtual N_Port data structure.
420 *
421 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
422 * the @vport. This mailbox command is necessary for FCoE only.
423 *
424 * Return code
425 * 0 - successfully issued REG_VFI for @vport
426 * A failure code otherwise.
427 **/
428static int
429lpfc_issue_reg_vfi(struct lpfc_vport *vport)
430{
431 struct lpfc_hba *phba = vport->phba;
432 LPFC_MBOXQ_t *mboxq;
433 struct lpfc_nodelist *ndlp;
434 struct serv_parm *sp;
435 struct lpfc_dmabuf *dmabuf;
436 int rc = 0;
437
438 sp = &phba->fc_fabparam;
439 ndlp = lpfc_findnode_did(vport, Fabric_DID);
440 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
441 rc = -ENODEV;
442 goto fail;
443 }
444
445 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
446 if (!dmabuf) {
447 rc = -ENOMEM;
448 goto fail;
449 }
450 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
451 if (!dmabuf->virt) {
452 rc = -ENOMEM;
453 goto fail_free_dmabuf;
454 }
455 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
456 if (!mboxq) {
457 rc = -ENOMEM;
458 goto fail_free_coherent;
459 }
460 vport->port_state = LPFC_FABRIC_CFG_LINK;
461 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
462 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
463 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
464 mboxq->vport = vport;
465 mboxq->context1 = dmabuf;
466 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
467 if (rc == MBX_NOT_FINISHED) {
468 rc = -ENXIO;
469 goto fail_free_mbox;
470 }
471 return 0;
472
473fail_free_mbox:
474 mempool_free(mboxq, phba->mbox_mem_pool);
475fail_free_coherent:
476 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
477fail_free_dmabuf:
478 kfree(dmabuf);
479fail:
480 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
482 "0289 Issue Register VFI failed: Err %d\n", rc);
483 return rc;
484}
485
486/**
James Smart3621a712009-04-06 18:47:14 -0400487 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400488 * @vport: pointer to a host virtual N_Port data structure.
489 * @ndlp: pointer to a node-list data structure.
490 * @sp: pointer to service parameter data structure.
491 * @irsp: pointer to the IOCB within the lpfc response IOCB.
492 *
493 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
494 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
495 * port in a fabric topology. It properly sets up the parameters to the @ndlp
496 * from the IOCB response. It also check the newly assigned N_Port ID to the
497 * @vport against the previously assigned N_Port ID. If it is different from
498 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
499 * is invoked on all the remaining nodes with the @vport to unregister the
500 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
501 * is invoked to register login to the fabric.
502 *
503 * Return code
504 * 0 - Success (currently, always return 0)
505 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500506static int
James Smart2e0fef82007-06-17 19:56:36 -0500507lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
508 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500509{
James Smart2e0fef82007-06-17 19:56:36 -0500510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
511 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500512 struct lpfc_nodelist *np;
513 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500514
James Smart2e0fef82007-06-17 19:56:36 -0500515 spin_lock_irq(shost->host_lock);
516 vport->fc_flag |= FC_FABRIC;
517 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500518
519 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
520 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
521 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
522
James Smart12265f62010-10-22 11:05:53 -0400523 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500524 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
525
James Smart76a95d72010-11-20 23:11:48 -0500526 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500527 spin_lock_irq(shost->host_lock);
528 vport->fc_flag |= FC_PUBLIC_LOOP;
529 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500530 }
531
James Smart2e0fef82007-06-17 19:56:36 -0500532 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500533 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500534 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500535 ndlp->nlp_class_sup = 0;
536 if (sp->cls1.classValid)
537 ndlp->nlp_class_sup |= FC_COS_CLASS1;
538 if (sp->cls2.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS2;
540 if (sp->cls3.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS3;
542 if (sp->cls4.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS4;
544 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
545 sp->cmn.bbRcvSizeLsb;
546 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
547
James Smart92d7f7b2007-06-17 19:56:38 -0500548 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
549 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400550 lpfc_printf_vlog(vport, KERN_WARNING,
551 LOG_ELS | LOG_VPORT,
552 "1816 FLOGI NPIV supported, "
553 "response data 0x%x\n",
554 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500555 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500556 } else {
557 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400558 to call reg_vnpid atleast for the physcial host */
559 lpfc_printf_vlog(vport, KERN_WARNING,
560 LOG_ELS | LOG_VPORT,
561 "1817 Fabric does not support NPIV "
562 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500563 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
564 }
565 }
566
567 if ((vport->fc_prevDID != vport->fc_myDID) &&
568 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
569
570 /* If our NportID changed, we need to ensure all
571 * remaining NPORTs get unreg_login'ed.
572 */
573 list_for_each_entry_safe(np, next_np,
574 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400575 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500576 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500577 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
578 !(np->nlp_flag & NLP_NPR_ADISC))
579 continue;
580 spin_lock_irq(shost->host_lock);
581 np->nlp_flag &= ~NLP_NPR_ADISC;
582 spin_unlock_irq(shost->host_lock);
583 lpfc_unreg_rpi(vport, np);
584 }
James Smart78730cf2010-04-06 15:06:30 -0400585 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400586
587 if (phba->sli_rev == LPFC_SLI_REV4)
588 lpfc_sli4_unreg_all_rpis(vport);
589
James Smart92d7f7b2007-06-17 19:56:38 -0500590 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
591 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500592 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500594 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500595 }
James Smartecfd03c2010-02-12 14:41:27 -0500596 /*
597 * If VPI is unreged, driver need to do INIT_VPI
598 * before re-registering
599 */
600 if (phba->sli_rev == LPFC_SLI_REV4) {
601 spin_lock_irq(shost->host_lock);
602 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
603 spin_unlock_irq(shost->host_lock);
604 }
James Smart38b92ef2010-08-04 16:11:39 -0400605 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
606 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
607 /*
608 * Driver needs to re-reg VPI in order for f/w
609 * to update the MAC address.
610 */
611 lpfc_register_new_vport(phba, vport, ndlp);
612 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500613 }
614
James Smart6fb120a2009-05-22 14:52:59 -0400615 if (phba->sli_rev < LPFC_SLI_REV4) {
616 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
617 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
618 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
619 lpfc_register_new_vport(phba, vport, ndlp);
620 else
621 lpfc_issue_fabric_reglogin(vport);
622 } else {
623 ndlp->nlp_type |= NLP_FABRIC;
624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500625 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
626 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400627 lpfc_start_fdiscs(phba);
628 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500629 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500630 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500631 else
James Smart6fb120a2009-05-22 14:52:59 -0400632 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500633 }
dea31012005-04-17 16:05:31 -0500634 return 0;
dea31012005-04-17 16:05:31 -0500635}
James Smarte59058c2008-08-24 21:49:00 -0400636/**
James Smart3621a712009-04-06 18:47:14 -0400637 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
641 *
642 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
643 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
644 * in a point-to-point topology. First, the @vport's N_Port Name is compared
645 * with the received N_Port Name: if the @vport's N_Port Name is greater than
646 * the received N_Port Name lexicographically, this node shall assign local
647 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
648 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
649 * this node shall just wait for the remote node to issue PLOGI and assign
650 * N_Port IDs.
651 *
652 * Return code
653 * 0 - Success
654 * -ENXIO - Fail
655 **/
dea31012005-04-17 16:05:31 -0500656static int
James Smart2e0fef82007-06-17 19:56:36 -0500657lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500659{
James Smart2e0fef82007-06-17 19:56:36 -0500660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500662 LPFC_MBOXQ_t *mbox;
663 int rc;
664
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
667 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500668
669 phba->fc_edtov = FF_DEF_EDTOV;
670 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500671 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500672 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500673 if (rc >= 0) {
674 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_PT2PT_PLOGI;
677 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500678
679 /*
680 * N_Port ID cannot be 0, set our to LocalID the other
681 * side will be RemoteID.
682 */
683
684 /* not equal */
685 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500686 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500687
688 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
689 if (!mbox)
690 goto fail;
691
692 lpfc_config_link(phba, mbox);
693
694 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500695 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400696 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500697 if (rc == MBX_NOT_FINISHED) {
698 mempool_free(mbox, phba->mbox_mem_pool);
699 goto fail;
700 }
James Smarte47c9092008-02-08 18:49:26 -0500701 /* Decrement ndlp reference count indicating that ndlp can be
702 * safely released when other references to it are done.
703 */
James Smart329f9bc2007-04-25 09:53:01 -0400704 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500705
James Smart2e0fef82007-06-17 19:56:36 -0500706 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500707 if (!ndlp) {
708 /*
709 * Cannot find existing Fabric ndlp, so allocate a
710 * new one
711 */
712 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
713 if (!ndlp)
714 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500715 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500716 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
717 ndlp = lpfc_enable_node(vport, ndlp,
718 NLP_STE_UNUSED_NODE);
719 if(!ndlp)
720 goto fail;
dea31012005-04-17 16:05:31 -0500721 }
722
723 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500724 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500725 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500726 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500727 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
729 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500730 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500731 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500732 } else
733 /* This side will wait for the PLOGI, decrement ndlp reference
734 * count indicating that ndlp can be released when other
735 * references to it are done.
736 */
James Smart329f9bc2007-04-25 09:53:01 -0400737 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500738
James Smart09372822008-01-11 01:52:54 -0500739 /* If we are pt2pt with another NPort, force NPIV off! */
740 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
741
James Smart2e0fef82007-06-17 19:56:36 -0500742 spin_lock_irq(shost->host_lock);
743 vport->fc_flag |= FC_PT2PT;
744 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500745
746 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500747 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500748 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500749fail:
dea31012005-04-17 16:05:31 -0500750 return -ENXIO;
751}
752
James Smarte59058c2008-08-24 21:49:00 -0400753/**
James Smart3621a712009-04-06 18:47:14 -0400754 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400755 * @phba: pointer to lpfc hba data structure.
756 * @cmdiocb: pointer to lpfc command iocb data structure.
757 * @rspiocb: pointer to lpfc response iocb data structure.
758 *
759 * This routine is the top-level completion callback function for issuing
760 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
761 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
762 * retry has been made (either immediately or delayed with lpfc_els_retry()
763 * returning 1), the command IOCB will be released and function returned.
764 * If the retry attempt has been given up (possibly reach the maximum
765 * number of retries), one additional decrement of ndlp reference shall be
766 * invoked before going out after releasing the command IOCB. This will
767 * actually release the remote node (Note, lpfc_els_free_iocb() will also
768 * invoke one decrement of ndlp reference count). If no error reported in
769 * the IOCB status, the command Port ID field is used to determine whether
770 * this is a point-to-point topology or a fabric topology: if the Port ID
771 * field is assigned, it is a fabric topology; otherwise, it is a
772 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
773 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
774 * specific topology completion conditions.
775 **/
dea31012005-04-17 16:05:31 -0500776static void
James Smart329f9bc2007-04-25 09:53:01 -0400777lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
778 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500779{
James Smart2e0fef82007-06-17 19:56:36 -0500780 struct lpfc_vport *vport = cmdiocb->vport;
781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500782 IOCB_t *irsp = &rspiocb->iocb;
783 struct lpfc_nodelist *ndlp = cmdiocb->context1;
784 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
785 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500786 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500787 int rc;
788
789 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500790 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500791 /* One additional decrement on node reference count to
792 * trigger the release of the node
793 */
James Smart329f9bc2007-04-25 09:53:01 -0400794 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500795 goto out;
796 }
797
James Smart858c9f62007-06-17 19:56:39 -0500798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
799 "FLOGI cmpl: status:x%x/x%x state:x%x",
800 irsp->ulpStatus, irsp->un.ulpWord[4],
801 vport->port_state);
802
dea31012005-04-17 16:05:31 -0500803 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500804 /*
James Smarta93ff372010-10-22 11:06:08 -0400805 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500806 * due to new FCF discovery
807 */
808 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400809 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
810 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
811 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500812 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400813 "2611 FLOGI failed on FCF (x%x), "
814 "status:x%x/x%x, tmo:x%x, perform "
815 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400816 phba->fcf.current_rec.fcf_indx,
817 irsp->ulpStatus, irsp->un.ulpWord[4],
818 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500819 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400820 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
821 if (rc)
822 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500823 }
824
James Smart38b92ef2010-08-04 16:11:39 -0400825 /* FLOGI failure */
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
827 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
828 irsp->ulpStatus, irsp->un.ulpWord[4],
829 irsp->ulpTimeout);
830
dea31012005-04-17 16:05:31 -0500831 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500832 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500833 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500834
James Smart76a95d72010-11-20 23:11:48 -0500835 /* FLOGI failure */
836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
837 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
838 irsp->ulpStatus, irsp->un.ulpWord[4],
839 irsp->ulpTimeout);
840
dea31012005-04-17 16:05:31 -0500841 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500842 spin_lock_irq(shost->host_lock);
843 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
844 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500845
James Smart329f9bc2007-04-25 09:53:01 -0400846 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500847 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
848 * alpa map would take too long otherwise.
849 */
850 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400851 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500852 if ((phba->sli_rev == LPFC_SLI_REV4) &&
853 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
854 (vport->fc_prevDID != vport->fc_myDID))) {
855 if (vport->fc_flag & FC_VFI_REGISTERED)
856 lpfc_sli4_unreg_all_rpis(vport);
857 lpfc_issue_reg_vfi(vport);
858 lpfc_nlp_put(ndlp);
859 goto out;
860 }
dea31012005-04-17 16:05:31 -0500861 }
dea31012005-04-17 16:05:31 -0500862 goto flogifail;
863 }
James Smart695a8142010-01-26 23:08:03 -0500864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400866 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500867 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500868
869 /*
870 * The FLogI succeeded. Sync the data for the CPU before
871 * accessing it.
872 */
873 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
874
875 sp = prsp->virt + sizeof(uint32_t);
876
877 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200879 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400880 "Data: x%x x%x x%x x%x\n",
881 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
882 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500883
James Smart2e0fef82007-06-17 19:56:36 -0500884 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500885 /*
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
888 */
889 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500890 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500891 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500892 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400893 else {
894 lpfc_printf_vlog(vport, KERN_ERR,
895 LOG_FIP | LOG_ELS,
896 "2831 FLOGI response with cleared Fabric "
897 "bit fcf_index 0x%x "
898 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
899 "Fabric Name "
900 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
901 phba->fcf.current_rec.fcf_indx,
902 phba->fcf.current_rec.switch_name[0],
903 phba->fcf.current_rec.switch_name[1],
904 phba->fcf.current_rec.switch_name[2],
905 phba->fcf.current_rec.switch_name[3],
906 phba->fcf.current_rec.switch_name[4],
907 phba->fcf.current_rec.switch_name[5],
908 phba->fcf.current_rec.switch_name[6],
909 phba->fcf.current_rec.switch_name[7],
910 phba->fcf.current_rec.fabric_name[0],
911 phba->fcf.current_rec.fabric_name[1],
912 phba->fcf.current_rec.fabric_name[2],
913 phba->fcf.current_rec.fabric_name[3],
914 phba->fcf.current_rec.fabric_name[4],
915 phba->fcf.current_rec.fabric_name[5],
916 phba->fcf.current_rec.fabric_name[6],
917 phba->fcf.current_rec.fabric_name[7]);
918 lpfc_nlp_put(ndlp);
919 spin_lock_irq(&phba->hbalock);
920 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400921 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400922 spin_unlock_irq(&phba->hbalock);
923 goto out;
924 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500925 if (!rc) {
926 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400927 if (phba->hba_flag & HBA_FIP_SUPPORT)
928 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
929 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400930 "2769 FLOGI to FCF (x%x) "
931 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400932 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500933 spin_lock_irq(&phba->hbalock);
934 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400935 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500936 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500937 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500938 }
dea31012005-04-17 16:05:31 -0500939 }
940
941flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400942 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500943
James Smart858c9f62007-06-17 19:56:39 -0500944 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500945 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500946 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500947
948 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500949 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400950 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
951 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
952 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
953 (phba->link_state != LPFC_CLEAR_LA)) {
954 /* If FLOGI failed enable link interrupt. */
955 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500956 }
dea31012005-04-17 16:05:31 -0500957out:
958 lpfc_els_free_iocb(phba, cmdiocb);
959}
960
James Smarte59058c2008-08-24 21:49:00 -0400961/**
James Smart3621a712009-04-06 18:47:14 -0400962 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400963 * @vport: pointer to a host virtual N_Port data structure.
964 * @ndlp: pointer to a node-list data structure.
965 * @retry: number of retries to the command IOCB.
966 *
967 * This routine issues a Fabric Login (FLOGI) Request ELS command
968 * for a @vport. The initiator service parameters are put into the payload
969 * of the FLOGI Request IOCB and the top-level callback function pointer
970 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
971 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
972 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
973 *
974 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
975 * will be incremented by 1 for holding the ndlp and the reference to ndlp
976 * will be stored into the context1 field of the IOCB for the completion
977 * callback function to the FLOGI ELS command.
978 *
979 * Return code
980 * 0 - successfully issued flogi iocb for @vport
981 * 1 - failed to issue flogi iocb for @vport
982 **/
dea31012005-04-17 16:05:31 -0500983static int
James Smart2e0fef82007-06-17 19:56:36 -0500984lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500985 uint8_t retry)
986{
James Smart2e0fef82007-06-17 19:56:36 -0500987 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500988 struct serv_parm *sp;
989 IOCB_t *icmd;
990 struct lpfc_iocbq *elsiocb;
991 struct lpfc_sli_ring *pring;
992 uint8_t *pcmd;
993 uint16_t cmdsize;
994 uint32_t tmo;
995 int rc;
996
997 pring = &phba->sli.ring[LPFC_ELS_RING];
998
James Smart92d7f7b2007-06-17 19:56:38 -0500999 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001000 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1001 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001002
James Smart488d1462006-03-07 15:02:37 -05001003 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001004 return 1;
dea31012005-04-17 16:05:31 -05001005
1006 icmd = &elsiocb->iocb;
1007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1008
1009 /* For FLOGI request, remainder of payload is service parameters */
1010 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001011 pcmd += sizeof(uint32_t);
1012 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001013 sp = (struct serv_parm *) pcmd;
1014
1015 /* Setup CSPs accordingly for Fabric */
1016 sp->cmn.e_d_tov = 0;
1017 sp->cmn.w2.r_a_tov = 0;
1018 sp->cls1.classValid = 0;
1019 sp->cls2.seqDelivery = 1;
1020 sp->cls3.seqDelivery = 1;
1021 if (sp->cmn.fcphLow < FC_PH3)
1022 sp->cmn.fcphLow = FC_PH3;
1023 if (sp->cmn.fcphHigh < FC_PH3)
1024 sp->cmn.fcphHigh = FC_PH3;
1025
James Smart6fb120a2009-05-22 14:52:59 -04001026 if (phba->sli_rev == LPFC_SLI_REV4) {
1027 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1028 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1029 /* FLOGI needs to be 3 for WQE FCFI */
1030 /* Set the fcfi to the fcfi we registered with */
1031 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1032 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001033 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001034 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1035 icmd->ulpCt_h = 1;
1036 icmd->ulpCt_l = 0;
1037 }
1038
James Smart76a95d72010-11-20 23:11:48 -05001039 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001040 icmd->un.elsreq64.myID = 0;
1041 icmd->un.elsreq64.fl = 1;
1042 }
1043
dea31012005-04-17 16:05:31 -05001044 tmo = phba->fc_ratov;
1045 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001046 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001047 phba->fc_ratov = tmo;
1048
1049 phba->fc_stat.elsXmitFLOGI++;
1050 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001051
1052 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1053 "Issue FLOGI: opt:x%x",
1054 phba->sli3_options, 0, 0);
1055
James Smart92d7f7b2007-06-17 19:56:38 -05001056 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001057 if (rc == IOCB_ERROR) {
1058 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001059 return 1;
dea31012005-04-17 16:05:31 -05001060 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001061 return 0;
dea31012005-04-17 16:05:31 -05001062}
1063
James Smarte59058c2008-08-24 21:49:00 -04001064/**
James Smart3621a712009-04-06 18:47:14 -04001065 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001066 * @phba: pointer to lpfc hba data structure.
1067 *
1068 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1069 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1070 * list and issues an abort IOCB commond on each outstanding IOCB that
1071 * contains a active Fabric_DID ndlp. Note that this function is to issue
1072 * the abort IOCB command on all the outstanding IOCBs, thus when this
1073 * function returns, it does not guarantee all the IOCBs are actually aborted.
1074 *
1075 * Return code
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08001076 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001077 **/
dea31012005-04-17 16:05:31 -05001078int
James Smart2e0fef82007-06-17 19:56:36 -05001079lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001080{
1081 struct lpfc_sli_ring *pring;
1082 struct lpfc_iocbq *iocb, *next_iocb;
1083 struct lpfc_nodelist *ndlp;
1084 IOCB_t *icmd;
1085
1086 /* Abort outstanding I/O on NPort <nlp_DID> */
1087 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001088 "0201 Abort outstanding I/O on NPort x%x\n",
1089 Fabric_DID);
dea31012005-04-17 16:05:31 -05001090
1091 pring = &phba->sli.ring[LPFC_ELS_RING];
1092
1093 /*
1094 * Check the txcmplq for an iocb that matches the nport the driver is
1095 * searching for.
1096 */
James Smart2e0fef82007-06-17 19:56:36 -05001097 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001098 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1099 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001100 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1101 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001102 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001103 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1104 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001105 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001106 }
1107 }
James Smart2e0fef82007-06-17 19:56:36 -05001108 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001109
1110 return 0;
1111}
1112
James Smarte59058c2008-08-24 21:49:00 -04001113/**
James Smart3621a712009-04-06 18:47:14 -04001114 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001115 * @vport: pointer to a host virtual N_Port data structure.
1116 *
1117 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1118 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1119 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1120 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1121 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1122 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1123 * @vport.
1124 *
1125 * Return code
1126 * 0 - failed to issue initial flogi for @vport
1127 * 1 - successfully issued initial flogi for @vport
1128 **/
dea31012005-04-17 16:05:31 -05001129int
James Smart2e0fef82007-06-17 19:56:36 -05001130lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001131{
James Smart2e0fef82007-06-17 19:56:36 -05001132 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001133 struct lpfc_nodelist *ndlp;
1134
James Smart98c9ea52007-10-27 13:37:33 -04001135 vport->port_state = LPFC_FLOGI;
1136 lpfc_set_disctmo(vport);
1137
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001138 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001139 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001140 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001141 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001142 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1143 if (!ndlp)
1144 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001145 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001146 /* Set the node type */
1147 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001148 /* Put ndlp onto node list */
1149 lpfc_enqueue_node(vport, ndlp);
1150 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1151 /* re-setup ndlp without removing from node list */
1152 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1153 if (!ndlp)
1154 return 0;
dea31012005-04-17 16:05:31 -05001155 }
James Smart87af33f2007-10-27 13:37:43 -04001156
James Smart5ac6b302010-10-22 11:05:36 -04001157 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001158 /* This decrement of reference count to node shall kick off
1159 * the release of the node.
1160 */
James Smart329f9bc2007-04-25 09:53:01 -04001161 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001162 return 0;
1163 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001164 return 1;
dea31012005-04-17 16:05:31 -05001165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001169 * @vport: pointer to a host virtual N_Port data structure.
1170 *
1171 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1172 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1173 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1174 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1175 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1176 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1177 * @vport.
1178 *
1179 * Return code
1180 * 0 - failed to issue initial fdisc for @vport
1181 * 1 - successfully issued initial fdisc for @vport
1182 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001183int
1184lpfc_initial_fdisc(struct lpfc_vport *vport)
1185{
1186 struct lpfc_hba *phba = vport->phba;
1187 struct lpfc_nodelist *ndlp;
1188
1189 /* First look for the Fabric ndlp */
1190 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1191 if (!ndlp) {
1192 /* Cannot find existing Fabric ndlp, so allocate a new one */
1193 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1194 if (!ndlp)
1195 return 0;
1196 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001197 /* Put ndlp onto node list */
1198 lpfc_enqueue_node(vport, ndlp);
1199 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1200 /* re-setup ndlp without removing from node list */
1201 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1202 if (!ndlp)
1203 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001204 }
James Smarte47c9092008-02-08 18:49:26 -05001205
James Smart92d7f7b2007-06-17 19:56:38 -05001206 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001207 /* decrement node reference count to trigger the release of
1208 * the node.
1209 */
James Smart92d7f7b2007-06-17 19:56:38 -05001210 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001211 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001212 }
1213 return 1;
1214}
James Smart87af33f2007-10-27 13:37:43 -04001215
James Smarte59058c2008-08-24 21:49:00 -04001216/**
James Smart3621a712009-04-06 18:47:14 -04001217 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001218 * @vport: pointer to a host virtual N_Port data structure.
1219 *
1220 * This routine checks whether there are more remaining Port Logins
1221 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1222 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1223 * to issue ELS PLOGIs up to the configured discover threads with the
1224 * @vport (@vport->cfg_discovery_threads). The function also decrement
1225 * the @vport's num_disc_node by 1 if it is not already 0.
1226 **/
James Smart87af33f2007-10-27 13:37:43 -04001227void
James Smart2e0fef82007-06-17 19:56:36 -05001228lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001229{
1230 int sentplogi;
1231
James Smart2e0fef82007-06-17 19:56:36 -05001232 if (vport->num_disc_nodes)
1233 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001234
1235 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "0232 Continue discovery with %d PLOGIs to go "
1238 "Data: x%x x%x x%x\n",
1239 vport->num_disc_nodes, vport->fc_plogi_cnt,
1240 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001241 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001242 if (vport->fc_flag & FC_NLP_MORE)
1243 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1244 sentplogi = lpfc_els_disc_plogi(vport);
1245
dea31012005-04-17 16:05:31 -05001246 return;
1247}
1248
James Smarte59058c2008-08-24 21:49:00 -04001249/**
James Smart3621a712009-04-06 18:47:14 -04001250 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001251 * @phba: pointer to lpfc hba data structure.
1252 * @prsp: pointer to response IOCB payload.
1253 * @ndlp: pointer to a node-list data structure.
1254 *
1255 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1256 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1257 * The following cases are considered N_Port confirmed:
1258 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1259 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1260 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1261 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1262 * 1) if there is a node on vport list other than the @ndlp with the same
1263 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1264 * on that node to release the RPI associated with the node; 2) if there is
1265 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1266 * into, a new node shall be allocated (or activated). In either case, the
1267 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1268 * be released and the new_ndlp shall be put on to the vport node list and
1269 * its pointer returned as the confirmed node.
1270 *
1271 * Note that before the @ndlp got "released", the keepDID from not-matching
1272 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1273 * of the @ndlp. This is because the release of @ndlp is actually to put it
1274 * into an inactive state on the vport node list and the vport node list
1275 * management algorithm does not allow two node with a same DID.
1276 *
1277 * Return code
1278 * pointer to the PLOGI N_Port @ndlp
1279 **/
James Smart488d1462006-03-07 15:02:37 -05001280static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001281lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001282 struct lpfc_nodelist *ndlp)
1283{
James Smart2e0fef82007-06-17 19:56:36 -05001284 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001285 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001286 struct lpfc_rport_data *rdata;
1287 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001288 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001289 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001290 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001291 int put_node;
1292 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001293
James Smart2fb9bd82006-12-02 13:33:57 -05001294 /* Fabric nodes can have the same WWPN so we don't bother searching
1295 * by WWPN. Just return the ndlp that was given to us.
1296 */
1297 if (ndlp->nlp_type & NLP_FABRIC)
1298 return ndlp;
1299
James Smart92d7f7b2007-06-17 19:56:38 -05001300 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001301 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001302
James Smart685f0bf2007-04-25 09:53:08 -04001303 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001304 * we have for that ndlp. If not, we have some work to do.
1305 */
James Smart2e0fef82007-06-17 19:56:36 -05001306 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001307
James Smarte47c9092008-02-08 18:49:26 -05001308 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001309 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001310
1311 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001312 rc = memcmp(&ndlp->nlp_portname, name,
1313 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001314 if (!rc)
1315 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001316 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1317 if (!new_ndlp)
1318 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001319 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001320 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001321 rc = memcmp(&ndlp->nlp_portname, name,
1322 sizeof(struct lpfc_name));
1323 if (!rc)
1324 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001325 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1326 NLP_STE_UNUSED_NODE);
1327 if (!new_ndlp)
1328 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001329 keepDID = new_ndlp->nlp_DID;
1330 } else
1331 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001332
James Smart2e0fef82007-06-17 19:56:36 -05001333 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001334 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001335 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001336
1337 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1338 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1339 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1340
James Smarte47c9092008-02-08 18:49:26 -05001341 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001342 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001343
James Smart2e0fef82007-06-17 19:56:36 -05001344 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001345 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1346 /* The new_ndlp is replacing ndlp totally, so we need
1347 * to put ndlp on UNUSED list and try to free it.
1348 */
James Smart0ff10d42008-01-11 01:52:36 -05001349
1350 /* Fix up the rport accordingly */
1351 rport = ndlp->rport;
1352 if (rport) {
1353 rdata = rport->dd_data;
1354 if (rdata->pnode == ndlp) {
1355 lpfc_nlp_put(ndlp);
1356 ndlp->rport = NULL;
1357 rdata->pnode = lpfc_nlp_get(new_ndlp);
1358 new_ndlp->rport = rport;
1359 }
1360 new_ndlp->nlp_type = ndlp->nlp_type;
1361 }
James Smart58da1ff2008-04-07 10:15:56 -04001362 /* We shall actually free the ndlp with both nlp_DID and
1363 * nlp_portname fields equals 0 to avoid any ndlp on the
1364 * nodelist never to be used.
1365 */
1366 if (ndlp->nlp_DID == 0) {
1367 spin_lock_irq(&phba->ndlp_lock);
1368 NLP_SET_FREE_REQ(ndlp);
1369 spin_unlock_irq(&phba->ndlp_lock);
1370 }
James Smart0ff10d42008-01-11 01:52:36 -05001371
James Smart58da1ff2008-04-07 10:15:56 -04001372 /* Two ndlps cannot have the same did on the nodelist */
1373 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001374 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001375 }
James Smart92795652006-07-06 15:50:02 -04001376 else {
James Smart2e0fef82007-06-17 19:56:36 -05001377 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001378 /* Two ndlps cannot have the same did */
1379 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001380 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001381 /* Since we are swapping the ndlp passed in with the new one
1382 * and the did has already been swapped, copy over the
1383 * state and names.
1384 */
1385 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1386 sizeof(struct lpfc_name));
1387 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1388 sizeof(struct lpfc_name));
1389 new_ndlp->nlp_state = ndlp->nlp_state;
1390 /* Fix up the rport accordingly */
1391 rport = ndlp->rport;
1392 if (rport) {
1393 rdata = rport->dd_data;
1394 put_node = rdata->pnode != NULL;
1395 put_rport = ndlp->rport != NULL;
1396 rdata->pnode = NULL;
1397 ndlp->rport = NULL;
1398 if (put_node)
1399 lpfc_nlp_put(ndlp);
1400 if (put_rport)
1401 put_device(&rport->dev);
1402 }
James Smart92795652006-07-06 15:50:02 -04001403 }
James Smart488d1462006-03-07 15:02:37 -05001404 return new_ndlp;
1405}
1406
James Smarte59058c2008-08-24 21:49:00 -04001407/**
James Smart3621a712009-04-06 18:47:14 -04001408 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001409 * @vport: pointer to a host virtual N_Port data structure.
1410 *
1411 * This routine checks whether more Registration State Change
1412 * Notifications (RSCNs) came in while the discovery state machine was in
1413 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1414 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1415 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1416 * handling the RSCNs.
1417 **/
James Smart87af33f2007-10-27 13:37:43 -04001418void
1419lpfc_end_rscn(struct lpfc_vport *vport)
1420{
1421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1422
1423 if (vport->fc_flag & FC_RSCN_MODE) {
1424 /*
1425 * Check to see if more RSCNs came in while we were
1426 * processing this one.
1427 */
1428 if (vport->fc_rscn_id_cnt ||
1429 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1430 lpfc_els_handle_rscn(vport);
1431 else {
1432 spin_lock_irq(shost->host_lock);
1433 vport->fc_flag &= ~FC_RSCN_MODE;
1434 spin_unlock_irq(shost->host_lock);
1435 }
1436 }
1437}
1438
James Smarte59058c2008-08-24 21:49:00 -04001439/**
James Smart3621a712009-04-06 18:47:14 -04001440 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001441 * @phba: pointer to lpfc hba data structure.
1442 * @cmdiocb: pointer to lpfc command iocb data structure.
1443 * @rspiocb: pointer to lpfc response iocb data structure.
1444 *
1445 * This routine is the completion callback function for issuing the Port
1446 * Login (PLOGI) command. For PLOGI completion, there must be an active
1447 * ndlp on the vport node list that matches the remote node ID from the
1448 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1449 * ignored and command IOCB released. The PLOGI response IOCB status is
1450 * checked for error conditons. If there is error status reported, PLOGI
1451 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1452 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1453 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1454 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1455 * there are additional N_Port nodes with the vport that need to perform
1456 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1457 * PLOGIs.
1458 **/
dea31012005-04-17 16:05:31 -05001459static void
James Smart2e0fef82007-06-17 19:56:36 -05001460lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1461 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001462{
James Smart2e0fef82007-06-17 19:56:36 -05001463 struct lpfc_vport *vport = cmdiocb->vport;
1464 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001465 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001466 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001467 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001468 int disc, rc, did, type;
1469
dea31012005-04-17 16:05:31 -05001470 /* we pass cmdiocb to state machine which needs rspiocb as well */
1471 cmdiocb->context_un.rsp_iocb = rspiocb;
1472
1473 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001474 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1475 "PLOGI cmpl: status:x%x/x%x did:x%x",
1476 irsp->ulpStatus, irsp->un.ulpWord[4],
1477 irsp->un.elsreq64.remoteID);
1478
James Smart2e0fef82007-06-17 19:56:36 -05001479 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001480 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1482 "0136 PLOGI completes to NPort x%x "
1483 "with no ndlp. Data: x%x x%x x%x\n",
1484 irsp->un.elsreq64.remoteID,
1485 irsp->ulpStatus, irsp->un.ulpWord[4],
1486 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001487 goto out;
James Smarted957682007-06-17 19:56:37 -05001488 }
dea31012005-04-17 16:05:31 -05001489
1490 /* Since ndlp can be freed in the disc state machine, note if this node
1491 * is being used during discovery.
1492 */
James Smart2e0fef82007-06-17 19:56:36 -05001493 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001494 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001495 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001496 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001497 rc = 0;
1498
1499 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1501 "0102 PLOGI completes to NPort x%x "
1502 "Data: x%x x%x x%x x%x x%x\n",
1503 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1504 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001505 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001506 if (lpfc_els_chk_latt(vport)) {
1507 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001508 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001509 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001510 goto out;
1511 }
1512
1513 /* ndlp could be freed in DSM, save these values now */
1514 type = ndlp->nlp_type;
1515 did = ndlp->nlp_DID;
1516
1517 if (irsp->ulpStatus) {
1518 /* Check for retry */
1519 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1520 /* ELS command is being retried */
1521 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001522 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001523 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001524 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001525 }
1526 goto out;
1527 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001528 /* PLOGI failed Don't print the vport to vport rjts */
1529 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1530 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1531 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1532 (phba)->pport->cfg_log_verbose & LOG_ELS)
1533 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001534 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1535 ndlp->nlp_DID, irsp->ulpStatus,
1536 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001537 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001538 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001539 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001540 else
James Smart2e0fef82007-06-17 19:56:36 -05001541 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001542 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001543 } else {
1544 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001545 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001546 cmdiocb->context2)->list.next,
1547 struct lpfc_dmabuf, list);
1548 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001549 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001550 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001551 }
1552
James Smart2e0fef82007-06-17 19:56:36 -05001553 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001554 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001555 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001556
James Smart2e0fef82007-06-17 19:56:36 -05001557 if (vport->num_disc_nodes == 0) {
1558 spin_lock_irq(shost->host_lock);
1559 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1560 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001561
James Smart2e0fef82007-06-17 19:56:36 -05001562 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001563 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001564 }
1565 }
1566
1567out:
1568 lpfc_els_free_iocb(phba, cmdiocb);
1569 return;
1570}
1571
James Smarte59058c2008-08-24 21:49:00 -04001572/**
James Smart3621a712009-04-06 18:47:14 -04001573 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001574 * @vport: pointer to a host virtual N_Port data structure.
1575 * @did: destination port identifier.
1576 * @retry: number of retries to the command IOCB.
1577 *
1578 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1579 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1580 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1581 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1582 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1583 *
1584 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1585 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1586 * will be stored into the context1 field of the IOCB for the completion
1587 * callback function to the PLOGI ELS command.
1588 *
1589 * Return code
1590 * 0 - Successfully issued a plogi for @vport
1591 * 1 - failed to issue a plogi for @vport
1592 **/
dea31012005-04-17 16:05:31 -05001593int
James Smart2e0fef82007-06-17 19:56:36 -05001594lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001595{
James Smart2e0fef82007-06-17 19:56:36 -05001596 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001597 struct serv_parm *sp;
1598 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001599 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001600 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001601 struct lpfc_sli *psli;
1602 uint8_t *pcmd;
1603 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001604 int ret;
dea31012005-04-17 16:05:31 -05001605
1606 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001607
James Smart98c9ea52007-10-27 13:37:33 -04001608 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001609 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1610 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001611
James Smarte47c9092008-02-08 18:49:26 -05001612 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001613 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001614 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001615 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001616 if (!elsiocb)
1617 return 1;
dea31012005-04-17 16:05:31 -05001618
1619 icmd = &elsiocb->iocb;
1620 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1621
1622 /* For PLOGI request, remainder of payload is service parameters */
1623 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001624 pcmd += sizeof(uint32_t);
1625 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001626 sp = (struct serv_parm *) pcmd;
1627
James Smart5ac6b302010-10-22 11:05:36 -04001628 /*
1629 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1630 * to device on remote loops work.
1631 */
1632 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1633 sp->cmn.altBbCredit = 1;
1634
dea31012005-04-17 16:05:31 -05001635 if (sp->cmn.fcphLow < FC_PH_4_3)
1636 sp->cmn.fcphLow = FC_PH_4_3;
1637
1638 if (sp->cmn.fcphHigh < FC_PH3)
1639 sp->cmn.fcphHigh = FC_PH3;
1640
James Smart858c9f62007-06-17 19:56:39 -05001641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1642 "Issue PLOGI: did:x%x",
1643 did, 0, 0);
1644
dea31012005-04-17 16:05:31 -05001645 phba->fc_stat.elsXmitPLOGI++;
1646 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001647 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001648
1649 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001650 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001651 return 1;
dea31012005-04-17 16:05:31 -05001652 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001653 return 0;
dea31012005-04-17 16:05:31 -05001654}
1655
James Smarte59058c2008-08-24 21:49:00 -04001656/**
James Smart3621a712009-04-06 18:47:14 -04001657 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001658 * @phba: pointer to lpfc hba data structure.
1659 * @cmdiocb: pointer to lpfc command iocb data structure.
1660 * @rspiocb: pointer to lpfc response iocb data structure.
1661 *
1662 * This routine is the completion callback function for a Process Login
1663 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1664 * status. If there is error status reported, PRLI retry shall be attempted
1665 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1666 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1667 * ndlp to mark the PRLI completion.
1668 **/
dea31012005-04-17 16:05:31 -05001669static void
James Smart2e0fef82007-06-17 19:56:36 -05001670lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1671 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001672{
James Smart2e0fef82007-06-17 19:56:36 -05001673 struct lpfc_vport *vport = cmdiocb->vport;
1674 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001675 IOCB_t *irsp;
1676 struct lpfc_sli *psli;
1677 struct lpfc_nodelist *ndlp;
1678
1679 psli = &phba->sli;
1680 /* we pass cmdiocb to state machine which needs rspiocb as well */
1681 cmdiocb->context_un.rsp_iocb = rspiocb;
1682
1683 irsp = &(rspiocb->iocb);
1684 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001685 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001686 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001687 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001688
James Smart858c9f62007-06-17 19:56:39 -05001689 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1690 "PRLI cmpl: status:x%x/x%x did:x%x",
1691 irsp->ulpStatus, irsp->un.ulpWord[4],
1692 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001693 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001694 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1695 "0103 PRLI completes to NPort x%x "
1696 "Data: x%x x%x x%x x%x\n",
1697 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1698 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001699
James Smart2e0fef82007-06-17 19:56:36 -05001700 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001701 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001702 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001703 goto out;
1704
1705 if (irsp->ulpStatus) {
1706 /* Check for retry */
1707 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1708 /* ELS command is being retried */
1709 goto out;
1710 }
1711 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001712 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1713 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1714 ndlp->nlp_DID, irsp->ulpStatus,
1715 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001716 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001717 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001718 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001719 else
James Smart2e0fef82007-06-17 19:56:36 -05001720 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001721 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001722 } else
dea31012005-04-17 16:05:31 -05001723 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001724 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001725 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001726out:
1727 lpfc_els_free_iocb(phba, cmdiocb);
1728 return;
1729}
1730
James Smarte59058c2008-08-24 21:49:00 -04001731/**
James Smart3621a712009-04-06 18:47:14 -04001732 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001733 * @vport: pointer to a host virtual N_Port data structure.
1734 * @ndlp: pointer to a node-list data structure.
1735 * @retry: number of retries to the command IOCB.
1736 *
1737 * This routine issues a Process Login (PRLI) ELS command for the
1738 * @vport. The PRLI service parameters are set up in the payload of the
1739 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1740 * is put to the IOCB completion callback func field before invoking the
1741 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1742 *
1743 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1744 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1745 * will be stored into the context1 field of the IOCB for the completion
1746 * callback function to the PRLI ELS command.
1747 *
1748 * Return code
1749 * 0 - successfully issued prli iocb command for @vport
1750 * 1 - failed to issue prli iocb command for @vport
1751 **/
dea31012005-04-17 16:05:31 -05001752int
James Smart2e0fef82007-06-17 19:56:36 -05001753lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001754 uint8_t retry)
1755{
James Smart2e0fef82007-06-17 19:56:36 -05001756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1757 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001758 PRLI *npr;
1759 IOCB_t *icmd;
1760 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001761 uint8_t *pcmd;
1762 uint16_t cmdsize;
1763
James Smart92d7f7b2007-06-17 19:56:38 -05001764 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001765 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1766 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001767 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001768 return 1;
dea31012005-04-17 16:05:31 -05001769
1770 icmd = &elsiocb->iocb;
1771 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1772
1773 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001774 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001775 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001776 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001777
1778 /* For PRLI, remainder of payload is PRLI parameter page */
1779 npr = (PRLI *) pcmd;
1780 /*
1781 * If our firmware version is 3.20 or later,
1782 * set the following bits for FC-TAPE support.
1783 */
1784 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1785 npr->ConfmComplAllowed = 1;
1786 npr->Retry = 1;
1787 npr->TaskRetryIdReq = 1;
1788 }
1789 npr->estabImagePair = 1;
1790 npr->readXferRdyDis = 1;
1791
1792 /* For FCP support */
1793 npr->prliType = PRLI_FCP_TYPE;
1794 npr->initiatorFunc = 1;
1795
James Smart858c9f62007-06-17 19:56:39 -05001796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1797 "Issue PRLI: did:x%x",
1798 ndlp->nlp_DID, 0, 0);
1799
dea31012005-04-17 16:05:31 -05001800 phba->fc_stat.elsXmitPRLI++;
1801 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001802 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001803 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001804 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001805 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1806 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001807 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001808 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001809 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001810 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001811 return 1;
dea31012005-04-17 16:05:31 -05001812 }
James Smart2e0fef82007-06-17 19:56:36 -05001813 vport->fc_prli_sent++;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001814 return 0;
dea31012005-04-17 16:05:31 -05001815}
1816
James Smarte59058c2008-08-24 21:49:00 -04001817/**
James Smart3621a712009-04-06 18:47:14 -04001818 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001819 * @vport: pointer to a host virtual N_Port data structure.
1820 *
1821 * This routine performs Registration State Change Notification (RSCN)
1822 * discovery for a @vport. If the @vport's node port recovery count is not
1823 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1824 * the nodes that need recovery. If none of the PLOGI were needed through
1825 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1826 * invoked to check and handle possible more RSCN came in during the period
1827 * of processing the current ones.
1828 **/
1829static void
1830lpfc_rscn_disc(struct lpfc_vport *vport)
1831{
1832 lpfc_can_disctmo(vport);
1833
1834 /* RSCN discovery */
1835 /* go thru NPR nodes and issue ELS PLOGIs */
1836 if (vport->fc_npr_cnt)
1837 if (lpfc_els_disc_plogi(vport))
1838 return;
1839
1840 lpfc_end_rscn(vport);
1841}
1842
1843/**
James Smart3621a712009-04-06 18:47:14 -04001844 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001845 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1846 *
1847 * This function is called when the final ADISC is completed during discovery.
1848 * This function handles clearing link attention or issuing reg_vpi depending
1849 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1850 * discovery.
1851 * This function is called with no locks held.
1852 **/
1853static void
1854lpfc_adisc_done(struct lpfc_vport *vport)
1855{
1856 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1857 struct lpfc_hba *phba = vport->phba;
1858
1859 /*
1860 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1861 * and continue discovery.
1862 */
1863 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001864 !(vport->fc_flag & FC_RSCN_MODE) &&
1865 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001866 lpfc_issue_reg_vpi(phba, vport);
1867 return;
1868 }
1869 /*
1870 * For SLI2, we need to set port_state to READY
1871 * and continue discovery.
1872 */
1873 if (vport->port_state < LPFC_VPORT_READY) {
1874 /* If we get here, there is nothing to ADISC */
1875 if (vport->port_type == LPFC_PHYSICAL_PORT)
1876 lpfc_issue_clear_la(phba, vport);
1877 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1878 vport->num_disc_nodes = 0;
1879 /* go thru NPR list, issue ELS PLOGIs */
1880 if (vport->fc_npr_cnt)
1881 lpfc_els_disc_plogi(vport);
1882 if (!vport->num_disc_nodes) {
1883 spin_lock_irq(shost->host_lock);
1884 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1885 spin_unlock_irq(shost->host_lock);
1886 lpfc_can_disctmo(vport);
1887 lpfc_end_rscn(vport);
1888 }
1889 }
1890 vport->port_state = LPFC_VPORT_READY;
1891 } else
1892 lpfc_rscn_disc(vport);
1893}
1894
1895/**
James Smart3621a712009-04-06 18:47:14 -04001896 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001897 * @vport: pointer to a host virtual N_Port data structure.
1898 *
1899 * This routine determines whether there are more ndlps on a @vport
1900 * node list need to have Address Discover (ADISC) issued. If so, it will
1901 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1902 * remaining nodes which need to have ADISC sent.
1903 **/
James Smart0ff10d42008-01-11 01:52:36 -05001904void
James Smart2e0fef82007-06-17 19:56:36 -05001905lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001906{
1907 int sentadisc;
1908
James Smart2e0fef82007-06-17 19:56:36 -05001909 if (vport->num_disc_nodes)
1910 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001911 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001912 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1913 "0210 Continue discovery with %d ADISCs to go "
1914 "Data: x%x x%x x%x\n",
1915 vport->num_disc_nodes, vport->fc_adisc_cnt,
1916 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001917 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001918 if (vport->fc_flag & FC_NLP_MORE) {
1919 lpfc_set_disctmo(vport);
1920 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1921 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001922 }
James Smart90160e02008-08-24 21:49:45 -04001923 if (!vport->num_disc_nodes)
1924 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001925 return;
1926}
1927
James Smarte59058c2008-08-24 21:49:00 -04001928/**
James Smart3621a712009-04-06 18:47:14 -04001929 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001930 * @phba: pointer to lpfc hba data structure.
1931 * @cmdiocb: pointer to lpfc command iocb data structure.
1932 * @rspiocb: pointer to lpfc response iocb data structure.
1933 *
1934 * This routine is the completion function for issuing the Address Discover
1935 * (ADISC) command. It first checks to see whether link went down during
1936 * the discovery process. If so, the node will be marked as node port
1937 * recovery for issuing discover IOCB by the link attention handler and
1938 * exit. Otherwise, the response status is checked. If error was reported
1939 * in the response status, the ADISC command shall be retried by invoking
1940 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1941 * the response status, the state machine is invoked to set transition
1942 * with respect to NLP_EVT_CMPL_ADISC event.
1943 **/
dea31012005-04-17 16:05:31 -05001944static void
James Smart2e0fef82007-06-17 19:56:36 -05001945lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1946 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001947{
James Smart2e0fef82007-06-17 19:56:36 -05001948 struct lpfc_vport *vport = cmdiocb->vport;
1949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001950 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001951 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001952 int disc;
dea31012005-04-17 16:05:31 -05001953
1954 /* we pass cmdiocb to state machine which needs rspiocb as well */
1955 cmdiocb->context_un.rsp_iocb = rspiocb;
1956
1957 irsp = &(rspiocb->iocb);
1958 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001959
James Smart858c9f62007-06-17 19:56:39 -05001960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1961 "ADISC cmpl: status:x%x/x%x did:x%x",
1962 irsp->ulpStatus, irsp->un.ulpWord[4],
1963 ndlp->nlp_DID);
1964
dea31012005-04-17 16:05:31 -05001965 /* Since ndlp can be freed in the disc state machine, note if this node
1966 * is being used during discovery.
1967 */
James Smart2e0fef82007-06-17 19:56:36 -05001968 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001969 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001970 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001971 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001972 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001973 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1974 "0104 ADISC completes to NPort x%x "
1975 "Data: x%x x%x x%x x%x x%x\n",
1976 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1977 irsp->ulpTimeout, disc, vport->num_disc_nodes);
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)) {
1980 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001981 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001982 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001983 goto out;
1984 }
1985
1986 if (irsp->ulpStatus) {
1987 /* Check for retry */
1988 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1989 /* ELS command is being retried */
1990 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001991 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001992 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001993 spin_unlock_irq(shost->host_lock);
1994 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001995 }
1996 goto out;
1997 }
1998 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001999 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2000 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2001 ndlp->nlp_DID, irsp->ulpStatus,
2002 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002003 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002004 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002005 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002006 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002007 } else
dea31012005-04-17 16:05:31 -05002008 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002009 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002010 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002011
James Smart90160e02008-08-24 21:49:45 -04002012 /* Check to see if there are more ADISCs to be sent */
2013 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002014 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002015out:
2016 lpfc_els_free_iocb(phba, cmdiocb);
2017 return;
2018}
2019
James Smarte59058c2008-08-24 21:49:00 -04002020/**
James Smart3621a712009-04-06 18:47:14 -04002021 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002022 * @vport: pointer to a virtual N_Port data structure.
2023 * @ndlp: pointer to a node-list data structure.
2024 * @retry: number of retries to the command IOCB.
2025 *
2026 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2027 * @vport. It prepares the payload of the ADISC ELS command, updates the
2028 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2029 * to issue the ADISC ELS command.
2030 *
2031 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2032 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2033 * will be stored into the context1 field of the IOCB for the completion
2034 * callback function to the ADISC ELS command.
2035 *
2036 * Return code
2037 * 0 - successfully issued adisc
2038 * 1 - failed to issue adisc
2039 **/
dea31012005-04-17 16:05:31 -05002040int
James Smart2e0fef82007-06-17 19:56:36 -05002041lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002042 uint8_t retry)
2043{
James Smart2e0fef82007-06-17 19:56:36 -05002044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2045 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002046 ADISC *ap;
2047 IOCB_t *icmd;
2048 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002049 uint8_t *pcmd;
2050 uint16_t cmdsize;
2051
James Smart92d7f7b2007-06-17 19:56:38 -05002052 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002053 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2054 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002055 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002056 return 1;
dea31012005-04-17 16:05:31 -05002057
2058 icmd = &elsiocb->iocb;
2059 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2060
2061 /* For ADISC request, remainder of payload is service parameters */
2062 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002063 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002064
2065 /* Fill in ADISC payload */
2066 ap = (ADISC *) pcmd;
2067 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002068 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2069 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002070 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002071
James Smart858c9f62007-06-17 19:56:39 -05002072 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2073 "Issue ADISC: did:x%x",
2074 ndlp->nlp_DID, 0, 0);
2075
dea31012005-04-17 16:05:31 -05002076 phba->fc_stat.elsXmitADISC++;
2077 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002078 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002079 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002080 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002081 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2082 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002083 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002084 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002085 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002086 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002087 return 1;
dea31012005-04-17 16:05:31 -05002088 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002089 return 0;
dea31012005-04-17 16:05:31 -05002090}
2091
James Smarte59058c2008-08-24 21:49:00 -04002092/**
James Smart3621a712009-04-06 18:47:14 -04002093 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002094 * @phba: pointer to lpfc hba data structure.
2095 * @cmdiocb: pointer to lpfc command iocb data structure.
2096 * @rspiocb: pointer to lpfc response iocb data structure.
2097 *
2098 * This routine is the completion function for issuing the ELS Logout (LOGO)
2099 * command. If no error status was reported from the LOGO response, the
2100 * state machine of the associated ndlp shall be invoked for transition with
2101 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2102 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2103 **/
dea31012005-04-17 16:05:31 -05002104static void
James Smart2e0fef82007-06-17 19:56:36 -05002105lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2106 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002107{
James Smart2e0fef82007-06-17 19:56:36 -05002108 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2109 struct lpfc_vport *vport = ndlp->vport;
2110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002111 IOCB_t *irsp;
2112 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002113
2114 psli = &phba->sli;
2115 /* we pass cmdiocb to state machine which needs rspiocb as well */
2116 cmdiocb->context_un.rsp_iocb = rspiocb;
2117
2118 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002119 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002120 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002121 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002122
James Smart858c9f62007-06-17 19:56:39 -05002123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2124 "LOGO cmpl: status:x%x/x%x did:x%x",
2125 irsp->ulpStatus, irsp->un.ulpWord[4],
2126 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002127 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2129 "0105 LOGO completes to NPort x%x "
2130 "Data: x%x x%x x%x x%x\n",
2131 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2132 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002133 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002134 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002135 goto out;
2136
James Smart92d7f7b2007-06-17 19:56:38 -05002137 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2138 /* NLP_EVT_DEVICE_RM should unregister the RPI
2139 * which should abort all outstanding IOs.
2140 */
2141 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2142 NLP_EVT_DEVICE_RM);
2143 goto out;
2144 }
2145
dea31012005-04-17 16:05:31 -05002146 if (irsp->ulpStatus) {
2147 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002148 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002149 /* ELS command is being retried */
2150 goto out;
dea31012005-04-17 16:05:31 -05002151 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002152 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2153 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2154 ndlp->nlp_DID, irsp->ulpStatus,
2155 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002156 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002157 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002158 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002159 else
James Smart2e0fef82007-06-17 19:56:36 -05002160 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002161 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002162 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002163 /* Good status, call state machine.
2164 * This will unregister the rpi if needed.
2165 */
James Smart2e0fef82007-06-17 19:56:36 -05002166 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002167 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002168out:
2169 lpfc_els_free_iocb(phba, cmdiocb);
2170 return;
2171}
2172
James Smarte59058c2008-08-24 21:49:00 -04002173/**
James Smart3621a712009-04-06 18:47:14 -04002174 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002175 * @vport: pointer to a virtual N_Port data structure.
2176 * @ndlp: pointer to a node-list data structure.
2177 * @retry: number of retries to the command IOCB.
2178 *
2179 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2180 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2181 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2182 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2183 *
2184 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2185 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2186 * will be stored into the context1 field of the IOCB for the completion
2187 * callback function to the LOGO ELS command.
2188 *
2189 * Return code
2190 * 0 - successfully issued logo
2191 * 1 - failed to issue logo
2192 **/
dea31012005-04-17 16:05:31 -05002193int
James Smart2e0fef82007-06-17 19:56:36 -05002194lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002195 uint8_t retry)
2196{
James Smart2e0fef82007-06-17 19:56:36 -05002197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2198 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002199 IOCB_t *icmd;
2200 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002201 uint8_t *pcmd;
2202 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002203 int rc;
dea31012005-04-17 16:05:31 -05002204
James Smart98c9ea52007-10-27 13:37:33 -04002205 spin_lock_irq(shost->host_lock);
2206 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2207 spin_unlock_irq(shost->host_lock);
2208 return 0;
2209 }
2210 spin_unlock_irq(shost->host_lock);
2211
James Smart92d7f7b2007-06-17 19:56:38 -05002212 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002213 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2214 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002215 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002216 return 1;
dea31012005-04-17 16:05:31 -05002217
2218 icmd = &elsiocb->iocb;
2219 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2220 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002221 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002222
2223 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002224 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002225 pcmd += sizeof(uint32_t);
2226 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002227
James Smart858c9f62007-06-17 19:56:39 -05002228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2229 "Issue LOGO: did:x%x",
2230 ndlp->nlp_DID, 0, 0);
2231
dea31012005-04-17 16:05:31 -05002232 phba->fc_stat.elsXmitLOGO++;
2233 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002234 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002235 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002236 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002237 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002238
2239 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002240 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002241 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002242 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002243 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002244 return 1;
dea31012005-04-17 16:05:31 -05002245 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002246 return 0;
dea31012005-04-17 16:05:31 -05002247}
2248
James Smarte59058c2008-08-24 21:49:00 -04002249/**
James Smart3621a712009-04-06 18:47:14 -04002250 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002251 * @phba: pointer to lpfc hba data structure.
2252 * @cmdiocb: pointer to lpfc command iocb data structure.
2253 * @rspiocb: pointer to lpfc response iocb data structure.
2254 *
2255 * This routine is a generic completion callback function for ELS commands.
2256 * Specifically, it is the callback function which does not need to perform
2257 * any command specific operations. It is currently used by the ELS command
2258 * issuing routines for the ELS State Change Request (SCR),
2259 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2260 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2261 * certain debug loggings, this callback function simply invokes the
2262 * lpfc_els_chk_latt() routine to check whether link went down during the
2263 * discovery process.
2264 **/
dea31012005-04-17 16:05:31 -05002265static void
James Smart2e0fef82007-06-17 19:56:36 -05002266lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2267 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002268{
James Smart2e0fef82007-06-17 19:56:36 -05002269 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002270 IOCB_t *irsp;
2271
2272 irsp = &rspiocb->iocb;
2273
James Smart858c9f62007-06-17 19:56:39 -05002274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2275 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2276 irsp->ulpStatus, irsp->un.ulpWord[4],
2277 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002278 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002279 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2280 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2281 irsp->ulpIoTag, irsp->ulpStatus,
2282 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002283 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002284 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002285 lpfc_els_free_iocb(phba, cmdiocb);
2286 return;
2287}
2288
James Smarte59058c2008-08-24 21:49:00 -04002289/**
James Smart3621a712009-04-06 18:47:14 -04002290 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002291 * @vport: pointer to a host virtual N_Port data structure.
2292 * @nportid: N_Port identifier to the remote node.
2293 * @retry: number of retries to the command IOCB.
2294 *
2295 * This routine issues a State Change Request (SCR) to a fabric node
2296 * on a @vport. The remote node @nportid is passed into the function. It
2297 * first search the @vport node list to find the matching ndlp. If no such
2298 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2299 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2300 * routine is invoked to send the SCR IOCB.
2301 *
2302 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2303 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2304 * will be stored into the context1 field of the IOCB for the completion
2305 * callback function to the SCR ELS command.
2306 *
2307 * Return code
2308 * 0 - Successfully issued scr command
2309 * 1 - Failed to issue scr command
2310 **/
dea31012005-04-17 16:05:31 -05002311int
James Smart2e0fef82007-06-17 19:56:36 -05002312lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002313{
James Smart2e0fef82007-06-17 19:56:36 -05002314 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002315 IOCB_t *icmd;
2316 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002317 struct lpfc_sli *psli;
2318 uint8_t *pcmd;
2319 uint16_t cmdsize;
2320 struct lpfc_nodelist *ndlp;
2321
2322 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002323 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002324
James Smarte47c9092008-02-08 18:49:26 -05002325 ndlp = lpfc_findnode_did(vport, nportid);
2326 if (!ndlp) {
2327 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2328 if (!ndlp)
2329 return 1;
2330 lpfc_nlp_init(vport, ndlp, nportid);
2331 lpfc_enqueue_node(vport, ndlp);
2332 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2333 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2334 if (!ndlp)
2335 return 1;
2336 }
dea31012005-04-17 16:05:31 -05002337
James Smart2e0fef82007-06-17 19:56:36 -05002338 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2339 ndlp->nlp_DID, ELS_CMD_SCR);
2340
James Smart488d1462006-03-07 15:02:37 -05002341 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002342 /* This will trigger the release of the node just
2343 * allocated
2344 */
James Smart329f9bc2007-04-25 09:53:01 -04002345 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002346 return 1;
dea31012005-04-17 16:05:31 -05002347 }
2348
2349 icmd = &elsiocb->iocb;
2350 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2351
2352 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002353 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002354
2355 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002356 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002357 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2358
James Smart858c9f62007-06-17 19:56:39 -05002359 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2360 "Issue SCR: did:x%x",
2361 ndlp->nlp_DID, 0, 0);
2362
dea31012005-04-17 16:05:31 -05002363 phba->fc_stat.elsXmitSCR++;
2364 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002365 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2366 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002367 /* The additional lpfc_nlp_put will cause the following
2368 * lpfc_els_free_iocb routine to trigger the rlease of
2369 * the node.
2370 */
James Smart329f9bc2007-04-25 09:53:01 -04002371 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002372 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002373 return 1;
dea31012005-04-17 16:05:31 -05002374 }
James Smartfa4066b2008-01-11 01:53:27 -05002375 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2376 * trigger the release of node.
2377 */
James Smart329f9bc2007-04-25 09:53:01 -04002378 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002379 return 0;
dea31012005-04-17 16:05:31 -05002380}
2381
James Smarte59058c2008-08-24 21:49:00 -04002382/**
James Smart3621a712009-04-06 18:47:14 -04002383 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002384 * @vport: pointer to a host virtual N_Port data structure.
2385 * @nportid: N_Port identifier to the remote node.
2386 * @retry: number of retries to the command IOCB.
2387 *
2388 * This routine issues a Fibre Channel Address Resolution Response
2389 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2390 * is passed into the function. It first search the @vport node list to find
2391 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2392 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2393 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2394 *
2395 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2396 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2397 * will be stored into the context1 field of the IOCB for the completion
2398 * callback function to the PARPR ELS command.
2399 *
2400 * Return code
2401 * 0 - Successfully issued farpr command
2402 * 1 - Failed to issue farpr command
2403 **/
dea31012005-04-17 16:05:31 -05002404static int
James Smart2e0fef82007-06-17 19:56:36 -05002405lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002406{
James Smart2e0fef82007-06-17 19:56:36 -05002407 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002408 IOCB_t *icmd;
2409 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002410 struct lpfc_sli *psli;
2411 FARP *fp;
2412 uint8_t *pcmd;
2413 uint32_t *lp;
2414 uint16_t cmdsize;
2415 struct lpfc_nodelist *ondlp;
2416 struct lpfc_nodelist *ndlp;
2417
2418 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002419 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002420
James Smarte47c9092008-02-08 18:49:26 -05002421 ndlp = lpfc_findnode_did(vport, nportid);
2422 if (!ndlp) {
2423 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2424 if (!ndlp)
2425 return 1;
2426 lpfc_nlp_init(vport, ndlp, nportid);
2427 lpfc_enqueue_node(vport, ndlp);
2428 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2429 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2430 if (!ndlp)
2431 return 1;
2432 }
James Smart2e0fef82007-06-17 19:56:36 -05002433
2434 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2435 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002436 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002437 /* This will trigger the release of the node just
2438 * allocated
2439 */
James Smart329f9bc2007-04-25 09:53:01 -04002440 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002441 return 1;
dea31012005-04-17 16:05:31 -05002442 }
2443
2444 icmd = &elsiocb->iocb;
2445 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2446
2447 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002448 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002449
2450 /* Fill in FARPR payload */
2451 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002452 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002453 lp = (uint32_t *) pcmd;
2454 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002455 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002456 fp->Rflags = 0;
2457 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2458
James Smart92d7f7b2007-06-17 19:56:38 -05002459 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2460 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002461 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002462 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002463 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002464 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002465 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002466 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002467 }
2468
James Smart858c9f62007-06-17 19:56:39 -05002469 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2470 "Issue FARPR: did:x%x",
2471 ndlp->nlp_DID, 0, 0);
2472
dea31012005-04-17 16:05:31 -05002473 phba->fc_stat.elsXmitFARPR++;
2474 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002475 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2476 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002477 /* The additional lpfc_nlp_put will cause the following
2478 * lpfc_els_free_iocb routine to trigger the release of
2479 * the node.
2480 */
James Smart329f9bc2007-04-25 09:53:01 -04002481 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002482 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002483 return 1;
dea31012005-04-17 16:05:31 -05002484 }
James Smartfa4066b2008-01-11 01:53:27 -05002485 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2486 * trigger the release of the node.
2487 */
James Smart329f9bc2007-04-25 09:53:01 -04002488 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002489 return 0;
dea31012005-04-17 16:05:31 -05002490}
2491
James Smarte59058c2008-08-24 21:49:00 -04002492/**
James Smart3621a712009-04-06 18:47:14 -04002493 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002494 * @vport: pointer to a host virtual N_Port data structure.
2495 * @nlp: pointer to a node-list data structure.
2496 *
2497 * This routine cancels the timer with a delayed IOCB-command retry for
2498 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2499 * removes the ELS retry event if it presents. In addition, if the
2500 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2501 * commands are sent for the @vport's nodes that require issuing discovery
2502 * ADISC.
2503 **/
dea31012005-04-17 16:05:31 -05002504void
James Smart2e0fef82007-06-17 19:56:36 -05002505lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002506{
James Smart2e0fef82007-06-17 19:56:36 -05002507 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002508 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002509
James Smart0d2b6b82008-06-14 22:52:47 -04002510 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2511 return;
James Smart2e0fef82007-06-17 19:56:36 -05002512 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002513 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002514 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002515 del_timer_sync(&nlp->nlp_delayfunc);
2516 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002517 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002518 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002519 /* Decrement nlp reference count held for the delayed retry */
2520 evtp = &nlp->els_retry_evt;
2521 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2522 }
James Smartfdcebe22006-03-07 15:04:01 -05002523 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002524 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002525 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002526 spin_unlock_irq(shost->host_lock);
2527 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002528 if (vport->port_state < LPFC_VPORT_READY) {
2529 /* Check if there are more ADISCs to be sent */
2530 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002531 } else {
2532 /* Check if there are more PLOGIs to be sent */
2533 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002534 if (vport->num_disc_nodes == 0) {
2535 spin_lock_irq(shost->host_lock);
2536 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2537 spin_unlock_irq(shost->host_lock);
2538 lpfc_can_disctmo(vport);
2539 lpfc_end_rscn(vport);
2540 }
James Smartfdcebe22006-03-07 15:04:01 -05002541 }
2542 }
2543 }
2544 return;
2545}
2546
James Smarte59058c2008-08-24 21:49:00 -04002547/**
James Smart3621a712009-04-06 18:47:14 -04002548 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002549 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2550 *
2551 * This routine is invoked by the ndlp delayed-function timer to check
2552 * whether there is any pending ELS retry event(s) with the node. If not, it
2553 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2554 * adds the delayed events to the HBA work list and invokes the
2555 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2556 * event. Note that lpfc_nlp_get() is called before posting the event to
2557 * the work list to hold reference count of ndlp so that it guarantees the
2558 * reference to ndlp will still be available when the worker thread gets
2559 * to the event associated with the ndlp.
2560 **/
James Smartfdcebe22006-03-07 15:04:01 -05002561void
dea31012005-04-17 16:05:31 -05002562lpfc_els_retry_delay(unsigned long ptr)
2563{
James Smart2e0fef82007-06-17 19:56:36 -05002564 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2565 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002566 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002567 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002568 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002569
James Smart92d7f7b2007-06-17 19:56:38 -05002570 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002571 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002572 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002573 return;
2574 }
2575
James Smartfa4066b2008-01-11 01:53:27 -05002576 /* We need to hold the node by incrementing the reference
2577 * count until the queued work is done
2578 */
2579 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002580 if (evtp->evt_arg1) {
2581 evtp->evt = LPFC_EVT_ELS_RETRY;
2582 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002583 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002584 }
James Smart92d7f7b2007-06-17 19:56:38 -05002585 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002586 return;
2587}
2588
James Smarte59058c2008-08-24 21:49:00 -04002589/**
James Smart3621a712009-04-06 18:47:14 -04002590 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002591 * @ndlp: pointer to a node-list data structure.
2592 *
2593 * This routine is the worker-thread handler for processing the @ndlp delayed
2594 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2595 * the last ELS command from the associated ndlp and invokes the proper ELS
2596 * function according to the delayed ELS command to retry the command.
2597 **/
dea31012005-04-17 16:05:31 -05002598void
2599lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2600{
James Smart2e0fef82007-06-17 19:56:36 -05002601 struct lpfc_vport *vport = ndlp->vport;
2602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2603 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002604
James Smart2e0fef82007-06-17 19:56:36 -05002605 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002606 did = ndlp->nlp_DID;
2607 cmd = ndlp->nlp_last_elscmd;
2608 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002609
2610 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002611 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002612 return;
2613 }
2614
2615 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002616 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002617 /*
2618 * If a discovery event readded nlp_delayfunc after timer
2619 * firing and before processing the timer, cancel the
2620 * nlp_delayfunc.
2621 */
2622 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002623 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002624 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002625
2626 switch (cmd) {
2627 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002628 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002629 break;
2630 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002631 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002632 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002633 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002634 }
dea31012005-04-17 16:05:31 -05002635 break;
2636 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002637 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002638 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002639 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002640 }
dea31012005-04-17 16:05:31 -05002641 break;
2642 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002643 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002644 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002645 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002646 }
dea31012005-04-17 16:05:31 -05002647 break;
2648 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002649 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002650 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002651 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002652 }
dea31012005-04-17 16:05:31 -05002653 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002654 case ELS_CMD_FDISC:
2655 lpfc_issue_els_fdisc(vport, ndlp, retry);
2656 break;
dea31012005-04-17 16:05:31 -05002657 }
2658 return;
2659}
2660
James Smarte59058c2008-08-24 21:49:00 -04002661/**
James Smart3621a712009-04-06 18:47:14 -04002662 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002663 * @phba: pointer to lpfc hba data structure.
2664 * @cmdiocb: pointer to lpfc command iocb data structure.
2665 * @rspiocb: pointer to lpfc response iocb data structure.
2666 *
2667 * This routine makes a retry decision on an ELS command IOCB, which has
2668 * failed. The following ELS IOCBs use this function for retrying the command
2669 * when previously issued command responsed with error status: FLOGI, PLOGI,
2670 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2671 * returned error status, it makes the decision whether a retry shall be
2672 * issued for the command, and whether a retry shall be made immediately or
2673 * delayed. In the former case, the corresponding ELS command issuing-function
2674 * is called to retry the command. In the later case, the ELS command shall
2675 * be posted to the ndlp delayed event and delayed function timer set to the
2676 * ndlp for the delayed command issusing.
2677 *
2678 * Return code
2679 * 0 - No retry of els command is made
2680 * 1 - Immediate or delayed retry of els command is made
2681 **/
dea31012005-04-17 16:05:31 -05002682static int
James Smart2e0fef82007-06-17 19:56:36 -05002683lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2684 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002685{
James Smart2e0fef82007-06-17 19:56:36 -05002686 struct lpfc_vport *vport = cmdiocb->vport;
2687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2688 IOCB_t *irsp = &rspiocb->iocb;
2689 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2690 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002691 uint32_t *elscmd;
2692 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002693 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002694 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002695 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002696 uint32_t did;
dea31012005-04-17 16:05:31 -05002697
James Smart488d1462006-03-07 15:02:37 -05002698
dea31012005-04-17 16:05:31 -05002699 /* Note: context2 may be 0 for internal driver abort
2700 * of delays ELS command.
2701 */
2702
2703 if (pcmd && pcmd->virt) {
2704 elscmd = (uint32_t *) (pcmd->virt);
2705 cmd = *elscmd++;
2706 }
2707
James Smarte47c9092008-02-08 18:49:26 -05002708 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002709 did = ndlp->nlp_DID;
2710 else {
2711 /* We should only hit this case for retrying PLOGI */
2712 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002713 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002714 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2715 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002716 return 1;
2717 }
2718
James Smart858c9f62007-06-17 19:56:39 -05002719 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2720 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2721 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2722
dea31012005-04-17 16:05:31 -05002723 switch (irsp->ulpStatus) {
2724 case IOSTAT_FCP_RSP_ERROR:
2725 case IOSTAT_REMOTE_STOP:
2726 break;
2727
2728 case IOSTAT_LOCAL_REJECT:
2729 switch ((irsp->un.ulpWord[4] & 0xff)) {
2730 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002731 if (cmd == ELS_CMD_FLOGI) {
2732 if (PCI_DEVICE_ID_HORNET ==
2733 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002734 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002735 phba->pport->fc_myDID = 0;
2736 phba->alpa_map[0] = 0;
2737 phba->alpa_map[1] = 0;
2738 }
2739 }
James Smart2e0fef82007-06-17 19:56:36 -05002740 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002741 delay = 1000;
dea31012005-04-17 16:05:31 -05002742 retry = 1;
2743 break;
2744
James Smart92d7f7b2007-06-17 19:56:38 -05002745 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002746 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2747 "0124 Retry illegal cmd x%x "
2748 "retry:x%x delay:x%x\n",
2749 cmd, cmdiocb->retry, delay);
2750 retry = 1;
2751 /* All command's retry policy */
2752 maxretry = 8;
2753 if (cmdiocb->retry > 2)
2754 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002755 break;
2756
dea31012005-04-17 16:05:31 -05002757 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002758 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002759 retry = 1;
2760 if (cmdiocb->retry > 100)
2761 delay = 100;
2762 maxretry = 250;
2763 break;
2764
2765 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002766 delay = 100;
dea31012005-04-17 16:05:31 -05002767 retry = 1;
2768 break;
2769
James Smart858c9f62007-06-17 19:56:39 -05002770 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002771 case IOERR_INVALID_RPI:
2772 retry = 1;
2773 break;
2774 }
2775 break;
2776
2777 case IOSTAT_NPORT_RJT:
2778 case IOSTAT_FABRIC_RJT:
2779 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2780 retry = 1;
2781 break;
2782 }
2783 break;
2784
2785 case IOSTAT_NPORT_BSY:
2786 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002787 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002788 retry = 1;
2789 break;
2790
2791 case IOSTAT_LS_RJT:
2792 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2793 /* Added for Vendor specifc support
2794 * Just keep retrying for these Rsn / Exp codes
2795 */
2796 switch (stat.un.b.lsRjtRsnCode) {
2797 case LSRJT_UNABLE_TPC:
2798 if (stat.un.b.lsRjtRsnCodeExp ==
2799 LSEXP_CMD_IN_PROGRESS) {
2800 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002801 delay = 1000;
dea31012005-04-17 16:05:31 -05002802 maxretry = 48;
2803 }
2804 retry = 1;
2805 break;
2806 }
James Smartffc95492010-06-07 15:23:17 -04002807 if (stat.un.b.lsRjtRsnCodeExp ==
2808 LSEXP_CANT_GIVE_DATA) {
2809 if (cmd == ELS_CMD_PLOGI) {
2810 delay = 1000;
2811 maxretry = 48;
2812 }
2813 retry = 1;
2814 break;
2815 }
dea31012005-04-17 16:05:31 -05002816 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002817 delay = 1000;
dea31012005-04-17 16:05:31 -05002818 maxretry = lpfc_max_els_tries + 1;
2819 retry = 1;
2820 break;
2821 }
James Smart92d7f7b2007-06-17 19:56:38 -05002822 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2823 (cmd == ELS_CMD_FDISC) &&
2824 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2826 "0125 FDISC Failed (x%x). "
2827 "Fabric out of resources\n",
2828 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002829 lpfc_vport_set_state(vport,
2830 FC_VPORT_NO_FABRIC_RSCS);
2831 }
dea31012005-04-17 16:05:31 -05002832 break;
2833
2834 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002835 if ((cmd == ELS_CMD_PLOGI) ||
2836 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002837 delay = 1000;
dea31012005-04-17 16:05:31 -05002838 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002839 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002840 /* FDISC retry policy */
2841 maxretry = 48;
2842 if (cmdiocb->retry >= 32)
2843 delay = 1000;
dea31012005-04-17 16:05:31 -05002844 }
2845 retry = 1;
2846 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002847
2848 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002849 /* There are some cases where switches return this
2850 * error when they are not ready and should be returning
2851 * Logical Busy. We should delay every time.
2852 */
2853 if (cmd == ELS_CMD_FDISC &&
2854 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2855 maxretry = 3;
2856 delay = 1000;
2857 retry = 1;
2858 break;
2859 }
James Smart92d7f7b2007-06-17 19:56:38 -05002860 case LSRJT_PROTOCOL_ERR:
2861 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2862 (cmd == ELS_CMD_FDISC) &&
2863 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2864 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2865 ) {
James Smarte8b62012007-08-02 11:10:09 -04002866 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002867 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002868 "Fabric Detected Bad WWN\n",
2869 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002870 lpfc_vport_set_state(vport,
2871 FC_VPORT_FABRIC_REJ_WWN);
2872 }
2873 break;
dea31012005-04-17 16:05:31 -05002874 }
2875 break;
2876
2877 case IOSTAT_INTERMED_RSP:
2878 case IOSTAT_BA_RJT:
2879 break;
2880
2881 default:
2882 break;
2883 }
2884
James Smart488d1462006-03-07 15:02:37 -05002885 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002886 retry = 1;
dea31012005-04-17 16:05:31 -05002887
James Smart695a8142010-01-26 23:08:03 -05002888 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05002889 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002890 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002891 /* FLOGI retry policy */
2892 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002893 /* retry forever */
2894 maxretry = 0;
2895 if (cmdiocb->retry >= 100)
2896 delay = 5000;
2897 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002898 delay = 1000;
2899 }
2900
James Smart6669f9b2009-10-02 15:16:45 -04002901 cmdiocb->retry++;
2902 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002903 phba->fc_stat.elsRetryExceeded++;
2904 retry = 0;
2905 }
2906
James Smarted957682007-06-17 19:56:37 -05002907 if ((vport->load_flag & FC_UNLOADING) != 0)
2908 retry = 0;
2909
dea31012005-04-17 16:05:31 -05002910 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002911 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2912 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2913 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2914 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2915 "2849 Stop retry ELS command "
2916 "x%x to remote NPORT x%x, "
2917 "Data: x%x x%x\n", cmd, did,
2918 cmdiocb->retry, delay);
2919 return 0;
2920 }
2921 }
dea31012005-04-17 16:05:31 -05002922
2923 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002924 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2925 "0107 Retry ELS command x%x to remote "
2926 "NPORT x%x Data: x%x x%x\n",
2927 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002928
James Smart858c9f62007-06-17 19:56:39 -05002929 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2930 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2931 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2932 /* Don't reset timer for no resources */
2933
dea31012005-04-17 16:05:31 -05002934 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002935 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002936 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002937 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002938 }
2939
2940 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002941 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002942 phba->fc_stat.elsDelayRetry++;
2943 ndlp->nlp_retry = cmdiocb->retry;
2944
James Smart92d7f7b2007-06-17 19:56:38 -05002945 /* delay is specified in milliseconds */
2946 mod_timer(&ndlp->nlp_delayfunc,
2947 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002948 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002949 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002950 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002951
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002952 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002953 if (cmd == ELS_CMD_PRLI)
2954 lpfc_nlp_set_state(vport, ndlp,
2955 NLP_STE_REG_LOGIN_ISSUE);
2956 else
2957 lpfc_nlp_set_state(vport, ndlp,
2958 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002959 ndlp->nlp_last_elscmd = cmd;
2960
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002961 return 1;
dea31012005-04-17 16:05:31 -05002962 }
2963 switch (cmd) {
2964 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002965 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002966 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002967 case ELS_CMD_FDISC:
2968 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2969 return 1;
dea31012005-04-17 16:05:31 -05002970 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002971 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002972 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002973 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002974 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002975 }
James Smart2e0fef82007-06-17 19:56:36 -05002976 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002977 return 1;
dea31012005-04-17 16:05:31 -05002978 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002979 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2981 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002982 return 1;
dea31012005-04-17 16:05:31 -05002983 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002984 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002985 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2986 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002987 return 1;
dea31012005-04-17 16:05:31 -05002988 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002989 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002990 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2991 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002992 return 1;
dea31012005-04-17 16:05:31 -05002993 }
2994 }
dea31012005-04-17 16:05:31 -05002995 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002996 if (logerr) {
2997 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2998 "0137 No retry ELS command x%x to remote "
2999 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3000 cmd, did, irsp->ulpStatus,
3001 irsp->un.ulpWord[4]);
3002 }
3003 else {
3004 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003005 "0108 No retry ELS command x%x to remote "
3006 "NPORT x%x Retried:%d Error:x%x/%x\n",
3007 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3008 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003009 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003010 return 0;
dea31012005-04-17 16:05:31 -05003011}
3012
James Smarte59058c2008-08-24 21:49:00 -04003013/**
James Smart3621a712009-04-06 18:47:14 -04003014 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003015 * @phba: pointer to lpfc hba data structure.
3016 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3017 *
3018 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3019 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3020 * checks to see whether there is a lpfc DMA buffer associated with the
3021 * response of the command IOCB. If so, it will be released before releasing
3022 * the lpfc DMA buffer associated with the IOCB itself.
3023 *
3024 * Return code
3025 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3026 **/
James Smart09372822008-01-11 01:52:54 -05003027static int
James Smart87af33f2007-10-27 13:37:43 -04003028lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3029{
3030 struct lpfc_dmabuf *buf_ptr;
3031
James Smarte59058c2008-08-24 21:49:00 -04003032 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003033 if (!list_empty(&buf_ptr1->list)) {
3034 list_remove_head(&buf_ptr1->list, buf_ptr,
3035 struct lpfc_dmabuf,
3036 list);
3037 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3038 kfree(buf_ptr);
3039 }
3040 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3041 kfree(buf_ptr1);
3042 return 0;
3043}
3044
James Smarte59058c2008-08-24 21:49:00 -04003045/**
James Smart3621a712009-04-06 18:47:14 -04003046 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003047 * @phba: pointer to lpfc hba data structure.
3048 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3049 *
3050 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3051 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3052 * pool.
3053 *
3054 * Return code
3055 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3056 **/
James Smart09372822008-01-11 01:52:54 -05003057static int
James Smart87af33f2007-10-27 13:37:43 -04003058lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3059{
3060 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3061 kfree(buf_ptr);
3062 return 0;
3063}
3064
James Smarte59058c2008-08-24 21:49:00 -04003065/**
James Smart3621a712009-04-06 18:47:14 -04003066 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003067 * @phba: pointer to lpfc hba data structure.
3068 * @elsiocb: pointer to lpfc els command iocb data structure.
3069 *
3070 * This routine frees a command IOCB and its associated resources. The
3071 * command IOCB data structure contains the reference to various associated
3072 * resources, these fields must be set to NULL if the associated reference
3073 * not present:
3074 * context1 - reference to ndlp
3075 * context2 - reference to cmd
3076 * context2->next - reference to rsp
3077 * context3 - reference to bpl
3078 *
3079 * It first properly decrements the reference count held on ndlp for the
3080 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3081 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3082 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3083 * adds the DMA buffer the @phba data structure for the delayed release.
3084 * If reference to the Buffer Pointer List (BPL) is present, the
3085 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3086 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3087 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3088 *
3089 * Return code
3090 * 0 - Success (currently, always return 0)
3091 **/
James Smart87af33f2007-10-27 13:37:43 -04003092int
James Smart329f9bc2007-04-25 09:53:01 -04003093lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003094{
3095 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003096 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003097
James Smarta8adb832007-10-27 13:37:53 -04003098 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3099 if (ndlp) {
3100 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3101 lpfc_nlp_put(ndlp);
3102
3103 /* If the ndlp is not being used by another discovery
3104 * thread, free it.
3105 */
3106 if (!lpfc_nlp_not_used(ndlp)) {
3107 /* If ndlp is being used by another discovery
3108 * thread, just clear NLP_DEFER_RM
3109 */
3110 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3111 }
3112 }
3113 else
3114 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003115 elsiocb->context1 = NULL;
3116 }
dea31012005-04-17 16:05:31 -05003117 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3118 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003119 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3120 /* Firmware could still be in progress of DMAing
3121 * payload, so don't free data buffer till after
3122 * a hbeat.
3123 */
3124 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3125 buf_ptr = elsiocb->context2;
3126 elsiocb->context2 = NULL;
3127 if (buf_ptr) {
3128 buf_ptr1 = NULL;
3129 spin_lock_irq(&phba->hbalock);
3130 if (!list_empty(&buf_ptr->list)) {
3131 list_remove_head(&buf_ptr->list,
3132 buf_ptr1, struct lpfc_dmabuf,
3133 list);
3134 INIT_LIST_HEAD(&buf_ptr1->list);
3135 list_add_tail(&buf_ptr1->list,
3136 &phba->elsbuf);
3137 phba->elsbuf_cnt++;
3138 }
3139 INIT_LIST_HEAD(&buf_ptr->list);
3140 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3141 phba->elsbuf_cnt++;
3142 spin_unlock_irq(&phba->hbalock);
3143 }
3144 } else {
3145 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3146 lpfc_els_free_data(phba, buf_ptr1);
3147 }
dea31012005-04-17 16:05:31 -05003148 }
3149
3150 if (elsiocb->context3) {
3151 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003152 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003153 }
James Bottomley604a3e32005-10-29 10:28:33 -05003154 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003155 return 0;
3156}
3157
James Smarte59058c2008-08-24 21:49:00 -04003158/**
James Smart3621a712009-04-06 18:47:14 -04003159 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003160 * @phba: pointer to lpfc hba data structure.
3161 * @cmdiocb: pointer to lpfc command iocb data structure.
3162 * @rspiocb: pointer to lpfc response iocb data structure.
3163 *
3164 * This routine is the completion callback function to the Logout (LOGO)
3165 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3166 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3167 * release the ndlp if it has the last reference remaining (reference count
3168 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3169 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3170 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3171 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3172 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3173 * IOCB data structure.
3174 **/
dea31012005-04-17 16:05:31 -05003175static void
James Smart2e0fef82007-06-17 19:56:36 -05003176lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3177 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003178{
James Smart2e0fef82007-06-17 19:56:36 -05003179 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3180 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003181 IOCB_t *irsp;
3182
3183 irsp = &rspiocb->iocb;
3184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3185 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3186 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003187 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003188 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3189 "0109 ACC to LOGO completes to NPort x%x "
3190 "Data: x%x x%x x%x\n",
3191 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3192 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003193
3194 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3195 /* NPort Recovery mode or node is just allocated */
3196 if (!lpfc_nlp_not_used(ndlp)) {
3197 /* If the ndlp is being used by another discovery
3198 * thread, just unregister the RPI.
3199 */
3200 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003201 } else {
3202 /* Indicate the node has already released, should
3203 * not reference to it from within lpfc_els_free_iocb.
3204 */
3205 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003206 }
dea31012005-04-17 16:05:31 -05003207 }
3208 lpfc_els_free_iocb(phba, cmdiocb);
3209 return;
3210}
3211
James Smarte59058c2008-08-24 21:49:00 -04003212/**
James Smart3621a712009-04-06 18:47:14 -04003213 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003214 * @phba: pointer to lpfc hba data structure.
3215 * @pmb: pointer to the driver internal queue element for mailbox command.
3216 *
3217 * This routine is the completion callback function for unregister default
3218 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3219 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3220 * decrements the ndlp reference count held for this completion callback
3221 * function. After that, it invokes the lpfc_nlp_not_used() to check
3222 * whether there is only one reference left on the ndlp. If so, it will
3223 * perform one more decrement and trigger the release of the ndlp.
3224 **/
James Smart858c9f62007-06-17 19:56:39 -05003225void
3226lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3227{
3228 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3229 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3230
James Smart6fb120a2009-05-22 14:52:59 -04003231 /*
3232 * This routine is used to register and unregister in previous SLI
3233 * modes.
3234 */
3235 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3236 (phba->sli_rev == LPFC_SLI_REV4))
3237 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3238
James Smart858c9f62007-06-17 19:56:39 -05003239 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003240 pmb->context2 = NULL;
3241
James Smart858c9f62007-06-17 19:56:39 -05003242 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3243 kfree(mp);
3244 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003245 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003246 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003247 /* This is the end of the default RPI cleanup logic for this
3248 * ndlp. If no other discovery threads are using this ndlp.
3249 * we should free all resources associated with it.
3250 */
3251 lpfc_nlp_not_used(ndlp);
3252 }
James Smart3772a992009-05-22 14:50:54 -04003253
James Smart858c9f62007-06-17 19:56:39 -05003254 return;
3255}
3256
James Smarte59058c2008-08-24 21:49:00 -04003257/**
James Smart3621a712009-04-06 18:47:14 -04003258 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003259 * @phba: pointer to lpfc hba data structure.
3260 * @cmdiocb: pointer to lpfc command iocb data structure.
3261 * @rspiocb: pointer to lpfc response iocb data structure.
3262 *
3263 * This routine is the completion callback function for ELS Response IOCB
3264 * command. In normal case, this callback function just properly sets the
3265 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3266 * field in the command IOCB is not NULL, the referred mailbox command will
3267 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3268 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3269 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3270 * routine shall be invoked trying to release the ndlp if no other threads
3271 * are currently referring it.
3272 **/
dea31012005-04-17 16:05:31 -05003273static void
James Smart858c9f62007-06-17 19:56:39 -05003274lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003275 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003276{
James Smart2e0fef82007-06-17 19:56:36 -05003277 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3278 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3279 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003280 IOCB_t *irsp;
3281 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003282 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003283 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003284 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003285
James Smart33ccf8d2006-08-17 11:57:58 -04003286 irsp = &rspiocb->iocb;
3287
dea31012005-04-17 16:05:31 -05003288 if (cmdiocb->context_un.mbox)
3289 mbox = cmdiocb->context_un.mbox;
3290
James Smartfa4066b2008-01-11 01:53:27 -05003291 /* First determine if this is a LS_RJT cmpl. Note, this callback
3292 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3293 */
James Smart87af33f2007-10-27 13:37:43 -04003294 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003295 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3296 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003297 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3fb2010-02-03 08:01:28 +08003298 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003299 */
3300 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3301 ls_rjt = 1;
3302 }
3303
dea31012005-04-17 16:05:31 -05003304 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003305 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003306 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003307 mp = (struct lpfc_dmabuf *) mbox->context1;
3308 if (mp) {
3309 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3310 kfree(mp);
3311 }
James Smart329f9bc2007-04-25 09:53:01 -04003312 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003313 }
James Smart58da1ff2008-04-07 10:15:56 -04003314 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3315 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003316 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003317 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003318 /* Indicate the node has already released,
3319 * should not reference to it from within
3320 * the routine lpfc_els_free_iocb.
3321 */
3322 cmdiocb->context1 = NULL;
3323 }
dea31012005-04-17 16:05:31 -05003324 goto out;
3325 }
3326
James Smart858c9f62007-06-17 19:56:39 -05003327 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003328 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003329 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003330 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003331 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003332 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3333 "0110 ELS response tag x%x completes "
3334 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3335 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3336 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3337 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3338 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003339 if (mbox) {
3340 if ((rspiocb->iocb.ulpStatus == 0)
3341 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003342 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003343 /* Increment reference count to ndlp to hold the
3344 * reference to ndlp for the callback function.
3345 */
James Smart329f9bc2007-04-25 09:53:01 -04003346 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003347 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003348 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3349 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3350 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3351 }
3352 else {
3353 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3354 ndlp->nlp_prev_state = ndlp->nlp_state;
3355 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003356 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003357 }
James Smart0b727fe2007-10-27 13:37:25 -04003358 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003359 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003360 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003361 else
3362 /* Decrement the ndlp reference count we
3363 * set for this failed mailbox command.
3364 */
3365 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003366
3367 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3368 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3369 "0138 ELS rsp: Cannot issue reg_login for x%x "
3370 "Data: x%x x%x x%x\n",
3371 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3372 ndlp->nlp_rpi);
3373
James Smartfa4066b2008-01-11 01:53:27 -05003374 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003375 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003376 /* Indicate node has already been released,
3377 * should not reference to it from within
3378 * the routine lpfc_els_free_iocb.
3379 */
3380 cmdiocb->context1 = NULL;
3381 }
dea31012005-04-17 16:05:31 -05003382 } else {
James Smart858c9f62007-06-17 19:56:39 -05003383 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3384 if (!lpfc_error_lost_link(irsp) &&
3385 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003386 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003387 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003388 /* Indicate node has already been
3389 * released, should not reference
3390 * to it from within the routine
3391 * lpfc_els_free_iocb.
3392 */
3393 cmdiocb->context1 = NULL;
3394 }
dea31012005-04-17 16:05:31 -05003395 }
3396 }
James Smart14691152006-12-02 13:34:28 -05003397 mp = (struct lpfc_dmabuf *) mbox->context1;
3398 if (mp) {
3399 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3400 kfree(mp);
3401 }
3402 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003403 }
3404out:
James Smart58da1ff2008-04-07 10:15:56 -04003405 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003406 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003407 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003408 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003409
3410 /* If the node is not being used by another discovery thread,
3411 * and we are sending a reject, we are done with it.
3412 * Release driver reference count here and free associated
3413 * resources.
3414 */
3415 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003416 if (lpfc_nlp_not_used(ndlp))
3417 /* Indicate node has already been released,
3418 * should not reference to it from within
3419 * the routine lpfc_els_free_iocb.
3420 */
3421 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003422 }
James Smart87af33f2007-10-27 13:37:43 -04003423
dea31012005-04-17 16:05:31 -05003424 lpfc_els_free_iocb(phba, cmdiocb);
3425 return;
3426}
3427
James Smarte59058c2008-08-24 21:49:00 -04003428/**
James Smart3621a712009-04-06 18:47:14 -04003429 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003430 * @vport: pointer to a host virtual N_Port data structure.
3431 * @flag: the els command code to be accepted.
3432 * @oldiocb: pointer to the original lpfc command iocb data structure.
3433 * @ndlp: pointer to a node-list data structure.
3434 * @mbox: pointer to the driver internal queue element for mailbox command.
3435 *
3436 * This routine prepares and issues an Accept (ACC) response IOCB
3437 * command. It uses the @flag to properly set up the IOCB field for the
3438 * specific ACC response command to be issued and invokes the
3439 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3440 * @mbox pointer is passed in, it will be put into the context_un.mbox
3441 * field of the IOCB for the completion callback function to issue the
3442 * mailbox command to the HBA later when callback is invoked.
3443 *
3444 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3445 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3446 * will be stored into the context1 field of the IOCB for the completion
3447 * callback function to the corresponding response ELS IOCB command.
3448 *
3449 * Return code
3450 * 0 - Successfully issued acc response
3451 * 1 - Failed to issue acc response
3452 **/
dea31012005-04-17 16:05:31 -05003453int
James Smart2e0fef82007-06-17 19:56:36 -05003454lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3455 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003456 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003457{
James Smart2e0fef82007-06-17 19:56:36 -05003458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3459 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003460 IOCB_t *icmd;
3461 IOCB_t *oldcmd;
3462 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003463 struct lpfc_sli *psli;
3464 uint8_t *pcmd;
3465 uint16_t cmdsize;
3466 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003467 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003468
3469 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003470 oldcmd = &oldiocb->iocb;
3471
3472 switch (flag) {
3473 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003474 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003475 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3476 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003477 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003478 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003479 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003480 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003481 return 1;
dea31012005-04-17 16:05:31 -05003482 }
James Smart2e0fef82007-06-17 19:56:36 -05003483
dea31012005-04-17 16:05:31 -05003484 icmd = &elsiocb->iocb;
3485 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3486 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3487 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003488 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003489
3490 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3491 "Issue ACC: did:x%x flg:x%x",
3492 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003493 break;
3494 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003495 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003496 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3497 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003498 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003499 return 1;
James Smart488d1462006-03-07 15:02:37 -05003500
dea31012005-04-17 16:05:31 -05003501 icmd = &elsiocb->iocb;
3502 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3503 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3504
3505 if (mbox)
3506 elsiocb->context_un.mbox = mbox;
3507
3508 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003509 pcmd += sizeof(uint32_t);
3510 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003511
3512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3513 "Issue ACC PLOGI: did:x%x flg:x%x",
3514 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003515 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003516 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003517 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003518 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003519 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3520 if (!elsiocb)
3521 return 1;
3522
3523 icmd = &elsiocb->iocb;
3524 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3525 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3526
3527 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003528 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003529 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3530 els_pkt_ptr = (ELS_PKT *) pcmd;
3531 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003532
3533 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3534 "Issue ACC PRLO: did:x%x flg:x%x",
3535 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003536 break;
dea31012005-04-17 16:05:31 -05003537 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003538 return 1;
dea31012005-04-17 16:05:31 -05003539 }
dea31012005-04-17 16:05:31 -05003540 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003541 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3542 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3543 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3544 elsiocb->iotag, elsiocb->iocb.ulpContext,
3545 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3546 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003547 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003548 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003549 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003550 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003551 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3552 } else {
James Smart858c9f62007-06-17 19:56:39 -05003553 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003554 }
3555
3556 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003557 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003558 if (rc == IOCB_ERROR) {
3559 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003560 return 1;
dea31012005-04-17 16:05:31 -05003561 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003562 return 0;
dea31012005-04-17 16:05:31 -05003563}
3564
James Smarte59058c2008-08-24 21:49:00 -04003565/**
James Smart3621a712009-04-06 18:47:14 -04003566 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003567 * @vport: pointer to a virtual N_Port data structure.
3568 * @rejectError:
3569 * @oldiocb: pointer to the original lpfc command iocb data structure.
3570 * @ndlp: pointer to a node-list data structure.
3571 * @mbox: pointer to the driver internal queue element for mailbox command.
3572 *
3573 * This routine prepares and issue an Reject (RJT) response IOCB
3574 * command. If a @mbox pointer is passed in, it will be put into the
3575 * context_un.mbox field of the IOCB for the completion callback function
3576 * to issue to the HBA later.
3577 *
3578 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3579 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3580 * will be stored into the context1 field of the IOCB for the completion
3581 * callback function to the reject response ELS IOCB command.
3582 *
3583 * Return code
3584 * 0 - Successfully issued reject response
3585 * 1 - Failed to issue reject response
3586 **/
dea31012005-04-17 16:05:31 -05003587int
James Smart2e0fef82007-06-17 19:56:36 -05003588lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003589 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3590 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003591{
James Smart2e0fef82007-06-17 19:56:36 -05003592 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003593 IOCB_t *icmd;
3594 IOCB_t *oldcmd;
3595 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003596 struct lpfc_sli *psli;
3597 uint8_t *pcmd;
3598 uint16_t cmdsize;
3599 int rc;
3600
3601 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003602 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003603 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3604 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003605 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003606 return 1;
dea31012005-04-17 16:05:31 -05003607
3608 icmd = &elsiocb->iocb;
3609 oldcmd = &oldiocb->iocb;
3610 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3611 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3612
3613 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003614 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003615 *((uint32_t *) (pcmd)) = rejectError;
3616
James Smart51ef4c22007-08-02 11:10:31 -04003617 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003618 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003619
dea31012005-04-17 16:05:31 -05003620 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003621 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3622 "0129 Xmit ELS RJT x%x response tag x%x "
3623 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3624 "rpi x%x\n",
3625 rejectError, elsiocb->iotag,
3626 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3627 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003628 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3629 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3630 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3631
dea31012005-04-17 16:05:31 -05003632 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003633 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003634 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003635
dea31012005-04-17 16:05:31 -05003636 if (rc == IOCB_ERROR) {
3637 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003638 return 1;
dea31012005-04-17 16:05:31 -05003639 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003640 return 0;
dea31012005-04-17 16:05:31 -05003641}
3642
James Smarte59058c2008-08-24 21:49:00 -04003643/**
James Smart3621a712009-04-06 18:47:14 -04003644 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003645 * @vport: pointer to a virtual N_Port data structure.
3646 * @oldiocb: pointer to the original lpfc command iocb data structure.
3647 * @ndlp: pointer to a node-list data structure.
3648 *
3649 * This routine prepares and issues an Accept (ACC) response to Address
3650 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3651 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3652 *
3653 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3654 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3655 * will be stored into the context1 field of the IOCB for the completion
3656 * callback function to the ADISC Accept response ELS IOCB command.
3657 *
3658 * Return code
3659 * 0 - Successfully issued acc adisc response
3660 * 1 - Failed to issue adisc acc response
3661 **/
dea31012005-04-17 16:05:31 -05003662int
James Smart2e0fef82007-06-17 19:56:36 -05003663lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3664 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003665{
James Smart2e0fef82007-06-17 19:56:36 -05003666 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003667 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003668 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003669 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003670 uint8_t *pcmd;
3671 uint16_t cmdsize;
3672 int rc;
3673
James Smart92d7f7b2007-06-17 19:56:38 -05003674 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003675 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3676 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003677 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003678 return 1;
dea31012005-04-17 16:05:31 -05003679
dea31012005-04-17 16:05:31 -05003680 icmd = &elsiocb->iocb;
3681 oldcmd = &oldiocb->iocb;
3682 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003683
3684 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003685 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3686 "0130 Xmit ADISC ACC response iotag x%x xri: "
3687 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3688 elsiocb->iotag, elsiocb->iocb.ulpContext,
3689 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3690 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003691 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3692
3693 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003694 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003695
3696 ap = (ADISC *) (pcmd);
3697 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003698 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3699 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003700 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003701
James Smart858c9f62007-06-17 19:56:39 -05003702 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3703 "Issue ACC ADISC: did:x%x flg:x%x",
3704 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3705
dea31012005-04-17 16:05:31 -05003706 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003707 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003708 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003709 if (rc == IOCB_ERROR) {
3710 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003711 return 1;
dea31012005-04-17 16:05:31 -05003712 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003713 return 0;
dea31012005-04-17 16:05:31 -05003714}
3715
James Smarte59058c2008-08-24 21:49:00 -04003716/**
James Smart3621a712009-04-06 18:47:14 -04003717 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003718 * @vport: pointer to a virtual N_Port data structure.
3719 * @oldiocb: pointer to the original lpfc command iocb data structure.
3720 * @ndlp: pointer to a node-list data structure.
3721 *
3722 * This routine prepares and issues an Accept (ACC) response to Process
3723 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3724 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3725 *
3726 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3727 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3728 * will be stored into the context1 field of the IOCB for the completion
3729 * callback function to the PRLI Accept response ELS IOCB command.
3730 *
3731 * Return code
3732 * 0 - Successfully issued acc prli response
3733 * 1 - Failed to issue acc prli response
3734 **/
dea31012005-04-17 16:05:31 -05003735int
James Smart2e0fef82007-06-17 19:56:36 -05003736lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003737 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003738{
James Smart2e0fef82007-06-17 19:56:36 -05003739 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003740 PRLI *npr;
3741 lpfc_vpd_t *vpd;
3742 IOCB_t *icmd;
3743 IOCB_t *oldcmd;
3744 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003745 struct lpfc_sli *psli;
3746 uint8_t *pcmd;
3747 uint16_t cmdsize;
3748 int rc;
3749
3750 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003751
James Smart92d7f7b2007-06-17 19:56:38 -05003752 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003753 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003754 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003755 if (!elsiocb)
3756 return 1;
dea31012005-04-17 16:05:31 -05003757
dea31012005-04-17 16:05:31 -05003758 icmd = &elsiocb->iocb;
3759 oldcmd = &oldiocb->iocb;
3760 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003761 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003762 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3763 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3764 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3765 elsiocb->iotag, elsiocb->iocb.ulpContext,
3766 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3767 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003768 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3769
3770 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003771 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003772
3773 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003774 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003775
3776 npr = (PRLI *) pcmd;
3777 vpd = &phba->vpd;
3778 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003779 * If the remote port is a target and our firmware version is 3.20 or
3780 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003781 */
James Smart0d2b6b82008-06-14 22:52:47 -04003782 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3783 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003784 npr->ConfmComplAllowed = 1;
3785 npr->Retry = 1;
3786 npr->TaskRetryIdReq = 1;
3787 }
3788
3789 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3790 npr->estabImagePair = 1;
3791 npr->readXferRdyDis = 1;
3792 npr->ConfmComplAllowed = 1;
3793
3794 npr->prliType = PRLI_FCP_TYPE;
3795 npr->initiatorFunc = 1;
3796
James Smart858c9f62007-06-17 19:56:39 -05003797 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3798 "Issue ACC PRLI: did:x%x flg:x%x",
3799 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3800
dea31012005-04-17 16:05:31 -05003801 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003802 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003803
James Smart3772a992009-05-22 14:50:54 -04003804 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003805 if (rc == IOCB_ERROR) {
3806 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003807 return 1;
dea31012005-04-17 16:05:31 -05003808 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003809 return 0;
dea31012005-04-17 16:05:31 -05003810}
3811
James Smarte59058c2008-08-24 21:49:00 -04003812/**
James Smart3621a712009-04-06 18:47:14 -04003813 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003814 * @vport: pointer to a virtual N_Port data structure.
3815 * @format: rnid command format.
3816 * @oldiocb: pointer to the original lpfc command iocb data structure.
3817 * @ndlp: pointer to a node-list data structure.
3818 *
3819 * This routine issues a Request Node Identification Data (RNID) Accept
3820 * (ACC) response. It constructs the RNID ACC response command according to
3821 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3822 * issue the response. Note that this command does not need to hold the ndlp
3823 * reference count for the callback. So, the ndlp reference count taken by
3824 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3825 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3826 * there is no ndlp reference available.
3827 *
3828 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3829 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3830 * will be stored into the context1 field of the IOCB for the completion
3831 * callback function. However, for the RNID Accept Response ELS command,
3832 * this is undone later by this routine after the IOCB is allocated.
3833 *
3834 * Return code
3835 * 0 - Successfully issued acc rnid response
3836 * 1 - Failed to issue acc rnid response
3837 **/
dea31012005-04-17 16:05:31 -05003838static int
James Smart2e0fef82007-06-17 19:56:36 -05003839lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003840 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003841{
James Smart2e0fef82007-06-17 19:56:36 -05003842 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003843 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003844 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003845 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003846 struct lpfc_sli *psli;
3847 uint8_t *pcmd;
3848 uint16_t cmdsize;
3849 int rc;
3850
3851 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003852 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3853 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003854 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003855 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003856
James Smart2e0fef82007-06-17 19:56:36 -05003857 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3858 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003859 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003860 return 1;
dea31012005-04-17 16:05:31 -05003861
dea31012005-04-17 16:05:31 -05003862 icmd = &elsiocb->iocb;
3863 oldcmd = &oldiocb->iocb;
3864 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003865 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003866 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3867 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3868 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003869 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003870 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003871 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003872
James Smart92d7f7b2007-06-17 19:56:38 -05003873 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003874 rn = (RNID *) (pcmd);
3875 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003876 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3877 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3878 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003879 switch (format) {
3880 case 0:
3881 rn->SpecificLen = 0;
3882 break;
3883 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003884 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003885 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003886 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003887 rn->un.topologyDisc.unitType = RNID_HBA;
3888 rn->un.topologyDisc.physPort = 0;
3889 rn->un.topologyDisc.attachedNodes = 0;
3890 break;
3891 default:
3892 rn->CommonLen = 0;
3893 rn->SpecificLen = 0;
3894 break;
3895 }
3896
James Smart858c9f62007-06-17 19:56:39 -05003897 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3898 "Issue ACC RNID: did:x%x flg:x%x",
3899 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3900
dea31012005-04-17 16:05:31 -05003901 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003902 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003903 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003904 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3905 * it could be freed */
3906
James Smart3772a992009-05-22 14:50:54 -04003907 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003908 if (rc == IOCB_ERROR) {
3909 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003910 return 1;
dea31012005-04-17 16:05:31 -05003911 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003912 return 0;
dea31012005-04-17 16:05:31 -05003913}
3914
James Smarte59058c2008-08-24 21:49:00 -04003915/**
James Smart12265f62010-10-22 11:05:53 -04003916 * lpfc_els_rsp_echo_acc - Issue echo acc response
3917 * @vport: pointer to a virtual N_Port data structure.
3918 * @data: pointer to echo data to return in the accept.
3919 * @oldiocb: pointer to the original lpfc command iocb data structure.
3920 * @ndlp: pointer to a node-list data structure.
3921 *
3922 * Return code
3923 * 0 - Successfully issued acc echo response
3924 * 1 - Failed to issue acc echo response
3925 **/
3926static int
3927lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3928 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3929{
3930 struct lpfc_hba *phba = vport->phba;
3931 struct lpfc_iocbq *elsiocb;
3932 struct lpfc_sli *psli;
3933 uint8_t *pcmd;
3934 uint16_t cmdsize;
3935 int rc;
3936
3937 psli = &phba->sli;
3938 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3939
3940 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3941 ndlp->nlp_DID, ELS_CMD_ACC);
3942 if (!elsiocb)
3943 return 1;
3944
3945 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3946 /* Xmit ECHO ACC response tag <ulpIoTag> */
3947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3948 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3949 elsiocb->iotag, elsiocb->iocb.ulpContext);
3950 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3951 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3952 pcmd += sizeof(uint32_t);
3953 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3954
3955 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3956 "Issue ACC ECHO: did:x%x flg:x%x",
3957 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3958
3959 phba->fc_stat.elsXmitACC++;
3960 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3961 lpfc_nlp_put(ndlp);
3962 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3963 * it could be freed */
3964
3965 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3966 if (rc == IOCB_ERROR) {
3967 lpfc_els_free_iocb(phba, elsiocb);
3968 return 1;
3969 }
3970 return 0;
3971}
3972
3973/**
James Smart3621a712009-04-06 18:47:14 -04003974 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003975 * @vport: pointer to a host virtual N_Port data structure.
3976 *
3977 * This routine issues Address Discover (ADISC) ELS commands to those
3978 * N_Ports which are in node port recovery state and ADISC has not been issued
3979 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3980 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3981 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3982 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3983 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3984 * IOCBs quit for later pick up. On the other hand, after walking through
3985 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3986 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3987 * no more ADISC need to be sent.
3988 *
3989 * Return code
3990 * The number of N_Ports with adisc issued.
3991 **/
dea31012005-04-17 16:05:31 -05003992int
James Smart2e0fef82007-06-17 19:56:36 -05003993lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003994{
James Smart2e0fef82007-06-17 19:56:36 -05003995 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003996 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003997 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003998
James Smart685f0bf2007-04-25 09:53:08 -04003999 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004000 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004001 if (!NLP_CHK_NODE_ACT(ndlp))
4002 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004003 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4004 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4005 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004006 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004007 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004008 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004009 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004010 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4011 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004012 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004013 vport->num_disc_nodes++;
4014 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004015 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004016 spin_lock_irq(shost->host_lock);
4017 vport->fc_flag |= FC_NLP_MORE;
4018 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004019 break;
dea31012005-04-17 16:05:31 -05004020 }
4021 }
4022 }
4023 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004024 spin_lock_irq(shost->host_lock);
4025 vport->fc_flag &= ~FC_NLP_MORE;
4026 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004027 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004028 return sentadisc;
dea31012005-04-17 16:05:31 -05004029}
4030
James Smarte59058c2008-08-24 21:49:00 -04004031/**
James Smart3621a712009-04-06 18:47:14 -04004032 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004033 * @vport: pointer to a host virtual N_Port data structure.
4034 *
4035 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4036 * which are in node port recovery state, with a @vport. Each time an ELS
4037 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4038 * the per @vport number of discover count (num_disc_nodes) shall be
4039 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4040 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4041 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4042 * later pick up. On the other hand, after walking through all the ndlps with
4043 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4044 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4045 * PLOGI need to be sent.
4046 *
4047 * Return code
4048 * The number of N_Ports with plogi issued.
4049 **/
dea31012005-04-17 16:05:31 -05004050int
James Smart2e0fef82007-06-17 19:56:36 -05004051lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004052{
James Smart2e0fef82007-06-17 19:56:36 -05004053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004054 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004055 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004056
James Smart2e0fef82007-06-17 19:56:36 -05004057 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4058 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004059 if (!NLP_CHK_NODE_ACT(ndlp))
4060 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004061 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4062 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4063 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4064 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4065 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004066 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4067 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004068 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004069 vport->num_disc_nodes++;
4070 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004071 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004072 spin_lock_irq(shost->host_lock);
4073 vport->fc_flag |= FC_NLP_MORE;
4074 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004075 break;
dea31012005-04-17 16:05:31 -05004076 }
4077 }
4078 }
James Smart87af33f2007-10-27 13:37:43 -04004079 if (sentplogi) {
4080 lpfc_set_disctmo(vport);
4081 }
4082 else {
James Smart2e0fef82007-06-17 19:56:36 -05004083 spin_lock_irq(shost->host_lock);
4084 vport->fc_flag &= ~FC_NLP_MORE;
4085 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004086 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004087 return sentplogi;
dea31012005-04-17 16:05:31 -05004088}
4089
James Smarte59058c2008-08-24 21:49:00 -04004090/**
James Smart3621a712009-04-06 18:47:14 -04004091 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004092 * @vport: pointer to a host virtual N_Port data structure.
4093 *
4094 * This routine cleans up any Registration State Change Notification
4095 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4096 * @vport together with the host_lock is used to prevent multiple thread
4097 * trying to access the RSCN array on a same @vport at the same time.
4098 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004099void
James Smart2e0fef82007-06-17 19:56:36 -05004100lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004101{
James Smart2e0fef82007-06-17 19:56:36 -05004102 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4103 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004104 int i;
4105
James Smart7f5f3d02008-02-08 18:50:14 -05004106 spin_lock_irq(shost->host_lock);
4107 if (vport->fc_rscn_flush) {
4108 /* Another thread is walking fc_rscn_id_list on this vport */
4109 spin_unlock_irq(shost->host_lock);
4110 return;
4111 }
4112 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4113 vport->fc_rscn_flush = 1;
4114 spin_unlock_irq(shost->host_lock);
4115
James Smart2e0fef82007-06-17 19:56:36 -05004116 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004117 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004118 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004119 }
James Smart2e0fef82007-06-17 19:56:36 -05004120 spin_lock_irq(shost->host_lock);
4121 vport->fc_rscn_id_cnt = 0;
4122 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4123 spin_unlock_irq(shost->host_lock);
4124 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004125 /* Indicate we are done walking this fc_rscn_id_list */
4126 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004127}
4128
James Smarte59058c2008-08-24 21:49:00 -04004129/**
James Smart3621a712009-04-06 18:47:14 -04004130 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004131 * @vport: pointer to a host virtual N_Port data structure.
4132 * @did: remote destination port identifier.
4133 *
4134 * This routine checks whether there is any pending Registration State
4135 * Configuration Notification (RSCN) to a @did on @vport.
4136 *
4137 * Return code
4138 * None zero - The @did matched with a pending rscn
4139 * 0 - not able to match @did with a pending rscn
4140 **/
dea31012005-04-17 16:05:31 -05004141int
James Smart2e0fef82007-06-17 19:56:36 -05004142lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004143{
4144 D_ID ns_did;
4145 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004146 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004147 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004148 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004149
4150 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004151
4152 /* Never match fabric nodes for RSCNs */
4153 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004154 return 0;
dea31012005-04-17 16:05:31 -05004155
4156 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004157 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004158 return did;
dea31012005-04-17 16:05:31 -05004159
James Smart7f5f3d02008-02-08 18:50:14 -05004160 spin_lock_irq(shost->host_lock);
4161 if (vport->fc_rscn_flush) {
4162 /* Another thread is walking fc_rscn_id_list on this vport */
4163 spin_unlock_irq(shost->host_lock);
4164 return 0;
4165 }
4166 /* Indicate we are walking fc_rscn_id_list on this vport */
4167 vport->fc_rscn_flush = 1;
4168 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004169 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004170 lp = vport->fc_rscn_id_list[i]->virt;
4171 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4172 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004173 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004174 rscn_did.un.word = be32_to_cpu(*lp++);
4175 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004176 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4177 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004178 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4179 && (ns_did.un.b.area == rscn_did.un.b.area)
4180 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004181 goto return_did_out;
dea31012005-04-17 16:05:31 -05004182 break;
James Smarteaf15d52008-12-04 22:39:29 -05004183 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004184 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4185 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004186 goto return_did_out;
dea31012005-04-17 16:05:31 -05004187 break;
James Smarteaf15d52008-12-04 22:39:29 -05004188 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004189 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004190 goto return_did_out;
dea31012005-04-17 16:05:31 -05004191 break;
James Smarteaf15d52008-12-04 22:39:29 -05004192 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004193 goto return_did_out;
dea31012005-04-17 16:05:31 -05004194 }
4195 }
James Smart92d7f7b2007-06-17 19:56:38 -05004196 }
James Smart7f5f3d02008-02-08 18:50:14 -05004197 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4198 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004199 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004200return_did_out:
4201 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4202 vport->fc_rscn_flush = 0;
4203 return did;
dea31012005-04-17 16:05:31 -05004204}
4205
James Smarte59058c2008-08-24 21:49:00 -04004206/**
James Smart3621a712009-04-06 18:47:14 -04004207 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004208 * @vport: pointer to a host virtual N_Port data structure.
4209 *
4210 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4211 * state machine for a @vport's nodes that are with pending RSCN (Registration
4212 * State Change Notification).
4213 *
4214 * Return code
4215 * 0 - Successful (currently alway return 0)
4216 **/
dea31012005-04-17 16:05:31 -05004217static int
James Smart2e0fef82007-06-17 19:56:36 -05004218lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004219{
James Smart685f0bf2007-04-25 09:53:08 -04004220 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004221
James Smart0d2b6b82008-06-14 22:52:47 -04004222 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004223 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004224 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004225 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4226 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004227 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004228 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004229 NLP_EVT_DEVICE_RECOVERY);
4230 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004231 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004232 return 0;
dea31012005-04-17 16:05:31 -05004233}
4234
James Smarte59058c2008-08-24 21:49:00 -04004235/**
James Smart3621a712009-04-06 18:47:14 -04004236 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004237 * @vport: pointer to a host virtual N_Port data structure.
4238 * @cmdiocb: pointer to lpfc command iocb data structure.
4239 *
4240 * lpfc_send_rscn_event sends an RSCN netlink event to management
4241 * applications.
4242 */
4243static void
4244lpfc_send_rscn_event(struct lpfc_vport *vport,
4245 struct lpfc_iocbq *cmdiocb)
4246{
4247 struct lpfc_dmabuf *pcmd;
4248 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4249 uint32_t *payload_ptr;
4250 uint32_t payload_len;
4251 struct lpfc_rscn_event_header *rscn_event_data;
4252
4253 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4254 payload_ptr = (uint32_t *) pcmd->virt;
4255 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4256
4257 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4258 payload_len, GFP_KERNEL);
4259 if (!rscn_event_data) {
4260 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4261 "0147 Failed to allocate memory for RSCN event\n");
4262 return;
4263 }
4264 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4265 rscn_event_data->payload_length = payload_len;
4266 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4267 payload_len);
4268
4269 fc_host_post_vendor_event(shost,
4270 fc_get_event_number(),
4271 sizeof(struct lpfc_els_event_header) + payload_len,
4272 (char *)rscn_event_data,
4273 LPFC_NL_VENDOR_ID);
4274
4275 kfree(rscn_event_data);
4276}
4277
4278/**
James Smart3621a712009-04-06 18:47:14 -04004279 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004280 * @vport: pointer to a host virtual N_Port data structure.
4281 * @cmdiocb: pointer to lpfc command iocb data structure.
4282 * @ndlp: pointer to a node-list data structure.
4283 *
4284 * This routine processes an unsolicited RSCN (Registration State Change
4285 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4286 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4287 * discover state machine is about to begin discovery, it just accepts the
4288 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4289 * contains N_Port IDs for other vports on this HBA, it just accepts the
4290 * RSCN and ignore processing it. If the state machine is in the recovery
4291 * state, the fc_rscn_id_list of this @vport is walked and the
4292 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4293 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4294 * routine is invoked to handle the RSCN event.
4295 *
4296 * Return code
4297 * 0 - Just sent the acc response
4298 * 1 - Sent the acc response and waited for name server completion
4299 **/
dea31012005-04-17 16:05:31 -05004300static int
James Smart2e0fef82007-06-17 19:56:36 -05004301lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004302 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004303{
James Smart2e0fef82007-06-17 19:56:36 -05004304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4305 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004306 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004307 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004308 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004309 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004310 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004311 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004312 int i;
dea31012005-04-17 16:05:31 -05004313
4314 icmd = &cmdiocb->iocb;
4315 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4316 lp = (uint32_t *) pcmd->virt;
4317
James Smart92d7f7b2007-06-17 19:56:38 -05004318 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4319 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004320 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004321 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4322 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004323 vport->fc_flag, payload_len, *lp,
4324 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004325
4326 /* Send an RSCN event to the management application */
4327 lpfc_send_rscn_event(vport, cmdiocb);
4328
James Smartd2873e42006-08-18 17:46:43 -04004329 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004330 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004331 FCH_EVT_RSCN, lp[i]);
4332
dea31012005-04-17 16:05:31 -05004333 /* If we are about to begin discovery, just ACC the RSCN.
4334 * Discovery processing will satisfy it.
4335 */
James Smart2e0fef82007-06-17 19:56:36 -05004336 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4338 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4339 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4340
James Smart51ef4c22007-08-02 11:10:31 -04004341 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004342 return 0;
dea31012005-04-17 16:05:31 -05004343 }
4344
James Smart92d7f7b2007-06-17 19:56:38 -05004345 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4346 * just ACC and ignore it.
4347 */
4348 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004349 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004350 i = payload_len;
4351 datap = lp;
4352 while (i > 0) {
4353 nportid = *datap++;
4354 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4355 i -= sizeof(uint32_t);
4356 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004357 if (lpfc_find_vport_by_did(phba, nportid))
4358 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004359 }
4360 if (rscn_id == hba_id) {
4361 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004362 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004363 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004364 "Data: x%x x%x x%x x%x\n",
4365 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004366 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004367 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4368 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4369 ndlp->nlp_DID, vport->port_state,
4370 ndlp->nlp_flag);
4371
James Smart92d7f7b2007-06-17 19:56:38 -05004372 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004373 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004374 return 0;
4375 }
4376 }
4377
James Smart7f5f3d02008-02-08 18:50:14 -05004378 spin_lock_irq(shost->host_lock);
4379 if (vport->fc_rscn_flush) {
4380 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004381 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004382 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004383 /* Send back ACC */
4384 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004385 return 0;
4386 }
4387 /* Indicate we are walking fc_rscn_id_list on this vport */
4388 vport->fc_rscn_flush = 1;
4389 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004390 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004391 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004392 /* If we are already processing an RSCN, save the received
4393 * RSCN payload buffer, cmdiocb->context2 to process later.
4394 */
James Smart2e0fef82007-06-17 19:56:36 -05004395 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004396 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4397 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4398 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4399
James Smart09372822008-01-11 01:52:54 -05004400 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004401 vport->fc_flag |= FC_RSCN_DEFERRED;
4402 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004403 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004404 vport->fc_flag |= FC_RSCN_MODE;
4405 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004406 if (rscn_cnt) {
4407 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4408 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4409 }
4410 if ((rscn_cnt) &&
4411 (payload_len + length <= LPFC_BPL_SIZE)) {
4412 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004413 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004414 memcpy(((uint8_t *)cmd) + length, lp,
4415 payload_len);
4416 } else {
4417 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4418 vport->fc_rscn_id_cnt++;
4419 /* If we zero, cmdiocb->context2, the calling
4420 * routine will not try to free it.
4421 */
4422 cmdiocb->context2 = NULL;
4423 }
dea31012005-04-17 16:05:31 -05004424 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004425 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4426 "0235 Deferred RSCN "
4427 "Data: x%x x%x x%x\n",
4428 vport->fc_rscn_id_cnt, vport->fc_flag,
4429 vport->port_state);
dea31012005-04-17 16:05:31 -05004430 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004431 vport->fc_flag |= FC_RSCN_DISCOVERY;
4432 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004433 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004434 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4435 "0234 ReDiscovery RSCN "
4436 "Data: x%x x%x x%x\n",
4437 vport->fc_rscn_id_cnt, vport->fc_flag,
4438 vport->port_state);
dea31012005-04-17 16:05:31 -05004439 }
James Smart7f5f3d02008-02-08 18:50:14 -05004440 /* Indicate we are done walking fc_rscn_id_list on this vport */
4441 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004442 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004443 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004444 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004445 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004446 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004447 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004448 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004449 return 0;
dea31012005-04-17 16:05:31 -05004450 }
James Smart858c9f62007-06-17 19:56:39 -05004451 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4452 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4453 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4454
James Smart2e0fef82007-06-17 19:56:36 -05004455 spin_lock_irq(shost->host_lock);
4456 vport->fc_flag |= FC_RSCN_MODE;
4457 spin_unlock_irq(shost->host_lock);
4458 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004459 /* Indicate we are done walking fc_rscn_id_list on this vport */
4460 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004461 /*
4462 * If we zero, cmdiocb->context2, the calling routine will
4463 * not try to free it.
4464 */
4465 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004466 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004467 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004468 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004469 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004470 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004471 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004472}
4473
James Smarte59058c2008-08-24 21:49:00 -04004474/**
James Smart3621a712009-04-06 18:47:14 -04004475 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004476 * @vport: pointer to a host virtual N_Port data structure.
4477 *
4478 * This routine handles the Registration State Configuration Notification
4479 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4480 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4481 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4482 * NameServer shall be issued. If CT command to the NameServer fails to be
4483 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4484 * RSCN activities with the @vport.
4485 *
4486 * Return code
4487 * 0 - Cleaned up rscn on the @vport
4488 * 1 - Wait for plogi to name server before proceed
4489 **/
dea31012005-04-17 16:05:31 -05004490int
James Smart2e0fef82007-06-17 19:56:36 -05004491lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004492{
4493 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004494 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004495
James Smart92d7f7b2007-06-17 19:56:38 -05004496 /* Ignore RSCN if the port is being torn down. */
4497 if (vport->load_flag & FC_UNLOADING) {
4498 lpfc_els_flush_rscn(vport);
4499 return 0;
4500 }
4501
dea31012005-04-17 16:05:31 -05004502 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004503 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004504
4505 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004506 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4507 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4508 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4509 vport->port_state);
dea31012005-04-17 16:05:31 -05004510
4511 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004512 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004513 vport->num_disc_nodes = 0;
4514
James Smart2e0fef82007-06-17 19:56:36 -05004515 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004516 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4517 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004518 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004519 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004520 /* Wait for NameServer query cmpl before we can
4521 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004522 return 1;
dea31012005-04-17 16:05:31 -05004523 } else {
4524 /* If login to NameServer does not exist, issue one */
4525 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004526 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004527 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004528 /* Wait for NameServer login cmpl before we can
4529 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004530 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004531
James Smarte47c9092008-02-08 18:49:26 -05004532 if (ndlp) {
4533 ndlp = lpfc_enable_node(vport, ndlp,
4534 NLP_STE_PLOGI_ISSUE);
4535 if (!ndlp) {
4536 lpfc_els_flush_rscn(vport);
4537 return 0;
4538 }
4539 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004540 } else {
James Smarte47c9092008-02-08 18:49:26 -05004541 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4542 if (!ndlp) {
4543 lpfc_els_flush_rscn(vport);
4544 return 0;
4545 }
James Smart2e0fef82007-06-17 19:56:36 -05004546 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004547 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004548 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004549 }
James Smarte47c9092008-02-08 18:49:26 -05004550 ndlp->nlp_type |= NLP_FABRIC;
4551 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4552 /* Wait for NameServer login cmpl before we can
4553 * continue
4554 */
4555 return 1;
dea31012005-04-17 16:05:31 -05004556 }
4557
James Smart2e0fef82007-06-17 19:56:36 -05004558 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004559 return 0;
dea31012005-04-17 16:05:31 -05004560}
4561
James Smarte59058c2008-08-24 21:49:00 -04004562/**
James Smart3621a712009-04-06 18:47:14 -04004563 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004564 * @vport: pointer to a host virtual N_Port data structure.
4565 * @cmdiocb: pointer to lpfc command iocb data structure.
4566 * @ndlp: pointer to a node-list data structure.
4567 *
4568 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4569 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4570 * point topology. As an unsolicited FLOGI should not be received in a loop
4571 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4572 * lpfc_check_sparm() routine is invoked to check the parameters in the
4573 * unsolicited FLOGI. If parameters validation failed, the routine
4574 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4575 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4576 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4577 * will initiate PLOGI. The higher lexicographical value party shall has
4578 * higher priority (as the winning port) and will initiate PLOGI and
4579 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4580 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4581 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4582 *
4583 * Return code
4584 * 0 - Successfully processed the unsolicited flogi
4585 * 1 - Failed to process the unsolicited flogi
4586 **/
dea31012005-04-17 16:05:31 -05004587static int
James Smart2e0fef82007-06-17 19:56:36 -05004588lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004589 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004590{
James Smart2e0fef82007-06-17 19:56:36 -05004591 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4592 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004593 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4594 uint32_t *lp = (uint32_t *) pcmd->virt;
4595 IOCB_t *icmd = &cmdiocb->iocb;
4596 struct serv_parm *sp;
4597 LPFC_MBOXQ_t *mbox;
4598 struct ls_rjt stat;
4599 uint32_t cmd, did;
4600 int rc;
4601
4602 cmd = *lp++;
4603 sp = (struct serv_parm *) lp;
4604
4605 /* FLOGI received */
4606
James Smart2e0fef82007-06-17 19:56:36 -05004607 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004608
James Smart76a95d72010-11-20 23:11:48 -05004609 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004610 /* We should never receive a FLOGI in loop mode, ignore it */
4611 did = icmd->un.elsreq64.remoteID;
4612
4613 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4614 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004615 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4616 "0113 An FLOGI ELS command x%x was "
4617 "received from DID x%x in Loop Mode\n",
4618 cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004619 return 1;
dea31012005-04-17 16:05:31 -05004620 }
4621
4622 did = Fabric_DID;
4623
James Smart341af102010-01-26 23:07:37 -05004624 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004625 /* For a FLOGI we accept, then if our portname is greater
4626 * then the remote portname we initiate Nport login.
4627 */
4628
James Smart2e0fef82007-06-17 19:56:36 -05004629 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004630 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004631
4632 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004633 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4634 if (!mbox)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004635 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004636
dea31012005-04-17 16:05:31 -05004637 lpfc_linkdown(phba);
4638 lpfc_init_link(phba, mbox,
4639 phba->cfg_topology,
4640 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004641 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004642 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004643 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004644 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004645 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004646 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004647 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004648 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004649 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004650 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004651 spin_lock_irq(shost->host_lock);
4652 vport->fc_flag |= FC_PT2PT_PLOGI;
4653 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004654 }
James Smart2e0fef82007-06-17 19:56:36 -05004655 spin_lock_irq(shost->host_lock);
4656 vport->fc_flag |= FC_PT2PT;
4657 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4658 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004659 } else {
4660 /* Reject this request because invalid parameters */
4661 stat.un.b.lsRjtRsvd0 = 0;
4662 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4663 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4664 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004665 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4666 NULL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004667 return 1;
dea31012005-04-17 16:05:31 -05004668 }
4669
4670 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004671 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004672
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004673 return 0;
dea31012005-04-17 16:05:31 -05004674}
4675
James Smarte59058c2008-08-24 21:49:00 -04004676/**
James Smart3621a712009-04-06 18:47:14 -04004677 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004678 * @vport: pointer to a host virtual N_Port data structure.
4679 * @cmdiocb: pointer to lpfc command iocb data structure.
4680 * @ndlp: pointer to a node-list data structure.
4681 *
4682 * This routine processes Request Node Identification Data (RNID) IOCB
4683 * received as an ELS unsolicited event. Only when the RNID specified format
4684 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4685 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4686 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4687 * rejected by invoking the lpfc_els_rsp_reject() routine.
4688 *
4689 * Return code
4690 * 0 - Successfully processed rnid iocb (currently always return 0)
4691 **/
dea31012005-04-17 16:05:31 -05004692static int
James Smart2e0fef82007-06-17 19:56:36 -05004693lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4694 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004695{
4696 struct lpfc_dmabuf *pcmd;
4697 uint32_t *lp;
4698 IOCB_t *icmd;
4699 RNID *rn;
4700 struct ls_rjt stat;
4701 uint32_t cmd, did;
4702
4703 icmd = &cmdiocb->iocb;
4704 did = icmd->un.elsreq64.remoteID;
4705 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4706 lp = (uint32_t *) pcmd->virt;
4707
4708 cmd = *lp++;
4709 rn = (RNID *) lp;
4710
4711 /* RNID received */
4712
4713 switch (rn->Format) {
4714 case 0:
4715 case RNID_TOPOLOGY_DISC:
4716 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004717 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004718 break;
4719 default:
4720 /* Reject this request because format not supported */
4721 stat.un.b.lsRjtRsvd0 = 0;
4722 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4723 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4724 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004725 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4726 NULL);
dea31012005-04-17 16:05:31 -05004727 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004728 return 0;
dea31012005-04-17 16:05:31 -05004729}
4730
James Smarte59058c2008-08-24 21:49:00 -04004731/**
James Smart12265f62010-10-22 11:05:53 -04004732 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4733 * @vport: pointer to a host virtual N_Port data structure.
4734 * @cmdiocb: pointer to lpfc command iocb data structure.
4735 * @ndlp: pointer to a node-list data structure.
4736 *
4737 * Return code
4738 * 0 - Successfully processed echo iocb (currently always return 0)
4739 **/
4740static int
4741lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4742 struct lpfc_nodelist *ndlp)
4743{
4744 uint8_t *pcmd;
4745
4746 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4747
4748 /* skip over first word of echo command to find echo data */
4749 pcmd += sizeof(uint32_t);
4750
4751 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4752 return 0;
4753}
4754
4755/**
James Smart3621a712009-04-06 18:47:14 -04004756 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004757 * @vport: pointer to a host virtual N_Port data structure.
4758 * @cmdiocb: pointer to lpfc command iocb data structure.
4759 * @ndlp: pointer to a node-list data structure.
4760 *
4761 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4762 * received as an ELS unsolicited event. Currently, this function just invokes
4763 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4764 *
4765 * Return code
4766 * 0 - Successfully processed lirr iocb (currently always return 0)
4767 **/
dea31012005-04-17 16:05:31 -05004768static int
James Smart2e0fef82007-06-17 19:56:36 -05004769lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4770 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004771{
4772 struct ls_rjt stat;
4773
4774 /* For now, unconditionally reject this command */
4775 stat.un.b.lsRjtRsvd0 = 0;
4776 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4777 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4778 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004779 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004780 return 0;
4781}
4782
James Smarte59058c2008-08-24 21:49:00 -04004783/**
James Smart5ffc2662009-11-18 15:39:44 -05004784 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4785 * @vport: pointer to a host virtual N_Port data structure.
4786 * @cmdiocb: pointer to lpfc command iocb data structure.
4787 * @ndlp: pointer to a node-list data structure.
4788 *
4789 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4790 * received as an ELS unsolicited event. A request to RRQ shall only
4791 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4792 * Nx_Port N_Port_ID of the target Exchange is the same as the
4793 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4794 * not accepted, an LS_RJT with reason code "Unable to perform
4795 * command request" and reason code explanation "Invalid Originator
4796 * S_ID" shall be returned. For now, we just unconditionally accept
4797 * RRQ from the target.
4798 **/
4799static void
4800lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4801 struct lpfc_nodelist *ndlp)
4802{
4803 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4804}
4805
4806/**
James Smart12265f62010-10-22 11:05:53 -04004807 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4808 * @phba: pointer to lpfc hba data structure.
4809 * @pmb: pointer to the driver internal queue element for mailbox command.
4810 *
4811 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4812 * mailbox command. This callback function is to actually send the Accept
4813 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4814 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4815 * mailbox command, constructs the RPS response with the link statistics
4816 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4817 * response to the RPS.
4818 *
4819 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4820 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4821 * will be stored into the context1 field of the IOCB for the completion
4822 * callback function to the RPS Accept Response ELS IOCB command.
4823 *
4824 **/
4825static void
4826lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4827{
4828 MAILBOX_t *mb;
4829 IOCB_t *icmd;
4830 struct RLS_RSP *rls_rsp;
4831 uint8_t *pcmd;
4832 struct lpfc_iocbq *elsiocb;
4833 struct lpfc_nodelist *ndlp;
4834 uint16_t xri;
4835 uint32_t cmdsize;
4836
4837 mb = &pmb->u.mb;
4838
4839 ndlp = (struct lpfc_nodelist *) pmb->context2;
4840 xri = (uint16_t) ((unsigned long)(pmb->context1));
4841 pmb->context1 = NULL;
4842 pmb->context2 = NULL;
4843
4844 if (mb->mbxStatus) {
4845 mempool_free(pmb, phba->mbox_mem_pool);
4846 return;
4847 }
4848
4849 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4850 mempool_free(pmb, phba->mbox_mem_pool);
4851 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4852 lpfc_max_els_tries, ndlp,
4853 ndlp->nlp_DID, ELS_CMD_ACC);
4854
4855 /* Decrement the ndlp reference count from previous mbox command */
4856 lpfc_nlp_put(ndlp);
4857
4858 if (!elsiocb)
4859 return;
4860
4861 icmd = &elsiocb->iocb;
4862 icmd->ulpContext = xri;
4863
4864 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4865 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4866 pcmd += sizeof(uint32_t); /* Skip past command */
4867 rls_rsp = (struct RLS_RSP *)pcmd;
4868
4869 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4870 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4871 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4872 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4873 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4874 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4875
4876 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4877 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4878 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4879 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4880 elsiocb->iotag, elsiocb->iocb.ulpContext,
4881 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4882 ndlp->nlp_rpi);
4883 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4884 phba->fc_stat.elsXmitACC++;
4885 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4886 lpfc_els_free_iocb(phba, elsiocb);
4887}
4888
4889/**
James Smart3621a712009-04-06 18:47:14 -04004890 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004891 * @phba: pointer to lpfc hba data structure.
4892 * @pmb: pointer to the driver internal queue element for mailbox command.
4893 *
4894 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4895 * mailbox command. This callback function is to actually send the Accept
4896 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4897 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4898 * mailbox command, constructs the RPS response with the link statistics
4899 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4900 * response to the RPS.
4901 *
4902 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4903 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4904 * will be stored into the context1 field of the IOCB for the completion
4905 * callback function to the RPS Accept Response ELS IOCB command.
4906 *
4907 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004908static void
James Smart329f9bc2007-04-25 09:53:01 -04004909lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004910{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004911 MAILBOX_t *mb;
4912 IOCB_t *icmd;
4913 RPS_RSP *rps_rsp;
4914 uint8_t *pcmd;
4915 struct lpfc_iocbq *elsiocb;
4916 struct lpfc_nodelist *ndlp;
4917 uint16_t xri, status;
4918 uint32_t cmdsize;
4919
James Smart04c68492009-05-22 14:52:52 -04004920 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004921
4922 ndlp = (struct lpfc_nodelist *) pmb->context2;
4923 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004924 pmb->context1 = NULL;
4925 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004926
4927 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004928 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004929 return;
4930 }
4931
4932 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004933 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004934 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4935 lpfc_max_els_tries, ndlp,
4936 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004937
4938 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004939 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004940
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05004941 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004942 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004943
4944 icmd = &elsiocb->iocb;
4945 icmd->ulpContext = xri;
4946
4947 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4948 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004949 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004950 rps_rsp = (RPS_RSP *)pcmd;
4951
James Smart76a95d72010-11-20 23:11:48 -05004952 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004953 status = 0x10;
4954 else
4955 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004956 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004957 status |= 0x4;
4958
4959 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004960 rps_rsp->portStatus = cpu_to_be16(status);
4961 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4962 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4963 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4964 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4965 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4966 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004967 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004968 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4969 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4970 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4971 elsiocb->iotag, elsiocb->iocb.ulpContext,
4972 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4973 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004974 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004975 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004976 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004977 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004978 return;
4979}
4980
James Smarte59058c2008-08-24 21:49:00 -04004981/**
James Smart12265f62010-10-22 11:05:53 -04004982 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4983 * @vport: pointer to a host virtual N_Port data structure.
4984 * @cmdiocb: pointer to lpfc command iocb data structure.
4985 * @ndlp: pointer to a node-list data structure.
4986 *
4987 * This routine processes Read Port Status (RPL) IOCB received as an
4988 * ELS unsolicited event. It first checks the remote port state. If the
4989 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4990 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4991 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4992 * for reading the HBA link statistics. It is for the callback function,
4993 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4994 * to actually sending out RPL Accept (ACC) response.
4995 *
4996 * Return codes
4997 * 0 - Successfully processed rls iocb (currently always return 0)
4998 **/
4999static int
5000lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5001 struct lpfc_nodelist *ndlp)
5002{
5003 struct lpfc_hba *phba = vport->phba;
5004 LPFC_MBOXQ_t *mbox;
5005 struct lpfc_dmabuf *pcmd;
5006 struct ls_rjt stat;
5007
5008 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5009 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5010 /* reject the unsolicited RPS request and done with it */
5011 goto reject_out;
5012
5013 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5014
5015 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5016 if (mbox) {
5017 lpfc_read_lnk_stat(phba, mbox);
5018 mbox->context1 =
5019 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5020 mbox->context2 = lpfc_nlp_get(ndlp);
5021 mbox->vport = vport;
5022 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5023 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5024 != MBX_NOT_FINISHED)
5025 /* Mbox completion will send ELS Response */
5026 return 0;
5027 /* Decrement reference count used for the failed mbox
5028 * command.
5029 */
5030 lpfc_nlp_put(ndlp);
5031 mempool_free(mbox, phba->mbox_mem_pool);
5032 }
5033reject_out:
5034 /* issue rejection response */
5035 stat.un.b.lsRjtRsvd0 = 0;
5036 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5037 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5038 stat.un.b.vendorUnique = 0;
5039 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5040 return 0;
5041}
5042
5043/**
5044 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5045 * @vport: pointer to a host virtual N_Port data structure.
5046 * @cmdiocb: pointer to lpfc command iocb data structure.
5047 * @ndlp: pointer to a node-list data structure.
5048 *
5049 * This routine processes Read Timout Value (RTV) IOCB received as an
5050 * ELS unsolicited event. It first checks the remote port state. If the
5051 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5052 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5053 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5054 * Value (RTV) unsolicited IOCB event.
5055 *
5056 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5057 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5058 * will be stored into the context1 field of the IOCB for the completion
5059 * callback function to the RPS Accept Response ELS IOCB command.
5060 *
5061 * Return codes
5062 * 0 - Successfully processed rtv iocb (currently always return 0)
5063 **/
5064static int
5065lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5066 struct lpfc_nodelist *ndlp)
5067{
5068 struct lpfc_hba *phba = vport->phba;
5069 struct ls_rjt stat;
5070 struct RTV_RSP *rtv_rsp;
5071 uint8_t *pcmd;
5072 struct lpfc_iocbq *elsiocb;
5073 uint32_t cmdsize;
5074
5075
5076 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5077 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5078 /* reject the unsolicited RPS request and done with it */
5079 goto reject_out;
5080
5081 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5082 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5083 lpfc_max_els_tries, ndlp,
5084 ndlp->nlp_DID, ELS_CMD_ACC);
5085
5086 if (!elsiocb)
5087 return 1;
5088
5089 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5090 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5091 pcmd += sizeof(uint32_t); /* Skip past command */
5092
5093 /* use the command's xri in the response */
5094 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5095
5096 rtv_rsp = (struct RTV_RSP *)pcmd;
5097
5098 /* populate RTV payload */
5099 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5100 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5101 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5102 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5103 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5104
5105 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5106 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5107 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5108 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5109 "Data: x%x x%x x%x\n",
5110 elsiocb->iotag, elsiocb->iocb.ulpContext,
5111 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5112 ndlp->nlp_rpi,
5113 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5114 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5115 phba->fc_stat.elsXmitACC++;
5116 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5117 lpfc_els_free_iocb(phba, elsiocb);
5118 return 0;
5119
5120reject_out:
5121 /* issue rejection response */
5122 stat.un.b.lsRjtRsvd0 = 0;
5123 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5124 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5125 stat.un.b.vendorUnique = 0;
5126 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5127 return 0;
5128}
5129
5130/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005131 * @vport: pointer to a host virtual N_Port data structure.
5132 * @cmdiocb: pointer to lpfc command iocb data structure.
5133 * @ndlp: pointer to a node-list data structure.
5134 *
5135 * This routine processes Read Port Status (RPS) IOCB received as an
5136 * ELS unsolicited event. It first checks the remote port state. If the
5137 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5138 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5139 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5140 * for reading the HBA link statistics. It is for the callback function,
5141 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5142 * to actually sending out RPS Accept (ACC) response.
5143 *
5144 * Return codes
5145 * 0 - Successfully processed rps iocb (currently always return 0)
5146 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005147static int
James Smart2e0fef82007-06-17 19:56:36 -05005148lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5149 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005150{
James Smart2e0fef82007-06-17 19:56:36 -05005151 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005152 uint32_t *lp;
5153 uint8_t flag;
5154 LPFC_MBOXQ_t *mbox;
5155 struct lpfc_dmabuf *pcmd;
5156 RPS *rps;
5157 struct ls_rjt stat;
5158
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005159 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005160 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5161 /* reject the unsolicited RPS request and done with it */
5162 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005163
5164 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5165 lp = (uint32_t *) pcmd->virt;
5166 flag = (be32_to_cpu(*lp++) & 0xf);
5167 rps = (RPS *) lp;
5168
5169 if ((flag == 0) ||
5170 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005171 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005172 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005173
James Smart92d7f7b2007-06-17 19:56:38 -05005174 printk("Fix me....\n");
5175 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005176 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5177 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005178 lpfc_read_lnk_stat(phba, mbox);
5179 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005180 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005181 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005182 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005183 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005184 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005185 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005186 /* Mbox completion will send ELS Response */
5187 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005188 /* Decrement reference count used for the failed mbox
5189 * command.
5190 */
James Smart329f9bc2007-04-25 09:53:01 -04005191 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005192 mempool_free(mbox, phba->mbox_mem_pool);
5193 }
5194 }
James Smart90160e02008-08-24 21:49:45 -04005195
5196reject_out:
5197 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005198 stat.un.b.lsRjtRsvd0 = 0;
5199 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5200 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5201 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005202 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005203 return 0;
5204}
5205
James Smarte59058c2008-08-24 21:49:00 -04005206/**
James Smart3621a712009-04-06 18:47:14 -04005207 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005208 * @vport: pointer to a host virtual N_Port data structure.
5209 * @cmdsize: size of the ELS command.
5210 * @oldiocb: pointer to the original lpfc command iocb data structure.
5211 * @ndlp: pointer to a node-list data structure.
5212 *
5213 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5214 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5215 *
5216 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5217 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5218 * will be stored into the context1 field of the IOCB for the completion
5219 * callback function to the RPL Accept Response ELS command.
5220 *
5221 * Return code
5222 * 0 - Successfully issued ACC RPL ELS command
5223 * 1 - Failed to issue ACC RPL ELS command
5224 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005225static int
James Smart2e0fef82007-06-17 19:56:36 -05005226lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5227 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005228{
James Smart2e0fef82007-06-17 19:56:36 -05005229 struct lpfc_hba *phba = vport->phba;
5230 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005231 RPL_RSP rpl_rsp;
5232 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005233 uint8_t *pcmd;
5234
James Smart2e0fef82007-06-17 19:56:36 -05005235 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5236 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005237
James Smart488d1462006-03-07 15:02:37 -05005238 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005239 return 1;
James Smart488d1462006-03-07 15:02:37 -05005240
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005241 icmd = &elsiocb->iocb;
5242 oldcmd = &oldiocb->iocb;
5243 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5244
5245 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5246 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005247 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005248 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5249 pcmd += sizeof(uint16_t);
5250
5251 /* Setup the RPL ACC payload */
5252 rpl_rsp.listLen = be32_to_cpu(1);
5253 rpl_rsp.index = 0;
5254 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005255 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5256 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005257 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005258 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005259 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5261 "0120 Xmit ELS RPL ACC response tag x%x "
5262 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5263 "rpi x%x\n",
5264 elsiocb->iotag, elsiocb->iocb.ulpContext,
5265 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5266 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005267 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005268 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005269 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5270 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005271 lpfc_els_free_iocb(phba, elsiocb);
5272 return 1;
5273 }
5274 return 0;
5275}
5276
James Smarte59058c2008-08-24 21:49:00 -04005277/**
James Smart3621a712009-04-06 18:47:14 -04005278 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005279 * @vport: pointer to a host virtual N_Port data structure.
5280 * @cmdiocb: pointer to lpfc command iocb data structure.
5281 * @ndlp: pointer to a node-list data structure.
5282 *
5283 * This routine processes Read Port List (RPL) IOCB received as an ELS
5284 * unsolicited event. It first checks the remote port state. If the remote
5285 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5286 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5287 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5288 * to accept the RPL.
5289 *
5290 * Return code
5291 * 0 - Successfully processed rpl iocb (currently always return 0)
5292 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005293static int
James Smart2e0fef82007-06-17 19:56:36 -05005294lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5295 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005296{
5297 struct lpfc_dmabuf *pcmd;
5298 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005299 uint32_t maxsize;
5300 uint16_t cmdsize;
5301 RPL *rpl;
5302 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005303
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005304 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5305 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005306 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005307 stat.un.b.lsRjtRsvd0 = 0;
5308 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5309 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5310 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5312 NULL);
James Smart90160e02008-08-24 21:49:45 -04005313 /* rejected the unsolicited RPL request and done with it */
5314 return 0;
dea31012005-04-17 16:05:31 -05005315 }
5316
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005317 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5318 lp = (uint32_t *) pcmd->virt;
5319 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005320 maxsize = be32_to_cpu(rpl->maxsize);
5321
5322 /* We support only one port */
5323 if ((rpl->index == 0) &&
5324 ((maxsize == 0) ||
5325 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5326 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005327 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005328 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5329 }
James Smart2e0fef82007-06-17 19:56:36 -05005330 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005331
5332 return 0;
5333}
5334
James Smarte59058c2008-08-24 21:49:00 -04005335/**
James Smart3621a712009-04-06 18:47:14 -04005336 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005337 * @vport: pointer to a virtual N_Port data structure.
5338 * @cmdiocb: pointer to lpfc command iocb data structure.
5339 * @ndlp: pointer to a node-list data structure.
5340 *
5341 * This routine processes Fibre Channel Address Resolution Protocol
5342 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5343 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5344 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5345 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5346 * remote PortName is compared against the FC PortName stored in the @vport
5347 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5348 * compared against the FC NodeName stored in the @vport data structure.
5349 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5350 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5351 * invoked to send out FARP Response to the remote node. Before sending the
5352 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5353 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5354 * routine is invoked to log into the remote port first.
5355 *
5356 * Return code
5357 * 0 - Either the FARP Match Mode not supported or successfully processed
5358 **/
dea31012005-04-17 16:05:31 -05005359static int
James Smart2e0fef82007-06-17 19:56:36 -05005360lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5361 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005362{
5363 struct lpfc_dmabuf *pcmd;
5364 uint32_t *lp;
5365 IOCB_t *icmd;
5366 FARP *fp;
5367 uint32_t cmd, cnt, did;
5368
5369 icmd = &cmdiocb->iocb;
5370 did = icmd->un.elsreq64.remoteID;
5371 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5372 lp = (uint32_t *) pcmd->virt;
5373
5374 cmd = *lp++;
5375 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005376 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005377 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5378 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005379 /* We will only support match on WWPN or WWNN */
5380 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005381 return 0;
dea31012005-04-17 16:05:31 -05005382 }
5383
5384 cnt = 0;
5385 /* If this FARP command is searching for my portname */
5386 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005387 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005388 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005389 cnt = 1;
5390 }
5391
5392 /* If this FARP command is searching for my nodename */
5393 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005394 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005395 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005396 cnt = 1;
5397 }
5398
5399 if (cnt) {
5400 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5401 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5402 /* Log back into the node before sending the FARP. */
5403 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005404 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005405 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005406 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005407 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005408 }
5409
5410 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005411 if (fp->Rflags & FARP_REQUEST_FARPR)
5412 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005413 }
5414 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005415 return 0;
dea31012005-04-17 16:05:31 -05005416}
5417
James Smarte59058c2008-08-24 21:49:00 -04005418/**
James Smart3621a712009-04-06 18:47:14 -04005419 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005420 * @vport: pointer to a host virtual N_Port data structure.
5421 * @cmdiocb: pointer to lpfc command iocb data structure.
5422 * @ndlp: pointer to a node-list data structure.
5423 *
5424 * This routine processes Fibre Channel Address Resolution Protocol
5425 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5426 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5427 * the FARP response request.
5428 *
5429 * Return code
5430 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5431 **/
dea31012005-04-17 16:05:31 -05005432static int
James Smart2e0fef82007-06-17 19:56:36 -05005433lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5434 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005435{
5436 struct lpfc_dmabuf *pcmd;
5437 uint32_t *lp;
5438 IOCB_t *icmd;
5439 uint32_t cmd, did;
5440
5441 icmd = &cmdiocb->iocb;
5442 did = icmd->un.elsreq64.remoteID;
5443 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5444 lp = (uint32_t *) pcmd->virt;
5445
5446 cmd = *lp++;
5447 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005448 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5449 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005450 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005451 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005452
5453 return 0;
5454}
5455
James Smarte59058c2008-08-24 21:49:00 -04005456/**
James Smart3621a712009-04-06 18:47:14 -04005457 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005458 * @vport: pointer to a host virtual N_Port data structure.
5459 * @cmdiocb: pointer to lpfc command iocb data structure.
5460 * @fan_ndlp: pointer to a node-list data structure.
5461 *
5462 * This routine processes a Fabric Address Notification (FAN) IOCB
5463 * command received as an ELS unsolicited event. The FAN ELS command will
5464 * only be processed on a physical port (i.e., the @vport represents the
5465 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5466 * compared against those in the phba data structure. If any of those is
5467 * different, the lpfc_initial_flogi() routine is invoked to initialize
5468 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5469 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5470 * is invoked to register login to the fabric.
5471 *
5472 * Return code
5473 * 0 - Successfully processed fan iocb (currently always return 0).
5474 **/
dea31012005-04-17 16:05:31 -05005475static int
James Smart2e0fef82007-06-17 19:56:36 -05005476lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5477 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005478{
James Smart2e0fef82007-06-17 19:56:36 -05005479 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005480 uint32_t *lp;
5481 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005482
James Smart0d2b6b82008-06-14 22:52:47 -04005483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5484 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5485 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005486 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005487 if ((vport == phba->pport) &&
5488 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005489 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005490 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005491 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005492 sizeof(struct lpfc_name)))) {
5493 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005494 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005495 } else {
5496 /* FAN verified - skip FLOGI */
5497 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005498 if (phba->sli_rev < LPFC_SLI_REV4)
5499 lpfc_issue_fabric_reglogin(vport);
5500 else
5501 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005502 }
dea31012005-04-17 16:05:31 -05005503 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005504 return 0;
dea31012005-04-17 16:05:31 -05005505}
5506
James Smarte59058c2008-08-24 21:49:00 -04005507/**
James Smart3621a712009-04-06 18:47:14 -04005508 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005509 * @ptr: holder for the timer function associated data.
5510 *
5511 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5512 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5513 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5514 * up the worker thread. It is for the worker thread to invoke the routine
5515 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5516 **/
dea31012005-04-17 16:05:31 -05005517void
5518lpfc_els_timeout(unsigned long ptr)
5519{
James Smart2e0fef82007-06-17 19:56:36 -05005520 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5521 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005522 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005523 unsigned long iflag;
5524
James Smart2e0fef82007-06-17 19:56:36 -05005525 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005526 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5527 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005528 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005529 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005530
James Smart5e9d9b82008-06-14 22:52:53 -04005531 if (!tmo_posted)
5532 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005533 return;
5534}
5535
James Smart2a9bf3d2010-06-07 15:24:45 -04005536
James Smarte59058c2008-08-24 21:49:00 -04005537/**
James Smart3621a712009-04-06 18:47:14 -04005538 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005539 * @vport: pointer to a virtual N_Port data structure.
5540 *
5541 * This routine is the actual handler function that processes an ELS timeout
5542 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5543 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5544 * invoking the lpfc_sli_issue_abort_iotag() routine.
5545 **/
dea31012005-04-17 16:05:31 -05005546void
James Smart2e0fef82007-06-17 19:56:36 -05005547lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005548{
James Smart2e0fef82007-06-17 19:56:36 -05005549 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005550 struct lpfc_sli_ring *pring;
5551 struct lpfc_iocbq *tmp_iocb, *piocb;
5552 IOCB_t *cmd = NULL;
5553 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005554 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005555 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005556 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005557 LIST_HEAD(txcmplq_completions);
5558 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005559
James Smart2a9bf3d2010-06-07 15:24:45 -04005560
dea31012005-04-17 16:05:31 -05005561 timeout = (uint32_t)(phba->fc_ratov << 1);
5562
5563 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005564
James Smart2a9bf3d2010-06-07 15:24:45 -04005565 spin_lock_irq(&phba->hbalock);
5566 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5567 spin_unlock_irq(&phba->hbalock);
5568
5569 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005570 cmd = &piocb->iocb;
5571
James Smart2e0fef82007-06-17 19:56:36 -05005572 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5573 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5574 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005575 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005576
5577 if (piocb->vport != vport)
5578 continue;
5579
dea31012005-04-17 16:05:31 -05005580 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005581 if (pcmd)
5582 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005583
James Smart92d7f7b2007-06-17 19:56:38 -05005584 if (els_command == ELS_CMD_FARP ||
5585 els_command == ELS_CMD_FARPR ||
5586 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005587 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005588
dea31012005-04-17 16:05:31 -05005589 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005590 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005591 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005592 else
dea31012005-04-17 16:05:31 -05005593 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005594 continue;
5595 }
5596
James Smart2e0fef82007-06-17 19:56:36 -05005597 remote_ID = 0xffffffff;
5598 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005599 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005600 else {
5601 struct lpfc_nodelist *ndlp;
5602 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005603 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005604 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005605 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005606 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005607 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005608 spin_lock_irq(&phba->hbalock);
5609 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005610 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005611
James Smart2a9bf3d2010-06-07 15:24:45 -04005612 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5613 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5614 "0127 ELS timeout Data: x%x x%x x%x "
5615 "x%x\n", els_command,
5616 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5617 spin_lock_irq(&phba->hbalock);
5618 list_del_init(&piocb->dlist);
5619 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5620 spin_unlock_irq(&phba->hbalock);
5621 }
5622
James Smart2e0fef82007-06-17 19:56:36 -05005623 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5624 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005625}
5626
James Smarte59058c2008-08-24 21:49:00 -04005627/**
James Smart3621a712009-04-06 18:47:14 -04005628 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005629 * @vport: pointer to a host virtual N_Port data structure.
5630 *
5631 * This routine is used to clean up all the outstanding ELS commands on a
5632 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5633 * routine. After that, it walks the ELS transmit queue to remove all the
5634 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5635 * the IOCBs with a non-NULL completion callback function, the callback
5636 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5637 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5638 * callback function, the IOCB will simply be released. Finally, it walks
5639 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5640 * completion queue IOCB that is associated with the @vport and is not
5641 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5642 * part of the discovery state machine) out to HBA by invoking the
5643 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5644 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5645 * the IOCBs are aborted when this function returns.
5646 **/
dea31012005-04-17 16:05:31 -05005647void
James Smart2e0fef82007-06-17 19:56:36 -05005648lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005649{
James Smart2534ba72007-04-25 09:52:20 -04005650 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005651 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005652 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005653 struct lpfc_iocbq *tmp_iocb, *piocb;
5654 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005655
5656 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005657
James Smart2e0fef82007-06-17 19:56:36 -05005658 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005659 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5660 cmd = &piocb->iocb;
5661
5662 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5663 continue;
5664 }
5665
5666 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005667 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5668 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5669 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5670 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005671 continue;
dea31012005-04-17 16:05:31 -05005672
James Smart2e0fef82007-06-17 19:56:36 -05005673 if (piocb->vport != vport)
5674 continue;
5675
James Smart2534ba72007-04-25 09:52:20 -04005676 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005677 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005678 }
5679
5680 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005681 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5682 continue;
5683 }
dea31012005-04-17 16:05:31 -05005684
James Smart2e0fef82007-06-17 19:56:36 -05005685 if (piocb->vport != vport)
5686 continue;
5687
James Smart07951072007-04-25 09:51:38 -04005688 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005689 }
James Smart2e0fef82007-06-17 19:56:36 -05005690 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005691
James Smarta257bf92009-04-06 18:48:10 -04005692 /* Cancell all the IOCBs from the completions list */
5693 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5694 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005695
dea31012005-04-17 16:05:31 -05005696 return;
5697}
5698
James Smarte59058c2008-08-24 21:49:00 -04005699/**
James Smart3621a712009-04-06 18:47:14 -04005700 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005701 * @phba: pointer to lpfc hba data structure.
5702 *
5703 * This routine is used to clean up all the outstanding ELS commands on a
5704 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5705 * routine. After that, it walks the ELS transmit queue to remove all the
5706 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5707 * the IOCBs with the completion callback function associated, the callback
5708 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5709 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5710 * callback function associated, the IOCB will simply be released. Finally,
5711 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5712 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5713 * management plane IOCBs that are not part of the discovery state machine)
5714 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5715 **/
James Smart549e55c2007-08-02 11:09:51 -04005716void
5717lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5718{
5719 LIST_HEAD(completions);
5720 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5721 struct lpfc_iocbq *tmp_iocb, *piocb;
5722 IOCB_t *cmd = NULL;
5723
5724 lpfc_fabric_abort_hba(phba);
5725 spin_lock_irq(&phba->hbalock);
5726 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5727 cmd = &piocb->iocb;
5728 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5729 continue;
5730 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5731 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5732 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5733 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5734 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5735 continue;
5736 list_move_tail(&piocb->list, &completions);
5737 pring->txq_cnt--;
5738 }
5739 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5740 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5741 continue;
5742 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5743 }
5744 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005745
5746 /* Cancel all the IOCBs from the completions list */
5747 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5748 IOERR_SLI_ABORTED);
5749
James Smart549e55c2007-08-02 11:09:51 -04005750 return;
5751}
5752
James Smarte59058c2008-08-24 21:49:00 -04005753/**
James Smart3621a712009-04-06 18:47:14 -04005754 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005755 * @phba: Pointer to hba context object.
5756 * @cmdiocbp: Pointer to command iocb which reported error.
5757 * @rspiocbp: Pointer to response iocb which reported error.
5758 *
5759 * This function sends an event when there is an ELS command
5760 * failure.
5761 **/
5762void
5763lpfc_send_els_failure_event(struct lpfc_hba *phba,
5764 struct lpfc_iocbq *cmdiocbp,
5765 struct lpfc_iocbq *rspiocbp)
5766{
5767 struct lpfc_vport *vport = cmdiocbp->vport;
5768 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5769 struct lpfc_lsrjt_event lsrjt_event;
5770 struct lpfc_fabric_event_header fabric_event;
5771 struct ls_rjt stat;
5772 struct lpfc_nodelist *ndlp;
5773 uint32_t *pcmd;
5774
5775 ndlp = cmdiocbp->context1;
5776 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5777 return;
5778
5779 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5780 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5781 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5782 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5783 sizeof(struct lpfc_name));
5784 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5785 sizeof(struct lpfc_name));
5786 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5787 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005788 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005789 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5790 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5791 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5792 fc_host_post_vendor_event(shost,
5793 fc_get_event_number(),
5794 sizeof(lsrjt_event),
5795 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005796 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005797 return;
5798 }
5799 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5800 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5801 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5802 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5803 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5804 else
5805 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5806 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5807 sizeof(struct lpfc_name));
5808 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5809 sizeof(struct lpfc_name));
5810 fc_host_post_vendor_event(shost,
5811 fc_get_event_number(),
5812 sizeof(fabric_event),
5813 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005814 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005815 return;
5816 }
5817
5818}
5819
5820/**
James Smart3621a712009-04-06 18:47:14 -04005821 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005822 * @vport: Pointer to vport object.
5823 * @ndlp: Pointer FC node object.
5824 * @cmd: ELS command code.
5825 *
5826 * This function posts an event when there is an incoming
5827 * unsolicited ELS command.
5828 **/
5829static void
5830lpfc_send_els_event(struct lpfc_vport *vport,
5831 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005832 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005833{
James Smartddcc50f2008-12-04 22:38:46 -05005834 struct lpfc_els_event_header *els_data = NULL;
5835 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005836 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5837
James Smartddcc50f2008-12-04 22:38:46 -05005838 if (*payload == ELS_CMD_LOGO) {
5839 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5840 if (!logo_data) {
5841 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5842 "0148 Failed to allocate memory "
5843 "for LOGO event\n");
5844 return;
5845 }
5846 els_data = &logo_data->header;
5847 } else {
5848 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5849 GFP_KERNEL);
5850 if (!els_data) {
5851 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5852 "0149 Failed to allocate memory "
5853 "for ELS event\n");
5854 return;
5855 }
5856 }
5857 els_data->event_type = FC_REG_ELS_EVENT;
5858 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005859 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005860 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005861 break;
5862 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005863 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005864 break;
5865 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005866 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5867 break;
5868 case ELS_CMD_LOGO:
5869 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5870 /* Copy the WWPN in the LOGO payload */
5871 memcpy(logo_data->logo_wwpn, &payload[2],
5872 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005873 break;
5874 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005875 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005876 return;
5877 }
James Smartddcc50f2008-12-04 22:38:46 -05005878 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5879 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5880 if (*payload == ELS_CMD_LOGO) {
5881 fc_host_post_vendor_event(shost,
5882 fc_get_event_number(),
5883 sizeof(struct lpfc_logo_event),
5884 (char *)logo_data,
5885 LPFC_NL_VENDOR_ID);
5886 kfree(logo_data);
5887 } else {
5888 fc_host_post_vendor_event(shost,
5889 fc_get_event_number(),
5890 sizeof(struct lpfc_els_event_header),
5891 (char *)els_data,
5892 LPFC_NL_VENDOR_ID);
5893 kfree(els_data);
5894 }
James Smartea2151b2008-09-07 11:52:10 -04005895
5896 return;
5897}
5898
5899
5900/**
James Smart3621a712009-04-06 18:47:14 -04005901 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005902 * @phba: pointer to lpfc hba data structure.
5903 * @pring: pointer to a SLI ring.
5904 * @vport: pointer to a host virtual N_Port data structure.
5905 * @elsiocb: pointer to lpfc els command iocb data structure.
5906 *
5907 * This routine is used for processing the IOCB associated with a unsolicited
5908 * event. It first determines whether there is an existing ndlp that matches
5909 * the DID from the unsolicited IOCB. If not, it will create a new one with
5910 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5911 * IOCB is then used to invoke the proper routine and to set up proper state
5912 * of the discovery state machine.
5913 **/
James Smarted957682007-06-17 19:56:37 -05005914static void
5915lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005916 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005917{
James Smart87af33f2007-10-27 13:37:43 -04005918 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005919 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005920 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005921 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005922 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005923 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005924
James Smarte47c9092008-02-08 18:49:26 -05005925 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005926 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005927
dea31012005-04-17 16:05:31 -05005928 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005929 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5930 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005931 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005932 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005933
James Smart858c9f62007-06-17 19:56:39 -05005934 did = icmd->un.rcvels.remoteID;
5935 if (icmd->ulpStatus) {
5936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5937 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5938 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005939 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005940 }
dea31012005-04-17 16:05:31 -05005941
5942 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005943 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005944 goto dropit;
dea31012005-04-17 16:05:31 -05005945
James Smartc8685952009-11-18 15:39:16 -05005946 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005947 if (vport->load_flag & FC_UNLOADING)
5948 goto dropit;
5949
James Smart2e0fef82007-06-17 19:56:36 -05005950 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005951 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005952 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05005953 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005954 if (!ndlp)
dea31012005-04-17 16:05:31 -05005955 goto dropit;
dea31012005-04-17 16:05:31 -05005956
James Smart2e0fef82007-06-17 19:56:36 -05005957 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005958 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005959 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005960 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005961 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005962 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5963 ndlp = lpfc_enable_node(vport, ndlp,
5964 NLP_STE_UNUSED_NODE);
5965 if (!ndlp)
5966 goto dropit;
5967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5968 newnode = 1;
5969 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5970 ndlp->nlp_type |= NLP_FABRIC;
5971 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5972 /* This is similar to the new node path */
5973 ndlp = lpfc_nlp_get(ndlp);
5974 if (!ndlp)
5975 goto dropit;
5976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5977 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005978 }
dea31012005-04-17 16:05:31 -05005979
5980 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005981
James Smart329f9bc2007-04-25 09:53:01 -04005982 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005983 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005984
5985 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5986 cmd &= ELS_CMD_MASK;
5987 }
5988 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005989 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5990 "0112 ELS command x%x received from NPORT x%x "
5991 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005992 switch (cmd) {
5993 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005994 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5995 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5996 did, vport->port_state, ndlp->nlp_flag);
5997
dea31012005-04-17 16:05:31 -05005998 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005999 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6000
James Smartddcc50f2008-12-04 22:38:46 -05006001 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05006002 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006003 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6004 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6005 rjt_err = LSRJT_UNABLE_TPC;
6006 break;
6007 }
6008 /* We get here, and drop thru, if we are PT2PT with
6009 * another NPort and the other side has initiated
6010 * the PLOGI before responding to our FLOGI.
6011 */
dea31012005-04-17 16:05:31 -05006012 }
James Smart87af33f2007-10-27 13:37:43 -04006013
6014 shost = lpfc_shost_from_vport(vport);
6015 spin_lock_irq(shost->host_lock);
6016 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6017 spin_unlock_irq(shost->host_lock);
6018
James Smart2e0fef82007-06-17 19:56:36 -05006019 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6020 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006021
dea31012005-04-17 16:05:31 -05006022 break;
6023 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6025 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6026 did, vport->port_state, ndlp->nlp_flag);
6027
dea31012005-04-17 16:05:31 -05006028 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006029 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006030 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006031 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006032 break;
6033 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6035 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6036 did, vport->port_state, ndlp->nlp_flag);
6037
dea31012005-04-17 16:05:31 -05006038 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006039 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006040 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006041 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006042 break;
6043 }
James Smart2e0fef82007-06-17 19:56:36 -05006044 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006045 break;
6046 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006047 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6048 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6049 did, vport->port_state, ndlp->nlp_flag);
6050
dea31012005-04-17 16:05:31 -05006051 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006052 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006053 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006054 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006055 break;
6056 }
James Smart2e0fef82007-06-17 19:56:36 -05006057 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006058 break;
6059 case ELS_CMD_RSCN:
6060 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006061 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006062 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006063 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006064 break;
6065 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006066 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6067 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6068 did, vport->port_state, ndlp->nlp_flag);
6069
James Smartddcc50f2008-12-04 22:38:46 -05006070 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006071 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006072 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006073 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006074 break;
6075 }
James Smart2e0fef82007-06-17 19:56:36 -05006076 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6077 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006078 break;
6079 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006080 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6081 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6082 did, vport->port_state, ndlp->nlp_flag);
6083
dea31012005-04-17 16:05:31 -05006084 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006085 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006086 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006087 break;
6088 }
James Smart2e0fef82007-06-17 19:56:36 -05006089 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6090 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006091 break;
6092 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006093 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6094 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6095 did, vport->port_state, ndlp->nlp_flag);
6096
dea31012005-04-17 16:05:31 -05006097 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006098 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006099 break;
6100 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006101 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6102 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6103 did, vport->port_state, ndlp->nlp_flag);
6104
dea31012005-04-17 16:05:31 -05006105 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006106 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006107 break;
6108 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006109 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6110 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6111 did, vport->port_state, ndlp->nlp_flag);
6112
dea31012005-04-17 16:05:31 -05006113 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006114 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006115 break;
dea31012005-04-17 16:05:31 -05006116 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006117 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6118 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6119 did, vport->port_state, ndlp->nlp_flag);
6120
dea31012005-04-17 16:05:31 -05006121 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006122 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006123 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006124 break;
6125 }
James Smart2e0fef82007-06-17 19:56:36 -05006126 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006127 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006128 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6130 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6131 did, vport->port_state, ndlp->nlp_flag);
6132
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006133 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006134 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006135 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006136 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006137 break;
James Smart12265f62010-10-22 11:05:53 -04006138 case ELS_CMD_RLS:
6139 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6140 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6141 did, vport->port_state, ndlp->nlp_flag);
6142
6143 phba->fc_stat.elsRcvRLS++;
6144 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6145 if (newnode)
6146 lpfc_nlp_put(ndlp);
6147 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006148 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006149 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6150 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6151 did, vport->port_state, ndlp->nlp_flag);
6152
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006153 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006154 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006155 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006156 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006157 break;
6158 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6160 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6161 did, vport->port_state, ndlp->nlp_flag);
6162
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006163 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006164 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006165 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006166 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006167 break;
dea31012005-04-17 16:05:31 -05006168 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006169 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6170 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6171 did, vport->port_state, ndlp->nlp_flag);
6172
dea31012005-04-17 16:05:31 -05006173 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006174 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006175 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006176 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006177 break;
James Smart12265f62010-10-22 11:05:53 -04006178 case ELS_CMD_RTV:
6179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6180 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6181 did, vport->port_state, ndlp->nlp_flag);
6182 phba->fc_stat.elsRcvRTV++;
6183 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6184 if (newnode)
6185 lpfc_nlp_put(ndlp);
6186 break;
James Smart5ffc2662009-11-18 15:39:44 -05006187 case ELS_CMD_RRQ:
6188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6189 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6190 did, vport->port_state, ndlp->nlp_flag);
6191
6192 phba->fc_stat.elsRcvRRQ++;
6193 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6194 if (newnode)
6195 lpfc_nlp_put(ndlp);
6196 break;
James Smart12265f62010-10-22 11:05:53 -04006197 case ELS_CMD_ECHO:
6198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6199 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6200 did, vport->port_state, ndlp->nlp_flag);
6201
6202 phba->fc_stat.elsRcvECHO++;
6203 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6204 if (newnode)
6205 lpfc_nlp_put(ndlp);
6206 break;
dea31012005-04-17 16:05:31 -05006207 default:
James Smart858c9f62007-06-17 19:56:39 -05006208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6209 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6210 cmd, did, vport->port_state);
6211
dea31012005-04-17 16:05:31 -05006212 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006213 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006214
6215 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006216 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6217 "0115 Unknown ELS command x%x "
6218 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006219 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006220 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006221 break;
6222 }
6223
6224 /* check if need to LS_RJT received ELS cmd */
6225 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006226 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006227 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006228 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006229 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6230 NULL);
dea31012005-04-17 16:05:31 -05006231 }
6232
James Smartd7c255b2008-08-24 21:50:00 -04006233 lpfc_nlp_put(elsiocb->context1);
6234 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006235 return;
6236
6237dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006238 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006239 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6240 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006241 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006242 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006243 phba->fc_stat.elsRcvDrop++;
6244}
6245
James Smarte59058c2008-08-24 21:49:00 -04006246/**
James Smart3621a712009-04-06 18:47:14 -04006247 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006248 * @phba: pointer to lpfc hba data structure.
6249 * @vpi: host virtual N_Port identifier.
6250 *
6251 * This routine finds a vport on a HBA (referred by @phba) through a
6252 * @vpi. The function walks the HBA's vport list and returns the address
6253 * of the vport with the matching @vpi.
6254 *
6255 * Return code
6256 * NULL - No vport with the matching @vpi found
6257 * Otherwise - Address to the vport with the matching @vpi.
6258 **/
James Smart6669f9b2009-10-02 15:16:45 -04006259struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006260lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6261{
6262 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006263 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006264
James Smart549e55c2007-08-02 11:09:51 -04006265 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006266 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006267 if (vport->vpi == vpi) {
6268 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006269 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006270 }
James Smart92d7f7b2007-06-17 19:56:38 -05006271 }
James Smart549e55c2007-08-02 11:09:51 -04006272 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006273 return NULL;
6274}
James Smarted957682007-06-17 19:56:37 -05006275
James Smarte59058c2008-08-24 21:49:00 -04006276/**
James Smart3621a712009-04-06 18:47:14 -04006277 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006278 * @phba: pointer to lpfc hba data structure.
6279 * @pring: pointer to a SLI ring.
6280 * @elsiocb: pointer to lpfc els iocb data structure.
6281 *
6282 * This routine is used to process an unsolicited event received from a SLI
6283 * (Service Level Interface) ring. The actual processing of the data buffer
6284 * associated with the unsolicited event is done by invoking the routine
6285 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6286 * SLI ring on which the unsolicited event was received.
6287 **/
James Smarted957682007-06-17 19:56:37 -05006288void
6289lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6290 struct lpfc_iocbq *elsiocb)
6291{
6292 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006293 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006294 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006295 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6296 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006297
James Smartd7c255b2008-08-24 21:50:00 -04006298 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006299 elsiocb->context2 = NULL;
6300 elsiocb->context3 = NULL;
6301
6302 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6303 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6304 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6305 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006306 phba->fc_stat.NoRcvBuf++;
6307 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006308 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006309 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006310 return;
6311 }
6312
James Smart92d7f7b2007-06-17 19:56:38 -05006313 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6314 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6315 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6316 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6317 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006318 else
6319 vport = lpfc_find_vport_by_vpid(phba,
6320 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006321 }
James Smart7f5f3d02008-02-08 18:50:14 -05006322 /* If there are no BDEs associated
6323 * with this IOCB, there is nothing to do.
6324 */
James Smarted957682007-06-17 19:56:37 -05006325 if (icmd->ulpBdeCount == 0)
6326 return;
6327
James Smart7f5f3d02008-02-08 18:50:14 -05006328 /* type of ELS cmd is first 32bit word
6329 * in packet
6330 */
James Smarted957682007-06-17 19:56:37 -05006331 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006332 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006333 } else {
6334 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6335 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006336 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6337 paddr);
James Smarted957682007-06-17 19:56:37 -05006338 }
6339
James Smart92d7f7b2007-06-17 19:56:38 -05006340 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6341 /*
6342 * The different unsolicited event handlers would tell us
6343 * if they are done with "mp" by setting context2 to NULL.
6344 */
dea31012005-04-17 16:05:31 -05006345 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006346 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6347 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006348 }
James Smarted957682007-06-17 19:56:37 -05006349
6350 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006351 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006352 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006353 elsiocb->context2 = bdeBuf2;
6354 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006355 /* free mp if we are done with it */
6356 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006357 lpfc_in_buf_free(phba, elsiocb->context2);
6358 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006359 }
dea31012005-04-17 16:05:31 -05006360 }
dea31012005-04-17 16:05:31 -05006361}
James Smart92d7f7b2007-06-17 19:56:38 -05006362
James Smarte59058c2008-08-24 21:49:00 -04006363/**
James Smart3621a712009-04-06 18:47:14 -04006364 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006365 * @phba: pointer to lpfc hba data structure.
6366 * @vport: pointer to a virtual N_Port data structure.
6367 *
6368 * This routine issues a Port Login (PLOGI) to the Name Server with
6369 * State Change Request (SCR) for a @vport. This routine will create an
6370 * ndlp for the Name Server associated to the @vport if such node does
6371 * not already exist. The PLOGI to Name Server is issued by invoking the
6372 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6373 * (FDMI) is configured to the @vport, a FDMI node will be created and
6374 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6375 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006376void
6377lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6378{
6379 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6380
6381 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6382 if (!ndlp) {
6383 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6384 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006385 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006386 lpfc_disc_start(vport);
6387 return;
6388 }
6389 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006390 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6391 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006392 return;
6393 }
6394 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006395 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6396 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6397 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006398 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006399 lpfc_disc_start(vport);
6400 return;
6401 }
6402 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6403 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6404 "0348 NameServer login: node freed\n");
6405 return;
6406 }
James Smart92d7f7b2007-06-17 19:56:38 -05006407 }
James Smart58da1ff2008-04-07 10:15:56 -04006408 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006409
6410 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6411
6412 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6413 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006414 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6415 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006416 return;
6417 }
6418
James Smart3de2a652007-08-02 11:09:59 -04006419 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006420 /* If this is the first time, allocate an ndlp and initialize
6421 * it. Otherwise, make sure the node is enabled and then do the
6422 * login.
6423 */
6424 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6425 if (!ndlp_fdmi) {
6426 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6427 GFP_KERNEL);
6428 if (ndlp_fdmi) {
6429 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6430 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6431 } else
6432 return;
6433 }
6434 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6435 ndlp_fdmi = lpfc_enable_node(vport,
6436 ndlp_fdmi,
6437 NLP_STE_NPR_NODE);
6438
James Smart92d7f7b2007-06-17 19:56:38 -05006439 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006440 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006441 NLP_STE_PLOGI_ISSUE);
6442 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006443 }
6444 }
James Smart92d7f7b2007-06-17 19:56:38 -05006445}
6446
James Smarte59058c2008-08-24 21:49:00 -04006447/**
James Smart3621a712009-04-06 18:47:14 -04006448 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006449 * @phba: pointer to lpfc hba data structure.
6450 * @pmb: pointer to the driver internal queue element for mailbox command.
6451 *
6452 * This routine is the completion callback function to register new vport
6453 * mailbox command. If the new vport mailbox command completes successfully,
6454 * the fabric registration login shall be performed on physical port (the
6455 * new vport created is actually a physical port, with VPI 0) or the port
6456 * login to Name Server for State Change Request (SCR) will be performed
6457 * on virtual port (real virtual port, with VPI greater than 0).
6458 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006459static void
6460lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6461{
6462 struct lpfc_vport *vport = pmb->vport;
6463 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6464 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006465 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006466 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006467
James Smart09372822008-01-11 01:52:54 -05006468 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006469 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006470 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006471
6472 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006473 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006474 "0915 Register VPI failed : Status: x%x"
6475 " upd bit: x%x \n", mb->mbxStatus,
6476 mb->un.varRegVpi.upd);
6477 if (phba->sli_rev == LPFC_SLI_REV4 &&
6478 mb->un.varRegVpi.upd)
6479 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006480
6481 switch (mb->mbxStatus) {
6482 case 0x11: /* unsupported feature */
6483 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006484 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006485 /* giving up on vport registration */
6486 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6487 spin_lock_irq(shost->host_lock);
6488 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6489 spin_unlock_irq(shost->host_lock);
6490 lpfc_can_disctmo(vport);
6491 break;
James Smart695a8142010-01-26 23:08:03 -05006492 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6493 case 0x20:
6494 spin_lock_irq(shost->host_lock);
6495 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6496 spin_unlock_irq(shost->host_lock);
6497 lpfc_init_vpi(phba, pmb, vport->vpi);
6498 pmb->vport = vport;
6499 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6500 rc = lpfc_sli_issue_mbox(phba, pmb,
6501 MBX_NOWAIT);
6502 if (rc == MBX_NOT_FINISHED) {
6503 lpfc_printf_vlog(vport,
6504 KERN_ERR, LOG_MBOX,
6505 "2732 Failed to issue INIT_VPI"
6506 " mailbox command\n");
6507 } else {
6508 lpfc_nlp_put(ndlp);
6509 return;
6510 }
6511
James Smart92d7f7b2007-06-17 19:56:38 -05006512 default:
6513 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006514 if (phba->sli_rev == LPFC_SLI_REV4)
6515 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006516 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006517 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006518 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006519 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006520 if (vport->port_type == LPFC_PHYSICAL_PORT
6521 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006522 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006523 else
6524 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006525 break;
6526 }
James Smart92d7f7b2007-06-17 19:56:38 -05006527 } else {
James Smart695a8142010-01-26 23:08:03 -05006528 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006529 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006530 spin_unlock_irq(shost->host_lock);
6531 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006532 if (phba->sli_rev < LPFC_SLI_REV4)
6533 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006534 else {
James Smartfc2b9892010-02-26 14:15:29 -05006535 /*
6536 * If the physical port is instantiated using
6537 * FDISC, do not start vport discovery.
6538 */
6539 if (vport->port_state != LPFC_FDISC)
6540 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006541 lpfc_do_scr_ns_plogi(phba, vport);
6542 }
6543 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006544 lpfc_do_scr_ns_plogi(phba, vport);
6545 }
James Smart38b92ef2010-08-04 16:11:39 -04006546mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006547 /* Now, we decrement the ndlp reference count held for this
6548 * callback function
6549 */
6550 lpfc_nlp_put(ndlp);
6551
James Smart92d7f7b2007-06-17 19:56:38 -05006552 mempool_free(pmb, phba->mbox_mem_pool);
6553 return;
6554}
6555
James Smarte59058c2008-08-24 21:49:00 -04006556/**
James Smart3621a712009-04-06 18:47:14 -04006557 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006558 * @phba: pointer to lpfc hba data structure.
6559 * @vport: pointer to a host virtual N_Port data structure.
6560 * @ndlp: pointer to a node-list data structure.
6561 *
6562 * This routine registers the @vport as a new virtual port with a HBA.
6563 * It is done through a registering vpi mailbox command.
6564 **/
James Smart695a8142010-01-26 23:08:03 -05006565void
James Smart92d7f7b2007-06-17 19:56:38 -05006566lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6567 struct lpfc_nodelist *ndlp)
6568{
James Smart09372822008-01-11 01:52:54 -05006569 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006570 LPFC_MBOXQ_t *mbox;
6571
6572 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6573 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006574 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006575 mbox->vport = vport;
6576 mbox->context2 = lpfc_nlp_get(ndlp);
6577 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006578 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006579 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006580 /* mailbox command not success, decrement ndlp
6581 * reference count for this command
6582 */
6583 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006584 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006585
James Smarte8b62012007-08-02 11:10:09 -04006586 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6587 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006588 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006589 }
6590 } else {
James Smarte8b62012007-08-02 11:10:09 -04006591 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6592 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006593 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006594 }
James Smartfa4066b2008-01-11 01:53:27 -05006595 return;
6596
6597mbox_err_exit:
6598 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6599 spin_lock_irq(shost->host_lock);
6600 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6601 spin_unlock_irq(shost->host_lock);
6602 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006603}
6604
James Smarte59058c2008-08-24 21:49:00 -04006605/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006606 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006607 * @phba: pointer to lpfc hba data structure.
6608 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006609 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006610 **/
6611void
James Smart0c9ab6f2010-02-26 14:15:57 -05006612lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006613{
6614 struct lpfc_vport **vports;
6615 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006616 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006617 int i;
James Smart695a8142010-01-26 23:08:03 -05006618
6619 /* Treat this failure as linkdown for all vports */
6620 link_state = phba->link_state;
6621 lpfc_linkdown(phba);
6622 phba->link_state = link_state;
6623
6624 vports = lpfc_create_vport_work_array(phba);
6625
6626 if (vports) {
6627 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6628 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6629 if (ndlp)
6630 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6631 lpfc_els_flush_cmd(vports[i]);
6632 }
6633 lpfc_destroy_vport_work_array(phba, vports);
6634 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006635}
6636
6637/**
6638 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6639 * @phba: pointer to lpfc hba data structure.
6640 *
6641 * This routine abort all pending discovery commands and
6642 * start a timer to retry FLOGI for the physical port
6643 * discovery.
6644 **/
6645void
6646lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6647{
6648 struct lpfc_nodelist *ndlp;
6649 struct Scsi_Host *shost;
6650
6651 /* Cancel the all vports retry delay retry timers */
6652 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006653
6654 /* If fabric require FLOGI, then re-instantiate physical login */
6655 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6656 if (!ndlp)
6657 return;
6658
James Smart695a8142010-01-26 23:08:03 -05006659 shost = lpfc_shost_from_vport(phba->pport);
6660 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6661 spin_lock_irq(shost->host_lock);
6662 ndlp->nlp_flag |= NLP_DELAY_TMO;
6663 spin_unlock_irq(shost->host_lock);
6664 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6665 phba->pport->port_state = LPFC_FLOGI;
6666 return;
6667}
6668
6669/**
6670 * lpfc_fabric_login_reqd - Check if FLOGI required.
6671 * @phba: pointer to lpfc hba data structure.
6672 * @cmdiocb: pointer to FDISC command iocb.
6673 * @rspiocb: pointer to FDISC response iocb.
6674 *
6675 * This routine checks if a FLOGI is reguired for FDISC
6676 * to succeed.
6677 **/
6678static int
6679lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6680 struct lpfc_iocbq *cmdiocb,
6681 struct lpfc_iocbq *rspiocb)
6682{
6683
6684 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6685 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6686 return 0;
6687 else
6688 return 1;
6689}
6690
6691/**
James Smart3621a712009-04-06 18:47:14 -04006692 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006693 * @phba: pointer to lpfc hba data structure.
6694 * @cmdiocb: pointer to lpfc command iocb data structure.
6695 * @rspiocb: pointer to lpfc response iocb data structure.
6696 *
6697 * This routine is the completion callback function to a Fabric Discover
6698 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6699 * single threaded, each FDISC completion callback function will reset
6700 * the discovery timer for all vports such that the timers will not get
6701 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6702 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6703 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6704 * assigned to the vport has been changed with the completion of the FDISC
6705 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6706 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6707 * routine is invoked to register new vport with the HBA. Otherwise, the
6708 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6709 * Server for State Change Request (SCR).
6710 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006711static void
6712lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6713 struct lpfc_iocbq *rspiocb)
6714{
6715 struct lpfc_vport *vport = cmdiocb->vport;
6716 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6717 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6718 struct lpfc_nodelist *np;
6719 struct lpfc_nodelist *next_np;
6720 IOCB_t *irsp = &rspiocb->iocb;
6721 struct lpfc_iocbq *piocb;
6722
James Smarte8b62012007-08-02 11:10:09 -04006723 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6724 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6725 irsp->ulpStatus, irsp->un.ulpWord[4],
6726 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006727 /* Since all FDISCs are being single threaded, we
6728 * must reset the discovery timer for ALL vports
6729 * waiting to send FDISC when one completes.
6730 */
6731 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6732 lpfc_set_disctmo(piocb->vport);
6733 }
6734
James Smart858c9f62007-06-17 19:56:39 -05006735 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6736 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6737 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6738
James Smart92d7f7b2007-06-17 19:56:38 -05006739 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006740
6741 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6742 lpfc_retry_pport_discovery(phba);
6743 goto out;
6744 }
6745
James Smart92d7f7b2007-06-17 19:56:38 -05006746 /* Check for retry */
6747 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6748 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006749 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006750 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006751 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006752 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006753 goto fdisc_failed;
6754 }
James Smartd7c255b2008-08-24 21:50:00 -04006755 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006756 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006757 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006758 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05006759 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04006760 vport->fc_flag |= FC_PUBLIC_LOOP;
6761 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006762
James Smartd7c255b2008-08-24 21:50:00 -04006763 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6764 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6765 if ((vport->fc_prevDID != vport->fc_myDID) &&
6766 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6767 /* If our NportID changed, we need to ensure all
6768 * remaining NPORTs get unreg_login'ed so we can
6769 * issue unreg_vpi.
6770 */
6771 list_for_each_entry_safe(np, next_np,
6772 &vport->fc_nodes, nlp_listp) {
6773 if (!NLP_CHK_NODE_ACT(ndlp) ||
6774 (np->nlp_state != NLP_STE_NPR_NODE) ||
6775 !(np->nlp_flag & NLP_NPR_ADISC))
6776 continue;
James Smart09372822008-01-11 01:52:54 -05006777 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006778 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006779 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006780 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006781 }
James Smart78730cf2010-04-06 15:06:30 -04006782 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04006783
6784 if (phba->sli_rev == LPFC_SLI_REV4)
6785 lpfc_sli4_unreg_all_rpis(vport);
6786
James Smartd7c255b2008-08-24 21:50:00 -04006787 lpfc_mbx_unreg_vpi(vport);
6788 spin_lock_irq(shost->host_lock);
6789 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006790 if (phba->sli_rev == LPFC_SLI_REV4)
6791 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006792 else
6793 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006794 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006795 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6796 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6797 /*
6798 * Driver needs to re-reg VPI in order for f/w
6799 * to update the MAC address.
6800 */
6801 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04006802 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006803 }
6804
James Smartecfd03c2010-02-12 14:41:27 -05006805 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6806 lpfc_issue_init_vpi(vport);
6807 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006808 lpfc_register_new_vport(phba, vport, ndlp);
6809 else
6810 lpfc_do_scr_ns_plogi(phba, vport);
6811 goto out;
6812fdisc_failed:
6813 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6814 /* Cancel discovery timer */
6815 lpfc_can_disctmo(vport);
6816 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006817out:
6818 lpfc_els_free_iocb(phba, cmdiocb);
6819}
6820
James Smarte59058c2008-08-24 21:49:00 -04006821/**
James Smart3621a712009-04-06 18:47:14 -04006822 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006823 * @vport: pointer to a virtual N_Port data structure.
6824 * @ndlp: pointer to a node-list data structure.
6825 * @retry: number of retries to the command IOCB.
6826 *
6827 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6828 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6829 * routine to issue the IOCB, which makes sure only one outstanding fabric
6830 * IOCB will be sent off HBA at any given time.
6831 *
6832 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6833 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6834 * will be stored into the context1 field of the IOCB for the completion
6835 * callback function to the FDISC ELS command.
6836 *
6837 * Return code
6838 * 0 - Successfully issued fdisc iocb command
6839 * 1 - Failed to issue fdisc iocb command
6840 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006841static int
James Smart92d7f7b2007-06-17 19:56:38 -05006842lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6843 uint8_t retry)
6844{
6845 struct lpfc_hba *phba = vport->phba;
6846 IOCB_t *icmd;
6847 struct lpfc_iocbq *elsiocb;
6848 struct serv_parm *sp;
6849 uint8_t *pcmd;
6850 uint16_t cmdsize;
6851 int did = ndlp->nlp_DID;
6852 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006853
James Smart5ffc2662009-11-18 15:39:44 -05006854 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006855 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6856 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6857 ELS_CMD_FDISC);
6858 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006859 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006860 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6861 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006862 return 1;
6863 }
6864
6865 icmd = &elsiocb->iocb;
6866 icmd->un.elsreq64.myID = 0;
6867 icmd->un.elsreq64.fl = 1;
6868
James Smartf1126682009-06-10 17:22:44 -04006869 if (phba->sli_rev == LPFC_SLI_REV4) {
6870 /* FDISC needs to be 1 for WQE VPI */
6871 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6872 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6873 /* Set the ulpContext to the vpi */
6874 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6875 } else {
6876 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6877 icmd->ulpCt_h = 1;
6878 icmd->ulpCt_l = 0;
6879 }
James Smart92d7f7b2007-06-17 19:56:38 -05006880
6881 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6882 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6883 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6884 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6885 sp = (struct serv_parm *) pcmd;
6886 /* Setup CSPs accordingly for Fabric */
6887 sp->cmn.e_d_tov = 0;
6888 sp->cmn.w2.r_a_tov = 0;
6889 sp->cls1.classValid = 0;
6890 sp->cls2.seqDelivery = 1;
6891 sp->cls3.seqDelivery = 1;
6892
6893 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6894 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6895 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6896 pcmd += sizeof(uint32_t); /* Port Name */
6897 memcpy(pcmd, &vport->fc_portname, 8);
6898 pcmd += sizeof(uint32_t); /* Node Name */
6899 pcmd += sizeof(uint32_t); /* Node Name */
6900 memcpy(pcmd, &vport->fc_nodename, 8);
6901
6902 lpfc_set_disctmo(vport);
6903
6904 phba->fc_stat.elsXmitFDISC++;
6905 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6906
James Smart858c9f62007-06-17 19:56:39 -05006907 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6908 "Issue FDISC: did:x%x",
6909 did, 0, 0);
6910
James Smart92d7f7b2007-06-17 19:56:38 -05006911 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6912 if (rc == IOCB_ERROR) {
6913 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006914 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006915 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6916 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006917 return 1;
6918 }
6919 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006920 return 0;
6921}
6922
James Smarte59058c2008-08-24 21:49:00 -04006923/**
James Smart3621a712009-04-06 18:47:14 -04006924 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006925 * @phba: pointer to lpfc hba data structure.
6926 * @cmdiocb: pointer to lpfc command iocb data structure.
6927 * @rspiocb: pointer to lpfc response iocb data structure.
6928 *
6929 * This routine is the completion callback function to the issuing of a LOGO
6930 * ELS command off a vport. It frees the command IOCB and then decrement the
6931 * reference count held on ndlp for this completion function, indicating that
6932 * the reference to the ndlp is no long needed. Note that the
6933 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6934 * callback function and an additional explicit ndlp reference decrementation
6935 * will trigger the actual release of the ndlp.
6936 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006937static void
6938lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6939 struct lpfc_iocbq *rspiocb)
6940{
6941 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006942 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006943 struct lpfc_nodelist *ndlp;
6944 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006945
6946 irsp = &rspiocb->iocb;
6947 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6948 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6949 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006950
6951 lpfc_els_free_iocb(phba, cmdiocb);
6952 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006953
6954 /* Trigger the release of the ndlp after logo */
6955 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006956}
6957
James Smarte59058c2008-08-24 21:49:00 -04006958/**
James Smart3621a712009-04-06 18:47:14 -04006959 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006960 * @vport: pointer to a virtual N_Port data structure.
6961 * @ndlp: pointer to a node-list data structure.
6962 *
6963 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6964 *
6965 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6966 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6967 * will be stored into the context1 field of the IOCB for the completion
6968 * callback function to the LOGO ELS command.
6969 *
6970 * Return codes
6971 * 0 - Successfully issued logo off the @vport
6972 * 1 - Failed to issue logo off the @vport
6973 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006974int
6975lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6976{
6977 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6978 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006979 IOCB_t *icmd;
6980 struct lpfc_iocbq *elsiocb;
6981 uint8_t *pcmd;
6982 uint16_t cmdsize;
6983
6984 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6985 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6986 ELS_CMD_LOGO);
6987 if (!elsiocb)
6988 return 1;
6989
6990 icmd = &elsiocb->iocb;
6991 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6992 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6993 pcmd += sizeof(uint32_t);
6994
6995 /* Fill in LOGO payload */
6996 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6997 pcmd += sizeof(uint32_t);
6998 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6999
James Smart858c9f62007-06-17 19:56:39 -05007000 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7001 "Issue LOGO npiv did:x%x flg:x%x",
7002 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7003
James Smart92d7f7b2007-06-17 19:56:38 -05007004 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7005 spin_lock_irq(shost->host_lock);
7006 ndlp->nlp_flag |= NLP_LOGO_SND;
7007 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007008 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7009 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007010 spin_lock_irq(shost->host_lock);
7011 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7012 spin_unlock_irq(shost->host_lock);
7013 lpfc_els_free_iocb(phba, elsiocb);
7014 return 1;
7015 }
7016 return 0;
7017}
7018
James Smarte59058c2008-08-24 21:49:00 -04007019/**
James Smart3621a712009-04-06 18:47:14 -04007020 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007021 * @ptr: holder for the timer function associated data.
7022 *
7023 * This routine is invoked by the fabric iocb block timer after
7024 * timeout. It posts the fabric iocb block timeout event by setting the
7025 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7026 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7027 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7028 * posted event WORKER_FABRIC_BLOCK_TMO.
7029 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007030void
7031lpfc_fabric_block_timeout(unsigned long ptr)
7032{
7033 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7034 unsigned long iflags;
7035 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007036
James Smart92d7f7b2007-06-17 19:56:38 -05007037 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7038 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7039 if (!tmo_posted)
7040 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7041 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7042
James Smart5e9d9b82008-06-14 22:52:53 -04007043 if (!tmo_posted)
7044 lpfc_worker_wake_up(phba);
7045 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007046}
7047
James Smarte59058c2008-08-24 21:49:00 -04007048/**
James Smart3621a712009-04-06 18:47:14 -04007049 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007050 * @phba: pointer to lpfc hba data structure.
7051 *
7052 * This routine issues one fabric iocb from the driver internal list to
7053 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7054 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7055 * remove one pending fabric iocb from the driver internal list and invokes
7056 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7057 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007058static void
7059lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7060{
7061 struct lpfc_iocbq *iocb;
7062 unsigned long iflags;
7063 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007064 IOCB_t *cmd;
7065
7066repeat:
7067 iocb = NULL;
7068 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007069 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007070 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7071 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7072 list);
7073 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007074 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007075 atomic_inc(&phba->fabric_iocb_count);
7076 }
7077 spin_unlock_irqrestore(&phba->hbalock, iflags);
7078 if (iocb) {
7079 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7080 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7081 iocb->iocb_flag |= LPFC_IO_FABRIC;
7082
James Smart858c9f62007-06-17 19:56:39 -05007083 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7084 "Fabric sched1: ste:x%x",
7085 iocb->vport->port_state, 0, 0);
7086
James Smart3772a992009-05-22 14:50:54 -04007087 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007088
7089 if (ret == IOCB_ERROR) {
7090 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7091 iocb->fabric_iocb_cmpl = NULL;
7092 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7093 cmd = &iocb->iocb;
7094 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7095 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7096 iocb->iocb_cmpl(phba, iocb, iocb);
7097
7098 atomic_dec(&phba->fabric_iocb_count);
7099 goto repeat;
7100 }
7101 }
7102
7103 return;
7104}
7105
James Smarte59058c2008-08-24 21:49:00 -04007106/**
James Smart3621a712009-04-06 18:47:14 -04007107 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007108 * @phba: pointer to lpfc hba data structure.
7109 *
7110 * This routine unblocks the issuing fabric iocb command. The function
7111 * will clear the fabric iocb block bit and then invoke the routine
7112 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7113 * from the driver internal fabric iocb list.
7114 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007115void
7116lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7117{
7118 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7119
7120 lpfc_resume_fabric_iocbs(phba);
7121 return;
7122}
7123
James Smarte59058c2008-08-24 21:49:00 -04007124/**
James Smart3621a712009-04-06 18:47:14 -04007125 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007126 * @phba: pointer to lpfc hba data structure.
7127 *
7128 * This routine blocks the issuing fabric iocb for a specified amount of
7129 * time (currently 100 ms). This is done by set the fabric iocb block bit
7130 * and set up a timeout timer for 100ms. When the block bit is set, no more
7131 * fabric iocb will be issued out of the HBA.
7132 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007133static void
7134lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7135{
7136 int blocked;
7137
7138 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007139 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007140 if (!blocked)
7141 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7142
7143 return;
7144}
7145
James Smarte59058c2008-08-24 21:49:00 -04007146/**
James Smart3621a712009-04-06 18:47:14 -04007147 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007148 * @phba: pointer to lpfc hba data structure.
7149 * @cmdiocb: pointer to lpfc command iocb data structure.
7150 * @rspiocb: pointer to lpfc response iocb data structure.
7151 *
7152 * This routine is the callback function that is put to the fabric iocb's
7153 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7154 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7155 * function first restores and invokes the original iocb's callback function
7156 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7157 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7158 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007159static void
7160lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7161 struct lpfc_iocbq *rspiocb)
7162{
7163 struct ls_rjt stat;
7164
7165 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7166 BUG();
7167
7168 switch (rspiocb->iocb.ulpStatus) {
7169 case IOSTAT_NPORT_RJT:
7170 case IOSTAT_FABRIC_RJT:
7171 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7172 lpfc_block_fabric_iocbs(phba);
7173 }
7174 break;
7175
7176 case IOSTAT_NPORT_BSY:
7177 case IOSTAT_FABRIC_BSY:
7178 lpfc_block_fabric_iocbs(phba);
7179 break;
7180
7181 case IOSTAT_LS_RJT:
7182 stat.un.lsRjtError =
7183 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7184 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7185 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7186 lpfc_block_fabric_iocbs(phba);
7187 break;
7188 }
7189
7190 if (atomic_read(&phba->fabric_iocb_count) == 0)
7191 BUG();
7192
7193 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7194 cmdiocb->fabric_iocb_cmpl = NULL;
7195 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7196 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7197
7198 atomic_dec(&phba->fabric_iocb_count);
7199 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007200 /* Post any pending iocbs to HBA */
7201 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007202 }
7203}
7204
James Smarte59058c2008-08-24 21:49:00 -04007205/**
James Smart3621a712009-04-06 18:47:14 -04007206 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007207 * @phba: pointer to lpfc hba data structure.
7208 * @iocb: pointer to lpfc command iocb data structure.
7209 *
7210 * This routine is used as the top-level API for issuing a fabric iocb command
7211 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7212 * function makes sure that only one fabric bound iocb will be outstanding at
7213 * any given time. As such, this function will first check to see whether there
7214 * is already an outstanding fabric iocb on the wire. If so, it will put the
7215 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7216 * issued later. Otherwise, it will issue the iocb on the wire and update the
7217 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7218 *
7219 * Note, this implementation has a potential sending out fabric IOCBs out of
7220 * order. The problem is caused by the construction of the "ready" boolen does
7221 * not include the condition that the internal fabric IOCB list is empty. As
7222 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7223 * ahead of the fabric IOCBs in the internal list.
7224 *
7225 * Return code
7226 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7227 * IOCB_ERROR - failed to issue fabric iocb
7228 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007229static int
James Smart92d7f7b2007-06-17 19:56:38 -05007230lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7231{
7232 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007233 int ready;
7234 int ret;
7235
7236 if (atomic_read(&phba->fabric_iocb_count) > 1)
7237 BUG();
7238
7239 spin_lock_irqsave(&phba->hbalock, iflags);
7240 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7241 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7242
James Smart7f5f3d02008-02-08 18:50:14 -05007243 if (ready)
7244 /* Increment fabric iocb count to hold the position */
7245 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007246 spin_unlock_irqrestore(&phba->hbalock, iflags);
7247 if (ready) {
7248 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7249 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7250 iocb->iocb_flag |= LPFC_IO_FABRIC;
7251
James Smart858c9f62007-06-17 19:56:39 -05007252 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7253 "Fabric sched2: ste:x%x",
7254 iocb->vport->port_state, 0, 0);
7255
James Smart3772a992009-05-22 14:50:54 -04007256 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007257
7258 if (ret == IOCB_ERROR) {
7259 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7260 iocb->fabric_iocb_cmpl = NULL;
7261 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7262 atomic_dec(&phba->fabric_iocb_count);
7263 }
7264 } else {
7265 spin_lock_irqsave(&phba->hbalock, iflags);
7266 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7267 spin_unlock_irqrestore(&phba->hbalock, iflags);
7268 ret = IOCB_SUCCESS;
7269 }
7270 return ret;
7271}
7272
James Smarte59058c2008-08-24 21:49:00 -04007273/**
James Smart3621a712009-04-06 18:47:14 -04007274 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007275 * @vport: pointer to a virtual N_Port data structure.
7276 *
7277 * This routine aborts all the IOCBs associated with a @vport from the
7278 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7279 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7280 * list, removes each IOCB associated with the @vport off the list, set the
7281 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7282 * associated with the IOCB.
7283 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007284static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007285{
7286 LIST_HEAD(completions);
7287 struct lpfc_hba *phba = vport->phba;
7288 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007289
7290 spin_lock_irq(&phba->hbalock);
7291 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7292 list) {
7293
7294 if (piocb->vport != vport)
7295 continue;
7296
7297 list_move_tail(&piocb->list, &completions);
7298 }
7299 spin_unlock_irq(&phba->hbalock);
7300
James Smarta257bf92009-04-06 18:48:10 -04007301 /* Cancel all the IOCBs from the completions list */
7302 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7303 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007304}
7305
James Smarte59058c2008-08-24 21:49:00 -04007306/**
James Smart3621a712009-04-06 18:47:14 -04007307 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007308 * @ndlp: pointer to a node-list data structure.
7309 *
7310 * This routine aborts all the IOCBs associated with an @ndlp from the
7311 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7312 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7313 * list, removes each IOCB associated with the @ndlp off the list, set the
7314 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7315 * associated with the IOCB.
7316 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007317void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7318{
7319 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007320 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007321 struct lpfc_iocbq *tmp_iocb, *piocb;
7322 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007323
7324 spin_lock_irq(&phba->hbalock);
7325 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7326 list) {
7327 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7328
7329 list_move_tail(&piocb->list, &completions);
7330 }
7331 }
7332 spin_unlock_irq(&phba->hbalock);
7333
James Smarta257bf92009-04-06 18:48:10 -04007334 /* Cancel all the IOCBs from the completions list */
7335 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7336 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007337}
7338
James Smarte59058c2008-08-24 21:49:00 -04007339/**
James Smart3621a712009-04-06 18:47:14 -04007340 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007341 * @phba: pointer to lpfc hba data structure.
7342 *
7343 * This routine aborts all the IOCBs currently on the driver internal
7344 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7345 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7346 * list, removes IOCBs off the list, set the status feild to
7347 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7348 * the IOCB.
7349 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007350void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7351{
7352 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007353
7354 spin_lock_irq(&phba->hbalock);
7355 list_splice_init(&phba->fabric_iocb_list, &completions);
7356 spin_unlock_irq(&phba->hbalock);
7357
James Smarta257bf92009-04-06 18:48:10 -04007358 /* Cancel all the IOCBs from the completions list */
7359 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7360 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007361}
James Smart6fb120a2009-05-22 14:52:59 -04007362
7363/**
7364 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7365 * @phba: pointer to lpfc hba data structure.
7366 * @axri: pointer to the els xri abort wcqe structure.
7367 *
7368 * This routine is invoked by the worker thread to process a SLI4 slow-path
7369 * ELS aborted xri.
7370 **/
7371void
7372lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7373 struct sli4_wcqe_xri_aborted *axri)
7374{
7375 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7376 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7377 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007378 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007379
James Smart0f65ff62010-02-26 14:14:23 -05007380 spin_lock_irqsave(&phba->hbalock, iflag);
7381 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007382 list_for_each_entry_safe(sglq_entry, sglq_next,
7383 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7384 if (sglq_entry->sli4_xritag == xri) {
7385 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007386 list_add_tail(&sglq_entry->list,
7387 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007388 sglq_entry->state = SGL_FREED;
7389 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007390 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007391
7392 /* Check if TXQ queue needs to be serviced */
7393 if (pring->txq_cnt)
7394 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007395 return;
7396 }
7397 }
James Smart0f65ff62010-02-26 14:14:23 -05007398 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7399 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7400 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7401 spin_unlock_irqrestore(&phba->hbalock, iflag);
7402 return;
7403 }
7404 sglq_entry->state = SGL_XRI_ABORTED;
7405 spin_unlock_irqrestore(&phba->hbalock, iflag);
7406 return;
James Smart6fb120a2009-05-22 14:52:59 -04007407}