blob: 884f4d321799cffda5bb5ea56295d4166fb0b32c [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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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
526 if (phba->fc_topology == 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
dea31012005-04-17 16:05:31 -0500835 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500836 spin_lock_irq(shost->host_lock);
837 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
838 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500839
James Smart329f9bc2007-04-25 09:53:01 -0400840 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500841 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
842 * alpa map would take too long otherwise.
843 */
844 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400845 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500846 }
847
848 /* FLOGI failure */
James Smarte40a02c2010-02-26 14:13:54 -0500849 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
850 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400851 irsp->ulpStatus, irsp->un.ulpWord[4],
852 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500853 goto flogifail;
854 }
James Smart695a8142010-01-26 23:08:03 -0500855 spin_lock_irq(shost->host_lock);
856 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400857 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500858 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500859
860 /*
861 * The FLogI succeeded. Sync the data for the CPU before
862 * accessing it.
863 */
864 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
865
866 sp = prsp->virt + sizeof(uint32_t);
867
868 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400869 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200870 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400871 "Data: x%x x%x x%x x%x\n",
872 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
873 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500874
James Smart2e0fef82007-06-17 19:56:36 -0500875 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500876 /*
877 * If Common Service Parameters indicate Nport
878 * we are point to point, if Fport we are Fabric.
879 */
880 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500881 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400882 else if (!(phba->hba_flag & HBA_FCOE_SUPPORT))
James Smart2e0fef82007-06-17 19:56:36 -0500883 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400884 else {
885 lpfc_printf_vlog(vport, KERN_ERR,
886 LOG_FIP | LOG_ELS,
887 "2831 FLOGI response with cleared Fabric "
888 "bit fcf_index 0x%x "
889 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
890 "Fabric Name "
891 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
892 phba->fcf.current_rec.fcf_indx,
893 phba->fcf.current_rec.switch_name[0],
894 phba->fcf.current_rec.switch_name[1],
895 phba->fcf.current_rec.switch_name[2],
896 phba->fcf.current_rec.switch_name[3],
897 phba->fcf.current_rec.switch_name[4],
898 phba->fcf.current_rec.switch_name[5],
899 phba->fcf.current_rec.switch_name[6],
900 phba->fcf.current_rec.switch_name[7],
901 phba->fcf.current_rec.fabric_name[0],
902 phba->fcf.current_rec.fabric_name[1],
903 phba->fcf.current_rec.fabric_name[2],
904 phba->fcf.current_rec.fabric_name[3],
905 phba->fcf.current_rec.fabric_name[4],
906 phba->fcf.current_rec.fabric_name[5],
907 phba->fcf.current_rec.fabric_name[6],
908 phba->fcf.current_rec.fabric_name[7]);
909 lpfc_nlp_put(ndlp);
910 spin_lock_irq(&phba->hbalock);
911 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400912 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400913 spin_unlock_irq(&phba->hbalock);
914 goto out;
915 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500916 if (!rc) {
917 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400918 if (phba->hba_flag & HBA_FIP_SUPPORT)
919 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
920 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400921 "2769 FLOGI to FCF (x%x) "
922 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400923 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500924 spin_lock_irq(&phba->hbalock);
925 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400926 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500927 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500928 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500929 }
dea31012005-04-17 16:05:31 -0500930 }
931
932flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400933 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500934
James Smart858c9f62007-06-17 19:56:39 -0500935 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500936 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500937 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500938
939 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500940 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400941 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
942 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
943 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
944 (phba->link_state != LPFC_CLEAR_LA)) {
945 /* If FLOGI failed enable link interrupt. */
946 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500947 }
dea31012005-04-17 16:05:31 -0500948out:
949 lpfc_els_free_iocb(phba, cmdiocb);
950}
951
James Smarte59058c2008-08-24 21:49:00 -0400952/**
James Smart3621a712009-04-06 18:47:14 -0400953 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400954 * @vport: pointer to a host virtual N_Port data structure.
955 * @ndlp: pointer to a node-list data structure.
956 * @retry: number of retries to the command IOCB.
957 *
958 * This routine issues a Fabric Login (FLOGI) Request ELS command
959 * for a @vport. The initiator service parameters are put into the payload
960 * of the FLOGI Request IOCB and the top-level callback function pointer
961 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
962 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
963 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
964 *
965 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
966 * will be incremented by 1 for holding the ndlp and the reference to ndlp
967 * will be stored into the context1 field of the IOCB for the completion
968 * callback function to the FLOGI ELS command.
969 *
970 * Return code
971 * 0 - successfully issued flogi iocb for @vport
972 * 1 - failed to issue flogi iocb for @vport
973 **/
dea31012005-04-17 16:05:31 -0500974static int
James Smart2e0fef82007-06-17 19:56:36 -0500975lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500976 uint8_t retry)
977{
James Smart2e0fef82007-06-17 19:56:36 -0500978 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500979 struct serv_parm *sp;
980 IOCB_t *icmd;
981 struct lpfc_iocbq *elsiocb;
982 struct lpfc_sli_ring *pring;
983 uint8_t *pcmd;
984 uint16_t cmdsize;
985 uint32_t tmo;
986 int rc;
987
988 pring = &phba->sli.ring[LPFC_ELS_RING];
989
James Smart92d7f7b2007-06-17 19:56:38 -0500990 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500991 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
992 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500993
James Smart488d1462006-03-07 15:02:37 -0500994 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500995 return 1;
dea31012005-04-17 16:05:31 -0500996
997 icmd = &elsiocb->iocb;
998 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
999
1000 /* For FLOGI request, remainder of payload is service parameters */
1001 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001002 pcmd += sizeof(uint32_t);
1003 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001004 sp = (struct serv_parm *) pcmd;
1005
1006 /* Setup CSPs accordingly for Fabric */
1007 sp->cmn.e_d_tov = 0;
1008 sp->cmn.w2.r_a_tov = 0;
1009 sp->cls1.classValid = 0;
1010 sp->cls2.seqDelivery = 1;
1011 sp->cls3.seqDelivery = 1;
1012 if (sp->cmn.fcphLow < FC_PH3)
1013 sp->cmn.fcphLow = FC_PH3;
1014 if (sp->cmn.fcphHigh < FC_PH3)
1015 sp->cmn.fcphHigh = FC_PH3;
1016
James Smart6fb120a2009-05-22 14:52:59 -04001017 if (phba->sli_rev == LPFC_SLI_REV4) {
1018 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1019 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1020 /* FLOGI needs to be 3 for WQE FCFI */
1021 /* Set the fcfi to the fcfi we registered with */
1022 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1023 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001024 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001025 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1026 icmd->ulpCt_h = 1;
1027 icmd->ulpCt_l = 0;
1028 }
1029
James Smart858c9f62007-06-17 19:56:39 -05001030 if (phba->fc_topology != TOPOLOGY_LOOP) {
1031 icmd->un.elsreq64.myID = 0;
1032 icmd->un.elsreq64.fl = 1;
1033 }
1034
dea31012005-04-17 16:05:31 -05001035 tmo = phba->fc_ratov;
1036 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001037 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001038 phba->fc_ratov = tmo;
1039
1040 phba->fc_stat.elsXmitFLOGI++;
1041 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001042
1043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1044 "Issue FLOGI: opt:x%x",
1045 phba->sli3_options, 0, 0);
1046
James Smart92d7f7b2007-06-17 19:56:38 -05001047 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001048 if (rc == IOCB_ERROR) {
1049 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001050 return 1;
dea31012005-04-17 16:05:31 -05001051 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001052 return 0;
dea31012005-04-17 16:05:31 -05001053}
1054
James Smarte59058c2008-08-24 21:49:00 -04001055/**
James Smart3621a712009-04-06 18:47:14 -04001056 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001057 * @phba: pointer to lpfc hba data structure.
1058 *
1059 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1060 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1061 * list and issues an abort IOCB commond on each outstanding IOCB that
1062 * contains a active Fabric_DID ndlp. Note that this function is to issue
1063 * the abort IOCB command on all the outstanding IOCBs, thus when this
1064 * function returns, it does not guarantee all the IOCBs are actually aborted.
1065 *
1066 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001067 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001068 **/
dea31012005-04-17 16:05:31 -05001069int
James Smart2e0fef82007-06-17 19:56:36 -05001070lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001071{
1072 struct lpfc_sli_ring *pring;
1073 struct lpfc_iocbq *iocb, *next_iocb;
1074 struct lpfc_nodelist *ndlp;
1075 IOCB_t *icmd;
1076
1077 /* Abort outstanding I/O on NPort <nlp_DID> */
1078 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001079 "0201 Abort outstanding I/O on NPort x%x\n",
1080 Fabric_DID);
dea31012005-04-17 16:05:31 -05001081
1082 pring = &phba->sli.ring[LPFC_ELS_RING];
1083
1084 /*
1085 * Check the txcmplq for an iocb that matches the nport the driver is
1086 * searching for.
1087 */
James Smart2e0fef82007-06-17 19:56:36 -05001088 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001089 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1090 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001091 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1092 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001093 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001094 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1095 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001096 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001097 }
1098 }
James Smart2e0fef82007-06-17 19:56:36 -05001099 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001100
1101 return 0;
1102}
1103
James Smarte59058c2008-08-24 21:49:00 -04001104/**
James Smart3621a712009-04-06 18:47:14 -04001105 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001106 * @vport: pointer to a host virtual N_Port data structure.
1107 *
1108 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1109 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1110 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1111 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1112 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1113 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1114 * @vport.
1115 *
1116 * Return code
1117 * 0 - failed to issue initial flogi for @vport
1118 * 1 - successfully issued initial flogi for @vport
1119 **/
dea31012005-04-17 16:05:31 -05001120int
James Smart2e0fef82007-06-17 19:56:36 -05001121lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001122{
James Smart2e0fef82007-06-17 19:56:36 -05001123 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001124 struct lpfc_nodelist *ndlp;
1125
James Smart98c9ea52007-10-27 13:37:33 -04001126 vport->port_state = LPFC_FLOGI;
1127 lpfc_set_disctmo(vport);
1128
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001129 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001130 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001131 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001132 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001133 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1134 if (!ndlp)
1135 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001136 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001137 /* Set the node type */
1138 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001139 /* Put ndlp onto node list */
1140 lpfc_enqueue_node(vport, ndlp);
1141 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1142 /* re-setup ndlp without removing from node list */
1143 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1144 if (!ndlp)
1145 return 0;
dea31012005-04-17 16:05:31 -05001146 }
James Smart87af33f2007-10-27 13:37:43 -04001147
James Smart5ac6b302010-10-22 11:05:36 -04001148 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001149 /* This decrement of reference count to node shall kick off
1150 * the release of the node.
1151 */
James Smart329f9bc2007-04-25 09:53:01 -04001152 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001153 return 0;
1154 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001155 return 1;
dea31012005-04-17 16:05:31 -05001156}
1157
James Smarte59058c2008-08-24 21:49:00 -04001158/**
James Smart3621a712009-04-06 18:47:14 -04001159 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001160 * @vport: pointer to a host virtual N_Port data structure.
1161 *
1162 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1163 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1164 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1165 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1166 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1167 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1168 * @vport.
1169 *
1170 * Return code
1171 * 0 - failed to issue initial fdisc for @vport
1172 * 1 - successfully issued initial fdisc for @vport
1173 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001174int
1175lpfc_initial_fdisc(struct lpfc_vport *vport)
1176{
1177 struct lpfc_hba *phba = vport->phba;
1178 struct lpfc_nodelist *ndlp;
1179
1180 /* First look for the Fabric ndlp */
1181 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1182 if (!ndlp) {
1183 /* Cannot find existing Fabric ndlp, so allocate a new one */
1184 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1185 if (!ndlp)
1186 return 0;
1187 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001188 /* Put ndlp onto node list */
1189 lpfc_enqueue_node(vport, ndlp);
1190 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1191 /* re-setup ndlp without removing from node list */
1192 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1193 if (!ndlp)
1194 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001195 }
James Smarte47c9092008-02-08 18:49:26 -05001196
James Smart92d7f7b2007-06-17 19:56:38 -05001197 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001198 /* decrement node reference count to trigger the release of
1199 * the node.
1200 */
James Smart92d7f7b2007-06-17 19:56:38 -05001201 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001202 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001203 }
1204 return 1;
1205}
James Smart87af33f2007-10-27 13:37:43 -04001206
James Smarte59058c2008-08-24 21:49:00 -04001207/**
James Smart3621a712009-04-06 18:47:14 -04001208 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001209 * @vport: pointer to a host virtual N_Port data structure.
1210 *
1211 * This routine checks whether there are more remaining Port Logins
1212 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1213 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1214 * to issue ELS PLOGIs up to the configured discover threads with the
1215 * @vport (@vport->cfg_discovery_threads). The function also decrement
1216 * the @vport's num_disc_node by 1 if it is not already 0.
1217 **/
James Smart87af33f2007-10-27 13:37:43 -04001218void
James Smart2e0fef82007-06-17 19:56:36 -05001219lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001220{
1221 int sentplogi;
1222
James Smart2e0fef82007-06-17 19:56:36 -05001223 if (vport->num_disc_nodes)
1224 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001225
1226 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001227 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1228 "0232 Continue discovery with %d PLOGIs to go "
1229 "Data: x%x x%x x%x\n",
1230 vport->num_disc_nodes, vport->fc_plogi_cnt,
1231 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001232 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001233 if (vport->fc_flag & FC_NLP_MORE)
1234 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1235 sentplogi = lpfc_els_disc_plogi(vport);
1236
dea31012005-04-17 16:05:31 -05001237 return;
1238}
1239
James Smarte59058c2008-08-24 21:49:00 -04001240/**
James Smart3621a712009-04-06 18:47:14 -04001241 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001242 * @phba: pointer to lpfc hba data structure.
1243 * @prsp: pointer to response IOCB payload.
1244 * @ndlp: pointer to a node-list data structure.
1245 *
1246 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1247 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1248 * The following cases are considered N_Port confirmed:
1249 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1250 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1251 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1252 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1253 * 1) if there is a node on vport list other than the @ndlp with the same
1254 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1255 * on that node to release the RPI associated with the node; 2) if there is
1256 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1257 * into, a new node shall be allocated (or activated). In either case, the
1258 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1259 * be released and the new_ndlp shall be put on to the vport node list and
1260 * its pointer returned as the confirmed node.
1261 *
1262 * Note that before the @ndlp got "released", the keepDID from not-matching
1263 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1264 * of the @ndlp. This is because the release of @ndlp is actually to put it
1265 * into an inactive state on the vport node list and the vport node list
1266 * management algorithm does not allow two node with a same DID.
1267 *
1268 * Return code
1269 * pointer to the PLOGI N_Port @ndlp
1270 **/
James Smart488d1462006-03-07 15:02:37 -05001271static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001272lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001273 struct lpfc_nodelist *ndlp)
1274{
James Smart2e0fef82007-06-17 19:56:36 -05001275 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001276 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001277 struct lpfc_rport_data *rdata;
1278 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001279 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001280 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001281 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001282 int put_node;
1283 int put_rport;
James Smart488d1462006-03-07 15:02:37 -05001284
James Smart2fb9bd82006-12-02 13:33:57 -05001285 /* Fabric nodes can have the same WWPN so we don't bother searching
1286 * by WWPN. Just return the ndlp that was given to us.
1287 */
1288 if (ndlp->nlp_type & NLP_FABRIC)
1289 return ndlp;
1290
James Smart92d7f7b2007-06-17 19:56:38 -05001291 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001292 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001293
James Smart685f0bf2007-04-25 09:53:08 -04001294 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001295 * we have for that ndlp. If not, we have some work to do.
1296 */
James Smart2e0fef82007-06-17 19:56:36 -05001297 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001298
James Smarte47c9092008-02-08 18:49:26 -05001299 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001300 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001301
1302 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001303 rc = memcmp(&ndlp->nlp_portname, name,
1304 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001305 if (!rc)
1306 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001307 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1308 if (!new_ndlp)
1309 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001310 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001311 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001312 rc = memcmp(&ndlp->nlp_portname, name,
1313 sizeof(struct lpfc_name));
1314 if (!rc)
1315 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001316 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1317 NLP_STE_UNUSED_NODE);
1318 if (!new_ndlp)
1319 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001320 keepDID = new_ndlp->nlp_DID;
1321 } else
1322 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001323
James Smart2e0fef82007-06-17 19:56:36 -05001324 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001325 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001326 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001327
1328 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1329 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1330 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1331
James Smarte47c9092008-02-08 18:49:26 -05001332 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001333 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001334
James Smart2e0fef82007-06-17 19:56:36 -05001335 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001336 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1337 /* The new_ndlp is replacing ndlp totally, so we need
1338 * to put ndlp on UNUSED list and try to free it.
1339 */
James Smart0ff10d42008-01-11 01:52:36 -05001340
1341 /* Fix up the rport accordingly */
1342 rport = ndlp->rport;
1343 if (rport) {
1344 rdata = rport->dd_data;
1345 if (rdata->pnode == ndlp) {
1346 lpfc_nlp_put(ndlp);
1347 ndlp->rport = NULL;
1348 rdata->pnode = lpfc_nlp_get(new_ndlp);
1349 new_ndlp->rport = rport;
1350 }
1351 new_ndlp->nlp_type = ndlp->nlp_type;
1352 }
James Smart58da1ff2008-04-07 10:15:56 -04001353 /* We shall actually free the ndlp with both nlp_DID and
1354 * nlp_portname fields equals 0 to avoid any ndlp on the
1355 * nodelist never to be used.
1356 */
1357 if (ndlp->nlp_DID == 0) {
1358 spin_lock_irq(&phba->ndlp_lock);
1359 NLP_SET_FREE_REQ(ndlp);
1360 spin_unlock_irq(&phba->ndlp_lock);
1361 }
James Smart0ff10d42008-01-11 01:52:36 -05001362
James Smart58da1ff2008-04-07 10:15:56 -04001363 /* Two ndlps cannot have the same did on the nodelist */
1364 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001365 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001366 }
James Smart92795652006-07-06 15:50:02 -04001367 else {
James Smart2e0fef82007-06-17 19:56:36 -05001368 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001369 /* Two ndlps cannot have the same did */
1370 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001371 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001372 /* Since we are swapping the ndlp passed in with the new one
1373 * and the did has already been swapped, copy over the
1374 * state and names.
1375 */
1376 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1377 sizeof(struct lpfc_name));
1378 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1379 sizeof(struct lpfc_name));
1380 new_ndlp->nlp_state = ndlp->nlp_state;
1381 /* Fix up the rport accordingly */
1382 rport = ndlp->rport;
1383 if (rport) {
1384 rdata = rport->dd_data;
1385 put_node = rdata->pnode != NULL;
1386 put_rport = ndlp->rport != NULL;
1387 rdata->pnode = NULL;
1388 ndlp->rport = NULL;
1389 if (put_node)
1390 lpfc_nlp_put(ndlp);
1391 if (put_rport)
1392 put_device(&rport->dev);
1393 }
James Smart92795652006-07-06 15:50:02 -04001394 }
James Smart488d1462006-03-07 15:02:37 -05001395 return new_ndlp;
1396}
1397
James Smarte59058c2008-08-24 21:49:00 -04001398/**
James Smart3621a712009-04-06 18:47:14 -04001399 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001400 * @vport: pointer to a host virtual N_Port data structure.
1401 *
1402 * This routine checks whether more Registration State Change
1403 * Notifications (RSCNs) came in while the discovery state machine was in
1404 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1405 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1406 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1407 * handling the RSCNs.
1408 **/
James Smart87af33f2007-10-27 13:37:43 -04001409void
1410lpfc_end_rscn(struct lpfc_vport *vport)
1411{
1412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1413
1414 if (vport->fc_flag & FC_RSCN_MODE) {
1415 /*
1416 * Check to see if more RSCNs came in while we were
1417 * processing this one.
1418 */
1419 if (vport->fc_rscn_id_cnt ||
1420 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1421 lpfc_els_handle_rscn(vport);
1422 else {
1423 spin_lock_irq(shost->host_lock);
1424 vport->fc_flag &= ~FC_RSCN_MODE;
1425 spin_unlock_irq(shost->host_lock);
1426 }
1427 }
1428}
1429
James Smarte59058c2008-08-24 21:49:00 -04001430/**
James Smart3621a712009-04-06 18:47:14 -04001431 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001432 * @phba: pointer to lpfc hba data structure.
1433 * @cmdiocb: pointer to lpfc command iocb data structure.
1434 * @rspiocb: pointer to lpfc response iocb data structure.
1435 *
1436 * This routine is the completion callback function for issuing the Port
1437 * Login (PLOGI) command. For PLOGI completion, there must be an active
1438 * ndlp on the vport node list that matches the remote node ID from the
1439 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1440 * ignored and command IOCB released. The PLOGI response IOCB status is
1441 * checked for error conditons. If there is error status reported, PLOGI
1442 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1443 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1444 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1445 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1446 * there are additional N_Port nodes with the vport that need to perform
1447 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1448 * PLOGIs.
1449 **/
dea31012005-04-17 16:05:31 -05001450static void
James Smart2e0fef82007-06-17 19:56:36 -05001451lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1452 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001453{
James Smart2e0fef82007-06-17 19:56:36 -05001454 struct lpfc_vport *vport = cmdiocb->vport;
1455 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001456 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001457 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001458 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001459 int disc, rc, did, type;
1460
dea31012005-04-17 16:05:31 -05001461 /* we pass cmdiocb to state machine which needs rspiocb as well */
1462 cmdiocb->context_un.rsp_iocb = rspiocb;
1463
1464 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1466 "PLOGI cmpl: status:x%x/x%x did:x%x",
1467 irsp->ulpStatus, irsp->un.ulpWord[4],
1468 irsp->un.elsreq64.remoteID);
1469
James Smart2e0fef82007-06-17 19:56:36 -05001470 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001471 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001472 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1473 "0136 PLOGI completes to NPort x%x "
1474 "with no ndlp. Data: x%x x%x x%x\n",
1475 irsp->un.elsreq64.remoteID,
1476 irsp->ulpStatus, irsp->un.ulpWord[4],
1477 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001478 goto out;
James Smarted957682007-06-17 19:56:37 -05001479 }
dea31012005-04-17 16:05:31 -05001480
1481 /* Since ndlp can be freed in the disc state machine, note if this node
1482 * is being used during discovery.
1483 */
James Smart2e0fef82007-06-17 19:56:36 -05001484 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001485 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001486 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001487 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001488 rc = 0;
1489
1490 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001491 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1492 "0102 PLOGI completes to NPort x%x "
1493 "Data: x%x x%x x%x x%x x%x\n",
1494 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1495 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001496 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001497 if (lpfc_els_chk_latt(vport)) {
1498 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001499 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001500 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001501 goto out;
1502 }
1503
1504 /* ndlp could be freed in DSM, save these values now */
1505 type = ndlp->nlp_type;
1506 did = ndlp->nlp_DID;
1507
1508 if (irsp->ulpStatus) {
1509 /* Check for retry */
1510 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1511 /* ELS command is being retried */
1512 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001513 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001514 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001515 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001516 }
1517 goto out;
1518 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001519 /* PLOGI failed Don't print the vport to vport rjts */
1520 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1521 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1522 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1523 (phba)->pport->cfg_log_verbose & LOG_ELS)
1524 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001525 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1526 ndlp->nlp_DID, irsp->ulpStatus,
1527 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001528 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001529 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001530 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001531 else
James Smart2e0fef82007-06-17 19:56:36 -05001532 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001533 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001534 } else {
1535 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001536 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001537 cmdiocb->context2)->list.next,
1538 struct lpfc_dmabuf, list);
1539 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001540 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001541 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001542 }
1543
James Smart2e0fef82007-06-17 19:56:36 -05001544 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001545 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001546 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001547
James Smart2e0fef82007-06-17 19:56:36 -05001548 if (vport->num_disc_nodes == 0) {
1549 spin_lock_irq(shost->host_lock);
1550 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1551 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001552
James Smart2e0fef82007-06-17 19:56:36 -05001553 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001554 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001555 }
1556 }
1557
1558out:
1559 lpfc_els_free_iocb(phba, cmdiocb);
1560 return;
1561}
1562
James Smarte59058c2008-08-24 21:49:00 -04001563/**
James Smart3621a712009-04-06 18:47:14 -04001564 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001565 * @vport: pointer to a host virtual N_Port data structure.
1566 * @did: destination port identifier.
1567 * @retry: number of retries to the command IOCB.
1568 *
1569 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1570 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1571 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1572 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1573 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1574 *
1575 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1576 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1577 * will be stored into the context1 field of the IOCB for the completion
1578 * callback function to the PLOGI ELS command.
1579 *
1580 * Return code
1581 * 0 - Successfully issued a plogi for @vport
1582 * 1 - failed to issue a plogi for @vport
1583 **/
dea31012005-04-17 16:05:31 -05001584int
James Smart2e0fef82007-06-17 19:56:36 -05001585lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001586{
James Smart2e0fef82007-06-17 19:56:36 -05001587 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001588 struct serv_parm *sp;
1589 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001590 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001591 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001592 struct lpfc_sli *psli;
1593 uint8_t *pcmd;
1594 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001595 int ret;
dea31012005-04-17 16:05:31 -05001596
1597 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001598
James Smart98c9ea52007-10-27 13:37:33 -04001599 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001600 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1601 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001602
James Smarte47c9092008-02-08 18:49:26 -05001603 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001604 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001605 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001606 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001607 if (!elsiocb)
1608 return 1;
dea31012005-04-17 16:05:31 -05001609
1610 icmd = &elsiocb->iocb;
1611 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1612
1613 /* For PLOGI request, remainder of payload is service parameters */
1614 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001615 pcmd += sizeof(uint32_t);
1616 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001617 sp = (struct serv_parm *) pcmd;
1618
James Smart5ac6b302010-10-22 11:05:36 -04001619 /*
1620 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1621 * to device on remote loops work.
1622 */
1623 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1624 sp->cmn.altBbCredit = 1;
1625
dea31012005-04-17 16:05:31 -05001626 if (sp->cmn.fcphLow < FC_PH_4_3)
1627 sp->cmn.fcphLow = FC_PH_4_3;
1628
1629 if (sp->cmn.fcphHigh < FC_PH3)
1630 sp->cmn.fcphHigh = FC_PH3;
1631
James Smart858c9f62007-06-17 19:56:39 -05001632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1633 "Issue PLOGI: did:x%x",
1634 did, 0, 0);
1635
dea31012005-04-17 16:05:31 -05001636 phba->fc_stat.elsXmitPLOGI++;
1637 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001638 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001639
1640 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001641 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001642 return 1;
dea31012005-04-17 16:05:31 -05001643 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001644 return 0;
dea31012005-04-17 16:05:31 -05001645}
1646
James Smarte59058c2008-08-24 21:49:00 -04001647/**
James Smart3621a712009-04-06 18:47:14 -04001648 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001649 * @phba: pointer to lpfc hba data structure.
1650 * @cmdiocb: pointer to lpfc command iocb data structure.
1651 * @rspiocb: pointer to lpfc response iocb data structure.
1652 *
1653 * This routine is the completion callback function for a Process Login
1654 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1655 * status. If there is error status reported, PRLI retry shall be attempted
1656 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1657 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1658 * ndlp to mark the PRLI completion.
1659 **/
dea31012005-04-17 16:05:31 -05001660static void
James Smart2e0fef82007-06-17 19:56:36 -05001661lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1662 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001663{
James Smart2e0fef82007-06-17 19:56:36 -05001664 struct lpfc_vport *vport = cmdiocb->vport;
1665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001666 IOCB_t *irsp;
1667 struct lpfc_sli *psli;
1668 struct lpfc_nodelist *ndlp;
1669
1670 psli = &phba->sli;
1671 /* we pass cmdiocb to state machine which needs rspiocb as well */
1672 cmdiocb->context_un.rsp_iocb = rspiocb;
1673
1674 irsp = &(rspiocb->iocb);
1675 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001676 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001677 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001678 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001679
James Smart858c9f62007-06-17 19:56:39 -05001680 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1681 "PRLI cmpl: status:x%x/x%x did:x%x",
1682 irsp->ulpStatus, irsp->un.ulpWord[4],
1683 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001684 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001685 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1686 "0103 PRLI completes to NPort x%x "
1687 "Data: x%x x%x x%x x%x\n",
1688 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1689 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001690
James Smart2e0fef82007-06-17 19:56:36 -05001691 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001692 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001693 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001694 goto out;
1695
1696 if (irsp->ulpStatus) {
1697 /* Check for retry */
1698 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1699 /* ELS command is being retried */
1700 goto out;
1701 }
1702 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001703 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1704 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1705 ndlp->nlp_DID, irsp->ulpStatus,
1706 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001707 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001708 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001709 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001710 else
James Smart2e0fef82007-06-17 19:56:36 -05001711 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001712 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001713 } else
dea31012005-04-17 16:05:31 -05001714 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001715 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001716 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001717out:
1718 lpfc_els_free_iocb(phba, cmdiocb);
1719 return;
1720}
1721
James Smarte59058c2008-08-24 21:49:00 -04001722/**
James Smart3621a712009-04-06 18:47:14 -04001723 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001724 * @vport: pointer to a host virtual N_Port data structure.
1725 * @ndlp: pointer to a node-list data structure.
1726 * @retry: number of retries to the command IOCB.
1727 *
1728 * This routine issues a Process Login (PRLI) ELS command for the
1729 * @vport. The PRLI service parameters are set up in the payload of the
1730 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1731 * is put to the IOCB completion callback func field before invoking the
1732 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1733 *
1734 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1735 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1736 * will be stored into the context1 field of the IOCB for the completion
1737 * callback function to the PRLI ELS command.
1738 *
1739 * Return code
1740 * 0 - successfully issued prli iocb command for @vport
1741 * 1 - failed to issue prli iocb command for @vport
1742 **/
dea31012005-04-17 16:05:31 -05001743int
James Smart2e0fef82007-06-17 19:56:36 -05001744lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001745 uint8_t retry)
1746{
James Smart2e0fef82007-06-17 19:56:36 -05001747 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1748 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001749 PRLI *npr;
1750 IOCB_t *icmd;
1751 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001752 uint8_t *pcmd;
1753 uint16_t cmdsize;
1754
James Smart92d7f7b2007-06-17 19:56:38 -05001755 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001756 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1757 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001758 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001759 return 1;
dea31012005-04-17 16:05:31 -05001760
1761 icmd = &elsiocb->iocb;
1762 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1763
1764 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001765 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001766 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001767 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001768
1769 /* For PRLI, remainder of payload is PRLI parameter page */
1770 npr = (PRLI *) pcmd;
1771 /*
1772 * If our firmware version is 3.20 or later,
1773 * set the following bits for FC-TAPE support.
1774 */
1775 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1776 npr->ConfmComplAllowed = 1;
1777 npr->Retry = 1;
1778 npr->TaskRetryIdReq = 1;
1779 }
1780 npr->estabImagePair = 1;
1781 npr->readXferRdyDis = 1;
1782
1783 /* For FCP support */
1784 npr->prliType = PRLI_FCP_TYPE;
1785 npr->initiatorFunc = 1;
1786
James Smart858c9f62007-06-17 19:56:39 -05001787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1788 "Issue PRLI: did:x%x",
1789 ndlp->nlp_DID, 0, 0);
1790
dea31012005-04-17 16:05:31 -05001791 phba->fc_stat.elsXmitPRLI++;
1792 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001793 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001794 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001795 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001796 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1797 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001798 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001799 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001800 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001801 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001802 return 1;
dea31012005-04-17 16:05:31 -05001803 }
James Smart2e0fef82007-06-17 19:56:36 -05001804 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001805 return 0;
dea31012005-04-17 16:05:31 -05001806}
1807
James Smarte59058c2008-08-24 21:49:00 -04001808/**
James Smart3621a712009-04-06 18:47:14 -04001809 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001810 * @vport: pointer to a host virtual N_Port data structure.
1811 *
1812 * This routine performs Registration State Change Notification (RSCN)
1813 * discovery for a @vport. If the @vport's node port recovery count is not
1814 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1815 * the nodes that need recovery. If none of the PLOGI were needed through
1816 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1817 * invoked to check and handle possible more RSCN came in during the period
1818 * of processing the current ones.
1819 **/
1820static void
1821lpfc_rscn_disc(struct lpfc_vport *vport)
1822{
1823 lpfc_can_disctmo(vport);
1824
1825 /* RSCN discovery */
1826 /* go thru NPR nodes and issue ELS PLOGIs */
1827 if (vport->fc_npr_cnt)
1828 if (lpfc_els_disc_plogi(vport))
1829 return;
1830
1831 lpfc_end_rscn(vport);
1832}
1833
1834/**
James Smart3621a712009-04-06 18:47:14 -04001835 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001836 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1837 *
1838 * This function is called when the final ADISC is completed during discovery.
1839 * This function handles clearing link attention or issuing reg_vpi depending
1840 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1841 * discovery.
1842 * This function is called with no locks held.
1843 **/
1844static void
1845lpfc_adisc_done(struct lpfc_vport *vport)
1846{
1847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1848 struct lpfc_hba *phba = vport->phba;
1849
1850 /*
1851 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1852 * and continue discovery.
1853 */
1854 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001855 !(vport->fc_flag & FC_RSCN_MODE) &&
1856 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001857 lpfc_issue_reg_vpi(phba, vport);
1858 return;
1859 }
1860 /*
1861 * For SLI2, we need to set port_state to READY
1862 * and continue discovery.
1863 */
1864 if (vport->port_state < LPFC_VPORT_READY) {
1865 /* If we get here, there is nothing to ADISC */
1866 if (vport->port_type == LPFC_PHYSICAL_PORT)
1867 lpfc_issue_clear_la(phba, vport);
1868 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1869 vport->num_disc_nodes = 0;
1870 /* go thru NPR list, issue ELS PLOGIs */
1871 if (vport->fc_npr_cnt)
1872 lpfc_els_disc_plogi(vport);
1873 if (!vport->num_disc_nodes) {
1874 spin_lock_irq(shost->host_lock);
1875 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1876 spin_unlock_irq(shost->host_lock);
1877 lpfc_can_disctmo(vport);
1878 lpfc_end_rscn(vport);
1879 }
1880 }
1881 vport->port_state = LPFC_VPORT_READY;
1882 } else
1883 lpfc_rscn_disc(vport);
1884}
1885
1886/**
James Smart3621a712009-04-06 18:47:14 -04001887 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001888 * @vport: pointer to a host virtual N_Port data structure.
1889 *
1890 * This routine determines whether there are more ndlps on a @vport
1891 * node list need to have Address Discover (ADISC) issued. If so, it will
1892 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1893 * remaining nodes which need to have ADISC sent.
1894 **/
James Smart0ff10d42008-01-11 01:52:36 -05001895void
James Smart2e0fef82007-06-17 19:56:36 -05001896lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001897{
1898 int sentadisc;
1899
James Smart2e0fef82007-06-17 19:56:36 -05001900 if (vport->num_disc_nodes)
1901 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001902 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001903 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1904 "0210 Continue discovery with %d ADISCs to go "
1905 "Data: x%x x%x x%x\n",
1906 vport->num_disc_nodes, vport->fc_adisc_cnt,
1907 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001908 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001909 if (vport->fc_flag & FC_NLP_MORE) {
1910 lpfc_set_disctmo(vport);
1911 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1912 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001913 }
James Smart90160e02008-08-24 21:49:45 -04001914 if (!vport->num_disc_nodes)
1915 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001916 return;
1917}
1918
James Smarte59058c2008-08-24 21:49:00 -04001919/**
James Smart3621a712009-04-06 18:47:14 -04001920 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001921 * @phba: pointer to lpfc hba data structure.
1922 * @cmdiocb: pointer to lpfc command iocb data structure.
1923 * @rspiocb: pointer to lpfc response iocb data structure.
1924 *
1925 * This routine is the completion function for issuing the Address Discover
1926 * (ADISC) command. It first checks to see whether link went down during
1927 * the discovery process. If so, the node will be marked as node port
1928 * recovery for issuing discover IOCB by the link attention handler and
1929 * exit. Otherwise, the response status is checked. If error was reported
1930 * in the response status, the ADISC command shall be retried by invoking
1931 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1932 * the response status, the state machine is invoked to set transition
1933 * with respect to NLP_EVT_CMPL_ADISC event.
1934 **/
dea31012005-04-17 16:05:31 -05001935static void
James Smart2e0fef82007-06-17 19:56:36 -05001936lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1937 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001938{
James Smart2e0fef82007-06-17 19:56:36 -05001939 struct lpfc_vport *vport = cmdiocb->vport;
1940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001941 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001942 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001943 int disc;
dea31012005-04-17 16:05:31 -05001944
1945 /* we pass cmdiocb to state machine which needs rspiocb as well */
1946 cmdiocb->context_un.rsp_iocb = rspiocb;
1947
1948 irsp = &(rspiocb->iocb);
1949 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001950
James Smart858c9f62007-06-17 19:56:39 -05001951 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1952 "ADISC cmpl: status:x%x/x%x did:x%x",
1953 irsp->ulpStatus, irsp->un.ulpWord[4],
1954 ndlp->nlp_DID);
1955
dea31012005-04-17 16:05:31 -05001956 /* Since ndlp can be freed in the disc state machine, note if this node
1957 * is being used during discovery.
1958 */
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001961 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001962 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001963 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001964 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1965 "0104 ADISC completes to NPort x%x "
1966 "Data: x%x x%x x%x x%x x%x\n",
1967 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1968 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001969 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001970 if (lpfc_els_chk_latt(vport)) {
1971 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001972 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001973 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001974 goto out;
1975 }
1976
1977 if (irsp->ulpStatus) {
1978 /* Check for retry */
1979 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1980 /* ELS command is being retried */
1981 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001982 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001983 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001984 spin_unlock_irq(shost->host_lock);
1985 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001986 }
1987 goto out;
1988 }
1989 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05001990 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1991 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
1992 ndlp->nlp_DID, irsp->ulpStatus,
1993 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001994 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001995 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001996 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001997 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001998 } else
dea31012005-04-17 16:05:31 -05001999 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002000 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002001 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002002
James Smart90160e02008-08-24 21:49:45 -04002003 /* Check to see if there are more ADISCs to be sent */
2004 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002005 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002006out:
2007 lpfc_els_free_iocb(phba, cmdiocb);
2008 return;
2009}
2010
James Smarte59058c2008-08-24 21:49:00 -04002011/**
James Smart3621a712009-04-06 18:47:14 -04002012 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002013 * @vport: pointer to a virtual N_Port data structure.
2014 * @ndlp: pointer to a node-list data structure.
2015 * @retry: number of retries to the command IOCB.
2016 *
2017 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2018 * @vport. It prepares the payload of the ADISC ELS command, updates the
2019 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2020 * to issue the ADISC ELS command.
2021 *
2022 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2023 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2024 * will be stored into the context1 field of the IOCB for the completion
2025 * callback function to the ADISC ELS command.
2026 *
2027 * Return code
2028 * 0 - successfully issued adisc
2029 * 1 - failed to issue adisc
2030 **/
dea31012005-04-17 16:05:31 -05002031int
James Smart2e0fef82007-06-17 19:56:36 -05002032lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002033 uint8_t retry)
2034{
James Smart2e0fef82007-06-17 19:56:36 -05002035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002037 ADISC *ap;
2038 IOCB_t *icmd;
2039 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002040 uint8_t *pcmd;
2041 uint16_t cmdsize;
2042
James Smart92d7f7b2007-06-17 19:56:38 -05002043 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002044 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2045 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002046 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002047 return 1;
dea31012005-04-17 16:05:31 -05002048
2049 icmd = &elsiocb->iocb;
2050 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2051
2052 /* For ADISC request, remainder of payload is service parameters */
2053 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002054 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002055
2056 /* Fill in ADISC payload */
2057 ap = (ADISC *) pcmd;
2058 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002059 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2060 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002061 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002062
James Smart858c9f62007-06-17 19:56:39 -05002063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2064 "Issue ADISC: did:x%x",
2065 ndlp->nlp_DID, 0, 0);
2066
dea31012005-04-17 16:05:31 -05002067 phba->fc_stat.elsXmitADISC++;
2068 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002069 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002070 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002071 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002072 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2073 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002074 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002075 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002076 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002077 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002078 return 1;
dea31012005-04-17 16:05:31 -05002079 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002080 return 0;
dea31012005-04-17 16:05:31 -05002081}
2082
James Smarte59058c2008-08-24 21:49:00 -04002083/**
James Smart3621a712009-04-06 18:47:14 -04002084 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002085 * @phba: pointer to lpfc hba data structure.
2086 * @cmdiocb: pointer to lpfc command iocb data structure.
2087 * @rspiocb: pointer to lpfc response iocb data structure.
2088 *
2089 * This routine is the completion function for issuing the ELS Logout (LOGO)
2090 * command. If no error status was reported from the LOGO response, the
2091 * state machine of the associated ndlp shall be invoked for transition with
2092 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2093 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2094 **/
dea31012005-04-17 16:05:31 -05002095static void
James Smart2e0fef82007-06-17 19:56:36 -05002096lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2097 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002098{
James Smart2e0fef82007-06-17 19:56:36 -05002099 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2100 struct lpfc_vport *vport = ndlp->vport;
2101 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002102 IOCB_t *irsp;
2103 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002104
2105 psli = &phba->sli;
2106 /* we pass cmdiocb to state machine which needs rspiocb as well */
2107 cmdiocb->context_un.rsp_iocb = rspiocb;
2108
2109 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002110 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002111 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002113
James Smart858c9f62007-06-17 19:56:39 -05002114 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2115 "LOGO cmpl: status:x%x/x%x did:x%x",
2116 irsp->ulpStatus, irsp->un.ulpWord[4],
2117 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002118 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002119 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2120 "0105 LOGO completes to NPort x%x "
2121 "Data: x%x x%x x%x x%x\n",
2122 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2123 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002124 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002125 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002126 goto out;
2127
James Smart92d7f7b2007-06-17 19:56:38 -05002128 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2129 /* NLP_EVT_DEVICE_RM should unregister the RPI
2130 * which should abort all outstanding IOs.
2131 */
2132 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2133 NLP_EVT_DEVICE_RM);
2134 goto out;
2135 }
2136
dea31012005-04-17 16:05:31 -05002137 if (irsp->ulpStatus) {
2138 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002139 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002140 /* ELS command is being retried */
2141 goto out;
dea31012005-04-17 16:05:31 -05002142 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002143 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2144 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2145 ndlp->nlp_DID, irsp->ulpStatus,
2146 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002147 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002148 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002149 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002150 else
James Smart2e0fef82007-06-17 19:56:36 -05002151 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002152 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002153 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002154 /* Good status, call state machine.
2155 * This will unregister the rpi if needed.
2156 */
James Smart2e0fef82007-06-17 19:56:36 -05002157 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002158 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002159out:
2160 lpfc_els_free_iocb(phba, cmdiocb);
2161 return;
2162}
2163
James Smarte59058c2008-08-24 21:49:00 -04002164/**
James Smart3621a712009-04-06 18:47:14 -04002165 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002166 * @vport: pointer to a virtual N_Port data structure.
2167 * @ndlp: pointer to a node-list data structure.
2168 * @retry: number of retries to the command IOCB.
2169 *
2170 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2171 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2172 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2173 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2174 *
2175 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2176 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2177 * will be stored into the context1 field of the IOCB for the completion
2178 * callback function to the LOGO ELS command.
2179 *
2180 * Return code
2181 * 0 - successfully issued logo
2182 * 1 - failed to issue logo
2183 **/
dea31012005-04-17 16:05:31 -05002184int
James Smart2e0fef82007-06-17 19:56:36 -05002185lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002186 uint8_t retry)
2187{
James Smart2e0fef82007-06-17 19:56:36 -05002188 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2189 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002190 IOCB_t *icmd;
2191 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002192 uint8_t *pcmd;
2193 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002194 int rc;
dea31012005-04-17 16:05:31 -05002195
James Smart98c9ea52007-10-27 13:37:33 -04002196 spin_lock_irq(shost->host_lock);
2197 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2198 spin_unlock_irq(shost->host_lock);
2199 return 0;
2200 }
2201 spin_unlock_irq(shost->host_lock);
2202
James Smart92d7f7b2007-06-17 19:56:38 -05002203 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002204 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2205 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002206 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002207 return 1;
dea31012005-04-17 16:05:31 -05002208
2209 icmd = &elsiocb->iocb;
2210 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2211 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002212 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002213
2214 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002215 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002216 pcmd += sizeof(uint32_t);
2217 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002218
James Smart858c9f62007-06-17 19:56:39 -05002219 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2220 "Issue LOGO: did:x%x",
2221 ndlp->nlp_DID, 0, 0);
2222
dea31012005-04-17 16:05:31 -05002223 phba->fc_stat.elsXmitLOGO++;
2224 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002225 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002226 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002227 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002228 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002229
2230 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002231 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002232 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002233 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002234 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002235 return 1;
dea31012005-04-17 16:05:31 -05002236 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002237 return 0;
dea31012005-04-17 16:05:31 -05002238}
2239
James Smarte59058c2008-08-24 21:49:00 -04002240/**
James Smart3621a712009-04-06 18:47:14 -04002241 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002242 * @phba: pointer to lpfc hba data structure.
2243 * @cmdiocb: pointer to lpfc command iocb data structure.
2244 * @rspiocb: pointer to lpfc response iocb data structure.
2245 *
2246 * This routine is a generic completion callback function for ELS commands.
2247 * Specifically, it is the callback function which does not need to perform
2248 * any command specific operations. It is currently used by the ELS command
2249 * issuing routines for the ELS State Change Request (SCR),
2250 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2251 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2252 * certain debug loggings, this callback function simply invokes the
2253 * lpfc_els_chk_latt() routine to check whether link went down during the
2254 * discovery process.
2255 **/
dea31012005-04-17 16:05:31 -05002256static void
James Smart2e0fef82007-06-17 19:56:36 -05002257lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2258 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002259{
James Smart2e0fef82007-06-17 19:56:36 -05002260 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002261 IOCB_t *irsp;
2262
2263 irsp = &rspiocb->iocb;
2264
James Smart858c9f62007-06-17 19:56:39 -05002265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2266 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2267 irsp->ulpStatus, irsp->un.ulpWord[4],
2268 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002269 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002270 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2271 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2272 irsp->ulpIoTag, irsp->ulpStatus,
2273 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002274 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002275 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002276 lpfc_els_free_iocb(phba, cmdiocb);
2277 return;
2278}
2279
James Smarte59058c2008-08-24 21:49:00 -04002280/**
James Smart3621a712009-04-06 18:47:14 -04002281 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002282 * @vport: pointer to a host virtual N_Port data structure.
2283 * @nportid: N_Port identifier to the remote node.
2284 * @retry: number of retries to the command IOCB.
2285 *
2286 * This routine issues a State Change Request (SCR) to a fabric node
2287 * on a @vport. The remote node @nportid is passed into the function. It
2288 * first search the @vport node list to find the matching ndlp. If no such
2289 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2290 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2291 * routine is invoked to send the SCR IOCB.
2292 *
2293 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2294 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2295 * will be stored into the context1 field of the IOCB for the completion
2296 * callback function to the SCR ELS command.
2297 *
2298 * Return code
2299 * 0 - Successfully issued scr command
2300 * 1 - Failed to issue scr command
2301 **/
dea31012005-04-17 16:05:31 -05002302int
James Smart2e0fef82007-06-17 19:56:36 -05002303lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002304{
James Smart2e0fef82007-06-17 19:56:36 -05002305 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002306 IOCB_t *icmd;
2307 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002308 struct lpfc_sli *psli;
2309 uint8_t *pcmd;
2310 uint16_t cmdsize;
2311 struct lpfc_nodelist *ndlp;
2312
2313 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002314 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002315
James Smarte47c9092008-02-08 18:49:26 -05002316 ndlp = lpfc_findnode_did(vport, nportid);
2317 if (!ndlp) {
2318 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2319 if (!ndlp)
2320 return 1;
2321 lpfc_nlp_init(vport, ndlp, nportid);
2322 lpfc_enqueue_node(vport, ndlp);
2323 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2324 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2325 if (!ndlp)
2326 return 1;
2327 }
dea31012005-04-17 16:05:31 -05002328
James Smart2e0fef82007-06-17 19:56:36 -05002329 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2330 ndlp->nlp_DID, ELS_CMD_SCR);
2331
James Smart488d1462006-03-07 15:02:37 -05002332 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002333 /* This will trigger the release of the node just
2334 * allocated
2335 */
James Smart329f9bc2007-04-25 09:53:01 -04002336 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002337 return 1;
dea31012005-04-17 16:05:31 -05002338 }
2339
2340 icmd = &elsiocb->iocb;
2341 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2342
2343 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002344 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002345
2346 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002347 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002348 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2349
James Smart858c9f62007-06-17 19:56:39 -05002350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2351 "Issue SCR: did:x%x",
2352 ndlp->nlp_DID, 0, 0);
2353
dea31012005-04-17 16:05:31 -05002354 phba->fc_stat.elsXmitSCR++;
2355 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002356 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2357 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002358 /* The additional lpfc_nlp_put will cause the following
2359 * lpfc_els_free_iocb routine to trigger the rlease of
2360 * the node.
2361 */
James Smart329f9bc2007-04-25 09:53:01 -04002362 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002363 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002364 return 1;
dea31012005-04-17 16:05:31 -05002365 }
James Smartfa4066b2008-01-11 01:53:27 -05002366 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2367 * trigger the release of node.
2368 */
James Smart329f9bc2007-04-25 09:53:01 -04002369 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002370 return 0;
dea31012005-04-17 16:05:31 -05002371}
2372
James Smarte59058c2008-08-24 21:49:00 -04002373/**
James Smart3621a712009-04-06 18:47:14 -04002374 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002375 * @vport: pointer to a host virtual N_Port data structure.
2376 * @nportid: N_Port identifier to the remote node.
2377 * @retry: number of retries to the command IOCB.
2378 *
2379 * This routine issues a Fibre Channel Address Resolution Response
2380 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2381 * is passed into the function. It first search the @vport node list to find
2382 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2383 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2384 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2385 *
2386 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2387 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2388 * will be stored into the context1 field of the IOCB for the completion
2389 * callback function to the PARPR ELS command.
2390 *
2391 * Return code
2392 * 0 - Successfully issued farpr command
2393 * 1 - Failed to issue farpr command
2394 **/
dea31012005-04-17 16:05:31 -05002395static int
James Smart2e0fef82007-06-17 19:56:36 -05002396lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002397{
James Smart2e0fef82007-06-17 19:56:36 -05002398 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002399 IOCB_t *icmd;
2400 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002401 struct lpfc_sli *psli;
2402 FARP *fp;
2403 uint8_t *pcmd;
2404 uint32_t *lp;
2405 uint16_t cmdsize;
2406 struct lpfc_nodelist *ondlp;
2407 struct lpfc_nodelist *ndlp;
2408
2409 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002410 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002411
James Smarte47c9092008-02-08 18:49:26 -05002412 ndlp = lpfc_findnode_did(vport, nportid);
2413 if (!ndlp) {
2414 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2415 if (!ndlp)
2416 return 1;
2417 lpfc_nlp_init(vport, ndlp, nportid);
2418 lpfc_enqueue_node(vport, ndlp);
2419 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2420 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2421 if (!ndlp)
2422 return 1;
2423 }
James Smart2e0fef82007-06-17 19:56:36 -05002424
2425 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2426 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002427 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002428 /* This will trigger the release of the node just
2429 * allocated
2430 */
James Smart329f9bc2007-04-25 09:53:01 -04002431 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002432 return 1;
dea31012005-04-17 16:05:31 -05002433 }
2434
2435 icmd = &elsiocb->iocb;
2436 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2437
2438 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002439 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002440
2441 /* Fill in FARPR payload */
2442 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002443 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002444 lp = (uint32_t *) pcmd;
2445 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002446 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002447 fp->Rflags = 0;
2448 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2449
James Smart92d7f7b2007-06-17 19:56:38 -05002450 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2451 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002452 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002453 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002454 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002455 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002456 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002457 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002458 }
2459
James Smart858c9f62007-06-17 19:56:39 -05002460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2461 "Issue FARPR: did:x%x",
2462 ndlp->nlp_DID, 0, 0);
2463
dea31012005-04-17 16:05:31 -05002464 phba->fc_stat.elsXmitFARPR++;
2465 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002466 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2467 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002468 /* The additional lpfc_nlp_put will cause the following
2469 * lpfc_els_free_iocb routine to trigger the release of
2470 * the node.
2471 */
James Smart329f9bc2007-04-25 09:53:01 -04002472 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002473 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002474 return 1;
dea31012005-04-17 16:05:31 -05002475 }
James Smartfa4066b2008-01-11 01:53:27 -05002476 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2477 * trigger the release of the node.
2478 */
James Smart329f9bc2007-04-25 09:53:01 -04002479 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002480 return 0;
dea31012005-04-17 16:05:31 -05002481}
2482
James Smarte59058c2008-08-24 21:49:00 -04002483/**
James Smart3621a712009-04-06 18:47:14 -04002484 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002485 * @vport: pointer to a host virtual N_Port data structure.
2486 * @nlp: pointer to a node-list data structure.
2487 *
2488 * This routine cancels the timer with a delayed IOCB-command retry for
2489 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2490 * removes the ELS retry event if it presents. In addition, if the
2491 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2492 * commands are sent for the @vport's nodes that require issuing discovery
2493 * ADISC.
2494 **/
dea31012005-04-17 16:05:31 -05002495void
James Smart2e0fef82007-06-17 19:56:36 -05002496lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002497{
James Smart2e0fef82007-06-17 19:56:36 -05002498 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002499 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002500
James Smart0d2b6b82008-06-14 22:52:47 -04002501 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2502 return;
James Smart2e0fef82007-06-17 19:56:36 -05002503 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002504 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002505 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002506 del_timer_sync(&nlp->nlp_delayfunc);
2507 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002508 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002509 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002510 /* Decrement nlp reference count held for the delayed retry */
2511 evtp = &nlp->els_retry_evt;
2512 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2513 }
James Smartfdcebe22006-03-07 15:04:01 -05002514 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002515 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002516 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002517 spin_unlock_irq(shost->host_lock);
2518 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002519 if (vport->port_state < LPFC_VPORT_READY) {
2520 /* Check if there are more ADISCs to be sent */
2521 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002522 } else {
2523 /* Check if there are more PLOGIs to be sent */
2524 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002525 if (vport->num_disc_nodes == 0) {
2526 spin_lock_irq(shost->host_lock);
2527 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2528 spin_unlock_irq(shost->host_lock);
2529 lpfc_can_disctmo(vport);
2530 lpfc_end_rscn(vport);
2531 }
James Smartfdcebe22006-03-07 15:04:01 -05002532 }
2533 }
2534 }
2535 return;
2536}
2537
James Smarte59058c2008-08-24 21:49:00 -04002538/**
James Smart3621a712009-04-06 18:47:14 -04002539 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002540 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2541 *
2542 * This routine is invoked by the ndlp delayed-function timer to check
2543 * whether there is any pending ELS retry event(s) with the node. If not, it
2544 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2545 * adds the delayed events to the HBA work list and invokes the
2546 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2547 * event. Note that lpfc_nlp_get() is called before posting the event to
2548 * the work list to hold reference count of ndlp so that it guarantees the
2549 * reference to ndlp will still be available when the worker thread gets
2550 * to the event associated with the ndlp.
2551 **/
James Smartfdcebe22006-03-07 15:04:01 -05002552void
dea31012005-04-17 16:05:31 -05002553lpfc_els_retry_delay(unsigned long ptr)
2554{
James Smart2e0fef82007-06-17 19:56:36 -05002555 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2556 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002557 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002558 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002559 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002560
James Smart92d7f7b2007-06-17 19:56:38 -05002561 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002562 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002563 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002564 return;
2565 }
2566
James Smartfa4066b2008-01-11 01:53:27 -05002567 /* We need to hold the node by incrementing the reference
2568 * count until the queued work is done
2569 */
2570 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002571 if (evtp->evt_arg1) {
2572 evtp->evt = LPFC_EVT_ELS_RETRY;
2573 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002574 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002575 }
James Smart92d7f7b2007-06-17 19:56:38 -05002576 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002577 return;
2578}
2579
James Smarte59058c2008-08-24 21:49:00 -04002580/**
James Smart3621a712009-04-06 18:47:14 -04002581 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002582 * @ndlp: pointer to a node-list data structure.
2583 *
2584 * This routine is the worker-thread handler for processing the @ndlp delayed
2585 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2586 * the last ELS command from the associated ndlp and invokes the proper ELS
2587 * function according to the delayed ELS command to retry the command.
2588 **/
dea31012005-04-17 16:05:31 -05002589void
2590lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2591{
James Smart2e0fef82007-06-17 19:56:36 -05002592 struct lpfc_vport *vport = ndlp->vport;
2593 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2594 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002595
James Smart2e0fef82007-06-17 19:56:36 -05002596 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002597 did = ndlp->nlp_DID;
2598 cmd = ndlp->nlp_last_elscmd;
2599 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002600
2601 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002602 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002603 return;
2604 }
2605
2606 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002607 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002608 /*
2609 * If a discovery event readded nlp_delayfunc after timer
2610 * firing and before processing the timer, cancel the
2611 * nlp_delayfunc.
2612 */
2613 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002614 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002615 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002616
2617 switch (cmd) {
2618 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002619 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002620 break;
2621 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002622 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002623 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002625 }
dea31012005-04-17 16:05:31 -05002626 break;
2627 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002628 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002629 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002631 }
dea31012005-04-17 16:05:31 -05002632 break;
2633 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002634 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002635 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002636 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002637 }
dea31012005-04-17 16:05:31 -05002638 break;
2639 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002640 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002641 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002642 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002643 }
dea31012005-04-17 16:05:31 -05002644 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002645 case ELS_CMD_FDISC:
2646 lpfc_issue_els_fdisc(vport, ndlp, retry);
2647 break;
dea31012005-04-17 16:05:31 -05002648 }
2649 return;
2650}
2651
James Smarte59058c2008-08-24 21:49:00 -04002652/**
James Smart3621a712009-04-06 18:47:14 -04002653 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002654 * @phba: pointer to lpfc hba data structure.
2655 * @cmdiocb: pointer to lpfc command iocb data structure.
2656 * @rspiocb: pointer to lpfc response iocb data structure.
2657 *
2658 * This routine makes a retry decision on an ELS command IOCB, which has
2659 * failed. The following ELS IOCBs use this function for retrying the command
2660 * when previously issued command responsed with error status: FLOGI, PLOGI,
2661 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2662 * returned error status, it makes the decision whether a retry shall be
2663 * issued for the command, and whether a retry shall be made immediately or
2664 * delayed. In the former case, the corresponding ELS command issuing-function
2665 * is called to retry the command. In the later case, the ELS command shall
2666 * be posted to the ndlp delayed event and delayed function timer set to the
2667 * ndlp for the delayed command issusing.
2668 *
2669 * Return code
2670 * 0 - No retry of els command is made
2671 * 1 - Immediate or delayed retry of els command is made
2672 **/
dea31012005-04-17 16:05:31 -05002673static int
James Smart2e0fef82007-06-17 19:56:36 -05002674lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2675 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002676{
James Smart2e0fef82007-06-17 19:56:36 -05002677 struct lpfc_vport *vport = cmdiocb->vport;
2678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2679 IOCB_t *irsp = &rspiocb->iocb;
2680 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2681 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002682 uint32_t *elscmd;
2683 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002684 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002685 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002686 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002687 uint32_t did;
dea31012005-04-17 16:05:31 -05002688
James Smart488d1462006-03-07 15:02:37 -05002689
dea31012005-04-17 16:05:31 -05002690 /* Note: context2 may be 0 for internal driver abort
2691 * of delays ELS command.
2692 */
2693
2694 if (pcmd && pcmd->virt) {
2695 elscmd = (uint32_t *) (pcmd->virt);
2696 cmd = *elscmd++;
2697 }
2698
James Smarte47c9092008-02-08 18:49:26 -05002699 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002700 did = ndlp->nlp_DID;
2701 else {
2702 /* We should only hit this case for retrying PLOGI */
2703 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002704 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002705 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2706 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002707 return 1;
2708 }
2709
James Smart858c9f62007-06-17 19:56:39 -05002710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2711 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2712 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2713
dea31012005-04-17 16:05:31 -05002714 switch (irsp->ulpStatus) {
2715 case IOSTAT_FCP_RSP_ERROR:
2716 case IOSTAT_REMOTE_STOP:
2717 break;
2718
2719 case IOSTAT_LOCAL_REJECT:
2720 switch ((irsp->un.ulpWord[4] & 0xff)) {
2721 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002722 if (cmd == ELS_CMD_FLOGI) {
2723 if (PCI_DEVICE_ID_HORNET ==
2724 phba->pcidev->device) {
2725 phba->fc_topology = TOPOLOGY_LOOP;
2726 phba->pport->fc_myDID = 0;
2727 phba->alpa_map[0] = 0;
2728 phba->alpa_map[1] = 0;
2729 }
2730 }
James Smart2e0fef82007-06-17 19:56:36 -05002731 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002732 delay = 1000;
dea31012005-04-17 16:05:31 -05002733 retry = 1;
2734 break;
2735
James Smart92d7f7b2007-06-17 19:56:38 -05002736 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002737 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2738 "0124 Retry illegal cmd x%x "
2739 "retry:x%x delay:x%x\n",
2740 cmd, cmdiocb->retry, delay);
2741 retry = 1;
2742 /* All command's retry policy */
2743 maxretry = 8;
2744 if (cmdiocb->retry > 2)
2745 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002746 break;
2747
dea31012005-04-17 16:05:31 -05002748 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002749 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002750 retry = 1;
2751 if (cmdiocb->retry > 100)
2752 delay = 100;
2753 maxretry = 250;
2754 break;
2755
2756 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002757 delay = 100;
dea31012005-04-17 16:05:31 -05002758 retry = 1;
2759 break;
2760
James Smart858c9f62007-06-17 19:56:39 -05002761 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002762 case IOERR_INVALID_RPI:
2763 retry = 1;
2764 break;
2765 }
2766 break;
2767
2768 case IOSTAT_NPORT_RJT:
2769 case IOSTAT_FABRIC_RJT:
2770 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2771 retry = 1;
2772 break;
2773 }
2774 break;
2775
2776 case IOSTAT_NPORT_BSY:
2777 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002778 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002779 retry = 1;
2780 break;
2781
2782 case IOSTAT_LS_RJT:
2783 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2784 /* Added for Vendor specifc support
2785 * Just keep retrying for these Rsn / Exp codes
2786 */
2787 switch (stat.un.b.lsRjtRsnCode) {
2788 case LSRJT_UNABLE_TPC:
2789 if (stat.un.b.lsRjtRsnCodeExp ==
2790 LSEXP_CMD_IN_PROGRESS) {
2791 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002792 delay = 1000;
dea31012005-04-17 16:05:31 -05002793 maxretry = 48;
2794 }
2795 retry = 1;
2796 break;
2797 }
James Smartffc95492010-06-07 15:23:17 -04002798 if (stat.un.b.lsRjtRsnCodeExp ==
2799 LSEXP_CANT_GIVE_DATA) {
2800 if (cmd == ELS_CMD_PLOGI) {
2801 delay = 1000;
2802 maxretry = 48;
2803 }
2804 retry = 1;
2805 break;
2806 }
dea31012005-04-17 16:05:31 -05002807 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002808 delay = 1000;
dea31012005-04-17 16:05:31 -05002809 maxretry = lpfc_max_els_tries + 1;
2810 retry = 1;
2811 break;
2812 }
James Smart92d7f7b2007-06-17 19:56:38 -05002813 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2814 (cmd == ELS_CMD_FDISC) &&
2815 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002816 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2817 "0125 FDISC Failed (x%x). "
2818 "Fabric out of resources\n",
2819 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002820 lpfc_vport_set_state(vport,
2821 FC_VPORT_NO_FABRIC_RSCS);
2822 }
dea31012005-04-17 16:05:31 -05002823 break;
2824
2825 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002826 if ((cmd == ELS_CMD_PLOGI) ||
2827 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002828 delay = 1000;
dea31012005-04-17 16:05:31 -05002829 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002830 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002831 /* FDISC retry policy */
2832 maxretry = 48;
2833 if (cmdiocb->retry >= 32)
2834 delay = 1000;
dea31012005-04-17 16:05:31 -05002835 }
2836 retry = 1;
2837 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002838
2839 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002840 /* There are some cases where switches return this
2841 * error when they are not ready and should be returning
2842 * Logical Busy. We should delay every time.
2843 */
2844 if (cmd == ELS_CMD_FDISC &&
2845 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2846 maxretry = 3;
2847 delay = 1000;
2848 retry = 1;
2849 break;
2850 }
James Smart92d7f7b2007-06-17 19:56:38 -05002851 case LSRJT_PROTOCOL_ERR:
2852 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2853 (cmd == ELS_CMD_FDISC) &&
2854 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2855 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2856 ) {
James Smarte8b62012007-08-02 11:10:09 -04002857 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002858 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002859 "Fabric Detected Bad WWN\n",
2860 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002861 lpfc_vport_set_state(vport,
2862 FC_VPORT_FABRIC_REJ_WWN);
2863 }
2864 break;
dea31012005-04-17 16:05:31 -05002865 }
2866 break;
2867
2868 case IOSTAT_INTERMED_RSP:
2869 case IOSTAT_BA_RJT:
2870 break;
2871
2872 default:
2873 break;
2874 }
2875
James Smart488d1462006-03-07 15:02:37 -05002876 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002877 retry = 1;
dea31012005-04-17 16:05:31 -05002878
James Smart695a8142010-01-26 23:08:03 -05002879 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002880 (phba->fc_topology != TOPOLOGY_LOOP) &&
2881 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002882 /* FLOGI retry policy */
2883 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002884 /* retry forever */
2885 maxretry = 0;
2886 if (cmdiocb->retry >= 100)
2887 delay = 5000;
2888 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002889 delay = 1000;
2890 }
2891
James Smart6669f9b2009-10-02 15:16:45 -04002892 cmdiocb->retry++;
2893 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002894 phba->fc_stat.elsRetryExceeded++;
2895 retry = 0;
2896 }
2897
James Smarted957682007-06-17 19:56:37 -05002898 if ((vport->load_flag & FC_UNLOADING) != 0)
2899 retry = 0;
2900
dea31012005-04-17 16:05:31 -05002901 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04002902 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
2903 /* Stop retrying PLOGI and FDISC if in FCF discovery */
2904 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
2905 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2906 "2849 Stop retry ELS command "
2907 "x%x to remote NPORT x%x, "
2908 "Data: x%x x%x\n", cmd, did,
2909 cmdiocb->retry, delay);
2910 return 0;
2911 }
2912 }
dea31012005-04-17 16:05:31 -05002913
2914 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002915 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2916 "0107 Retry ELS command x%x to remote "
2917 "NPORT x%x Data: x%x x%x\n",
2918 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002919
James Smart858c9f62007-06-17 19:56:39 -05002920 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2921 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2922 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2923 /* Don't reset timer for no resources */
2924
dea31012005-04-17 16:05:31 -05002925 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002926 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002927 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002928 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002929 }
2930
2931 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002932 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002933 phba->fc_stat.elsDelayRetry++;
2934 ndlp->nlp_retry = cmdiocb->retry;
2935
James Smart92d7f7b2007-06-17 19:56:38 -05002936 /* delay is specified in milliseconds */
2937 mod_timer(&ndlp->nlp_delayfunc,
2938 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002939 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002940 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002941 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002942
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002943 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002944 if (cmd == ELS_CMD_PRLI)
2945 lpfc_nlp_set_state(vport, ndlp,
2946 NLP_STE_REG_LOGIN_ISSUE);
2947 else
2948 lpfc_nlp_set_state(vport, ndlp,
2949 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002950 ndlp->nlp_last_elscmd = cmd;
2951
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002952 return 1;
dea31012005-04-17 16:05:31 -05002953 }
2954 switch (cmd) {
2955 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002956 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002957 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002958 case ELS_CMD_FDISC:
2959 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2960 return 1;
dea31012005-04-17 16:05:31 -05002961 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002962 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002963 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002964 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002965 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002966 }
James Smart2e0fef82007-06-17 19:56:36 -05002967 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002968 return 1;
dea31012005-04-17 16:05:31 -05002969 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002970 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002971 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2972 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002973 return 1;
dea31012005-04-17 16:05:31 -05002974 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002975 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002976 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2977 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002978 return 1;
dea31012005-04-17 16:05:31 -05002979 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002980 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002981 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2982 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002983 return 1;
dea31012005-04-17 16:05:31 -05002984 }
2985 }
dea31012005-04-17 16:05:31 -05002986 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002987 if (logerr) {
2988 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2989 "0137 No retry ELS command x%x to remote "
2990 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2991 cmd, did, irsp->ulpStatus,
2992 irsp->un.ulpWord[4]);
2993 }
2994 else {
2995 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002996 "0108 No retry ELS command x%x to remote "
2997 "NPORT x%x Retried:%d Error:x%x/%x\n",
2998 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2999 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003000 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003001 return 0;
dea31012005-04-17 16:05:31 -05003002}
3003
James Smarte59058c2008-08-24 21:49:00 -04003004/**
James Smart3621a712009-04-06 18:47:14 -04003005 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003006 * @phba: pointer to lpfc hba data structure.
3007 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3008 *
3009 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3010 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3011 * checks to see whether there is a lpfc DMA buffer associated with the
3012 * response of the command IOCB. If so, it will be released before releasing
3013 * the lpfc DMA buffer associated with the IOCB itself.
3014 *
3015 * Return code
3016 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3017 **/
James Smart09372822008-01-11 01:52:54 -05003018static int
James Smart87af33f2007-10-27 13:37:43 -04003019lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3020{
3021 struct lpfc_dmabuf *buf_ptr;
3022
James Smarte59058c2008-08-24 21:49:00 -04003023 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003024 if (!list_empty(&buf_ptr1->list)) {
3025 list_remove_head(&buf_ptr1->list, buf_ptr,
3026 struct lpfc_dmabuf,
3027 list);
3028 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3029 kfree(buf_ptr);
3030 }
3031 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3032 kfree(buf_ptr1);
3033 return 0;
3034}
3035
James Smarte59058c2008-08-24 21:49:00 -04003036/**
James Smart3621a712009-04-06 18:47:14 -04003037 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003038 * @phba: pointer to lpfc hba data structure.
3039 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3040 *
3041 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3042 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3043 * pool.
3044 *
3045 * Return code
3046 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3047 **/
James Smart09372822008-01-11 01:52:54 -05003048static int
James Smart87af33f2007-10-27 13:37:43 -04003049lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3050{
3051 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3052 kfree(buf_ptr);
3053 return 0;
3054}
3055
James Smarte59058c2008-08-24 21:49:00 -04003056/**
James Smart3621a712009-04-06 18:47:14 -04003057 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003058 * @phba: pointer to lpfc hba data structure.
3059 * @elsiocb: pointer to lpfc els command iocb data structure.
3060 *
3061 * This routine frees a command IOCB and its associated resources. The
3062 * command IOCB data structure contains the reference to various associated
3063 * resources, these fields must be set to NULL if the associated reference
3064 * not present:
3065 * context1 - reference to ndlp
3066 * context2 - reference to cmd
3067 * context2->next - reference to rsp
3068 * context3 - reference to bpl
3069 *
3070 * It first properly decrements the reference count held on ndlp for the
3071 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3072 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3073 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3074 * adds the DMA buffer the @phba data structure for the delayed release.
3075 * If reference to the Buffer Pointer List (BPL) is present, the
3076 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3077 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3078 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3079 *
3080 * Return code
3081 * 0 - Success (currently, always return 0)
3082 **/
James Smart87af33f2007-10-27 13:37:43 -04003083int
James Smart329f9bc2007-04-25 09:53:01 -04003084lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003085{
3086 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003087 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003088
James Smarta8adb832007-10-27 13:37:53 -04003089 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3090 if (ndlp) {
3091 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3092 lpfc_nlp_put(ndlp);
3093
3094 /* If the ndlp is not being used by another discovery
3095 * thread, free it.
3096 */
3097 if (!lpfc_nlp_not_used(ndlp)) {
3098 /* If ndlp is being used by another discovery
3099 * thread, just clear NLP_DEFER_RM
3100 */
3101 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3102 }
3103 }
3104 else
3105 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003106 elsiocb->context1 = NULL;
3107 }
dea31012005-04-17 16:05:31 -05003108 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3109 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003110 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3111 /* Firmware could still be in progress of DMAing
3112 * payload, so don't free data buffer till after
3113 * a hbeat.
3114 */
3115 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3116 buf_ptr = elsiocb->context2;
3117 elsiocb->context2 = NULL;
3118 if (buf_ptr) {
3119 buf_ptr1 = NULL;
3120 spin_lock_irq(&phba->hbalock);
3121 if (!list_empty(&buf_ptr->list)) {
3122 list_remove_head(&buf_ptr->list,
3123 buf_ptr1, struct lpfc_dmabuf,
3124 list);
3125 INIT_LIST_HEAD(&buf_ptr1->list);
3126 list_add_tail(&buf_ptr1->list,
3127 &phba->elsbuf);
3128 phba->elsbuf_cnt++;
3129 }
3130 INIT_LIST_HEAD(&buf_ptr->list);
3131 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3132 phba->elsbuf_cnt++;
3133 spin_unlock_irq(&phba->hbalock);
3134 }
3135 } else {
3136 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3137 lpfc_els_free_data(phba, buf_ptr1);
3138 }
dea31012005-04-17 16:05:31 -05003139 }
3140
3141 if (elsiocb->context3) {
3142 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003143 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003144 }
James Bottomley604a3e32005-10-29 10:28:33 -05003145 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003146 return 0;
3147}
3148
James Smarte59058c2008-08-24 21:49:00 -04003149/**
James Smart3621a712009-04-06 18:47:14 -04003150 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003151 * @phba: pointer to lpfc hba data structure.
3152 * @cmdiocb: pointer to lpfc command iocb data structure.
3153 * @rspiocb: pointer to lpfc response iocb data structure.
3154 *
3155 * This routine is the completion callback function to the Logout (LOGO)
3156 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3157 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3158 * release the ndlp if it has the last reference remaining (reference count
3159 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3160 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3161 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3162 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3163 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3164 * IOCB data structure.
3165 **/
dea31012005-04-17 16:05:31 -05003166static void
James Smart2e0fef82007-06-17 19:56:36 -05003167lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3168 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003169{
James Smart2e0fef82007-06-17 19:56:36 -05003170 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3171 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003172 IOCB_t *irsp;
3173
3174 irsp = &rspiocb->iocb;
3175 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3176 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3177 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003178 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003179 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3180 "0109 ACC to LOGO completes to NPort x%x "
3181 "Data: x%x x%x x%x\n",
3182 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3183 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003184
3185 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3186 /* NPort Recovery mode or node is just allocated */
3187 if (!lpfc_nlp_not_used(ndlp)) {
3188 /* If the ndlp is being used by another discovery
3189 * thread, just unregister the RPI.
3190 */
3191 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003192 } else {
3193 /* Indicate the node has already released, should
3194 * not reference to it from within lpfc_els_free_iocb.
3195 */
3196 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003197 }
dea31012005-04-17 16:05:31 -05003198 }
3199 lpfc_els_free_iocb(phba, cmdiocb);
3200 return;
3201}
3202
James Smarte59058c2008-08-24 21:49:00 -04003203/**
James Smart3621a712009-04-06 18:47:14 -04003204 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003205 * @phba: pointer to lpfc hba data structure.
3206 * @pmb: pointer to the driver internal queue element for mailbox command.
3207 *
3208 * This routine is the completion callback function for unregister default
3209 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3210 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3211 * decrements the ndlp reference count held for this completion callback
3212 * function. After that, it invokes the lpfc_nlp_not_used() to check
3213 * whether there is only one reference left on the ndlp. If so, it will
3214 * perform one more decrement and trigger the release of the ndlp.
3215 **/
James Smart858c9f62007-06-17 19:56:39 -05003216void
3217lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3218{
3219 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3220 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3221
James Smart6fb120a2009-05-22 14:52:59 -04003222 /*
3223 * This routine is used to register and unregister in previous SLI
3224 * modes.
3225 */
3226 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3227 (phba->sli_rev == LPFC_SLI_REV4))
3228 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3229
James Smart858c9f62007-06-17 19:56:39 -05003230 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003231 pmb->context2 = NULL;
3232
James Smart858c9f62007-06-17 19:56:39 -05003233 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3234 kfree(mp);
3235 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003236 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003237 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003238 /* This is the end of the default RPI cleanup logic for this
3239 * ndlp. If no other discovery threads are using this ndlp.
3240 * we should free all resources associated with it.
3241 */
3242 lpfc_nlp_not_used(ndlp);
3243 }
James Smart3772a992009-05-22 14:50:54 -04003244
James Smart858c9f62007-06-17 19:56:39 -05003245 return;
3246}
3247
James Smarte59058c2008-08-24 21:49:00 -04003248/**
James Smart3621a712009-04-06 18:47:14 -04003249 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003250 * @phba: pointer to lpfc hba data structure.
3251 * @cmdiocb: pointer to lpfc command iocb data structure.
3252 * @rspiocb: pointer to lpfc response iocb data structure.
3253 *
3254 * This routine is the completion callback function for ELS Response IOCB
3255 * command. In normal case, this callback function just properly sets the
3256 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3257 * field in the command IOCB is not NULL, the referred mailbox command will
3258 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3259 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3260 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3261 * routine shall be invoked trying to release the ndlp if no other threads
3262 * are currently referring it.
3263 **/
dea31012005-04-17 16:05:31 -05003264static void
James Smart858c9f62007-06-17 19:56:39 -05003265lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003266 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003267{
James Smart2e0fef82007-06-17 19:56:36 -05003268 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3269 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3270 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003271 IOCB_t *irsp;
3272 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003273 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003274 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003275 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003276
James Smart33ccf8d2006-08-17 11:57:58 -04003277 irsp = &rspiocb->iocb;
3278
dea31012005-04-17 16:05:31 -05003279 if (cmdiocb->context_un.mbox)
3280 mbox = cmdiocb->context_un.mbox;
3281
James Smartfa4066b2008-01-11 01:53:27 -05003282 /* First determine if this is a LS_RJT cmpl. Note, this callback
3283 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3284 */
James Smart87af33f2007-10-27 13:37:43 -04003285 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003286 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3287 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003288 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003289 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003290 */
3291 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3292 ls_rjt = 1;
3293 }
3294
dea31012005-04-17 16:05:31 -05003295 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003296 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003297 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003298 mp = (struct lpfc_dmabuf *) mbox->context1;
3299 if (mp) {
3300 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3301 kfree(mp);
3302 }
James Smart329f9bc2007-04-25 09:53:01 -04003303 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003304 }
James Smart58da1ff2008-04-07 10:15:56 -04003305 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3306 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003307 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003308 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003309 /* Indicate the node has already released,
3310 * should not reference to it from within
3311 * the routine lpfc_els_free_iocb.
3312 */
3313 cmdiocb->context1 = NULL;
3314 }
dea31012005-04-17 16:05:31 -05003315 goto out;
3316 }
3317
James Smart858c9f62007-06-17 19:56:39 -05003318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003319 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003320 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003321 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003322 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003323 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3324 "0110 ELS response tag x%x completes "
3325 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3326 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3327 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3328 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3329 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003330 if (mbox) {
3331 if ((rspiocb->iocb.ulpStatus == 0)
3332 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003333 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003334 /* Increment reference count to ndlp to hold the
3335 * reference to ndlp for the callback function.
3336 */
James Smart329f9bc2007-04-25 09:53:01 -04003337 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003338 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003339 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3340 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3341 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3342 }
3343 else {
3344 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3345 ndlp->nlp_prev_state = ndlp->nlp_state;
3346 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003347 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003348 }
James Smart0b727fe2007-10-27 13:37:25 -04003349 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003350 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003351 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003352 else
3353 /* Decrement the ndlp reference count we
3354 * set for this failed mailbox command.
3355 */
3356 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003357
3358 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3359 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3360 "0138 ELS rsp: Cannot issue reg_login for x%x "
3361 "Data: x%x x%x x%x\n",
3362 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3363 ndlp->nlp_rpi);
3364
James Smartfa4066b2008-01-11 01:53:27 -05003365 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003366 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003367 /* Indicate node has already been released,
3368 * should not reference to it from within
3369 * the routine lpfc_els_free_iocb.
3370 */
3371 cmdiocb->context1 = NULL;
3372 }
dea31012005-04-17 16:05:31 -05003373 } else {
James Smart858c9f62007-06-17 19:56:39 -05003374 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3375 if (!lpfc_error_lost_link(irsp) &&
3376 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003377 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003378 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003379 /* Indicate node has already been
3380 * released, should not reference
3381 * to it from within the routine
3382 * lpfc_els_free_iocb.
3383 */
3384 cmdiocb->context1 = NULL;
3385 }
dea31012005-04-17 16:05:31 -05003386 }
3387 }
James Smart14691152006-12-02 13:34:28 -05003388 mp = (struct lpfc_dmabuf *) mbox->context1;
3389 if (mp) {
3390 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3391 kfree(mp);
3392 }
3393 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003394 }
3395out:
James Smart58da1ff2008-04-07 10:15:56 -04003396 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003397 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003398 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003399 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003400
3401 /* If the node is not being used by another discovery thread,
3402 * and we are sending a reject, we are done with it.
3403 * Release driver reference count here and free associated
3404 * resources.
3405 */
3406 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003407 if (lpfc_nlp_not_used(ndlp))
3408 /* Indicate node has already been released,
3409 * should not reference to it from within
3410 * the routine lpfc_els_free_iocb.
3411 */
3412 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003413 }
James Smart87af33f2007-10-27 13:37:43 -04003414
dea31012005-04-17 16:05:31 -05003415 lpfc_els_free_iocb(phba, cmdiocb);
3416 return;
3417}
3418
James Smarte59058c2008-08-24 21:49:00 -04003419/**
James Smart3621a712009-04-06 18:47:14 -04003420 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003421 * @vport: pointer to a host virtual N_Port data structure.
3422 * @flag: the els command code to be accepted.
3423 * @oldiocb: pointer to the original lpfc command iocb data structure.
3424 * @ndlp: pointer to a node-list data structure.
3425 * @mbox: pointer to the driver internal queue element for mailbox command.
3426 *
3427 * This routine prepares and issues an Accept (ACC) response IOCB
3428 * command. It uses the @flag to properly set up the IOCB field for the
3429 * specific ACC response command to be issued and invokes the
3430 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3431 * @mbox pointer is passed in, it will be put into the context_un.mbox
3432 * field of the IOCB for the completion callback function to issue the
3433 * mailbox command to the HBA later when callback is invoked.
3434 *
3435 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3436 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3437 * will be stored into the context1 field of the IOCB for the completion
3438 * callback function to the corresponding response ELS IOCB command.
3439 *
3440 * Return code
3441 * 0 - Successfully issued acc response
3442 * 1 - Failed to issue acc response
3443 **/
dea31012005-04-17 16:05:31 -05003444int
James Smart2e0fef82007-06-17 19:56:36 -05003445lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3446 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003447 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003448{
James Smart2e0fef82007-06-17 19:56:36 -05003449 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3450 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003451 IOCB_t *icmd;
3452 IOCB_t *oldcmd;
3453 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003454 struct lpfc_sli *psli;
3455 uint8_t *pcmd;
3456 uint16_t cmdsize;
3457 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003458 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003459
3460 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003461 oldcmd = &oldiocb->iocb;
3462
3463 switch (flag) {
3464 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003465 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003466 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3467 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003468 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003469 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003470 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003471 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003472 return 1;
dea31012005-04-17 16:05:31 -05003473 }
James Smart2e0fef82007-06-17 19:56:36 -05003474
dea31012005-04-17 16:05:31 -05003475 icmd = &elsiocb->iocb;
3476 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3477 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3478 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003479 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003480
3481 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3482 "Issue ACC: did:x%x flg:x%x",
3483 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003484 break;
3485 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003486 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003487 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3488 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003489 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003490 return 1;
James Smart488d1462006-03-07 15:02:37 -05003491
dea31012005-04-17 16:05:31 -05003492 icmd = &elsiocb->iocb;
3493 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3494 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3495
3496 if (mbox)
3497 elsiocb->context_un.mbox = mbox;
3498
3499 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003500 pcmd += sizeof(uint32_t);
3501 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003502
3503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3504 "Issue ACC PLOGI: did:x%x flg:x%x",
3505 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003506 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003507 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003508 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003509 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003510 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3511 if (!elsiocb)
3512 return 1;
3513
3514 icmd = &elsiocb->iocb;
3515 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3516 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3517
3518 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003519 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003520 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3521 els_pkt_ptr = (ELS_PKT *) pcmd;
3522 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003523
3524 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3525 "Issue ACC PRLO: did:x%x flg:x%x",
3526 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003527 break;
dea31012005-04-17 16:05:31 -05003528 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003529 return 1;
dea31012005-04-17 16:05:31 -05003530 }
dea31012005-04-17 16:05:31 -05003531 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3533 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3534 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3535 elsiocb->iotag, elsiocb->iocb.ulpContext,
3536 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3537 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003538 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003539 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003540 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003541 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003542 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3543 } else {
James Smart858c9f62007-06-17 19:56:39 -05003544 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003545 }
3546
3547 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003548 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003549 if (rc == IOCB_ERROR) {
3550 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003551 return 1;
dea31012005-04-17 16:05:31 -05003552 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003553 return 0;
dea31012005-04-17 16:05:31 -05003554}
3555
James Smarte59058c2008-08-24 21:49:00 -04003556/**
James Smart3621a712009-04-06 18:47:14 -04003557 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003558 * @vport: pointer to a virtual N_Port data structure.
3559 * @rejectError:
3560 * @oldiocb: pointer to the original lpfc command iocb data structure.
3561 * @ndlp: pointer to a node-list data structure.
3562 * @mbox: pointer to the driver internal queue element for mailbox command.
3563 *
3564 * This routine prepares and issue an Reject (RJT) response IOCB
3565 * command. If a @mbox pointer is passed in, it will be put into the
3566 * context_un.mbox field of the IOCB for the completion callback function
3567 * to issue to the HBA later.
3568 *
3569 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3570 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3571 * will be stored into the context1 field of the IOCB for the completion
3572 * callback function to the reject response ELS IOCB command.
3573 *
3574 * Return code
3575 * 0 - Successfully issued reject response
3576 * 1 - Failed to issue reject response
3577 **/
dea31012005-04-17 16:05:31 -05003578int
James Smart2e0fef82007-06-17 19:56:36 -05003579lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003580 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3581 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003582{
James Smart2e0fef82007-06-17 19:56:36 -05003583 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003584 IOCB_t *icmd;
3585 IOCB_t *oldcmd;
3586 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003587 struct lpfc_sli *psli;
3588 uint8_t *pcmd;
3589 uint16_t cmdsize;
3590 int rc;
3591
3592 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003593 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003594 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3595 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003596 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003597 return 1;
dea31012005-04-17 16:05:31 -05003598
3599 icmd = &elsiocb->iocb;
3600 oldcmd = &oldiocb->iocb;
3601 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3603
3604 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003605 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003606 *((uint32_t *) (pcmd)) = rejectError;
3607
James Smart51ef4c22007-08-02 11:10:31 -04003608 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003609 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003610
dea31012005-04-17 16:05:31 -05003611 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003612 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3613 "0129 Xmit ELS RJT x%x response tag x%x "
3614 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3615 "rpi x%x\n",
3616 rejectError, elsiocb->iotag,
3617 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3618 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3620 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3621 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3622
dea31012005-04-17 16:05:31 -05003623 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003624 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003625 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003626
dea31012005-04-17 16:05:31 -05003627 if (rc == IOCB_ERROR) {
3628 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003629 return 1;
dea31012005-04-17 16:05:31 -05003630 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003631 return 0;
dea31012005-04-17 16:05:31 -05003632}
3633
James Smarte59058c2008-08-24 21:49:00 -04003634/**
James Smart3621a712009-04-06 18:47:14 -04003635 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003636 * @vport: pointer to a virtual N_Port data structure.
3637 * @oldiocb: pointer to the original lpfc command iocb data structure.
3638 * @ndlp: pointer to a node-list data structure.
3639 *
3640 * This routine prepares and issues an Accept (ACC) response to Address
3641 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3642 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3643 *
3644 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3645 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3646 * will be stored into the context1 field of the IOCB for the completion
3647 * callback function to the ADISC Accept response ELS IOCB command.
3648 *
3649 * Return code
3650 * 0 - Successfully issued acc adisc response
3651 * 1 - Failed to issue adisc acc response
3652 **/
dea31012005-04-17 16:05:31 -05003653int
James Smart2e0fef82007-06-17 19:56:36 -05003654lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3655 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003656{
James Smart2e0fef82007-06-17 19:56:36 -05003657 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003658 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003659 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003660 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003661 uint8_t *pcmd;
3662 uint16_t cmdsize;
3663 int rc;
3664
James Smart92d7f7b2007-06-17 19:56:38 -05003665 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003666 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3667 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003668 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003669 return 1;
dea31012005-04-17 16:05:31 -05003670
dea31012005-04-17 16:05:31 -05003671 icmd = &elsiocb->iocb;
3672 oldcmd = &oldiocb->iocb;
3673 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003674
3675 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003676 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3677 "0130 Xmit ADISC ACC response iotag x%x xri: "
3678 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3679 elsiocb->iotag, elsiocb->iocb.ulpContext,
3680 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3681 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003682 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3683
3684 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003685 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003686
3687 ap = (ADISC *) (pcmd);
3688 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003689 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3690 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003691 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003692
James Smart858c9f62007-06-17 19:56:39 -05003693 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3694 "Issue ACC ADISC: did:x%x flg:x%x",
3695 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3696
dea31012005-04-17 16:05:31 -05003697 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003698 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003699 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003700 if (rc == IOCB_ERROR) {
3701 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003702 return 1;
dea31012005-04-17 16:05:31 -05003703 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003704 return 0;
dea31012005-04-17 16:05:31 -05003705}
3706
James Smarte59058c2008-08-24 21:49:00 -04003707/**
James Smart3621a712009-04-06 18:47:14 -04003708 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003709 * @vport: pointer to a virtual N_Port data structure.
3710 * @oldiocb: pointer to the original lpfc command iocb data structure.
3711 * @ndlp: pointer to a node-list data structure.
3712 *
3713 * This routine prepares and issues an Accept (ACC) response to Process
3714 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3715 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3716 *
3717 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3718 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3719 * will be stored into the context1 field of the IOCB for the completion
3720 * callback function to the PRLI Accept response ELS IOCB command.
3721 *
3722 * Return code
3723 * 0 - Successfully issued acc prli response
3724 * 1 - Failed to issue acc prli response
3725 **/
dea31012005-04-17 16:05:31 -05003726int
James Smart2e0fef82007-06-17 19:56:36 -05003727lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003728 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003729{
James Smart2e0fef82007-06-17 19:56:36 -05003730 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003731 PRLI *npr;
3732 lpfc_vpd_t *vpd;
3733 IOCB_t *icmd;
3734 IOCB_t *oldcmd;
3735 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003736 struct lpfc_sli *psli;
3737 uint8_t *pcmd;
3738 uint16_t cmdsize;
3739 int rc;
3740
3741 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003742
James Smart92d7f7b2007-06-17 19:56:38 -05003743 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003744 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003745 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003746 if (!elsiocb)
3747 return 1;
dea31012005-04-17 16:05:31 -05003748
dea31012005-04-17 16:05:31 -05003749 icmd = &elsiocb->iocb;
3750 oldcmd = &oldiocb->iocb;
3751 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003752 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003753 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3754 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3755 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3756 elsiocb->iotag, elsiocb->iocb.ulpContext,
3757 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3758 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003759 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3760
3761 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003762 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003763
3764 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003765 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003766
3767 npr = (PRLI *) pcmd;
3768 vpd = &phba->vpd;
3769 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003770 * If the remote port is a target and our firmware version is 3.20 or
3771 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003772 */
James Smart0d2b6b82008-06-14 22:52:47 -04003773 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3774 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003775 npr->ConfmComplAllowed = 1;
3776 npr->Retry = 1;
3777 npr->TaskRetryIdReq = 1;
3778 }
3779
3780 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3781 npr->estabImagePair = 1;
3782 npr->readXferRdyDis = 1;
3783 npr->ConfmComplAllowed = 1;
3784
3785 npr->prliType = PRLI_FCP_TYPE;
3786 npr->initiatorFunc = 1;
3787
James Smart858c9f62007-06-17 19:56:39 -05003788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3789 "Issue ACC PRLI: did:x%x flg:x%x",
3790 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3791
dea31012005-04-17 16:05:31 -05003792 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003793 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003794
James Smart3772a992009-05-22 14:50:54 -04003795 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003796 if (rc == IOCB_ERROR) {
3797 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003798 return 1;
dea31012005-04-17 16:05:31 -05003799 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003800 return 0;
dea31012005-04-17 16:05:31 -05003801}
3802
James Smarte59058c2008-08-24 21:49:00 -04003803/**
James Smart3621a712009-04-06 18:47:14 -04003804 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003805 * @vport: pointer to a virtual N_Port data structure.
3806 * @format: rnid command format.
3807 * @oldiocb: pointer to the original lpfc command iocb data structure.
3808 * @ndlp: pointer to a node-list data structure.
3809 *
3810 * This routine issues a Request Node Identification Data (RNID) Accept
3811 * (ACC) response. It constructs the RNID ACC response command according to
3812 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3813 * issue the response. Note that this command does not need to hold the ndlp
3814 * reference count for the callback. So, the ndlp reference count taken by
3815 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3816 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3817 * there is no ndlp reference available.
3818 *
3819 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3820 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3821 * will be stored into the context1 field of the IOCB for the completion
3822 * callback function. However, for the RNID Accept Response ELS command,
3823 * this is undone later by this routine after the IOCB is allocated.
3824 *
3825 * Return code
3826 * 0 - Successfully issued acc rnid response
3827 * 1 - Failed to issue acc rnid response
3828 **/
dea31012005-04-17 16:05:31 -05003829static int
James Smart2e0fef82007-06-17 19:56:36 -05003830lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003831 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003832{
James Smart2e0fef82007-06-17 19:56:36 -05003833 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003834 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003835 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003836 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003837 struct lpfc_sli *psli;
3838 uint8_t *pcmd;
3839 uint16_t cmdsize;
3840 int rc;
3841
3842 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003843 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3844 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003845 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003846 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003847
James Smart2e0fef82007-06-17 19:56:36 -05003848 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3849 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003850 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003851 return 1;
dea31012005-04-17 16:05:31 -05003852
dea31012005-04-17 16:05:31 -05003853 icmd = &elsiocb->iocb;
3854 oldcmd = &oldiocb->iocb;
3855 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003856 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003857 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3858 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3859 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003860 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003861 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003862 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003863
James Smart92d7f7b2007-06-17 19:56:38 -05003864 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003865 rn = (RNID *) (pcmd);
3866 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003867 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3868 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3869 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003870 switch (format) {
3871 case 0:
3872 rn->SpecificLen = 0;
3873 break;
3874 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003875 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003876 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003877 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003878 rn->un.topologyDisc.unitType = RNID_HBA;
3879 rn->un.topologyDisc.physPort = 0;
3880 rn->un.topologyDisc.attachedNodes = 0;
3881 break;
3882 default:
3883 rn->CommonLen = 0;
3884 rn->SpecificLen = 0;
3885 break;
3886 }
3887
James Smart858c9f62007-06-17 19:56:39 -05003888 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3889 "Issue ACC RNID: did:x%x flg:x%x",
3890 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3891
dea31012005-04-17 16:05:31 -05003892 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003893 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003894 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003895 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3896 * it could be freed */
3897
James Smart3772a992009-05-22 14:50:54 -04003898 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003899 if (rc == IOCB_ERROR) {
3900 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003901 return 1;
dea31012005-04-17 16:05:31 -05003902 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003903 return 0;
dea31012005-04-17 16:05:31 -05003904}
3905
James Smarte59058c2008-08-24 21:49:00 -04003906/**
James Smart12265f62010-10-22 11:05:53 -04003907 * lpfc_els_rsp_echo_acc - Issue echo acc response
3908 * @vport: pointer to a virtual N_Port data structure.
3909 * @data: pointer to echo data to return in the accept.
3910 * @oldiocb: pointer to the original lpfc command iocb data structure.
3911 * @ndlp: pointer to a node-list data structure.
3912 *
3913 * Return code
3914 * 0 - Successfully issued acc echo response
3915 * 1 - Failed to issue acc echo response
3916 **/
3917static int
3918lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
3919 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3920{
3921 struct lpfc_hba *phba = vport->phba;
3922 struct lpfc_iocbq *elsiocb;
3923 struct lpfc_sli *psli;
3924 uint8_t *pcmd;
3925 uint16_t cmdsize;
3926 int rc;
3927
3928 psli = &phba->sli;
3929 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
3930
3931 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3932 ndlp->nlp_DID, ELS_CMD_ACC);
3933 if (!elsiocb)
3934 return 1;
3935
3936 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
3937 /* Xmit ECHO ACC response tag <ulpIoTag> */
3938 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3939 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
3940 elsiocb->iotag, elsiocb->iocb.ulpContext);
3941 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3942 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3943 pcmd += sizeof(uint32_t);
3944 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
3945
3946 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3947 "Issue ACC ECHO: did:x%x flg:x%x",
3948 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3949
3950 phba->fc_stat.elsXmitACC++;
3951 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3952 lpfc_nlp_put(ndlp);
3953 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3954 * it could be freed */
3955
3956 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3957 if (rc == IOCB_ERROR) {
3958 lpfc_els_free_iocb(phba, elsiocb);
3959 return 1;
3960 }
3961 return 0;
3962}
3963
3964/**
James Smart3621a712009-04-06 18:47:14 -04003965 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003966 * @vport: pointer to a host virtual N_Port data structure.
3967 *
3968 * This routine issues Address Discover (ADISC) ELS commands to those
3969 * N_Ports which are in node port recovery state and ADISC has not been issued
3970 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3971 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3972 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3973 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3974 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3975 * IOCBs quit for later pick up. On the other hand, after walking through
3976 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3977 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3978 * no more ADISC need to be sent.
3979 *
3980 * Return code
3981 * The number of N_Ports with adisc issued.
3982 **/
dea31012005-04-17 16:05:31 -05003983int
James Smart2e0fef82007-06-17 19:56:36 -05003984lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003985{
James Smart2e0fef82007-06-17 19:56:36 -05003986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003987 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003988 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003989
James Smart685f0bf2007-04-25 09:53:08 -04003990 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003991 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003992 if (!NLP_CHK_NODE_ACT(ndlp))
3993 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003994 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3995 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3996 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003997 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003998 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003999 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004000 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004001 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4002 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004003 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004004 vport->num_disc_nodes++;
4005 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004006 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004007 spin_lock_irq(shost->host_lock);
4008 vport->fc_flag |= FC_NLP_MORE;
4009 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004010 break;
dea31012005-04-17 16:05:31 -05004011 }
4012 }
4013 }
4014 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004015 spin_lock_irq(shost->host_lock);
4016 vport->fc_flag &= ~FC_NLP_MORE;
4017 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004018 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004019 return sentadisc;
dea31012005-04-17 16:05:31 -05004020}
4021
James Smarte59058c2008-08-24 21:49:00 -04004022/**
James Smart3621a712009-04-06 18:47:14 -04004023 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004024 * @vport: pointer to a host virtual N_Port data structure.
4025 *
4026 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4027 * which are in node port recovery state, with a @vport. Each time an ELS
4028 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4029 * the per @vport number of discover count (num_disc_nodes) shall be
4030 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4031 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4032 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4033 * later pick up. On the other hand, after walking through all the ndlps with
4034 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4035 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4036 * PLOGI need to be sent.
4037 *
4038 * Return code
4039 * The number of N_Ports with plogi issued.
4040 **/
dea31012005-04-17 16:05:31 -05004041int
James Smart2e0fef82007-06-17 19:56:36 -05004042lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004043{
James Smart2e0fef82007-06-17 19:56:36 -05004044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004045 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004046 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004047
James Smart2e0fef82007-06-17 19:56:36 -05004048 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4049 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004050 if (!NLP_CHK_NODE_ACT(ndlp))
4051 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004052 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4053 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4054 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4055 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4056 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004057 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4058 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004059 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004060 vport->num_disc_nodes++;
4061 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004062 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004063 spin_lock_irq(shost->host_lock);
4064 vport->fc_flag |= FC_NLP_MORE;
4065 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004066 break;
dea31012005-04-17 16:05:31 -05004067 }
4068 }
4069 }
James Smart87af33f2007-10-27 13:37:43 -04004070 if (sentplogi) {
4071 lpfc_set_disctmo(vport);
4072 }
4073 else {
James Smart2e0fef82007-06-17 19:56:36 -05004074 spin_lock_irq(shost->host_lock);
4075 vport->fc_flag &= ~FC_NLP_MORE;
4076 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004077 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004078 return sentplogi;
dea31012005-04-17 16:05:31 -05004079}
4080
James Smarte59058c2008-08-24 21:49:00 -04004081/**
James Smart3621a712009-04-06 18:47:14 -04004082 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004083 * @vport: pointer to a host virtual N_Port data structure.
4084 *
4085 * This routine cleans up any Registration State Change Notification
4086 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4087 * @vport together with the host_lock is used to prevent multiple thread
4088 * trying to access the RSCN array on a same @vport at the same time.
4089 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004090void
James Smart2e0fef82007-06-17 19:56:36 -05004091lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004092{
James Smart2e0fef82007-06-17 19:56:36 -05004093 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4094 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004095 int i;
4096
James Smart7f5f3d02008-02-08 18:50:14 -05004097 spin_lock_irq(shost->host_lock);
4098 if (vport->fc_rscn_flush) {
4099 /* Another thread is walking fc_rscn_id_list on this vport */
4100 spin_unlock_irq(shost->host_lock);
4101 return;
4102 }
4103 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4104 vport->fc_rscn_flush = 1;
4105 spin_unlock_irq(shost->host_lock);
4106
James Smart2e0fef82007-06-17 19:56:36 -05004107 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004108 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004109 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004110 }
James Smart2e0fef82007-06-17 19:56:36 -05004111 spin_lock_irq(shost->host_lock);
4112 vport->fc_rscn_id_cnt = 0;
4113 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4114 spin_unlock_irq(shost->host_lock);
4115 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004116 /* Indicate we are done walking this fc_rscn_id_list */
4117 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004118}
4119
James Smarte59058c2008-08-24 21:49:00 -04004120/**
James Smart3621a712009-04-06 18:47:14 -04004121 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004122 * @vport: pointer to a host virtual N_Port data structure.
4123 * @did: remote destination port identifier.
4124 *
4125 * This routine checks whether there is any pending Registration State
4126 * Configuration Notification (RSCN) to a @did on @vport.
4127 *
4128 * Return code
4129 * None zero - The @did matched with a pending rscn
4130 * 0 - not able to match @did with a pending rscn
4131 **/
dea31012005-04-17 16:05:31 -05004132int
James Smart2e0fef82007-06-17 19:56:36 -05004133lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004134{
4135 D_ID ns_did;
4136 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004137 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004138 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004140
4141 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004142
4143 /* Never match fabric nodes for RSCNs */
4144 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004145 return 0;
dea31012005-04-17 16:05:31 -05004146
4147 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004148 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004149 return did;
dea31012005-04-17 16:05:31 -05004150
James Smart7f5f3d02008-02-08 18:50:14 -05004151 spin_lock_irq(shost->host_lock);
4152 if (vport->fc_rscn_flush) {
4153 /* Another thread is walking fc_rscn_id_list on this vport */
4154 spin_unlock_irq(shost->host_lock);
4155 return 0;
4156 }
4157 /* Indicate we are walking fc_rscn_id_list on this vport */
4158 vport->fc_rscn_flush = 1;
4159 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004160 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004161 lp = vport->fc_rscn_id_list[i]->virt;
4162 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4163 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004164 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004165 rscn_did.un.word = be32_to_cpu(*lp++);
4166 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004167 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4168 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004169 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4170 && (ns_did.un.b.area == rscn_did.un.b.area)
4171 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004172 goto return_did_out;
dea31012005-04-17 16:05:31 -05004173 break;
James Smarteaf15d52008-12-04 22:39:29 -05004174 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004175 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4176 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004177 goto return_did_out;
dea31012005-04-17 16:05:31 -05004178 break;
James Smarteaf15d52008-12-04 22:39:29 -05004179 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004180 if (ns_did.un.b.domain == rscn_did.un.b.domain)
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_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004184 goto return_did_out;
dea31012005-04-17 16:05:31 -05004185 }
4186 }
James Smart92d7f7b2007-06-17 19:56:38 -05004187 }
James Smart7f5f3d02008-02-08 18:50:14 -05004188 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4189 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004190 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004191return_did_out:
4192 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4193 vport->fc_rscn_flush = 0;
4194 return did;
dea31012005-04-17 16:05:31 -05004195}
4196
James Smarte59058c2008-08-24 21:49:00 -04004197/**
James Smart3621a712009-04-06 18:47:14 -04004198 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004199 * @vport: pointer to a host virtual N_Port data structure.
4200 *
4201 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4202 * state machine for a @vport's nodes that are with pending RSCN (Registration
4203 * State Change Notification).
4204 *
4205 * Return code
4206 * 0 - Successful (currently alway return 0)
4207 **/
dea31012005-04-17 16:05:31 -05004208static int
James Smart2e0fef82007-06-17 19:56:36 -05004209lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004210{
James Smart685f0bf2007-04-25 09:53:08 -04004211 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004212
James Smart0d2b6b82008-06-14 22:52:47 -04004213 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004214 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004215 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004216 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4217 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004218 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004219 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004220 NLP_EVT_DEVICE_RECOVERY);
4221 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004222 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004223 return 0;
dea31012005-04-17 16:05:31 -05004224}
4225
James Smarte59058c2008-08-24 21:49:00 -04004226/**
James Smart3621a712009-04-06 18:47:14 -04004227 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004228 * @vport: pointer to a host virtual N_Port data structure.
4229 * @cmdiocb: pointer to lpfc command iocb data structure.
4230 *
4231 * lpfc_send_rscn_event sends an RSCN netlink event to management
4232 * applications.
4233 */
4234static void
4235lpfc_send_rscn_event(struct lpfc_vport *vport,
4236 struct lpfc_iocbq *cmdiocb)
4237{
4238 struct lpfc_dmabuf *pcmd;
4239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4240 uint32_t *payload_ptr;
4241 uint32_t payload_len;
4242 struct lpfc_rscn_event_header *rscn_event_data;
4243
4244 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4245 payload_ptr = (uint32_t *) pcmd->virt;
4246 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4247
4248 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4249 payload_len, GFP_KERNEL);
4250 if (!rscn_event_data) {
4251 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4252 "0147 Failed to allocate memory for RSCN event\n");
4253 return;
4254 }
4255 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4256 rscn_event_data->payload_length = payload_len;
4257 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4258 payload_len);
4259
4260 fc_host_post_vendor_event(shost,
4261 fc_get_event_number(),
4262 sizeof(struct lpfc_els_event_header) + payload_len,
4263 (char *)rscn_event_data,
4264 LPFC_NL_VENDOR_ID);
4265
4266 kfree(rscn_event_data);
4267}
4268
4269/**
James Smart3621a712009-04-06 18:47:14 -04004270 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004271 * @vport: pointer to a host virtual N_Port data structure.
4272 * @cmdiocb: pointer to lpfc command iocb data structure.
4273 * @ndlp: pointer to a node-list data structure.
4274 *
4275 * This routine processes an unsolicited RSCN (Registration State Change
4276 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4277 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4278 * discover state machine is about to begin discovery, it just accepts the
4279 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4280 * contains N_Port IDs for other vports on this HBA, it just accepts the
4281 * RSCN and ignore processing it. If the state machine is in the recovery
4282 * state, the fc_rscn_id_list of this @vport is walked and the
4283 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4284 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4285 * routine is invoked to handle the RSCN event.
4286 *
4287 * Return code
4288 * 0 - Just sent the acc response
4289 * 1 - Sent the acc response and waited for name server completion
4290 **/
dea31012005-04-17 16:05:31 -05004291static int
James Smart2e0fef82007-06-17 19:56:36 -05004292lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004293 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004294{
James Smart2e0fef82007-06-17 19:56:36 -05004295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4296 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004297 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004298 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004299 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004300 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004301 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004302 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004303 int i;
dea31012005-04-17 16:05:31 -05004304
4305 icmd = &cmdiocb->iocb;
4306 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4307 lp = (uint32_t *) pcmd->virt;
4308
James Smart92d7f7b2007-06-17 19:56:38 -05004309 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4310 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004311 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004312 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4313 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004314 vport->fc_flag, payload_len, *lp,
4315 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004316
4317 /* Send an RSCN event to the management application */
4318 lpfc_send_rscn_event(vport, cmdiocb);
4319
James Smartd2873e42006-08-18 17:46:43 -04004320 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004321 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004322 FCH_EVT_RSCN, lp[i]);
4323
dea31012005-04-17 16:05:31 -05004324 /* If we are about to begin discovery, just ACC the RSCN.
4325 * Discovery processing will satisfy it.
4326 */
James Smart2e0fef82007-06-17 19:56:36 -05004327 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4329 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4330 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4331
James Smart51ef4c22007-08-02 11:10:31 -04004332 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004333 return 0;
dea31012005-04-17 16:05:31 -05004334 }
4335
James Smart92d7f7b2007-06-17 19:56:38 -05004336 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4337 * just ACC and ignore it.
4338 */
4339 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004340 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004341 i = payload_len;
4342 datap = lp;
4343 while (i > 0) {
4344 nportid = *datap++;
4345 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4346 i -= sizeof(uint32_t);
4347 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004348 if (lpfc_find_vport_by_did(phba, nportid))
4349 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004350 }
4351 if (rscn_id == hba_id) {
4352 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004353 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004354 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004355 "Data: x%x x%x x%x x%x\n",
4356 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004357 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004358 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4359 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4360 ndlp->nlp_DID, vport->port_state,
4361 ndlp->nlp_flag);
4362
James Smart92d7f7b2007-06-17 19:56:38 -05004363 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004364 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004365 return 0;
4366 }
4367 }
4368
James Smart7f5f3d02008-02-08 18:50:14 -05004369 spin_lock_irq(shost->host_lock);
4370 if (vport->fc_rscn_flush) {
4371 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004372 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004373 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004374 /* Send back ACC */
4375 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004376 return 0;
4377 }
4378 /* Indicate we are walking fc_rscn_id_list on this vport */
4379 vport->fc_rscn_flush = 1;
4380 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004381 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004382 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004383 /* If we are already processing an RSCN, save the received
4384 * RSCN payload buffer, cmdiocb->context2 to process later.
4385 */
James Smart2e0fef82007-06-17 19:56:36 -05004386 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004387 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4388 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4389 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4390
James Smart09372822008-01-11 01:52:54 -05004391 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004392 vport->fc_flag |= FC_RSCN_DEFERRED;
4393 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004394 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004395 vport->fc_flag |= FC_RSCN_MODE;
4396 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004397 if (rscn_cnt) {
4398 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4399 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4400 }
4401 if ((rscn_cnt) &&
4402 (payload_len + length <= LPFC_BPL_SIZE)) {
4403 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004404 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004405 memcpy(((uint8_t *)cmd) + length, lp,
4406 payload_len);
4407 } else {
4408 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4409 vport->fc_rscn_id_cnt++;
4410 /* If we zero, cmdiocb->context2, the calling
4411 * routine will not try to free it.
4412 */
4413 cmdiocb->context2 = NULL;
4414 }
dea31012005-04-17 16:05:31 -05004415 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004416 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4417 "0235 Deferred RSCN "
4418 "Data: x%x x%x x%x\n",
4419 vport->fc_rscn_id_cnt, vport->fc_flag,
4420 vport->port_state);
dea31012005-04-17 16:05:31 -05004421 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004422 vport->fc_flag |= FC_RSCN_DISCOVERY;
4423 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004424 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004425 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4426 "0234 ReDiscovery 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 }
James Smart7f5f3d02008-02-08 18:50:14 -05004431 /* Indicate we are done walking fc_rscn_id_list on this vport */
4432 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004433 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004434 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004435 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004436 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004437 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004438 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004439 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004440 return 0;
dea31012005-04-17 16:05:31 -05004441 }
James Smart858c9f62007-06-17 19:56:39 -05004442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4443 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4444 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4445
James Smart2e0fef82007-06-17 19:56:36 -05004446 spin_lock_irq(shost->host_lock);
4447 vport->fc_flag |= FC_RSCN_MODE;
4448 spin_unlock_irq(shost->host_lock);
4449 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004450 /* Indicate we are done walking fc_rscn_id_list on this vport */
4451 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004452 /*
4453 * If we zero, cmdiocb->context2, the calling routine will
4454 * not try to free it.
4455 */
4456 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004457 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004458 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004459 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004460 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004461 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004462 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004463}
4464
James Smarte59058c2008-08-24 21:49:00 -04004465/**
James Smart3621a712009-04-06 18:47:14 -04004466 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004467 * @vport: pointer to a host virtual N_Port data structure.
4468 *
4469 * This routine handles the Registration State Configuration Notification
4470 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4471 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4472 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4473 * NameServer shall be issued. If CT command to the NameServer fails to be
4474 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4475 * RSCN activities with the @vport.
4476 *
4477 * Return code
4478 * 0 - Cleaned up rscn on the @vport
4479 * 1 - Wait for plogi to name server before proceed
4480 **/
dea31012005-04-17 16:05:31 -05004481int
James Smart2e0fef82007-06-17 19:56:36 -05004482lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004483{
4484 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004485 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004486
James Smart92d7f7b2007-06-17 19:56:38 -05004487 /* Ignore RSCN if the port is being torn down. */
4488 if (vport->load_flag & FC_UNLOADING) {
4489 lpfc_els_flush_rscn(vport);
4490 return 0;
4491 }
4492
dea31012005-04-17 16:05:31 -05004493 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004494 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004495
4496 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004497 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4498 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4499 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4500 vport->port_state);
dea31012005-04-17 16:05:31 -05004501
4502 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004503 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004504 vport->num_disc_nodes = 0;
4505
James Smart2e0fef82007-06-17 19:56:36 -05004506 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004507 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4508 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004509 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004510 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004511 /* Wait for NameServer query cmpl before we can
4512 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004513 return 1;
dea31012005-04-17 16:05:31 -05004514 } else {
4515 /* If login to NameServer does not exist, issue one */
4516 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004517 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004518 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004519 /* Wait for NameServer login cmpl before we can
4520 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004521 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004522
James Smarte47c9092008-02-08 18:49:26 -05004523 if (ndlp) {
4524 ndlp = lpfc_enable_node(vport, ndlp,
4525 NLP_STE_PLOGI_ISSUE);
4526 if (!ndlp) {
4527 lpfc_els_flush_rscn(vport);
4528 return 0;
4529 }
4530 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004531 } else {
James Smarte47c9092008-02-08 18:49:26 -05004532 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4533 if (!ndlp) {
4534 lpfc_els_flush_rscn(vport);
4535 return 0;
4536 }
James Smart2e0fef82007-06-17 19:56:36 -05004537 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004538 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004539 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004540 }
James Smarte47c9092008-02-08 18:49:26 -05004541 ndlp->nlp_type |= NLP_FABRIC;
4542 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4543 /* Wait for NameServer login cmpl before we can
4544 * continue
4545 */
4546 return 1;
dea31012005-04-17 16:05:31 -05004547 }
4548
James Smart2e0fef82007-06-17 19:56:36 -05004549 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004550 return 0;
dea31012005-04-17 16:05:31 -05004551}
4552
James Smarte59058c2008-08-24 21:49:00 -04004553/**
James Smart3621a712009-04-06 18:47:14 -04004554 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004555 * @vport: pointer to a host virtual N_Port data structure.
4556 * @cmdiocb: pointer to lpfc command iocb data structure.
4557 * @ndlp: pointer to a node-list data structure.
4558 *
4559 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4560 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4561 * point topology. As an unsolicited FLOGI should not be received in a loop
4562 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4563 * lpfc_check_sparm() routine is invoked to check the parameters in the
4564 * unsolicited FLOGI. If parameters validation failed, the routine
4565 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4566 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4567 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4568 * will initiate PLOGI. The higher lexicographical value party shall has
4569 * higher priority (as the winning port) and will initiate PLOGI and
4570 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4571 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4572 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4573 *
4574 * Return code
4575 * 0 - Successfully processed the unsolicited flogi
4576 * 1 - Failed to process the unsolicited flogi
4577 **/
dea31012005-04-17 16:05:31 -05004578static int
James Smart2e0fef82007-06-17 19:56:36 -05004579lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004580 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004581{
James Smart2e0fef82007-06-17 19:56:36 -05004582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4583 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004584 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4585 uint32_t *lp = (uint32_t *) pcmd->virt;
4586 IOCB_t *icmd = &cmdiocb->iocb;
4587 struct serv_parm *sp;
4588 LPFC_MBOXQ_t *mbox;
4589 struct ls_rjt stat;
4590 uint32_t cmd, did;
4591 int rc;
4592
4593 cmd = *lp++;
4594 sp = (struct serv_parm *) lp;
4595
4596 /* FLOGI received */
4597
James Smart2e0fef82007-06-17 19:56:36 -05004598 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004599
4600 if (phba->fc_topology == TOPOLOGY_LOOP) {
4601 /* We should never receive a FLOGI in loop mode, ignore it */
4602 did = icmd->un.elsreq64.remoteID;
4603
4604 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4605 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004606 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4607 "0113 An FLOGI ELS command x%x was "
4608 "received from DID x%x in Loop Mode\n",
4609 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004610 return 1;
dea31012005-04-17 16:05:31 -05004611 }
4612
4613 did = Fabric_DID;
4614
James Smart341af102010-01-26 23:07:37 -05004615 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004616 /* For a FLOGI we accept, then if our portname is greater
4617 * then the remote portname we initiate Nport login.
4618 */
4619
James Smart2e0fef82007-06-17 19:56:36 -05004620 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004621 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004622
4623 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004624 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4625 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004626 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004627
dea31012005-04-17 16:05:31 -05004628 lpfc_linkdown(phba);
4629 lpfc_init_link(phba, mbox,
4630 phba->cfg_topology,
4631 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004632 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004633 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004634 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004635 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004636 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004637 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004638 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004639 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004640 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004641 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004642 spin_lock_irq(shost->host_lock);
4643 vport->fc_flag |= FC_PT2PT_PLOGI;
4644 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004645 }
James Smart2e0fef82007-06-17 19:56:36 -05004646 spin_lock_irq(shost->host_lock);
4647 vport->fc_flag |= FC_PT2PT;
4648 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4649 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004650 } else {
4651 /* Reject this request because invalid parameters */
4652 stat.un.b.lsRjtRsvd0 = 0;
4653 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4654 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4655 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004656 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4657 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004658 return 1;
dea31012005-04-17 16:05:31 -05004659 }
4660
4661 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004662 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004663
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004664 return 0;
dea31012005-04-17 16:05:31 -05004665}
4666
James Smarte59058c2008-08-24 21:49:00 -04004667/**
James Smart3621a712009-04-06 18:47:14 -04004668 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004669 * @vport: pointer to a host virtual N_Port data structure.
4670 * @cmdiocb: pointer to lpfc command iocb data structure.
4671 * @ndlp: pointer to a node-list data structure.
4672 *
4673 * This routine processes Request Node Identification Data (RNID) IOCB
4674 * received as an ELS unsolicited event. Only when the RNID specified format
4675 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4676 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4677 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4678 * rejected by invoking the lpfc_els_rsp_reject() routine.
4679 *
4680 * Return code
4681 * 0 - Successfully processed rnid iocb (currently always return 0)
4682 **/
dea31012005-04-17 16:05:31 -05004683static int
James Smart2e0fef82007-06-17 19:56:36 -05004684lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4685 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004686{
4687 struct lpfc_dmabuf *pcmd;
4688 uint32_t *lp;
4689 IOCB_t *icmd;
4690 RNID *rn;
4691 struct ls_rjt stat;
4692 uint32_t cmd, did;
4693
4694 icmd = &cmdiocb->iocb;
4695 did = icmd->un.elsreq64.remoteID;
4696 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4697 lp = (uint32_t *) pcmd->virt;
4698
4699 cmd = *lp++;
4700 rn = (RNID *) lp;
4701
4702 /* RNID received */
4703
4704 switch (rn->Format) {
4705 case 0:
4706 case RNID_TOPOLOGY_DISC:
4707 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004708 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004709 break;
4710 default:
4711 /* Reject this request because format not supported */
4712 stat.un.b.lsRjtRsvd0 = 0;
4713 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4714 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4715 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004716 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4717 NULL);
dea31012005-04-17 16:05:31 -05004718 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004719 return 0;
dea31012005-04-17 16:05:31 -05004720}
4721
James Smarte59058c2008-08-24 21:49:00 -04004722/**
James Smart12265f62010-10-22 11:05:53 -04004723 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4724 * @vport: pointer to a host virtual N_Port data structure.
4725 * @cmdiocb: pointer to lpfc command iocb data structure.
4726 * @ndlp: pointer to a node-list data structure.
4727 *
4728 * Return code
4729 * 0 - Successfully processed echo iocb (currently always return 0)
4730 **/
4731static int
4732lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4733 struct lpfc_nodelist *ndlp)
4734{
4735 uint8_t *pcmd;
4736
4737 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4738
4739 /* skip over first word of echo command to find echo data */
4740 pcmd += sizeof(uint32_t);
4741
4742 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4743 return 0;
4744}
4745
4746/**
James Smart3621a712009-04-06 18:47:14 -04004747 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004748 * @vport: pointer to a host virtual N_Port data structure.
4749 * @cmdiocb: pointer to lpfc command iocb data structure.
4750 * @ndlp: pointer to a node-list data structure.
4751 *
4752 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4753 * received as an ELS unsolicited event. Currently, this function just invokes
4754 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4755 *
4756 * Return code
4757 * 0 - Successfully processed lirr iocb (currently always return 0)
4758 **/
dea31012005-04-17 16:05:31 -05004759static int
James Smart2e0fef82007-06-17 19:56:36 -05004760lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4761 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004762{
4763 struct ls_rjt stat;
4764
4765 /* For now, unconditionally reject this command */
4766 stat.un.b.lsRjtRsvd0 = 0;
4767 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4768 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4769 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004770 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004771 return 0;
4772}
4773
James Smarte59058c2008-08-24 21:49:00 -04004774/**
James Smart5ffc2662009-11-18 15:39:44 -05004775 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4776 * @vport: pointer to a host virtual N_Port data structure.
4777 * @cmdiocb: pointer to lpfc command iocb data structure.
4778 * @ndlp: pointer to a node-list data structure.
4779 *
4780 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4781 * received as an ELS unsolicited event. A request to RRQ shall only
4782 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4783 * Nx_Port N_Port_ID of the target Exchange is the same as the
4784 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4785 * not accepted, an LS_RJT with reason code "Unable to perform
4786 * command request" and reason code explanation "Invalid Originator
4787 * S_ID" shall be returned. For now, we just unconditionally accept
4788 * RRQ from the target.
4789 **/
4790static void
4791lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4792 struct lpfc_nodelist *ndlp)
4793{
4794 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4795}
4796
4797/**
James Smart12265f62010-10-22 11:05:53 -04004798 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4799 * @phba: pointer to lpfc hba data structure.
4800 * @pmb: pointer to the driver internal queue element for mailbox command.
4801 *
4802 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4803 * mailbox command. This callback function is to actually send the Accept
4804 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4805 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4806 * mailbox command, constructs the RPS response with the link statistics
4807 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4808 * response to the RPS.
4809 *
4810 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4811 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4812 * will be stored into the context1 field of the IOCB for the completion
4813 * callback function to the RPS Accept Response ELS IOCB command.
4814 *
4815 **/
4816static void
4817lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4818{
4819 MAILBOX_t *mb;
4820 IOCB_t *icmd;
4821 struct RLS_RSP *rls_rsp;
4822 uint8_t *pcmd;
4823 struct lpfc_iocbq *elsiocb;
4824 struct lpfc_nodelist *ndlp;
4825 uint16_t xri;
4826 uint32_t cmdsize;
4827
4828 mb = &pmb->u.mb;
4829
4830 ndlp = (struct lpfc_nodelist *) pmb->context2;
4831 xri = (uint16_t) ((unsigned long)(pmb->context1));
4832 pmb->context1 = NULL;
4833 pmb->context2 = NULL;
4834
4835 if (mb->mbxStatus) {
4836 mempool_free(pmb, phba->mbox_mem_pool);
4837 return;
4838 }
4839
4840 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4841 mempool_free(pmb, phba->mbox_mem_pool);
4842 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4843 lpfc_max_els_tries, ndlp,
4844 ndlp->nlp_DID, ELS_CMD_ACC);
4845
4846 /* Decrement the ndlp reference count from previous mbox command */
4847 lpfc_nlp_put(ndlp);
4848
4849 if (!elsiocb)
4850 return;
4851
4852 icmd = &elsiocb->iocb;
4853 icmd->ulpContext = xri;
4854
4855 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4857 pcmd += sizeof(uint32_t); /* Skip past command */
4858 rls_rsp = (struct RLS_RSP *)pcmd;
4859
4860 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4861 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4862 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4863 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4864 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4865 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
4866
4867 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
4868 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4869 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
4870 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4871 elsiocb->iotag, elsiocb->iocb.ulpContext,
4872 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4873 ndlp->nlp_rpi);
4874 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4875 phba->fc_stat.elsXmitACC++;
4876 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
4877 lpfc_els_free_iocb(phba, elsiocb);
4878}
4879
4880/**
James Smart3621a712009-04-06 18:47:14 -04004881 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004882 * @phba: pointer to lpfc hba data structure.
4883 * @pmb: pointer to the driver internal queue element for mailbox command.
4884 *
4885 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4886 * mailbox command. This callback function is to actually send the Accept
4887 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4888 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4889 * mailbox command, constructs the RPS response with the link statistics
4890 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4891 * response to the RPS.
4892 *
4893 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4894 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4895 * will be stored into the context1 field of the IOCB for the completion
4896 * callback function to the RPS Accept Response ELS IOCB command.
4897 *
4898 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004899static void
James Smart329f9bc2007-04-25 09:53:01 -04004900lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004901{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004902 MAILBOX_t *mb;
4903 IOCB_t *icmd;
4904 RPS_RSP *rps_rsp;
4905 uint8_t *pcmd;
4906 struct lpfc_iocbq *elsiocb;
4907 struct lpfc_nodelist *ndlp;
4908 uint16_t xri, status;
4909 uint32_t cmdsize;
4910
James Smart04c68492009-05-22 14:52:52 -04004911 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004912
4913 ndlp = (struct lpfc_nodelist *) pmb->context2;
4914 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004915 pmb->context1 = NULL;
4916 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004917
4918 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004919 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004920 return;
4921 }
4922
4923 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004924 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004925 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4926 lpfc_max_els_tries, ndlp,
4927 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004928
4929 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004930 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004931
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004932 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004933 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004934
4935 icmd = &elsiocb->iocb;
4936 icmd->ulpContext = xri;
4937
4938 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4939 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004940 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004941 rps_rsp = (RPS_RSP *)pcmd;
4942
4943 if (phba->fc_topology != TOPOLOGY_LOOP)
4944 status = 0x10;
4945 else
4946 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004947 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004948 status |= 0x4;
4949
4950 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004951 rps_rsp->portStatus = cpu_to_be16(status);
4952 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4953 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4954 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4955 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4956 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4957 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004958 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004959 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4960 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4961 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4962 elsiocb->iotag, elsiocb->iocb.ulpContext,
4963 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4964 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004965 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004966 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004967 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004968 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004969 return;
4970}
4971
James Smarte59058c2008-08-24 21:49:00 -04004972/**
James Smart12265f62010-10-22 11:05:53 -04004973 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
4974 * @vport: pointer to a host virtual N_Port data structure.
4975 * @cmdiocb: pointer to lpfc command iocb data structure.
4976 * @ndlp: pointer to a node-list data structure.
4977 *
4978 * This routine processes Read Port Status (RPL) IOCB received as an
4979 * ELS unsolicited event. It first checks the remote port state. If the
4980 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4981 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
4982 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4983 * for reading the HBA link statistics. It is for the callback function,
4984 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
4985 * to actually sending out RPL Accept (ACC) response.
4986 *
4987 * Return codes
4988 * 0 - Successfully processed rls iocb (currently always return 0)
4989 **/
4990static int
4991lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4992 struct lpfc_nodelist *ndlp)
4993{
4994 struct lpfc_hba *phba = vport->phba;
4995 LPFC_MBOXQ_t *mbox;
4996 struct lpfc_dmabuf *pcmd;
4997 struct ls_rjt stat;
4998
4999 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5000 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5001 /* reject the unsolicited RPS request and done with it */
5002 goto reject_out;
5003
5004 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5005
5006 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5007 if (mbox) {
5008 lpfc_read_lnk_stat(phba, mbox);
5009 mbox->context1 =
5010 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5011 mbox->context2 = lpfc_nlp_get(ndlp);
5012 mbox->vport = vport;
5013 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5014 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5015 != MBX_NOT_FINISHED)
5016 /* Mbox completion will send ELS Response */
5017 return 0;
5018 /* Decrement reference count used for the failed mbox
5019 * command.
5020 */
5021 lpfc_nlp_put(ndlp);
5022 mempool_free(mbox, phba->mbox_mem_pool);
5023 }
5024reject_out:
5025 /* issue rejection response */
5026 stat.un.b.lsRjtRsvd0 = 0;
5027 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5028 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5029 stat.un.b.vendorUnique = 0;
5030 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5031 return 0;
5032}
5033
5034/**
5035 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5036 * @vport: pointer to a host virtual N_Port data structure.
5037 * @cmdiocb: pointer to lpfc command iocb data structure.
5038 * @ndlp: pointer to a node-list data structure.
5039 *
5040 * This routine processes Read Timout Value (RTV) IOCB received as an
5041 * ELS unsolicited event. It first checks the remote port state. If the
5042 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5043 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5044 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5045 * Value (RTV) unsolicited IOCB event.
5046 *
5047 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5048 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5049 * will be stored into the context1 field of the IOCB for the completion
5050 * callback function to the RPS Accept Response ELS IOCB command.
5051 *
5052 * Return codes
5053 * 0 - Successfully processed rtv iocb (currently always return 0)
5054 **/
5055static int
5056lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5057 struct lpfc_nodelist *ndlp)
5058{
5059 struct lpfc_hba *phba = vport->phba;
5060 struct ls_rjt stat;
5061 struct RTV_RSP *rtv_rsp;
5062 uint8_t *pcmd;
5063 struct lpfc_iocbq *elsiocb;
5064 uint32_t cmdsize;
5065
5066
5067 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5068 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5069 /* reject the unsolicited RPS request and done with it */
5070 goto reject_out;
5071
5072 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5073 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5074 lpfc_max_els_tries, ndlp,
5075 ndlp->nlp_DID, ELS_CMD_ACC);
5076
5077 if (!elsiocb)
5078 return 1;
5079
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5081 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5082 pcmd += sizeof(uint32_t); /* Skip past command */
5083
5084 /* use the command's xri in the response */
5085 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5086
5087 rtv_rsp = (struct RTV_RSP *)pcmd;
5088
5089 /* populate RTV payload */
5090 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5091 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5092 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5093 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5094 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5095
5096 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5097 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5098 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5100 "Data: x%x x%x x%x\n",
5101 elsiocb->iotag, elsiocb->iocb.ulpContext,
5102 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5103 ndlp->nlp_rpi,
5104 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5105 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5106 phba->fc_stat.elsXmitACC++;
5107 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5108 lpfc_els_free_iocb(phba, elsiocb);
5109 return 0;
5110
5111reject_out:
5112 /* issue rejection response */
5113 stat.un.b.lsRjtRsvd0 = 0;
5114 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5115 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5116 stat.un.b.vendorUnique = 0;
5117 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5118 return 0;
5119}
5120
5121/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005122 * @vport: pointer to a host virtual N_Port data structure.
5123 * @cmdiocb: pointer to lpfc command iocb data structure.
5124 * @ndlp: pointer to a node-list data structure.
5125 *
5126 * This routine processes Read Port Status (RPS) IOCB received as an
5127 * ELS unsolicited event. It first checks the remote port state. If the
5128 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5129 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5130 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5131 * for reading the HBA link statistics. It is for the callback function,
5132 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5133 * to actually sending out RPS Accept (ACC) response.
5134 *
5135 * Return codes
5136 * 0 - Successfully processed rps iocb (currently always return 0)
5137 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005138static int
James Smart2e0fef82007-06-17 19:56:36 -05005139lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5140 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005141{
James Smart2e0fef82007-06-17 19:56:36 -05005142 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005143 uint32_t *lp;
5144 uint8_t flag;
5145 LPFC_MBOXQ_t *mbox;
5146 struct lpfc_dmabuf *pcmd;
5147 RPS *rps;
5148 struct ls_rjt stat;
5149
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005150 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005151 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5152 /* reject the unsolicited RPS request and done with it */
5153 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005154
5155 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5156 lp = (uint32_t *) pcmd->virt;
5157 flag = (be32_to_cpu(*lp++) & 0xf);
5158 rps = (RPS *) lp;
5159
5160 if ((flag == 0) ||
5161 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005162 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005163 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005164
James Smart92d7f7b2007-06-17 19:56:38 -05005165 printk("Fix me....\n");
5166 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005167 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5168 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005169 lpfc_read_lnk_stat(phba, mbox);
5170 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005171 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005172 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005173 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005174 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005175 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005176 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005177 /* Mbox completion will send ELS Response */
5178 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005179 /* Decrement reference count used for the failed mbox
5180 * command.
5181 */
James Smart329f9bc2007-04-25 09:53:01 -04005182 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005183 mempool_free(mbox, phba->mbox_mem_pool);
5184 }
5185 }
James Smart90160e02008-08-24 21:49:45 -04005186
5187reject_out:
5188 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005189 stat.un.b.lsRjtRsvd0 = 0;
5190 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5191 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5192 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005193 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005194 return 0;
5195}
5196
James Smarte59058c2008-08-24 21:49:00 -04005197/**
James Smart3621a712009-04-06 18:47:14 -04005198 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005199 * @vport: pointer to a host virtual N_Port data structure.
5200 * @cmdsize: size of the ELS command.
5201 * @oldiocb: pointer to the original lpfc command iocb data structure.
5202 * @ndlp: pointer to a node-list data structure.
5203 *
5204 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5205 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5206 *
5207 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5208 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5209 * will be stored into the context1 field of the IOCB for the completion
5210 * callback function to the RPL Accept Response ELS command.
5211 *
5212 * Return code
5213 * 0 - Successfully issued ACC RPL ELS command
5214 * 1 - Failed to issue ACC RPL ELS command
5215 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005216static int
James Smart2e0fef82007-06-17 19:56:36 -05005217lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5218 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005219{
James Smart2e0fef82007-06-17 19:56:36 -05005220 struct lpfc_hba *phba = vport->phba;
5221 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005222 RPL_RSP rpl_rsp;
5223 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005224 uint8_t *pcmd;
5225
James Smart2e0fef82007-06-17 19:56:36 -05005226 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5227 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005228
James Smart488d1462006-03-07 15:02:37 -05005229 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005230 return 1;
James Smart488d1462006-03-07 15:02:37 -05005231
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005232 icmd = &elsiocb->iocb;
5233 oldcmd = &oldiocb->iocb;
5234 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5235
5236 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5237 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005238 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005239 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5240 pcmd += sizeof(uint16_t);
5241
5242 /* Setup the RPL ACC payload */
5243 rpl_rsp.listLen = be32_to_cpu(1);
5244 rpl_rsp.index = 0;
5245 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005246 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5247 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005248 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005249 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005250 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005251 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5252 "0120 Xmit ELS RPL ACC response tag x%x "
5253 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5254 "rpi x%x\n",
5255 elsiocb->iotag, elsiocb->iocb.ulpContext,
5256 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5257 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005258 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005259 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005260 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5261 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005262 lpfc_els_free_iocb(phba, elsiocb);
5263 return 1;
5264 }
5265 return 0;
5266}
5267
James Smarte59058c2008-08-24 21:49:00 -04005268/**
James Smart3621a712009-04-06 18:47:14 -04005269 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005270 * @vport: pointer to a host virtual N_Port data structure.
5271 * @cmdiocb: pointer to lpfc command iocb data structure.
5272 * @ndlp: pointer to a node-list data structure.
5273 *
5274 * This routine processes Read Port List (RPL) IOCB received as an ELS
5275 * unsolicited event. It first checks the remote port state. If the remote
5276 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5277 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5278 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5279 * to accept the RPL.
5280 *
5281 * Return code
5282 * 0 - Successfully processed rpl iocb (currently always return 0)
5283 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005284static int
James Smart2e0fef82007-06-17 19:56:36 -05005285lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5286 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005287{
5288 struct lpfc_dmabuf *pcmd;
5289 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005290 uint32_t maxsize;
5291 uint16_t cmdsize;
5292 RPL *rpl;
5293 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005294
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005295 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5296 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005297 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005298 stat.un.b.lsRjtRsvd0 = 0;
5299 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5300 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5301 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005302 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5303 NULL);
James Smart90160e02008-08-24 21:49:45 -04005304 /* rejected the unsolicited RPL request and done with it */
5305 return 0;
dea31012005-04-17 16:05:31 -05005306 }
5307
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005308 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5309 lp = (uint32_t *) pcmd->virt;
5310 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005311 maxsize = be32_to_cpu(rpl->maxsize);
5312
5313 /* We support only one port */
5314 if ((rpl->index == 0) &&
5315 ((maxsize == 0) ||
5316 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5317 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005318 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005319 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5320 }
James Smart2e0fef82007-06-17 19:56:36 -05005321 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005322
5323 return 0;
5324}
5325
James Smarte59058c2008-08-24 21:49:00 -04005326/**
James Smart3621a712009-04-06 18:47:14 -04005327 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005328 * @vport: pointer to a virtual N_Port data structure.
5329 * @cmdiocb: pointer to lpfc command iocb data structure.
5330 * @ndlp: pointer to a node-list data structure.
5331 *
5332 * This routine processes Fibre Channel Address Resolution Protocol
5333 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5334 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5335 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5336 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5337 * remote PortName is compared against the FC PortName stored in the @vport
5338 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5339 * compared against the FC NodeName stored in the @vport data structure.
5340 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5341 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5342 * invoked to send out FARP Response to the remote node. Before sending the
5343 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5344 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5345 * routine is invoked to log into the remote port first.
5346 *
5347 * Return code
5348 * 0 - Either the FARP Match Mode not supported or successfully processed
5349 **/
dea31012005-04-17 16:05:31 -05005350static int
James Smart2e0fef82007-06-17 19:56:36 -05005351lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5352 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005353{
5354 struct lpfc_dmabuf *pcmd;
5355 uint32_t *lp;
5356 IOCB_t *icmd;
5357 FARP *fp;
5358 uint32_t cmd, cnt, did;
5359
5360 icmd = &cmdiocb->iocb;
5361 did = icmd->un.elsreq64.remoteID;
5362 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5363 lp = (uint32_t *) pcmd->virt;
5364
5365 cmd = *lp++;
5366 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005367 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005368 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5369 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005370 /* We will only support match on WWPN or WWNN */
5371 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005372 return 0;
dea31012005-04-17 16:05:31 -05005373 }
5374
5375 cnt = 0;
5376 /* If this FARP command is searching for my portname */
5377 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005378 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005379 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005380 cnt = 1;
5381 }
5382
5383 /* If this FARP command is searching for my nodename */
5384 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005385 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005386 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005387 cnt = 1;
5388 }
5389
5390 if (cnt) {
5391 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5392 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5393 /* Log back into the node before sending the FARP. */
5394 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005395 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005396 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005397 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005398 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005399 }
5400
5401 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005402 if (fp->Rflags & FARP_REQUEST_FARPR)
5403 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005404 }
5405 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005406 return 0;
dea31012005-04-17 16:05:31 -05005407}
5408
James Smarte59058c2008-08-24 21:49:00 -04005409/**
James Smart3621a712009-04-06 18:47:14 -04005410 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005411 * @vport: pointer to a host virtual N_Port data structure.
5412 * @cmdiocb: pointer to lpfc command iocb data structure.
5413 * @ndlp: pointer to a node-list data structure.
5414 *
5415 * This routine processes Fibre Channel Address Resolution Protocol
5416 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5417 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5418 * the FARP response request.
5419 *
5420 * Return code
5421 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5422 **/
dea31012005-04-17 16:05:31 -05005423static int
James Smart2e0fef82007-06-17 19:56:36 -05005424lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5425 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005426{
5427 struct lpfc_dmabuf *pcmd;
5428 uint32_t *lp;
5429 IOCB_t *icmd;
5430 uint32_t cmd, did;
5431
5432 icmd = &cmdiocb->iocb;
5433 did = icmd->un.elsreq64.remoteID;
5434 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5435 lp = (uint32_t *) pcmd->virt;
5436
5437 cmd = *lp++;
5438 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005439 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5440 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005441 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005442 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005443
5444 return 0;
5445}
5446
James Smarte59058c2008-08-24 21:49:00 -04005447/**
James Smart3621a712009-04-06 18:47:14 -04005448 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005449 * @vport: pointer to a host virtual N_Port data structure.
5450 * @cmdiocb: pointer to lpfc command iocb data structure.
5451 * @fan_ndlp: pointer to a node-list data structure.
5452 *
5453 * This routine processes a Fabric Address Notification (FAN) IOCB
5454 * command received as an ELS unsolicited event. The FAN ELS command will
5455 * only be processed on a physical port (i.e., the @vport represents the
5456 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5457 * compared against those in the phba data structure. If any of those is
5458 * different, the lpfc_initial_flogi() routine is invoked to initialize
5459 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5460 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5461 * is invoked to register login to the fabric.
5462 *
5463 * Return code
5464 * 0 - Successfully processed fan iocb (currently always return 0).
5465 **/
dea31012005-04-17 16:05:31 -05005466static int
James Smart2e0fef82007-06-17 19:56:36 -05005467lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5468 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005469{
James Smart2e0fef82007-06-17 19:56:36 -05005470 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005471 uint32_t *lp;
5472 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005473
James Smart0d2b6b82008-06-14 22:52:47 -04005474 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5475 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5476 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005477 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005478 if ((vport == phba->pport) &&
5479 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005480 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005481 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005482 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005483 sizeof(struct lpfc_name)))) {
5484 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005485 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005486 } else {
5487 /* FAN verified - skip FLOGI */
5488 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005489 if (phba->sli_rev < LPFC_SLI_REV4)
5490 lpfc_issue_fabric_reglogin(vport);
5491 else
5492 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005493 }
dea31012005-04-17 16:05:31 -05005494 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005495 return 0;
dea31012005-04-17 16:05:31 -05005496}
5497
James Smarte59058c2008-08-24 21:49:00 -04005498/**
James Smart3621a712009-04-06 18:47:14 -04005499 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005500 * @ptr: holder for the timer function associated data.
5501 *
5502 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5503 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5504 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5505 * up the worker thread. It is for the worker thread to invoke the routine
5506 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5507 **/
dea31012005-04-17 16:05:31 -05005508void
5509lpfc_els_timeout(unsigned long ptr)
5510{
James Smart2e0fef82007-06-17 19:56:36 -05005511 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5512 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005513 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005514 unsigned long iflag;
5515
James Smart2e0fef82007-06-17 19:56:36 -05005516 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005517 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5518 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005519 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005520 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005521
James Smart5e9d9b82008-06-14 22:52:53 -04005522 if (!tmo_posted)
5523 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005524 return;
5525}
5526
James Smart2a9bf3d2010-06-07 15:24:45 -04005527
James Smarte59058c2008-08-24 21:49:00 -04005528/**
James Smart3621a712009-04-06 18:47:14 -04005529 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005530 * @vport: pointer to a virtual N_Port data structure.
5531 *
5532 * This routine is the actual handler function that processes an ELS timeout
5533 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5534 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5535 * invoking the lpfc_sli_issue_abort_iotag() routine.
5536 **/
dea31012005-04-17 16:05:31 -05005537void
James Smart2e0fef82007-06-17 19:56:36 -05005538lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005539{
James Smart2e0fef82007-06-17 19:56:36 -05005540 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005541 struct lpfc_sli_ring *pring;
5542 struct lpfc_iocbq *tmp_iocb, *piocb;
5543 IOCB_t *cmd = NULL;
5544 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005545 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005546 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005547 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005548 LIST_HEAD(txcmplq_completions);
5549 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005550
James Smart2a9bf3d2010-06-07 15:24:45 -04005551
dea31012005-04-17 16:05:31 -05005552 timeout = (uint32_t)(phba->fc_ratov << 1);
5553
5554 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005555
James Smart2a9bf3d2010-06-07 15:24:45 -04005556 spin_lock_irq(&phba->hbalock);
5557 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5558 spin_unlock_irq(&phba->hbalock);
5559
5560 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005561 cmd = &piocb->iocb;
5562
James Smart2e0fef82007-06-17 19:56:36 -05005563 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5564 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5565 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005566 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005567
5568 if (piocb->vport != vport)
5569 continue;
5570
dea31012005-04-17 16:05:31 -05005571 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005572 if (pcmd)
5573 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005574
James Smart92d7f7b2007-06-17 19:56:38 -05005575 if (els_command == ELS_CMD_FARP ||
5576 els_command == ELS_CMD_FARPR ||
5577 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005578 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005579
dea31012005-04-17 16:05:31 -05005580 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005581 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005582 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005583 else
dea31012005-04-17 16:05:31 -05005584 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005585 continue;
5586 }
5587
James Smart2e0fef82007-06-17 19:56:36 -05005588 remote_ID = 0xffffffff;
5589 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005590 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005591 else {
5592 struct lpfc_nodelist *ndlp;
5593 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005594 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005595 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005596 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005597 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005598 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005599 spin_lock_irq(&phba->hbalock);
5600 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005601 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005602
James Smart2a9bf3d2010-06-07 15:24:45 -04005603 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5604 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5605 "0127 ELS timeout Data: x%x x%x x%x "
5606 "x%x\n", els_command,
5607 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5608 spin_lock_irq(&phba->hbalock);
5609 list_del_init(&piocb->dlist);
5610 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5611 spin_unlock_irq(&phba->hbalock);
5612 }
5613
James Smart2e0fef82007-06-17 19:56:36 -05005614 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5615 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005616}
5617
James Smarte59058c2008-08-24 21:49:00 -04005618/**
James Smart3621a712009-04-06 18:47:14 -04005619 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005620 * @vport: pointer to a host virtual N_Port data structure.
5621 *
5622 * This routine is used to clean up all the outstanding ELS commands on a
5623 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5624 * routine. After that, it walks the ELS transmit queue to remove all the
5625 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5626 * the IOCBs with a non-NULL completion callback function, the callback
5627 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5628 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5629 * callback function, the IOCB will simply be released. Finally, it walks
5630 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5631 * completion queue IOCB that is associated with the @vport and is not
5632 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5633 * part of the discovery state machine) out to HBA by invoking the
5634 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5635 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5636 * the IOCBs are aborted when this function returns.
5637 **/
dea31012005-04-17 16:05:31 -05005638void
James Smart2e0fef82007-06-17 19:56:36 -05005639lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005640{
James Smart2534ba72007-04-25 09:52:20 -04005641 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005642 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005643 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005644 struct lpfc_iocbq *tmp_iocb, *piocb;
5645 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005646
5647 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005648
James Smart2e0fef82007-06-17 19:56:36 -05005649 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005650 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5651 cmd = &piocb->iocb;
5652
5653 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5654 continue;
5655 }
5656
5657 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005658 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5659 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5660 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5661 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005662 continue;
dea31012005-04-17 16:05:31 -05005663
James Smart2e0fef82007-06-17 19:56:36 -05005664 if (piocb->vport != vport)
5665 continue;
5666
James Smart2534ba72007-04-25 09:52:20 -04005667 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005668 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005669 }
5670
5671 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005672 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5673 continue;
5674 }
dea31012005-04-17 16:05:31 -05005675
James Smart2e0fef82007-06-17 19:56:36 -05005676 if (piocb->vport != vport)
5677 continue;
5678
James Smart07951072007-04-25 09:51:38 -04005679 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005680 }
James Smart2e0fef82007-06-17 19:56:36 -05005681 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005682
James Smarta257bf92009-04-06 18:48:10 -04005683 /* Cancell all the IOCBs from the completions list */
5684 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5685 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005686
dea31012005-04-17 16:05:31 -05005687 return;
5688}
5689
James Smarte59058c2008-08-24 21:49:00 -04005690/**
James Smart3621a712009-04-06 18:47:14 -04005691 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005692 * @phba: pointer to lpfc hba data structure.
5693 *
5694 * This routine is used to clean up all the outstanding ELS commands on a
5695 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5696 * routine. After that, it walks the ELS transmit queue to remove all the
5697 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5698 * the IOCBs with the completion callback function associated, the callback
5699 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5700 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5701 * callback function associated, the IOCB will simply be released. Finally,
5702 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5703 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5704 * management plane IOCBs that are not part of the discovery state machine)
5705 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5706 **/
James Smart549e55c2007-08-02 11:09:51 -04005707void
5708lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5709{
5710 LIST_HEAD(completions);
5711 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5712 struct lpfc_iocbq *tmp_iocb, *piocb;
5713 IOCB_t *cmd = NULL;
5714
5715 lpfc_fabric_abort_hba(phba);
5716 spin_lock_irq(&phba->hbalock);
5717 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5718 cmd = &piocb->iocb;
5719 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5720 continue;
5721 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5722 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5723 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5724 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5725 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5726 continue;
5727 list_move_tail(&piocb->list, &completions);
5728 pring->txq_cnt--;
5729 }
5730 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5731 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5732 continue;
5733 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5734 }
5735 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005736
5737 /* Cancel all the IOCBs from the completions list */
5738 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5739 IOERR_SLI_ABORTED);
5740
James Smart549e55c2007-08-02 11:09:51 -04005741 return;
5742}
5743
James Smarte59058c2008-08-24 21:49:00 -04005744/**
James Smart3621a712009-04-06 18:47:14 -04005745 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005746 * @phba: Pointer to hba context object.
5747 * @cmdiocbp: Pointer to command iocb which reported error.
5748 * @rspiocbp: Pointer to response iocb which reported error.
5749 *
5750 * This function sends an event when there is an ELS command
5751 * failure.
5752 **/
5753void
5754lpfc_send_els_failure_event(struct lpfc_hba *phba,
5755 struct lpfc_iocbq *cmdiocbp,
5756 struct lpfc_iocbq *rspiocbp)
5757{
5758 struct lpfc_vport *vport = cmdiocbp->vport;
5759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5760 struct lpfc_lsrjt_event lsrjt_event;
5761 struct lpfc_fabric_event_header fabric_event;
5762 struct ls_rjt stat;
5763 struct lpfc_nodelist *ndlp;
5764 uint32_t *pcmd;
5765
5766 ndlp = cmdiocbp->context1;
5767 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5768 return;
5769
5770 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5771 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5772 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5773 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5774 sizeof(struct lpfc_name));
5775 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5776 sizeof(struct lpfc_name));
5777 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5778 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04005779 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04005780 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5781 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5782 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5783 fc_host_post_vendor_event(shost,
5784 fc_get_event_number(),
5785 sizeof(lsrjt_event),
5786 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005787 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005788 return;
5789 }
5790 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5791 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5792 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5793 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5794 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5795 else
5796 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5797 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5798 sizeof(struct lpfc_name));
5799 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5800 sizeof(struct lpfc_name));
5801 fc_host_post_vendor_event(shost,
5802 fc_get_event_number(),
5803 sizeof(fabric_event),
5804 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005805 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005806 return;
5807 }
5808
5809}
5810
5811/**
James Smart3621a712009-04-06 18:47:14 -04005812 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005813 * @vport: Pointer to vport object.
5814 * @ndlp: Pointer FC node object.
5815 * @cmd: ELS command code.
5816 *
5817 * This function posts an event when there is an incoming
5818 * unsolicited ELS command.
5819 **/
5820static void
5821lpfc_send_els_event(struct lpfc_vport *vport,
5822 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005823 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005824{
James Smartddcc50f2008-12-04 22:38:46 -05005825 struct lpfc_els_event_header *els_data = NULL;
5826 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005827 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5828
James Smartddcc50f2008-12-04 22:38:46 -05005829 if (*payload == ELS_CMD_LOGO) {
5830 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5831 if (!logo_data) {
5832 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5833 "0148 Failed to allocate memory "
5834 "for LOGO event\n");
5835 return;
5836 }
5837 els_data = &logo_data->header;
5838 } else {
5839 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5840 GFP_KERNEL);
5841 if (!els_data) {
5842 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5843 "0149 Failed to allocate memory "
5844 "for ELS event\n");
5845 return;
5846 }
5847 }
5848 els_data->event_type = FC_REG_ELS_EVENT;
5849 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005850 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005851 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005852 break;
5853 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005854 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005855 break;
5856 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005857 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5858 break;
5859 case ELS_CMD_LOGO:
5860 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5861 /* Copy the WWPN in the LOGO payload */
5862 memcpy(logo_data->logo_wwpn, &payload[2],
5863 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005864 break;
5865 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005866 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005867 return;
5868 }
James Smartddcc50f2008-12-04 22:38:46 -05005869 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5870 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5871 if (*payload == ELS_CMD_LOGO) {
5872 fc_host_post_vendor_event(shost,
5873 fc_get_event_number(),
5874 sizeof(struct lpfc_logo_event),
5875 (char *)logo_data,
5876 LPFC_NL_VENDOR_ID);
5877 kfree(logo_data);
5878 } else {
5879 fc_host_post_vendor_event(shost,
5880 fc_get_event_number(),
5881 sizeof(struct lpfc_els_event_header),
5882 (char *)els_data,
5883 LPFC_NL_VENDOR_ID);
5884 kfree(els_data);
5885 }
James Smartea2151b2008-09-07 11:52:10 -04005886
5887 return;
5888}
5889
5890
5891/**
James Smart3621a712009-04-06 18:47:14 -04005892 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005893 * @phba: pointer to lpfc hba data structure.
5894 * @pring: pointer to a SLI ring.
5895 * @vport: pointer to a host virtual N_Port data structure.
5896 * @elsiocb: pointer to lpfc els command iocb data structure.
5897 *
5898 * This routine is used for processing the IOCB associated with a unsolicited
5899 * event. It first determines whether there is an existing ndlp that matches
5900 * the DID from the unsolicited IOCB. If not, it will create a new one with
5901 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5902 * IOCB is then used to invoke the proper routine and to set up proper state
5903 * of the discovery state machine.
5904 **/
James Smarted957682007-06-17 19:56:37 -05005905static void
5906lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005907 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005908{
James Smart87af33f2007-10-27 13:37:43 -04005909 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005910 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005911 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005912 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005913 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005914 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005915
James Smarte47c9092008-02-08 18:49:26 -05005916 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005917 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005918
dea31012005-04-17 16:05:31 -05005919 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005920 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5921 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005922 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005923 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005924
James Smart858c9f62007-06-17 19:56:39 -05005925 did = icmd->un.rcvels.remoteID;
5926 if (icmd->ulpStatus) {
5927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5928 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5929 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005930 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005931 }
dea31012005-04-17 16:05:31 -05005932
5933 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005934 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005935 goto dropit;
dea31012005-04-17 16:05:31 -05005936
James Smartc8685952009-11-18 15:39:16 -05005937 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005938 if (vport->load_flag & FC_UNLOADING)
5939 goto dropit;
5940
James Smart2e0fef82007-06-17 19:56:36 -05005941 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005942 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005943 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005944 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005945 if (!ndlp)
dea31012005-04-17 16:05:31 -05005946 goto dropit;
dea31012005-04-17 16:05:31 -05005947
James Smart2e0fef82007-06-17 19:56:36 -05005948 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005949 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005950 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005951 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005952 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005953 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5954 ndlp = lpfc_enable_node(vport, ndlp,
5955 NLP_STE_UNUSED_NODE);
5956 if (!ndlp)
5957 goto dropit;
5958 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5959 newnode = 1;
5960 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5961 ndlp->nlp_type |= NLP_FABRIC;
5962 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5963 /* This is similar to the new node path */
5964 ndlp = lpfc_nlp_get(ndlp);
5965 if (!ndlp)
5966 goto dropit;
5967 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5968 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005969 }
dea31012005-04-17 16:05:31 -05005970
5971 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005972
James Smart329f9bc2007-04-25 09:53:01 -04005973 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005974 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005975
5976 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5977 cmd &= ELS_CMD_MASK;
5978 }
5979 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005980 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5981 "0112 ELS command x%x received from NPORT x%x "
5982 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005983 switch (cmd) {
5984 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005985 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5986 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5987 did, vport->port_state, ndlp->nlp_flag);
5988
dea31012005-04-17 16:05:31 -05005989 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005990 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5991
James Smartddcc50f2008-12-04 22:38:46 -05005992 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005993 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005994 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5995 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5996 rjt_err = LSRJT_UNABLE_TPC;
5997 break;
5998 }
5999 /* We get here, and drop thru, if we are PT2PT with
6000 * another NPort and the other side has initiated
6001 * the PLOGI before responding to our FLOGI.
6002 */
dea31012005-04-17 16:05:31 -05006003 }
James Smart87af33f2007-10-27 13:37:43 -04006004
6005 shost = lpfc_shost_from_vport(vport);
6006 spin_lock_irq(shost->host_lock);
6007 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6008 spin_unlock_irq(shost->host_lock);
6009
James Smart2e0fef82007-06-17 19:56:36 -05006010 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6011 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006012
dea31012005-04-17 16:05:31 -05006013 break;
6014 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006015 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6016 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6017 did, vport->port_state, ndlp->nlp_flag);
6018
dea31012005-04-17 16:05:31 -05006019 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006020 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006021 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006022 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006023 break;
6024 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006025 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6026 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6027 did, vport->port_state, ndlp->nlp_flag);
6028
dea31012005-04-17 16:05:31 -05006029 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006030 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006031 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006032 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006033 break;
6034 }
James Smart2e0fef82007-06-17 19:56:36 -05006035 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006036 break;
6037 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006038 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6039 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6040 did, vport->port_state, ndlp->nlp_flag);
6041
dea31012005-04-17 16:05:31 -05006042 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006043 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006044 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006045 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006046 break;
6047 }
James Smart2e0fef82007-06-17 19:56:36 -05006048 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006049 break;
6050 case ELS_CMD_RSCN:
6051 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006052 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006053 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006054 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006055 break;
6056 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6058 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6059 did, vport->port_state, ndlp->nlp_flag);
6060
James Smartddcc50f2008-12-04 22:38:46 -05006061 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006062 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006063 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006064 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006065 break;
6066 }
James Smart2e0fef82007-06-17 19:56:36 -05006067 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6068 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006069 break;
6070 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006071 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6072 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6073 did, vport->port_state, ndlp->nlp_flag);
6074
dea31012005-04-17 16:05:31 -05006075 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006076 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006077 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006078 break;
6079 }
James Smart2e0fef82007-06-17 19:56:36 -05006080 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6081 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006082 break;
6083 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6085 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6086 did, vport->port_state, ndlp->nlp_flag);
6087
dea31012005-04-17 16:05:31 -05006088 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006089 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006090 break;
6091 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6093 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6094 did, vport->port_state, ndlp->nlp_flag);
6095
dea31012005-04-17 16:05:31 -05006096 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006097 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006098 break;
6099 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6101 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6102 did, vport->port_state, ndlp->nlp_flag);
6103
dea31012005-04-17 16:05:31 -05006104 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006105 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006106 break;
dea31012005-04-17 16:05:31 -05006107 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6109 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6110 did, vport->port_state, ndlp->nlp_flag);
6111
dea31012005-04-17 16:05:31 -05006112 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006113 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006114 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006115 break;
6116 }
James Smart2e0fef82007-06-17 19:56:36 -05006117 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006118 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006119 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6121 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6122 did, vport->port_state, ndlp->nlp_flag);
6123
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006124 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006125 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006126 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006127 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006128 break;
James Smart12265f62010-10-22 11:05:53 -04006129 case ELS_CMD_RLS:
6130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6131 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6132 did, vport->port_state, ndlp->nlp_flag);
6133
6134 phba->fc_stat.elsRcvRLS++;
6135 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6136 if (newnode)
6137 lpfc_nlp_put(ndlp);
6138 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006139 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006140 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6141 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6142 did, vport->port_state, ndlp->nlp_flag);
6143
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006144 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006145 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006146 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006147 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006148 break;
6149 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006150 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6151 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6152 did, vport->port_state, ndlp->nlp_flag);
6153
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006154 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006155 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006156 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006157 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006158 break;
dea31012005-04-17 16:05:31 -05006159 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6161 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6162 did, vport->port_state, ndlp->nlp_flag);
6163
dea31012005-04-17 16:05:31 -05006164 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006165 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006166 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006167 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006168 break;
James Smart12265f62010-10-22 11:05:53 -04006169 case ELS_CMD_RTV:
6170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6171 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6172 did, vport->port_state, ndlp->nlp_flag);
6173 phba->fc_stat.elsRcvRTV++;
6174 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6175 if (newnode)
6176 lpfc_nlp_put(ndlp);
6177 break;
James Smart5ffc2662009-11-18 15:39:44 -05006178 case ELS_CMD_RRQ:
6179 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6180 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6181 did, vport->port_state, ndlp->nlp_flag);
6182
6183 phba->fc_stat.elsRcvRRQ++;
6184 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6185 if (newnode)
6186 lpfc_nlp_put(ndlp);
6187 break;
James Smart12265f62010-10-22 11:05:53 -04006188 case ELS_CMD_ECHO:
6189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6190 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6191 did, vport->port_state, ndlp->nlp_flag);
6192
6193 phba->fc_stat.elsRcvECHO++;
6194 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6195 if (newnode)
6196 lpfc_nlp_put(ndlp);
6197 break;
dea31012005-04-17 16:05:31 -05006198 default:
James Smart858c9f62007-06-17 19:56:39 -05006199 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6200 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6201 cmd, did, vport->port_state);
6202
dea31012005-04-17 16:05:31 -05006203 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05006204 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05006205
6206 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006207 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6208 "0115 Unknown ELS command x%x "
6209 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006210 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006211 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006212 break;
6213 }
6214
6215 /* check if need to LS_RJT received ELS cmd */
6216 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006217 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006218 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006219 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006220 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6221 NULL);
dea31012005-04-17 16:05:31 -05006222 }
6223
James Smartd7c255b2008-08-24 21:50:00 -04006224 lpfc_nlp_put(elsiocb->context1);
6225 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006226 return;
6227
6228dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006229 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006230 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6231 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006232 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006233 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006234 phba->fc_stat.elsRcvDrop++;
6235}
6236
James Smarte59058c2008-08-24 21:49:00 -04006237/**
James Smart3621a712009-04-06 18:47:14 -04006238 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006239 * @phba: pointer to lpfc hba data structure.
6240 * @vpi: host virtual N_Port identifier.
6241 *
6242 * This routine finds a vport on a HBA (referred by @phba) through a
6243 * @vpi. The function walks the HBA's vport list and returns the address
6244 * of the vport with the matching @vpi.
6245 *
6246 * Return code
6247 * NULL - No vport with the matching @vpi found
6248 * Otherwise - Address to the vport with the matching @vpi.
6249 **/
James Smart6669f9b2009-10-02 15:16:45 -04006250struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006251lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6252{
6253 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006254 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006255
James Smart549e55c2007-08-02 11:09:51 -04006256 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006257 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006258 if (vport->vpi == vpi) {
6259 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006260 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006261 }
James Smart92d7f7b2007-06-17 19:56:38 -05006262 }
James Smart549e55c2007-08-02 11:09:51 -04006263 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006264 return NULL;
6265}
James Smarted957682007-06-17 19:56:37 -05006266
James Smarte59058c2008-08-24 21:49:00 -04006267/**
James Smart3621a712009-04-06 18:47:14 -04006268 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006269 * @phba: pointer to lpfc hba data structure.
6270 * @pring: pointer to a SLI ring.
6271 * @elsiocb: pointer to lpfc els iocb data structure.
6272 *
6273 * This routine is used to process an unsolicited event received from a SLI
6274 * (Service Level Interface) ring. The actual processing of the data buffer
6275 * associated with the unsolicited event is done by invoking the routine
6276 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6277 * SLI ring on which the unsolicited event was received.
6278 **/
James Smarted957682007-06-17 19:56:37 -05006279void
6280lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6281 struct lpfc_iocbq *elsiocb)
6282{
6283 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006284 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006285 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006286 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6287 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006288
James Smartd7c255b2008-08-24 21:50:00 -04006289 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006290 elsiocb->context2 = NULL;
6291 elsiocb->context3 = NULL;
6292
6293 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6294 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6295 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6296 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006297 phba->fc_stat.NoRcvBuf++;
6298 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006299 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006300 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006301 return;
6302 }
6303
James Smart92d7f7b2007-06-17 19:56:38 -05006304 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6305 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6306 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6307 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6308 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006309 else
6310 vport = lpfc_find_vport_by_vpid(phba,
6311 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006312 }
James Smart7f5f3d02008-02-08 18:50:14 -05006313 /* If there are no BDEs associated
6314 * with this IOCB, there is nothing to do.
6315 */
James Smarted957682007-06-17 19:56:37 -05006316 if (icmd->ulpBdeCount == 0)
6317 return;
6318
James Smart7f5f3d02008-02-08 18:50:14 -05006319 /* type of ELS cmd is first 32bit word
6320 * in packet
6321 */
James Smarted957682007-06-17 19:56:37 -05006322 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006323 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006324 } else {
6325 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6326 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006327 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6328 paddr);
James Smarted957682007-06-17 19:56:37 -05006329 }
6330
James Smart92d7f7b2007-06-17 19:56:38 -05006331 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6332 /*
6333 * The different unsolicited event handlers would tell us
6334 * if they are done with "mp" by setting context2 to NULL.
6335 */
dea31012005-04-17 16:05:31 -05006336 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006337 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6338 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006339 }
James Smarted957682007-06-17 19:56:37 -05006340
6341 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006342 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006343 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006344 elsiocb->context2 = bdeBuf2;
6345 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006346 /* free mp if we are done with it */
6347 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006348 lpfc_in_buf_free(phba, elsiocb->context2);
6349 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006350 }
dea31012005-04-17 16:05:31 -05006351 }
dea31012005-04-17 16:05:31 -05006352}
James Smart92d7f7b2007-06-17 19:56:38 -05006353
James Smarte59058c2008-08-24 21:49:00 -04006354/**
James Smart3621a712009-04-06 18:47:14 -04006355 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006356 * @phba: pointer to lpfc hba data structure.
6357 * @vport: pointer to a virtual N_Port data structure.
6358 *
6359 * This routine issues a Port Login (PLOGI) to the Name Server with
6360 * State Change Request (SCR) for a @vport. This routine will create an
6361 * ndlp for the Name Server associated to the @vport if such node does
6362 * not already exist. The PLOGI to Name Server is issued by invoking the
6363 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6364 * (FDMI) is configured to the @vport, a FDMI node will be created and
6365 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6366 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006367void
6368lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6369{
6370 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6371
6372 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6373 if (!ndlp) {
6374 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6375 if (!ndlp) {
6376 if (phba->fc_topology == TOPOLOGY_LOOP) {
6377 lpfc_disc_start(vport);
6378 return;
6379 }
6380 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006381 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6382 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006383 return;
6384 }
6385 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006386 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6387 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6388 if (!ndlp) {
6389 if (phba->fc_topology == TOPOLOGY_LOOP) {
6390 lpfc_disc_start(vport);
6391 return;
6392 }
6393 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6394 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6395 "0348 NameServer login: node freed\n");
6396 return;
6397 }
James Smart92d7f7b2007-06-17 19:56:38 -05006398 }
James Smart58da1ff2008-04-07 10:15:56 -04006399 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006400
6401 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6402
6403 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6404 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006405 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6406 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006407 return;
6408 }
6409
James Smart3de2a652007-08-02 11:09:59 -04006410 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05006411 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6412 GFP_KERNEL);
6413 if (ndlp_fdmi) {
6414 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6415 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006416 lpfc_nlp_set_state(vport, ndlp_fdmi,
6417 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05006418 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
6419 0);
6420 }
6421 }
6422 return;
6423}
6424
James Smarte59058c2008-08-24 21:49:00 -04006425/**
James Smart3621a712009-04-06 18:47:14 -04006426 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006427 * @phba: pointer to lpfc hba data structure.
6428 * @pmb: pointer to the driver internal queue element for mailbox command.
6429 *
6430 * This routine is the completion callback function to register new vport
6431 * mailbox command. If the new vport mailbox command completes successfully,
6432 * the fabric registration login shall be performed on physical port (the
6433 * new vport created is actually a physical port, with VPI 0) or the port
6434 * login to Name Server for State Change Request (SCR) will be performed
6435 * on virtual port (real virtual port, with VPI greater than 0).
6436 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006437static void
6438lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6439{
6440 struct lpfc_vport *vport = pmb->vport;
6441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6442 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006443 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006444 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006445
James Smart09372822008-01-11 01:52:54 -05006446 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006447 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006448 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006449
6450 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006451 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006452 "0915 Register VPI failed : Status: x%x"
6453 " upd bit: x%x \n", mb->mbxStatus,
6454 mb->un.varRegVpi.upd);
6455 if (phba->sli_rev == LPFC_SLI_REV4 &&
6456 mb->un.varRegVpi.upd)
6457 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006458
6459 switch (mb->mbxStatus) {
6460 case 0x11: /* unsupported feature */
6461 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006462 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006463 /* giving up on vport registration */
6464 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6465 spin_lock_irq(shost->host_lock);
6466 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6467 spin_unlock_irq(shost->host_lock);
6468 lpfc_can_disctmo(vport);
6469 break;
James Smart695a8142010-01-26 23:08:03 -05006470 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6471 case 0x20:
6472 spin_lock_irq(shost->host_lock);
6473 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6474 spin_unlock_irq(shost->host_lock);
6475 lpfc_init_vpi(phba, pmb, vport->vpi);
6476 pmb->vport = vport;
6477 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6478 rc = lpfc_sli_issue_mbox(phba, pmb,
6479 MBX_NOWAIT);
6480 if (rc == MBX_NOT_FINISHED) {
6481 lpfc_printf_vlog(vport,
6482 KERN_ERR, LOG_MBOX,
6483 "2732 Failed to issue INIT_VPI"
6484 " mailbox command\n");
6485 } else {
6486 lpfc_nlp_put(ndlp);
6487 return;
6488 }
6489
James Smart92d7f7b2007-06-17 19:56:38 -05006490 default:
6491 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006492 if (phba->sli_rev == LPFC_SLI_REV4)
6493 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006494 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006495 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006496 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006497 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006498 if (vport->port_type == LPFC_PHYSICAL_PORT
6499 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart7f5f3d02008-02-08 18:50:14 -05006500 lpfc_initial_flogi(vport);
6501 else
6502 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006503 break;
6504 }
James Smart92d7f7b2007-06-17 19:56:38 -05006505 } else {
James Smart695a8142010-01-26 23:08:03 -05006506 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006507 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006508 spin_unlock_irq(shost->host_lock);
6509 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006510 if (phba->sli_rev < LPFC_SLI_REV4)
6511 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006512 else {
James Smartfc2b9892010-02-26 14:15:29 -05006513 /*
6514 * If the physical port is instantiated using
6515 * FDISC, do not start vport discovery.
6516 */
6517 if (vport->port_state != LPFC_FDISC)
6518 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006519 lpfc_do_scr_ns_plogi(phba, vport);
6520 }
6521 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006522 lpfc_do_scr_ns_plogi(phba, vport);
6523 }
James Smart38b92ef2010-08-04 16:11:39 -04006524mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006525 /* Now, we decrement the ndlp reference count held for this
6526 * callback function
6527 */
6528 lpfc_nlp_put(ndlp);
6529
James Smart92d7f7b2007-06-17 19:56:38 -05006530 mempool_free(pmb, phba->mbox_mem_pool);
6531 return;
6532}
6533
James Smarte59058c2008-08-24 21:49:00 -04006534/**
James Smart3621a712009-04-06 18:47:14 -04006535 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006536 * @phba: pointer to lpfc hba data structure.
6537 * @vport: pointer to a host virtual N_Port data structure.
6538 * @ndlp: pointer to a node-list data structure.
6539 *
6540 * This routine registers the @vport as a new virtual port with a HBA.
6541 * It is done through a registering vpi mailbox command.
6542 **/
James Smart695a8142010-01-26 23:08:03 -05006543void
James Smart92d7f7b2007-06-17 19:56:38 -05006544lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6545 struct lpfc_nodelist *ndlp)
6546{
James Smart09372822008-01-11 01:52:54 -05006547 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006548 LPFC_MBOXQ_t *mbox;
6549
6550 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6551 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006552 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006553 mbox->vport = vport;
6554 mbox->context2 = lpfc_nlp_get(ndlp);
6555 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006556 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006557 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006558 /* mailbox command not success, decrement ndlp
6559 * reference count for this command
6560 */
6561 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006562 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006563
James Smarte8b62012007-08-02 11:10:09 -04006564 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6565 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006566 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006567 }
6568 } else {
James Smarte8b62012007-08-02 11:10:09 -04006569 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6570 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006571 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006572 }
James Smartfa4066b2008-01-11 01:53:27 -05006573 return;
6574
6575mbox_err_exit:
6576 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6577 spin_lock_irq(shost->host_lock);
6578 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6579 spin_unlock_irq(shost->host_lock);
6580 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006581}
6582
James Smarte59058c2008-08-24 21:49:00 -04006583/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006584 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006585 * @phba: pointer to lpfc hba data structure.
6586 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006587 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006588 **/
6589void
James Smart0c9ab6f2010-02-26 14:15:57 -05006590lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006591{
6592 struct lpfc_vport **vports;
6593 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006594 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006595 int i;
James Smart695a8142010-01-26 23:08:03 -05006596
6597 /* Treat this failure as linkdown for all vports */
6598 link_state = phba->link_state;
6599 lpfc_linkdown(phba);
6600 phba->link_state = link_state;
6601
6602 vports = lpfc_create_vport_work_array(phba);
6603
6604 if (vports) {
6605 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6606 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6607 if (ndlp)
6608 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6609 lpfc_els_flush_cmd(vports[i]);
6610 }
6611 lpfc_destroy_vport_work_array(phba, vports);
6612 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006613}
6614
6615/**
6616 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6617 * @phba: pointer to lpfc hba data structure.
6618 *
6619 * This routine abort all pending discovery commands and
6620 * start a timer to retry FLOGI for the physical port
6621 * discovery.
6622 **/
6623void
6624lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6625{
6626 struct lpfc_nodelist *ndlp;
6627 struct Scsi_Host *shost;
6628
6629 /* Cancel the all vports retry delay retry timers */
6630 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006631
6632 /* If fabric require FLOGI, then re-instantiate physical login */
6633 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6634 if (!ndlp)
6635 return;
6636
James Smart695a8142010-01-26 23:08:03 -05006637 shost = lpfc_shost_from_vport(phba->pport);
6638 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6639 spin_lock_irq(shost->host_lock);
6640 ndlp->nlp_flag |= NLP_DELAY_TMO;
6641 spin_unlock_irq(shost->host_lock);
6642 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6643 phba->pport->port_state = LPFC_FLOGI;
6644 return;
6645}
6646
6647/**
6648 * lpfc_fabric_login_reqd - Check if FLOGI required.
6649 * @phba: pointer to lpfc hba data structure.
6650 * @cmdiocb: pointer to FDISC command iocb.
6651 * @rspiocb: pointer to FDISC response iocb.
6652 *
6653 * This routine checks if a FLOGI is reguired for FDISC
6654 * to succeed.
6655 **/
6656static int
6657lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6658 struct lpfc_iocbq *cmdiocb,
6659 struct lpfc_iocbq *rspiocb)
6660{
6661
6662 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6663 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6664 return 0;
6665 else
6666 return 1;
6667}
6668
6669/**
James Smart3621a712009-04-06 18:47:14 -04006670 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006671 * @phba: pointer to lpfc hba data structure.
6672 * @cmdiocb: pointer to lpfc command iocb data structure.
6673 * @rspiocb: pointer to lpfc response iocb data structure.
6674 *
6675 * This routine is the completion callback function to a Fabric Discover
6676 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6677 * single threaded, each FDISC completion callback function will reset
6678 * the discovery timer for all vports such that the timers will not get
6679 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6680 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6681 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6682 * assigned to the vport has been changed with the completion of the FDISC
6683 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6684 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6685 * routine is invoked to register new vport with the HBA. Otherwise, the
6686 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6687 * Server for State Change Request (SCR).
6688 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006689static void
6690lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6691 struct lpfc_iocbq *rspiocb)
6692{
6693 struct lpfc_vport *vport = cmdiocb->vport;
6694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6695 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6696 struct lpfc_nodelist *np;
6697 struct lpfc_nodelist *next_np;
6698 IOCB_t *irsp = &rspiocb->iocb;
6699 struct lpfc_iocbq *piocb;
6700
James Smarte8b62012007-08-02 11:10:09 -04006701 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6702 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6703 irsp->ulpStatus, irsp->un.ulpWord[4],
6704 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006705 /* Since all FDISCs are being single threaded, we
6706 * must reset the discovery timer for ALL vports
6707 * waiting to send FDISC when one completes.
6708 */
6709 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6710 lpfc_set_disctmo(piocb->vport);
6711 }
6712
James Smart858c9f62007-06-17 19:56:39 -05006713 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6714 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6715 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6716
James Smart92d7f7b2007-06-17 19:56:38 -05006717 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006718
6719 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6720 lpfc_retry_pport_discovery(phba);
6721 goto out;
6722 }
6723
James Smart92d7f7b2007-06-17 19:56:38 -05006724 /* Check for retry */
6725 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6726 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006727 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006728 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006729 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006730 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006731 goto fdisc_failed;
6732 }
James Smartd7c255b2008-08-24 21:50:00 -04006733 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006734 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006735 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006736 vport->fc_flag |= FC_FABRIC;
6737 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6738 vport->fc_flag |= FC_PUBLIC_LOOP;
6739 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006740
James Smartd7c255b2008-08-24 21:50:00 -04006741 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6742 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6743 if ((vport->fc_prevDID != vport->fc_myDID) &&
6744 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6745 /* If our NportID changed, we need to ensure all
6746 * remaining NPORTs get unreg_login'ed so we can
6747 * issue unreg_vpi.
6748 */
6749 list_for_each_entry_safe(np, next_np,
6750 &vport->fc_nodes, nlp_listp) {
6751 if (!NLP_CHK_NODE_ACT(ndlp) ||
6752 (np->nlp_state != NLP_STE_NPR_NODE) ||
6753 !(np->nlp_flag & NLP_NPR_ADISC))
6754 continue;
James Smart09372822008-01-11 01:52:54 -05006755 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006756 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006757 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006758 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006759 }
James Smart78730cf2010-04-06 15:06:30 -04006760 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04006761
6762 if (phba->sli_rev == LPFC_SLI_REV4)
6763 lpfc_sli4_unreg_all_rpis(vport);
6764
James Smartd7c255b2008-08-24 21:50:00 -04006765 lpfc_mbx_unreg_vpi(vport);
6766 spin_lock_irq(shost->host_lock);
6767 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05006768 if (phba->sli_rev == LPFC_SLI_REV4)
6769 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04006770 else
6771 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04006772 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04006773 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
6774 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6775 /*
6776 * Driver needs to re-reg VPI in order for f/w
6777 * to update the MAC address.
6778 */
6779 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04006780 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006781 }
6782
James Smartecfd03c2010-02-12 14:41:27 -05006783 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6784 lpfc_issue_init_vpi(vport);
6785 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006786 lpfc_register_new_vport(phba, vport, ndlp);
6787 else
6788 lpfc_do_scr_ns_plogi(phba, vport);
6789 goto out;
6790fdisc_failed:
6791 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6792 /* Cancel discovery timer */
6793 lpfc_can_disctmo(vport);
6794 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006795out:
6796 lpfc_els_free_iocb(phba, cmdiocb);
6797}
6798
James Smarte59058c2008-08-24 21:49:00 -04006799/**
James Smart3621a712009-04-06 18:47:14 -04006800 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006801 * @vport: pointer to a virtual N_Port data structure.
6802 * @ndlp: pointer to a node-list data structure.
6803 * @retry: number of retries to the command IOCB.
6804 *
6805 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6806 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6807 * routine to issue the IOCB, which makes sure only one outstanding fabric
6808 * IOCB will be sent off HBA at any given time.
6809 *
6810 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6811 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6812 * will be stored into the context1 field of the IOCB for the completion
6813 * callback function to the FDISC ELS command.
6814 *
6815 * Return code
6816 * 0 - Successfully issued fdisc iocb command
6817 * 1 - Failed to issue fdisc iocb command
6818 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006819static int
James Smart92d7f7b2007-06-17 19:56:38 -05006820lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6821 uint8_t retry)
6822{
6823 struct lpfc_hba *phba = vport->phba;
6824 IOCB_t *icmd;
6825 struct lpfc_iocbq *elsiocb;
6826 struct serv_parm *sp;
6827 uint8_t *pcmd;
6828 uint16_t cmdsize;
6829 int did = ndlp->nlp_DID;
6830 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006831
James Smart5ffc2662009-11-18 15:39:44 -05006832 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006833 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6834 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6835 ELS_CMD_FDISC);
6836 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006837 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006838 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6839 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006840 return 1;
6841 }
6842
6843 icmd = &elsiocb->iocb;
6844 icmd->un.elsreq64.myID = 0;
6845 icmd->un.elsreq64.fl = 1;
6846
James Smartf1126682009-06-10 17:22:44 -04006847 if (phba->sli_rev == LPFC_SLI_REV4) {
6848 /* FDISC needs to be 1 for WQE VPI */
6849 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6850 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6851 /* Set the ulpContext to the vpi */
6852 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6853 } else {
6854 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6855 icmd->ulpCt_h = 1;
6856 icmd->ulpCt_l = 0;
6857 }
James Smart92d7f7b2007-06-17 19:56:38 -05006858
6859 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6860 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6861 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6862 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6863 sp = (struct serv_parm *) pcmd;
6864 /* Setup CSPs accordingly for Fabric */
6865 sp->cmn.e_d_tov = 0;
6866 sp->cmn.w2.r_a_tov = 0;
6867 sp->cls1.classValid = 0;
6868 sp->cls2.seqDelivery = 1;
6869 sp->cls3.seqDelivery = 1;
6870
6871 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6872 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6873 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6874 pcmd += sizeof(uint32_t); /* Port Name */
6875 memcpy(pcmd, &vport->fc_portname, 8);
6876 pcmd += sizeof(uint32_t); /* Node Name */
6877 pcmd += sizeof(uint32_t); /* Node Name */
6878 memcpy(pcmd, &vport->fc_nodename, 8);
6879
6880 lpfc_set_disctmo(vport);
6881
6882 phba->fc_stat.elsXmitFDISC++;
6883 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6884
James Smart858c9f62007-06-17 19:56:39 -05006885 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6886 "Issue FDISC: did:x%x",
6887 did, 0, 0);
6888
James Smart92d7f7b2007-06-17 19:56:38 -05006889 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6890 if (rc == IOCB_ERROR) {
6891 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006892 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006893 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6894 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006895 return 1;
6896 }
6897 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006898 return 0;
6899}
6900
James Smarte59058c2008-08-24 21:49:00 -04006901/**
James Smart3621a712009-04-06 18:47:14 -04006902 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006903 * @phba: pointer to lpfc hba data structure.
6904 * @cmdiocb: pointer to lpfc command iocb data structure.
6905 * @rspiocb: pointer to lpfc response iocb data structure.
6906 *
6907 * This routine is the completion callback function to the issuing of a LOGO
6908 * ELS command off a vport. It frees the command IOCB and then decrement the
6909 * reference count held on ndlp for this completion function, indicating that
6910 * the reference to the ndlp is no long needed. Note that the
6911 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6912 * callback function and an additional explicit ndlp reference decrementation
6913 * will trigger the actual release of the ndlp.
6914 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006915static void
6916lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6917 struct lpfc_iocbq *rspiocb)
6918{
6919 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006920 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006921 struct lpfc_nodelist *ndlp;
6922 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006923
6924 irsp = &rspiocb->iocb;
6925 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6926 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6927 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006928
6929 lpfc_els_free_iocb(phba, cmdiocb);
6930 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006931
6932 /* Trigger the release of the ndlp after logo */
6933 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006934}
6935
James Smarte59058c2008-08-24 21:49:00 -04006936/**
James Smart3621a712009-04-06 18:47:14 -04006937 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006938 * @vport: pointer to a virtual N_Port data structure.
6939 * @ndlp: pointer to a node-list data structure.
6940 *
6941 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6942 *
6943 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6944 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6945 * will be stored into the context1 field of the IOCB for the completion
6946 * callback function to the LOGO ELS command.
6947 *
6948 * Return codes
6949 * 0 - Successfully issued logo off the @vport
6950 * 1 - Failed to issue logo off the @vport
6951 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006952int
6953lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6954{
6955 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6956 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006957 IOCB_t *icmd;
6958 struct lpfc_iocbq *elsiocb;
6959 uint8_t *pcmd;
6960 uint16_t cmdsize;
6961
6962 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6963 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6964 ELS_CMD_LOGO);
6965 if (!elsiocb)
6966 return 1;
6967
6968 icmd = &elsiocb->iocb;
6969 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6970 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6971 pcmd += sizeof(uint32_t);
6972
6973 /* Fill in LOGO payload */
6974 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6975 pcmd += sizeof(uint32_t);
6976 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6977
James Smart858c9f62007-06-17 19:56:39 -05006978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6979 "Issue LOGO npiv did:x%x flg:x%x",
6980 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6981
James Smart92d7f7b2007-06-17 19:56:38 -05006982 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6983 spin_lock_irq(shost->host_lock);
6984 ndlp->nlp_flag |= NLP_LOGO_SND;
6985 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006986 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6987 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006988 spin_lock_irq(shost->host_lock);
6989 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6990 spin_unlock_irq(shost->host_lock);
6991 lpfc_els_free_iocb(phba, elsiocb);
6992 return 1;
6993 }
6994 return 0;
6995}
6996
James Smarte59058c2008-08-24 21:49:00 -04006997/**
James Smart3621a712009-04-06 18:47:14 -04006998 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006999 * @ptr: holder for the timer function associated data.
7000 *
7001 * This routine is invoked by the fabric iocb block timer after
7002 * timeout. It posts the fabric iocb block timeout event by setting the
7003 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7004 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7005 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7006 * posted event WORKER_FABRIC_BLOCK_TMO.
7007 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007008void
7009lpfc_fabric_block_timeout(unsigned long ptr)
7010{
7011 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7012 unsigned long iflags;
7013 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007014
James Smart92d7f7b2007-06-17 19:56:38 -05007015 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7016 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7017 if (!tmo_posted)
7018 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7019 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7020
James Smart5e9d9b82008-06-14 22:52:53 -04007021 if (!tmo_posted)
7022 lpfc_worker_wake_up(phba);
7023 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007024}
7025
James Smarte59058c2008-08-24 21:49:00 -04007026/**
James Smart3621a712009-04-06 18:47:14 -04007027 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007028 * @phba: pointer to lpfc hba data structure.
7029 *
7030 * This routine issues one fabric iocb from the driver internal list to
7031 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7032 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7033 * remove one pending fabric iocb from the driver internal list and invokes
7034 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7035 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007036static void
7037lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7038{
7039 struct lpfc_iocbq *iocb;
7040 unsigned long iflags;
7041 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007042 IOCB_t *cmd;
7043
7044repeat:
7045 iocb = NULL;
7046 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007047 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007048 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7049 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7050 list);
7051 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007052 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007053 atomic_inc(&phba->fabric_iocb_count);
7054 }
7055 spin_unlock_irqrestore(&phba->hbalock, iflags);
7056 if (iocb) {
7057 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7058 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7059 iocb->iocb_flag |= LPFC_IO_FABRIC;
7060
James Smart858c9f62007-06-17 19:56:39 -05007061 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7062 "Fabric sched1: ste:x%x",
7063 iocb->vport->port_state, 0, 0);
7064
James Smart3772a992009-05-22 14:50:54 -04007065 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007066
7067 if (ret == IOCB_ERROR) {
7068 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7069 iocb->fabric_iocb_cmpl = NULL;
7070 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7071 cmd = &iocb->iocb;
7072 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7073 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7074 iocb->iocb_cmpl(phba, iocb, iocb);
7075
7076 atomic_dec(&phba->fabric_iocb_count);
7077 goto repeat;
7078 }
7079 }
7080
7081 return;
7082}
7083
James Smarte59058c2008-08-24 21:49:00 -04007084/**
James Smart3621a712009-04-06 18:47:14 -04007085 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007086 * @phba: pointer to lpfc hba data structure.
7087 *
7088 * This routine unblocks the issuing fabric iocb command. The function
7089 * will clear the fabric iocb block bit and then invoke the routine
7090 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7091 * from the driver internal fabric iocb list.
7092 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007093void
7094lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7095{
7096 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7097
7098 lpfc_resume_fabric_iocbs(phba);
7099 return;
7100}
7101
James Smarte59058c2008-08-24 21:49:00 -04007102/**
James Smart3621a712009-04-06 18:47:14 -04007103 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007104 * @phba: pointer to lpfc hba data structure.
7105 *
7106 * This routine blocks the issuing fabric iocb for a specified amount of
7107 * time (currently 100 ms). This is done by set the fabric iocb block bit
7108 * and set up a timeout timer for 100ms. When the block bit is set, no more
7109 * fabric iocb will be issued out of the HBA.
7110 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007111static void
7112lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7113{
7114 int blocked;
7115
7116 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007117 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007118 if (!blocked)
7119 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7120
7121 return;
7122}
7123
James Smarte59058c2008-08-24 21:49:00 -04007124/**
James Smart3621a712009-04-06 18:47:14 -04007125 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007126 * @phba: pointer to lpfc hba data structure.
7127 * @cmdiocb: pointer to lpfc command iocb data structure.
7128 * @rspiocb: pointer to lpfc response iocb data structure.
7129 *
7130 * This routine is the callback function that is put to the fabric iocb's
7131 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7132 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7133 * function first restores and invokes the original iocb's callback function
7134 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7135 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7136 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007137static void
7138lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7139 struct lpfc_iocbq *rspiocb)
7140{
7141 struct ls_rjt stat;
7142
7143 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7144 BUG();
7145
7146 switch (rspiocb->iocb.ulpStatus) {
7147 case IOSTAT_NPORT_RJT:
7148 case IOSTAT_FABRIC_RJT:
7149 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7150 lpfc_block_fabric_iocbs(phba);
7151 }
7152 break;
7153
7154 case IOSTAT_NPORT_BSY:
7155 case IOSTAT_FABRIC_BSY:
7156 lpfc_block_fabric_iocbs(phba);
7157 break;
7158
7159 case IOSTAT_LS_RJT:
7160 stat.un.lsRjtError =
7161 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7162 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7163 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7164 lpfc_block_fabric_iocbs(phba);
7165 break;
7166 }
7167
7168 if (atomic_read(&phba->fabric_iocb_count) == 0)
7169 BUG();
7170
7171 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7172 cmdiocb->fabric_iocb_cmpl = NULL;
7173 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7174 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7175
7176 atomic_dec(&phba->fabric_iocb_count);
7177 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007178 /* Post any pending iocbs to HBA */
7179 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007180 }
7181}
7182
James Smarte59058c2008-08-24 21:49:00 -04007183/**
James Smart3621a712009-04-06 18:47:14 -04007184 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007185 * @phba: pointer to lpfc hba data structure.
7186 * @iocb: pointer to lpfc command iocb data structure.
7187 *
7188 * This routine is used as the top-level API for issuing a fabric iocb command
7189 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7190 * function makes sure that only one fabric bound iocb will be outstanding at
7191 * any given time. As such, this function will first check to see whether there
7192 * is already an outstanding fabric iocb on the wire. If so, it will put the
7193 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7194 * issued later. Otherwise, it will issue the iocb on the wire and update the
7195 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7196 *
7197 * Note, this implementation has a potential sending out fabric IOCBs out of
7198 * order. The problem is caused by the construction of the "ready" boolen does
7199 * not include the condition that the internal fabric IOCB list is empty. As
7200 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7201 * ahead of the fabric IOCBs in the internal list.
7202 *
7203 * Return code
7204 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7205 * IOCB_ERROR - failed to issue fabric iocb
7206 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007207static int
James Smart92d7f7b2007-06-17 19:56:38 -05007208lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7209{
7210 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007211 int ready;
7212 int ret;
7213
7214 if (atomic_read(&phba->fabric_iocb_count) > 1)
7215 BUG();
7216
7217 spin_lock_irqsave(&phba->hbalock, iflags);
7218 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7219 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7220
James Smart7f5f3d02008-02-08 18:50:14 -05007221 if (ready)
7222 /* Increment fabric iocb count to hold the position */
7223 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007224 spin_unlock_irqrestore(&phba->hbalock, iflags);
7225 if (ready) {
7226 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7227 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7228 iocb->iocb_flag |= LPFC_IO_FABRIC;
7229
James Smart858c9f62007-06-17 19:56:39 -05007230 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7231 "Fabric sched2: ste:x%x",
7232 iocb->vport->port_state, 0, 0);
7233
James Smart3772a992009-05-22 14:50:54 -04007234 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007235
7236 if (ret == IOCB_ERROR) {
7237 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7238 iocb->fabric_iocb_cmpl = NULL;
7239 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7240 atomic_dec(&phba->fabric_iocb_count);
7241 }
7242 } else {
7243 spin_lock_irqsave(&phba->hbalock, iflags);
7244 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7245 spin_unlock_irqrestore(&phba->hbalock, iflags);
7246 ret = IOCB_SUCCESS;
7247 }
7248 return ret;
7249}
7250
James Smarte59058c2008-08-24 21:49:00 -04007251/**
James Smart3621a712009-04-06 18:47:14 -04007252 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007253 * @vport: pointer to a virtual N_Port data structure.
7254 *
7255 * This routine aborts all the IOCBs associated with a @vport from the
7256 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7257 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7258 * list, removes each IOCB associated with the @vport off the list, set the
7259 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7260 * associated with the IOCB.
7261 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007262static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007263{
7264 LIST_HEAD(completions);
7265 struct lpfc_hba *phba = vport->phba;
7266 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007267
7268 spin_lock_irq(&phba->hbalock);
7269 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7270 list) {
7271
7272 if (piocb->vport != vport)
7273 continue;
7274
7275 list_move_tail(&piocb->list, &completions);
7276 }
7277 spin_unlock_irq(&phba->hbalock);
7278
James Smarta257bf92009-04-06 18:48:10 -04007279 /* Cancel all the IOCBs from the completions list */
7280 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7281 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007282}
7283
James Smarte59058c2008-08-24 21:49:00 -04007284/**
James Smart3621a712009-04-06 18:47:14 -04007285 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007286 * @ndlp: pointer to a node-list data structure.
7287 *
7288 * This routine aborts all the IOCBs associated with an @ndlp from the
7289 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7290 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7291 * list, removes each IOCB associated with the @ndlp off the list, set the
7292 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7293 * associated with the IOCB.
7294 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007295void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7296{
7297 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007298 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007299 struct lpfc_iocbq *tmp_iocb, *piocb;
7300 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007301
7302 spin_lock_irq(&phba->hbalock);
7303 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7304 list) {
7305 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7306
7307 list_move_tail(&piocb->list, &completions);
7308 }
7309 }
7310 spin_unlock_irq(&phba->hbalock);
7311
James Smarta257bf92009-04-06 18:48:10 -04007312 /* Cancel all the IOCBs from the completions list */
7313 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7314 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007315}
7316
James Smarte59058c2008-08-24 21:49:00 -04007317/**
James Smart3621a712009-04-06 18:47:14 -04007318 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007319 * @phba: pointer to lpfc hba data structure.
7320 *
7321 * This routine aborts all the IOCBs currently on the driver internal
7322 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7323 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7324 * list, removes IOCBs off the list, set the status feild to
7325 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7326 * the IOCB.
7327 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007328void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7329{
7330 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007331
7332 spin_lock_irq(&phba->hbalock);
7333 list_splice_init(&phba->fabric_iocb_list, &completions);
7334 spin_unlock_irq(&phba->hbalock);
7335
James Smarta257bf92009-04-06 18:48:10 -04007336 /* Cancel all the IOCBs from the completions list */
7337 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7338 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007339}
James Smart6fb120a2009-05-22 14:52:59 -04007340
7341/**
7342 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7343 * @phba: pointer to lpfc hba data structure.
7344 * @axri: pointer to the els xri abort wcqe structure.
7345 *
7346 * This routine is invoked by the worker thread to process a SLI4 slow-path
7347 * ELS aborted xri.
7348 **/
7349void
7350lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7351 struct sli4_wcqe_xri_aborted *axri)
7352{
7353 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7354 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7355 unsigned long iflag = 0;
James Smart589a52d2010-07-14 15:30:54 -04007356 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007357
James Smart0f65ff62010-02-26 14:14:23 -05007358 spin_lock_irqsave(&phba->hbalock, iflag);
7359 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007360 list_for_each_entry_safe(sglq_entry, sglq_next,
7361 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7362 if (sglq_entry->sli4_xritag == xri) {
7363 list_del(&sglq_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04007364 list_add_tail(&sglq_entry->list,
7365 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007366 sglq_entry->state = SGL_FREED;
7367 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007368 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart589a52d2010-07-14 15:30:54 -04007369
7370 /* Check if TXQ queue needs to be serviced */
7371 if (pring->txq_cnt)
7372 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007373 return;
7374 }
7375 }
James Smart0f65ff62010-02-26 14:14:23 -05007376 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7377 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7378 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7379 spin_unlock_irqrestore(&phba->hbalock, iflag);
7380 return;
7381 }
7382 sglq_entry->state = SGL_XRI_ABORTED;
7383 spin_unlock_irqrestore(&phba->hbalock, iflag);
7384 return;
James Smart6fb120a2009-05-22 14:52:59 -04007385}