blob: c6d01f63f5571e34168b7d4a410f7fafce8a555e [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 Smart40426292010-12-15 17:58:10 -0500378 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
379 ndlp->nlp_rpi);
James Smart98c9ea52007-10-27 13:37:33 -0400380 if (rc) {
381 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500382 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400383 }
James Smart92d7f7b2007-06-17 19:56:38 -0500384
385 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
386 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500387 /* increment the reference count on ndlp to hold reference
388 * for the callback routine.
389 */
James Smart92d7f7b2007-06-17 19:56:38 -0500390 mbox->context2 = lpfc_nlp_get(ndlp);
391
James Smart0b727fe2007-10-27 13:37:25 -0400392 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400393 if (rc == MBX_NOT_FINISHED) {
394 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500395 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400396 }
James Smart92d7f7b2007-06-17 19:56:38 -0500397
398 return 0;
399
400fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500401 /* decrement the reference count on ndlp just incremented
402 * for the failed mbox command.
403 */
James Smart92d7f7b2007-06-17 19:56:38 -0500404 lpfc_nlp_put(ndlp);
405 mp = (struct lpfc_dmabuf *) mbox->context1;
406 lpfc_mbuf_free(phba, mp->virt, mp->phys);
407 kfree(mp);
408fail_free_mbox:
409 mempool_free(mbox, phba->mbox_mem_pool);
410
411fail:
412 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400413 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400414 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500415 return -ENXIO;
416}
417
James Smarte59058c2008-08-24 21:49:00 -0400418/**
James Smart6fb120a2009-05-22 14:52:59 -0400419 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
420 * @vport: pointer to a host virtual N_Port data structure.
421 *
422 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
423 * the @vport. This mailbox command is necessary for FCoE only.
424 *
425 * Return code
426 * 0 - successfully issued REG_VFI for @vport
427 * A failure code otherwise.
428 **/
429static int
430lpfc_issue_reg_vfi(struct lpfc_vport *vport)
431{
432 struct lpfc_hba *phba = vport->phba;
433 LPFC_MBOXQ_t *mboxq;
434 struct lpfc_nodelist *ndlp;
435 struct serv_parm *sp;
436 struct lpfc_dmabuf *dmabuf;
437 int rc = 0;
438
439 sp = &phba->fc_fabparam;
440 ndlp = lpfc_findnode_did(vport, Fabric_DID);
441 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
442 rc = -ENODEV;
443 goto fail;
444 }
445
446 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
447 if (!dmabuf) {
448 rc = -ENOMEM;
449 goto fail;
450 }
451 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
452 if (!dmabuf->virt) {
453 rc = -ENOMEM;
454 goto fail_free_dmabuf;
455 }
456 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
457 if (!mboxq) {
458 rc = -ENOMEM;
459 goto fail_free_coherent;
460 }
461 vport->port_state = LPFC_FABRIC_CFG_LINK;
462 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
463 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
464 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
465 mboxq->vport = vport;
466 mboxq->context1 = dmabuf;
467 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
468 if (rc == MBX_NOT_FINISHED) {
469 rc = -ENXIO;
470 goto fail_free_mbox;
471 }
472 return 0;
473
474fail_free_mbox:
475 mempool_free(mboxq, phba->mbox_mem_pool);
476fail_free_coherent:
477 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
478fail_free_dmabuf:
479 kfree(dmabuf);
480fail:
481 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
482 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
483 "0289 Issue Register VFI failed: Err %d\n", rc);
484 return rc;
485}
486
487/**
James Smart3621a712009-04-06 18:47:14 -0400488 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400489 * @vport: pointer to a host virtual N_Port data structure.
490 * @ndlp: pointer to a node-list data structure.
491 * @sp: pointer to service parameter data structure.
492 * @irsp: pointer to the IOCB within the lpfc response IOCB.
493 *
494 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
495 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
496 * port in a fabric topology. It properly sets up the parameters to the @ndlp
497 * from the IOCB response. It also check the newly assigned N_Port ID to the
498 * @vport against the previously assigned N_Port ID. If it is different from
499 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
500 * is invoked on all the remaining nodes with the @vport to unregister the
501 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
502 * is invoked to register login to the fabric.
503 *
504 * Return code
505 * 0 - Success (currently, always return 0)
506 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500507static int
James Smart2e0fef82007-06-17 19:56:36 -0500508lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
509 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500510{
James Smart2e0fef82007-06-17 19:56:36 -0500511 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
512 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500513 struct lpfc_nodelist *np;
514 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500515
James Smart2e0fef82007-06-17 19:56:36 -0500516 spin_lock_irq(shost->host_lock);
517 vport->fc_flag |= FC_FABRIC;
518 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500519
520 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
521 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
522 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
523
James Smart12265f62010-10-22 11:05:53 -0400524 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500525 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
526
James Smart76a95d72010-11-20 23:11:48 -0500527 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500528 spin_lock_irq(shost->host_lock);
529 vport->fc_flag |= FC_PUBLIC_LOOP;
530 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500531 }
532
James Smart2e0fef82007-06-17 19:56:36 -0500533 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500534 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500535 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500536 ndlp->nlp_class_sup = 0;
537 if (sp->cls1.classValid)
538 ndlp->nlp_class_sup |= FC_COS_CLASS1;
539 if (sp->cls2.classValid)
540 ndlp->nlp_class_sup |= FC_COS_CLASS2;
541 if (sp->cls3.classValid)
542 ndlp->nlp_class_sup |= FC_COS_CLASS3;
543 if (sp->cls4.classValid)
544 ndlp->nlp_class_sup |= FC_COS_CLASS4;
545 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
546 sp->cmn.bbRcvSizeLsb;
547 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
548
James Smart92d7f7b2007-06-17 19:56:38 -0500549 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
550 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400551 lpfc_printf_vlog(vport, KERN_WARNING,
552 LOG_ELS | LOG_VPORT,
553 "1816 FLOGI NPIV supported, "
554 "response data 0x%x\n",
555 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500556 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500557 } else {
558 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400559 to call reg_vnpid atleast for the physcial host */
560 lpfc_printf_vlog(vport, KERN_WARNING,
561 LOG_ELS | LOG_VPORT,
562 "1817 Fabric does not support NPIV "
563 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500564 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
565 }
566 }
567
568 if ((vport->fc_prevDID != vport->fc_myDID) &&
569 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
570
571 /* If our NportID changed, we need to ensure all
572 * remaining NPORTs get unreg_login'ed.
573 */
574 list_for_each_entry_safe(np, next_np,
575 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400576 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500577 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500578 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
579 !(np->nlp_flag & NLP_NPR_ADISC))
580 continue;
581 spin_lock_irq(shost->host_lock);
582 np->nlp_flag &= ~NLP_NPR_ADISC;
583 spin_unlock_irq(shost->host_lock);
584 lpfc_unreg_rpi(vport, np);
585 }
James Smart78730cf2010-04-06 15:06:30 -0400586 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400587
588 if (phba->sli_rev == LPFC_SLI_REV4)
589 lpfc_sli4_unreg_all_rpis(vport);
590
James Smart92d7f7b2007-06-17 19:56:38 -0500591 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
592 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500593 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500594 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500595 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500596 }
James Smartecfd03c2010-02-12 14:41:27 -0500597 /*
598 * If VPI is unreged, driver need to do INIT_VPI
599 * before re-registering
600 */
601 if (phba->sli_rev == LPFC_SLI_REV4) {
602 spin_lock_irq(shost->host_lock);
603 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
604 spin_unlock_irq(shost->host_lock);
605 }
James Smart38b92ef2010-08-04 16:11:39 -0400606 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
607 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
608 /*
609 * Driver needs to re-reg VPI in order for f/w
610 * to update the MAC address.
611 */
612 lpfc_register_new_vport(phba, vport, ndlp);
613 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500614 }
615
James Smart6fb120a2009-05-22 14:52:59 -0400616 if (phba->sli_rev < LPFC_SLI_REV4) {
617 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
618 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
619 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
620 lpfc_register_new_vport(phba, vport, ndlp);
621 else
622 lpfc_issue_fabric_reglogin(vport);
623 } else {
624 ndlp->nlp_type |= NLP_FABRIC;
625 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500626 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
627 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400628 lpfc_start_fdiscs(phba);
629 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500630 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500631 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500632 else
James Smart6fb120a2009-05-22 14:52:59 -0400633 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500634 }
dea31012005-04-17 16:05:31 -0500635 return 0;
dea31012005-04-17 16:05:31 -0500636}
James Smarte59058c2008-08-24 21:49:00 -0400637/**
James Smart3621a712009-04-06 18:47:14 -0400638 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400639 * @vport: pointer to a host virtual N_Port data structure.
640 * @ndlp: pointer to a node-list data structure.
641 * @sp: pointer to service parameter data structure.
642 *
643 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
644 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
645 * in a point-to-point topology. First, the @vport's N_Port Name is compared
646 * with the received N_Port Name: if the @vport's N_Port Name is greater than
647 * the received N_Port Name lexicographically, this node shall assign local
648 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
649 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
650 * this node shall just wait for the remote node to issue PLOGI and assign
651 * N_Port IDs.
652 *
653 * Return code
654 * 0 - Success
655 * -ENXIO - Fail
656 **/
dea31012005-04-17 16:05:31 -0500657static int
James Smart2e0fef82007-06-17 19:56:36 -0500658lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
659 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500660{
James Smart2e0fef82007-06-17 19:56:36 -0500661 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
662 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500663 LPFC_MBOXQ_t *mbox;
664 int rc;
665
James Smart2e0fef82007-06-17 19:56:36 -0500666 spin_lock_irq(shost->host_lock);
667 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
668 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500669
670 phba->fc_edtov = FF_DEF_EDTOV;
671 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500672 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500673 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500674 if (rc >= 0) {
675 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500676 spin_lock_irq(shost->host_lock);
677 vport->fc_flag |= FC_PT2PT_PLOGI;
678 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500679
680 /*
681 * N_Port ID cannot be 0, set our to LocalID the other
682 * side will be RemoteID.
683 */
684
685 /* not equal */
686 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500687 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500688
689 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
690 if (!mbox)
691 goto fail;
692
693 lpfc_config_link(phba, mbox);
694
695 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500696 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400697 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500698 if (rc == MBX_NOT_FINISHED) {
699 mempool_free(mbox, phba->mbox_mem_pool);
700 goto fail;
701 }
James Smarte47c9092008-02-08 18:49:26 -0500702 /* Decrement ndlp reference count indicating that ndlp can be
703 * safely released when other references to it are done.
704 */
James Smart329f9bc2007-04-25 09:53:01 -0400705 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500706
James Smart2e0fef82007-06-17 19:56:36 -0500707 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500708 if (!ndlp) {
709 /*
710 * Cannot find existing Fabric ndlp, so allocate a
711 * new one
712 */
713 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
714 if (!ndlp)
715 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500716 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500717 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
718 ndlp = lpfc_enable_node(vport, ndlp,
719 NLP_STE_UNUSED_NODE);
720 if(!ndlp)
721 goto fail;
dea31012005-04-17 16:05:31 -0500722 }
723
724 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500725 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500726 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500727 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500728 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
730 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500731 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500732 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500733 } else
734 /* This side will wait for the PLOGI, decrement ndlp reference
735 * count indicating that ndlp can be released when other
736 * references to it are done.
737 */
James Smart329f9bc2007-04-25 09:53:01 -0400738 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500739
James Smart09372822008-01-11 01:52:54 -0500740 /* If we are pt2pt with another NPort, force NPIV off! */
741 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
742
James Smart2e0fef82007-06-17 19:56:36 -0500743 spin_lock_irq(shost->host_lock);
744 vport->fc_flag |= FC_PT2PT;
745 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500746
747 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500748 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500749 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500750fail:
dea31012005-04-17 16:05:31 -0500751 return -ENXIO;
752}
753
James Smarte59058c2008-08-24 21:49:00 -0400754/**
James Smart3621a712009-04-06 18:47:14 -0400755 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400756 * @phba: pointer to lpfc hba data structure.
757 * @cmdiocb: pointer to lpfc command iocb data structure.
758 * @rspiocb: pointer to lpfc response iocb data structure.
759 *
760 * This routine is the top-level completion callback function for issuing
761 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
762 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
763 * retry has been made (either immediately or delayed with lpfc_els_retry()
764 * returning 1), the command IOCB will be released and function returned.
765 * If the retry attempt has been given up (possibly reach the maximum
766 * number of retries), one additional decrement of ndlp reference shall be
767 * invoked before going out after releasing the command IOCB. This will
768 * actually release the remote node (Note, lpfc_els_free_iocb() will also
769 * invoke one decrement of ndlp reference count). If no error reported in
770 * the IOCB status, the command Port ID field is used to determine whether
771 * this is a point-to-point topology or a fabric topology: if the Port ID
772 * field is assigned, it is a fabric topology; otherwise, it is a
773 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
774 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
775 * specific topology completion conditions.
776 **/
dea31012005-04-17 16:05:31 -0500777static void
James Smart329f9bc2007-04-25 09:53:01 -0400778lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
779 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500780{
James Smart2e0fef82007-06-17 19:56:36 -0500781 struct lpfc_vport *vport = cmdiocb->vport;
782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500783 IOCB_t *irsp = &rspiocb->iocb;
784 struct lpfc_nodelist *ndlp = cmdiocb->context1;
785 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
786 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500787 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500788 int rc;
789
790 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500791 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500792 /* One additional decrement on node reference count to
793 * trigger the release of the node
794 */
James Smart329f9bc2007-04-25 09:53:01 -0400795 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500796 goto out;
797 }
798
James Smart858c9f62007-06-17 19:56:39 -0500799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
800 "FLOGI cmpl: status:x%x/x%x state:x%x",
801 irsp->ulpStatus, irsp->un.ulpWord[4],
802 vport->port_state);
803
dea31012005-04-17 16:05:31 -0500804 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500805 /*
James Smarta93ff372010-10-22 11:06:08 -0400806 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500807 * due to new FCF discovery
808 */
809 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400810 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
811 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
812 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500813 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400814 "2611 FLOGI failed on FCF (x%x), "
815 "status:x%x/x%x, tmo:x%x, perform "
816 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400817 phba->fcf.current_rec.fcf_indx,
818 irsp->ulpStatus, irsp->un.ulpWord[4],
819 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500820 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400821 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
822 if (rc)
823 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500824 }
825
James Smart38b92ef2010-08-04 16:11:39 -0400826 /* FLOGI failure */
827 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
828 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
829 irsp->ulpStatus, irsp->un.ulpWord[4],
830 irsp->ulpTimeout);
831
dea31012005-04-17 16:05:31 -0500832 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500833 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500834 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500835
James Smart76a95d72010-11-20 23:11:48 -0500836 /* FLOGI failure */
837 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
838 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
839 irsp->ulpStatus, irsp->un.ulpWord[4],
840 irsp->ulpTimeout);
841
dea31012005-04-17 16:05:31 -0500842 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500843 spin_lock_irq(shost->host_lock);
844 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
845 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500846
James Smart329f9bc2007-04-25 09:53:01 -0400847 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500848 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
849 * alpa map would take too long otherwise.
850 */
851 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400852 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500853 if ((phba->sli_rev == LPFC_SLI_REV4) &&
854 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
855 (vport->fc_prevDID != vport->fc_myDID))) {
856 if (vport->fc_flag & FC_VFI_REGISTERED)
857 lpfc_sli4_unreg_all_rpis(vport);
858 lpfc_issue_reg_vfi(vport);
859 lpfc_nlp_put(ndlp);
860 goto out;
861 }
dea31012005-04-17 16:05:31 -0500862 }
dea31012005-04-17 16:05:31 -0500863 goto flogifail;
864 }
James Smart695a8142010-01-26 23:08:03 -0500865 spin_lock_irq(shost->host_lock);
866 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400867 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500868 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500869
870 /*
871 * The FLogI succeeded. Sync the data for the CPU before
872 * accessing it.
873 */
874 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
875
876 sp = prsp->virt + sizeof(uint32_t);
877
878 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400879 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200880 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400881 "Data: x%x x%x x%x x%x\n",
882 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
883 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500884
James Smart2e0fef82007-06-17 19:56:36 -0500885 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500886 /*
887 * If Common Service Parameters indicate Nport
888 * we are point to point, if Fport we are Fabric.
889 */
890 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500891 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500892 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500893 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400894 else {
895 lpfc_printf_vlog(vport, KERN_ERR,
896 LOG_FIP | LOG_ELS,
897 "2831 FLOGI response with cleared Fabric "
898 "bit fcf_index 0x%x "
899 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
900 "Fabric Name "
901 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
902 phba->fcf.current_rec.fcf_indx,
903 phba->fcf.current_rec.switch_name[0],
904 phba->fcf.current_rec.switch_name[1],
905 phba->fcf.current_rec.switch_name[2],
906 phba->fcf.current_rec.switch_name[3],
907 phba->fcf.current_rec.switch_name[4],
908 phba->fcf.current_rec.switch_name[5],
909 phba->fcf.current_rec.switch_name[6],
910 phba->fcf.current_rec.switch_name[7],
911 phba->fcf.current_rec.fabric_name[0],
912 phba->fcf.current_rec.fabric_name[1],
913 phba->fcf.current_rec.fabric_name[2],
914 phba->fcf.current_rec.fabric_name[3],
915 phba->fcf.current_rec.fabric_name[4],
916 phba->fcf.current_rec.fabric_name[5],
917 phba->fcf.current_rec.fabric_name[6],
918 phba->fcf.current_rec.fabric_name[7]);
919 lpfc_nlp_put(ndlp);
920 spin_lock_irq(&phba->hbalock);
921 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400922 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400923 spin_unlock_irq(&phba->hbalock);
924 goto out;
925 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500926 if (!rc) {
927 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400928 if (phba->hba_flag & HBA_FIP_SUPPORT)
929 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
930 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400931 "2769 FLOGI to FCF (x%x) "
932 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400933 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500934 spin_lock_irq(&phba->hbalock);
935 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400936 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500937 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500938 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500939 }
dea31012005-04-17 16:05:31 -0500940 }
941
942flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400943 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500944
James Smart858c9f62007-06-17 19:56:39 -0500945 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500946 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500947 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500948
949 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500950 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400951 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
952 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
953 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
954 (phba->link_state != LPFC_CLEAR_LA)) {
955 /* If FLOGI failed enable link interrupt. */
956 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500957 }
dea31012005-04-17 16:05:31 -0500958out:
959 lpfc_els_free_iocb(phba, cmdiocb);
960}
961
James Smarte59058c2008-08-24 21:49:00 -0400962/**
James Smart3621a712009-04-06 18:47:14 -0400963 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400964 * @vport: pointer to a host virtual N_Port data structure.
965 * @ndlp: pointer to a node-list data structure.
966 * @retry: number of retries to the command IOCB.
967 *
968 * This routine issues a Fabric Login (FLOGI) Request ELS command
969 * for a @vport. The initiator service parameters are put into the payload
970 * of the FLOGI Request IOCB and the top-level callback function pointer
971 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
972 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
973 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
974 *
975 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
976 * will be incremented by 1 for holding the ndlp and the reference to ndlp
977 * will be stored into the context1 field of the IOCB for the completion
978 * callback function to the FLOGI ELS command.
979 *
980 * Return code
981 * 0 - successfully issued flogi iocb for @vport
982 * 1 - failed to issue flogi iocb for @vport
983 **/
dea31012005-04-17 16:05:31 -0500984static int
James Smart2e0fef82007-06-17 19:56:36 -0500985lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500986 uint8_t retry)
987{
James Smart2e0fef82007-06-17 19:56:36 -0500988 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500989 struct serv_parm *sp;
990 IOCB_t *icmd;
991 struct lpfc_iocbq *elsiocb;
992 struct lpfc_sli_ring *pring;
993 uint8_t *pcmd;
994 uint16_t cmdsize;
995 uint32_t tmo;
996 int rc;
997
998 pring = &phba->sli.ring[LPFC_ELS_RING];
999
James Smart92d7f7b2007-06-17 19:56:38 -05001000 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001001 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1002 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001003
James Smart488d1462006-03-07 15:02:37 -05001004 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001005 return 1;
dea31012005-04-17 16:05:31 -05001006
1007 icmd = &elsiocb->iocb;
1008 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1009
1010 /* For FLOGI request, remainder of payload is service parameters */
1011 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001012 pcmd += sizeof(uint32_t);
1013 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001014 sp = (struct serv_parm *) pcmd;
1015
1016 /* Setup CSPs accordingly for Fabric */
1017 sp->cmn.e_d_tov = 0;
1018 sp->cmn.w2.r_a_tov = 0;
1019 sp->cls1.classValid = 0;
1020 sp->cls2.seqDelivery = 1;
1021 sp->cls3.seqDelivery = 1;
1022 if (sp->cmn.fcphLow < FC_PH3)
1023 sp->cmn.fcphLow = FC_PH3;
1024 if (sp->cmn.fcphHigh < FC_PH3)
1025 sp->cmn.fcphHigh = FC_PH3;
1026
James Smart40426292010-12-15 17:58:10 -05001027 if ((phba->sli_rev == LPFC_SLI_REV4) &&
1028 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
1029 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smart6fb120a2009-05-22 14:52:59 -04001030 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1031 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1032 /* FLOGI needs to be 3 for WQE FCFI */
1033 /* Set the fcfi to the fcfi we registered with */
1034 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1035 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001036 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001037 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1038 icmd->ulpCt_h = 1;
1039 icmd->ulpCt_l = 0;
1040 }
1041
James Smart76a95d72010-11-20 23:11:48 -05001042 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001043 icmd->un.elsreq64.myID = 0;
1044 icmd->un.elsreq64.fl = 1;
1045 }
1046
dea31012005-04-17 16:05:31 -05001047 tmo = phba->fc_ratov;
1048 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001049 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001050 phba->fc_ratov = tmo;
1051
1052 phba->fc_stat.elsXmitFLOGI++;
1053 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001054
1055 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1056 "Issue FLOGI: opt:x%x",
1057 phba->sli3_options, 0, 0);
1058
James Smart92d7f7b2007-06-17 19:56:38 -05001059 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001060 if (rc == IOCB_ERROR) {
1061 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001062 return 1;
dea31012005-04-17 16:05:31 -05001063 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001064 return 0;
dea31012005-04-17 16:05:31 -05001065}
1066
James Smarte59058c2008-08-24 21:49:00 -04001067/**
James Smart3621a712009-04-06 18:47:14 -04001068 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001069 * @phba: pointer to lpfc hba data structure.
1070 *
1071 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1072 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1073 * list and issues an abort IOCB commond on each outstanding IOCB that
1074 * contains a active Fabric_DID ndlp. Note that this function is to issue
1075 * the abort IOCB command on all the outstanding IOCBs, thus when this
1076 * function returns, it does not guarantee all the IOCBs are actually aborted.
1077 *
1078 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001079 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001080 **/
dea31012005-04-17 16:05:31 -05001081int
James Smart2e0fef82007-06-17 19:56:36 -05001082lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001083{
1084 struct lpfc_sli_ring *pring;
1085 struct lpfc_iocbq *iocb, *next_iocb;
1086 struct lpfc_nodelist *ndlp;
1087 IOCB_t *icmd;
1088
1089 /* Abort outstanding I/O on NPort <nlp_DID> */
1090 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001091 "0201 Abort outstanding I/O on NPort x%x\n",
1092 Fabric_DID);
dea31012005-04-17 16:05:31 -05001093
1094 pring = &phba->sli.ring[LPFC_ELS_RING];
1095
1096 /*
1097 * Check the txcmplq for an iocb that matches the nport the driver is
1098 * searching for.
1099 */
James Smart2e0fef82007-06-17 19:56:36 -05001100 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001101 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1102 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001103 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1104 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001105 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001106 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1107 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001108 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001109 }
1110 }
James Smart2e0fef82007-06-17 19:56:36 -05001111 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001112
1113 return 0;
1114}
1115
James Smarte59058c2008-08-24 21:49:00 -04001116/**
James Smart3621a712009-04-06 18:47:14 -04001117 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001118 * @vport: pointer to a host virtual N_Port data structure.
1119 *
1120 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1121 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1122 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1123 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1124 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1125 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1126 * @vport.
1127 *
1128 * Return code
1129 * 0 - failed to issue initial flogi for @vport
1130 * 1 - successfully issued initial flogi for @vport
1131 **/
dea31012005-04-17 16:05:31 -05001132int
James Smart2e0fef82007-06-17 19:56:36 -05001133lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001134{
James Smart2e0fef82007-06-17 19:56:36 -05001135 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001136 struct lpfc_nodelist *ndlp;
1137
James Smart98c9ea52007-10-27 13:37:33 -04001138 vport->port_state = LPFC_FLOGI;
1139 lpfc_set_disctmo(vport);
1140
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001141 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001142 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001143 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001144 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001145 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1146 if (!ndlp)
1147 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001148 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001149 /* Set the node type */
1150 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001151 /* Put ndlp onto node list */
1152 lpfc_enqueue_node(vport, ndlp);
1153 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1154 /* re-setup ndlp without removing from node list */
1155 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1156 if (!ndlp)
1157 return 0;
dea31012005-04-17 16:05:31 -05001158 }
James Smart87af33f2007-10-27 13:37:43 -04001159
James Smart5ac6b302010-10-22 11:05:36 -04001160 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001161 /* This decrement of reference count to node shall kick off
1162 * the release of the node.
1163 */
James Smart329f9bc2007-04-25 09:53:01 -04001164 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001165 return 0;
1166 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001167 return 1;
dea31012005-04-17 16:05:31 -05001168}
1169
James Smarte59058c2008-08-24 21:49:00 -04001170/**
James Smart3621a712009-04-06 18:47:14 -04001171 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001172 * @vport: pointer to a host virtual N_Port data structure.
1173 *
1174 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1175 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1176 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1177 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1178 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1179 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1180 * @vport.
1181 *
1182 * Return code
1183 * 0 - failed to issue initial fdisc for @vport
1184 * 1 - successfully issued initial fdisc for @vport
1185 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001186int
1187lpfc_initial_fdisc(struct lpfc_vport *vport)
1188{
1189 struct lpfc_hba *phba = vport->phba;
1190 struct lpfc_nodelist *ndlp;
1191
1192 /* First look for the Fabric ndlp */
1193 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1194 if (!ndlp) {
1195 /* Cannot find existing Fabric ndlp, so allocate a new one */
1196 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1197 if (!ndlp)
1198 return 0;
1199 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001200 /* Put ndlp onto node list */
1201 lpfc_enqueue_node(vport, ndlp);
1202 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1203 /* re-setup ndlp without removing from node list */
1204 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1205 if (!ndlp)
1206 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001207 }
James Smarte47c9092008-02-08 18:49:26 -05001208
James Smart92d7f7b2007-06-17 19:56:38 -05001209 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001210 /* decrement node reference count to trigger the release of
1211 * the node.
1212 */
James Smart92d7f7b2007-06-17 19:56:38 -05001213 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001214 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001215 }
1216 return 1;
1217}
James Smart87af33f2007-10-27 13:37:43 -04001218
James Smarte59058c2008-08-24 21:49:00 -04001219/**
James Smart3621a712009-04-06 18:47:14 -04001220 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001221 * @vport: pointer to a host virtual N_Port data structure.
1222 *
1223 * This routine checks whether there are more remaining Port Logins
1224 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1225 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1226 * to issue ELS PLOGIs up to the configured discover threads with the
1227 * @vport (@vport->cfg_discovery_threads). The function also decrement
1228 * the @vport's num_disc_node by 1 if it is not already 0.
1229 **/
James Smart87af33f2007-10-27 13:37:43 -04001230void
James Smart2e0fef82007-06-17 19:56:36 -05001231lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001232{
1233 int sentplogi;
1234
James Smart2e0fef82007-06-17 19:56:36 -05001235 if (vport->num_disc_nodes)
1236 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001237
1238 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001239 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1240 "0232 Continue discovery with %d PLOGIs to go "
1241 "Data: x%x x%x x%x\n",
1242 vport->num_disc_nodes, vport->fc_plogi_cnt,
1243 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001244 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001245 if (vport->fc_flag & FC_NLP_MORE)
1246 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1247 sentplogi = lpfc_els_disc_plogi(vport);
1248
dea31012005-04-17 16:05:31 -05001249 return;
1250}
1251
James Smarte59058c2008-08-24 21:49:00 -04001252/**
James Smart3621a712009-04-06 18:47:14 -04001253 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001254 * @phba: pointer to lpfc hba data structure.
1255 * @prsp: pointer to response IOCB payload.
1256 * @ndlp: pointer to a node-list data structure.
1257 *
1258 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1259 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1260 * The following cases are considered N_Port confirmed:
1261 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1262 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1263 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1264 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1265 * 1) if there is a node on vport list other than the @ndlp with the same
1266 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1267 * on that node to release the RPI associated with the node; 2) if there is
1268 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1269 * into, a new node shall be allocated (or activated). In either case, the
1270 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1271 * be released and the new_ndlp shall be put on to the vport node list and
1272 * its pointer returned as the confirmed node.
1273 *
1274 * Note that before the @ndlp got "released", the keepDID from not-matching
1275 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1276 * of the @ndlp. This is because the release of @ndlp is actually to put it
1277 * into an inactive state on the vport node list and the vport node list
1278 * management algorithm does not allow two node with a same DID.
1279 *
1280 * Return code
1281 * pointer to the PLOGI N_Port @ndlp
1282 **/
James Smart488d1462006-03-07 15:02:37 -05001283static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001284lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001285 struct lpfc_nodelist *ndlp)
1286{
James Smart2e0fef82007-06-17 19:56:36 -05001287 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001288 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001289 struct lpfc_rport_data *rdata;
1290 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001291 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001292 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001293 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001294 int put_node;
1295 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001296 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001297
James Smart2fb9bd82006-12-02 13:33:57 -05001298 /* Fabric nodes can have the same WWPN so we don't bother searching
1299 * by WWPN. Just return the ndlp that was given to us.
1300 */
1301 if (ndlp->nlp_type & NLP_FABRIC)
1302 return ndlp;
1303
James Smart92d7f7b2007-06-17 19:56:38 -05001304 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001305 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001306
James Smart685f0bf2007-04-25 09:53:08 -04001307 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001308 * we have for that ndlp. If not, we have some work to do.
1309 */
James Smart2e0fef82007-06-17 19:56:36 -05001310 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001311
James Smarte47c9092008-02-08 18:49:26 -05001312 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001313 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001314 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001315
1316 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001317 rc = memcmp(&ndlp->nlp_portname, name,
1318 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001319 if (!rc)
1320 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001321 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1322 if (!new_ndlp)
1323 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001324 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001325 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001326 rc = memcmp(&ndlp->nlp_portname, name,
1327 sizeof(struct lpfc_name));
1328 if (!rc)
1329 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001330 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1331 NLP_STE_UNUSED_NODE);
1332 if (!new_ndlp)
1333 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001334 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001335 if (phba->sli_rev == LPFC_SLI_REV4)
1336 memcpy(&rrq.xri_bitmap,
1337 &new_ndlp->active_rrqs.xri_bitmap,
1338 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1339 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001340 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001341 if (phba->sli_rev == LPFC_SLI_REV4)
1342 memcpy(&rrq.xri_bitmap,
1343 &new_ndlp->active_rrqs.xri_bitmap,
1344 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1345 }
James Smart488d1462006-03-07 15:02:37 -05001346
James Smart2e0fef82007-06-17 19:56:36 -05001347 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001348 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001349 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001350 if (phba->sli_rev == LPFC_SLI_REV4)
1351 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1352 &ndlp->active_rrqs.xri_bitmap,
1353 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001354
1355 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1356 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1357 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1358
James Smarte47c9092008-02-08 18:49:26 -05001359 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001360 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001361
James Smart2e0fef82007-06-17 19:56:36 -05001362 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001363 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1364 /* The new_ndlp is replacing ndlp totally, so we need
1365 * to put ndlp on UNUSED list and try to free it.
1366 */
James Smart0ff10d42008-01-11 01:52:36 -05001367
1368 /* Fix up the rport accordingly */
1369 rport = ndlp->rport;
1370 if (rport) {
1371 rdata = rport->dd_data;
1372 if (rdata->pnode == ndlp) {
1373 lpfc_nlp_put(ndlp);
1374 ndlp->rport = NULL;
1375 rdata->pnode = lpfc_nlp_get(new_ndlp);
1376 new_ndlp->rport = rport;
1377 }
1378 new_ndlp->nlp_type = ndlp->nlp_type;
1379 }
James Smart58da1ff2008-04-07 10:15:56 -04001380 /* We shall actually free the ndlp with both nlp_DID and
1381 * nlp_portname fields equals 0 to avoid any ndlp on the
1382 * nodelist never to be used.
1383 */
1384 if (ndlp->nlp_DID == 0) {
1385 spin_lock_irq(&phba->ndlp_lock);
1386 NLP_SET_FREE_REQ(ndlp);
1387 spin_unlock_irq(&phba->ndlp_lock);
1388 }
James Smart0ff10d42008-01-11 01:52:36 -05001389
James Smart58da1ff2008-04-07 10:15:56 -04001390 /* Two ndlps cannot have the same did on the nodelist */
1391 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001392 if (phba->sli_rev == LPFC_SLI_REV4)
1393 memcpy(&ndlp->active_rrqs.xri_bitmap,
1394 &rrq.xri_bitmap,
1395 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001396 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001397 }
James Smart92795652006-07-06 15:50:02 -04001398 else {
James Smart2e0fef82007-06-17 19:56:36 -05001399 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001400 /* Two ndlps cannot have the same did */
1401 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001402 if (phba->sli_rev == LPFC_SLI_REV4)
1403 memcpy(&ndlp->active_rrqs.xri_bitmap,
1404 &rrq.xri_bitmap,
1405 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001406 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001407 /* Since we are swapping the ndlp passed in with the new one
1408 * and the did has already been swapped, copy over the
1409 * state and names.
1410 */
1411 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1412 sizeof(struct lpfc_name));
1413 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1414 sizeof(struct lpfc_name));
1415 new_ndlp->nlp_state = ndlp->nlp_state;
1416 /* Fix up the rport accordingly */
1417 rport = ndlp->rport;
1418 if (rport) {
1419 rdata = rport->dd_data;
1420 put_node = rdata->pnode != NULL;
1421 put_rport = ndlp->rport != NULL;
1422 rdata->pnode = NULL;
1423 ndlp->rport = NULL;
1424 if (put_node)
1425 lpfc_nlp_put(ndlp);
1426 if (put_rport)
1427 put_device(&rport->dev);
1428 }
James Smart92795652006-07-06 15:50:02 -04001429 }
James Smart488d1462006-03-07 15:02:37 -05001430 return new_ndlp;
1431}
1432
James Smarte59058c2008-08-24 21:49:00 -04001433/**
James Smart3621a712009-04-06 18:47:14 -04001434 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001435 * @vport: pointer to a host virtual N_Port data structure.
1436 *
1437 * This routine checks whether more Registration State Change
1438 * Notifications (RSCNs) came in while the discovery state machine was in
1439 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1440 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1441 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1442 * handling the RSCNs.
1443 **/
James Smart87af33f2007-10-27 13:37:43 -04001444void
1445lpfc_end_rscn(struct lpfc_vport *vport)
1446{
1447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1448
1449 if (vport->fc_flag & FC_RSCN_MODE) {
1450 /*
1451 * Check to see if more RSCNs came in while we were
1452 * processing this one.
1453 */
1454 if (vport->fc_rscn_id_cnt ||
1455 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1456 lpfc_els_handle_rscn(vport);
1457 else {
1458 spin_lock_irq(shost->host_lock);
1459 vport->fc_flag &= ~FC_RSCN_MODE;
1460 spin_unlock_irq(shost->host_lock);
1461 }
1462 }
1463}
1464
James Smarte59058c2008-08-24 21:49:00 -04001465/**
James Smart19ca7602010-11-20 23:11:55 -05001466 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1467 * @phba: pointer to lpfc hba data structure.
1468 * @cmdiocb: pointer to lpfc command iocb data structure.
1469 * @rspiocb: pointer to lpfc response iocb data structure.
1470 *
1471 * This routine will call the clear rrq function to free the rrq and
1472 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1473 * exist then the clear_rrq is still called because the rrq needs to
1474 * be freed.
1475 **/
1476
1477static void
1478lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1479 struct lpfc_iocbq *rspiocb)
1480{
1481 struct lpfc_vport *vport = cmdiocb->vport;
1482 IOCB_t *irsp;
1483 struct lpfc_nodelist *ndlp;
1484 struct lpfc_node_rrq *rrq;
1485
1486 /* we pass cmdiocb to state machine which needs rspiocb as well */
1487 rrq = cmdiocb->context_un.rrq;
1488 cmdiocb->context_un.rsp_iocb = rspiocb;
1489
1490 irsp = &rspiocb->iocb;
1491 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1492 "RRQ cmpl: status:x%x/x%x did:x%x",
1493 irsp->ulpStatus, irsp->un.ulpWord[4],
1494 irsp->un.elsreq64.remoteID);
1495
1496 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1497 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1498 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1499 "2882 RRQ completes to NPort x%x "
1500 "with no ndlp. Data: x%x x%x x%x\n",
1501 irsp->un.elsreq64.remoteID,
1502 irsp->ulpStatus, irsp->un.ulpWord[4],
1503 irsp->ulpIoTag);
1504 goto out;
1505 }
1506
1507 /* rrq completes to NPort <nlp_DID> */
1508 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1509 "2880 RRQ completes to NPort x%x "
1510 "Data: x%x x%x x%x x%x x%x\n",
1511 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1512 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1513
1514 if (irsp->ulpStatus) {
1515 /* Check for retry */
1516 /* RRQ failed Don't print the vport to vport rjts */
1517 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1518 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1519 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1520 (phba)->pport->cfg_log_verbose & LOG_ELS)
1521 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1522 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1523 ndlp->nlp_DID, irsp->ulpStatus,
1524 irsp->un.ulpWord[4]);
1525 }
1526out:
1527 if (rrq)
1528 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1529 lpfc_els_free_iocb(phba, cmdiocb);
1530 return;
1531}
1532/**
James Smart3621a712009-04-06 18:47:14 -04001533 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001534 * @phba: pointer to lpfc hba data structure.
1535 * @cmdiocb: pointer to lpfc command iocb data structure.
1536 * @rspiocb: pointer to lpfc response iocb data structure.
1537 *
1538 * This routine is the completion callback function for issuing the Port
1539 * Login (PLOGI) command. For PLOGI completion, there must be an active
1540 * ndlp on the vport node list that matches the remote node ID from the
1541 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1542 * ignored and command IOCB released. The PLOGI response IOCB status is
1543 * checked for error conditons. If there is error status reported, PLOGI
1544 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1545 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1546 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1547 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1548 * there are additional N_Port nodes with the vport that need to perform
1549 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1550 * PLOGIs.
1551 **/
dea31012005-04-17 16:05:31 -05001552static void
James Smart2e0fef82007-06-17 19:56:36 -05001553lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1554 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001555{
James Smart2e0fef82007-06-17 19:56:36 -05001556 struct lpfc_vport *vport = cmdiocb->vport;
1557 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001558 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001559 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001560 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001561 int disc, rc, did, type;
1562
dea31012005-04-17 16:05:31 -05001563 /* we pass cmdiocb to state machine which needs rspiocb as well */
1564 cmdiocb->context_un.rsp_iocb = rspiocb;
1565
1566 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001567 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1568 "PLOGI cmpl: status:x%x/x%x did:x%x",
1569 irsp->ulpStatus, irsp->un.ulpWord[4],
1570 irsp->un.elsreq64.remoteID);
1571
James Smart2e0fef82007-06-17 19:56:36 -05001572 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001573 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001574 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1575 "0136 PLOGI completes to NPort x%x "
1576 "with no ndlp. Data: x%x x%x x%x\n",
1577 irsp->un.elsreq64.remoteID,
1578 irsp->ulpStatus, irsp->un.ulpWord[4],
1579 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001580 goto out;
James Smarted957682007-06-17 19:56:37 -05001581 }
dea31012005-04-17 16:05:31 -05001582
1583 /* Since ndlp can be freed in the disc state machine, note if this node
1584 * is being used during discovery.
1585 */
James Smart2e0fef82007-06-17 19:56:36 -05001586 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001587 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001588 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001589 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001590 rc = 0;
1591
1592 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001593 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1594 "0102 PLOGI completes to NPort x%x "
1595 "Data: x%x x%x x%x x%x x%x\n",
1596 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1597 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001598 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001599 if (lpfc_els_chk_latt(vport)) {
1600 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001601 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001602 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001603 goto out;
1604 }
1605
1606 /* ndlp could be freed in DSM, save these values now */
1607 type = ndlp->nlp_type;
1608 did = ndlp->nlp_DID;
1609
1610 if (irsp->ulpStatus) {
1611 /* Check for retry */
1612 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1613 /* ELS command is being retried */
1614 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001615 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001616 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001617 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001618 }
1619 goto out;
1620 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001621 /* PLOGI failed Don't print the vport to vport rjts */
1622 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1623 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1624 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1625 (phba)->pport->cfg_log_verbose & LOG_ELS)
1626 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001627 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1628 ndlp->nlp_DID, irsp->ulpStatus,
1629 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001630 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001631 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001632 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001633 else
James Smart2e0fef82007-06-17 19:56:36 -05001634 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001635 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001636 } else {
1637 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001638 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001639 cmdiocb->context2)->list.next,
1640 struct lpfc_dmabuf, list);
1641 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001642 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001643 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001644 }
1645
James Smart2e0fef82007-06-17 19:56:36 -05001646 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001647 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001648 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001649
James Smart2e0fef82007-06-17 19:56:36 -05001650 if (vport->num_disc_nodes == 0) {
1651 spin_lock_irq(shost->host_lock);
1652 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1653 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001654
James Smart2e0fef82007-06-17 19:56:36 -05001655 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001656 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001657 }
1658 }
1659
1660out:
1661 lpfc_els_free_iocb(phba, cmdiocb);
1662 return;
1663}
1664
James Smarte59058c2008-08-24 21:49:00 -04001665/**
James Smart3621a712009-04-06 18:47:14 -04001666 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001667 * @vport: pointer to a host virtual N_Port data structure.
1668 * @did: destination port identifier.
1669 * @retry: number of retries to the command IOCB.
1670 *
1671 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1672 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1673 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1674 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1675 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1676 *
1677 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1678 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1679 * will be stored into the context1 field of the IOCB for the completion
1680 * callback function to the PLOGI ELS command.
1681 *
1682 * Return code
1683 * 0 - Successfully issued a plogi for @vport
1684 * 1 - failed to issue a plogi for @vport
1685 **/
dea31012005-04-17 16:05:31 -05001686int
James Smart2e0fef82007-06-17 19:56:36 -05001687lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001688{
James Smart2e0fef82007-06-17 19:56:36 -05001689 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001690 struct serv_parm *sp;
1691 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001692 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001693 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001694 struct lpfc_sli *psli;
1695 uint8_t *pcmd;
1696 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001697 int ret;
dea31012005-04-17 16:05:31 -05001698
1699 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001700
James Smart98c9ea52007-10-27 13:37:33 -04001701 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001702 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1703 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001704
James Smarte47c9092008-02-08 18:49:26 -05001705 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001706 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001707 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001708 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001709 if (!elsiocb)
1710 return 1;
dea31012005-04-17 16:05:31 -05001711
1712 icmd = &elsiocb->iocb;
1713 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1714
1715 /* For PLOGI request, remainder of payload is service parameters */
1716 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001717 pcmd += sizeof(uint32_t);
1718 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001719 sp = (struct serv_parm *) pcmd;
1720
James Smart5ac6b302010-10-22 11:05:36 -04001721 /*
1722 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1723 * to device on remote loops work.
1724 */
1725 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1726 sp->cmn.altBbCredit = 1;
1727
dea31012005-04-17 16:05:31 -05001728 if (sp->cmn.fcphLow < FC_PH_4_3)
1729 sp->cmn.fcphLow = FC_PH_4_3;
1730
1731 if (sp->cmn.fcphHigh < FC_PH3)
1732 sp->cmn.fcphHigh = FC_PH3;
1733
James Smart858c9f62007-06-17 19:56:39 -05001734 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1735 "Issue PLOGI: did:x%x",
1736 did, 0, 0);
1737
dea31012005-04-17 16:05:31 -05001738 phba->fc_stat.elsXmitPLOGI++;
1739 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001740 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001741
1742 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001743 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001744 return 1;
dea31012005-04-17 16:05:31 -05001745 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001746 return 0;
dea31012005-04-17 16:05:31 -05001747}
1748
James Smarte59058c2008-08-24 21:49:00 -04001749/**
James Smart3621a712009-04-06 18:47:14 -04001750 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001751 * @phba: pointer to lpfc hba data structure.
1752 * @cmdiocb: pointer to lpfc command iocb data structure.
1753 * @rspiocb: pointer to lpfc response iocb data structure.
1754 *
1755 * This routine is the completion callback function for a Process Login
1756 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1757 * status. If there is error status reported, PRLI retry shall be attempted
1758 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1759 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1760 * ndlp to mark the PRLI completion.
1761 **/
dea31012005-04-17 16:05:31 -05001762static void
James Smart2e0fef82007-06-17 19:56:36 -05001763lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1764 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001765{
James Smart2e0fef82007-06-17 19:56:36 -05001766 struct lpfc_vport *vport = cmdiocb->vport;
1767 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001768 IOCB_t *irsp;
1769 struct lpfc_sli *psli;
1770 struct lpfc_nodelist *ndlp;
1771
1772 psli = &phba->sli;
1773 /* we pass cmdiocb to state machine which needs rspiocb as well */
1774 cmdiocb->context_un.rsp_iocb = rspiocb;
1775
1776 irsp = &(rspiocb->iocb);
1777 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001778 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001779 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001780 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001781
James Smart858c9f62007-06-17 19:56:39 -05001782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1783 "PRLI cmpl: status:x%x/x%x did:x%x",
1784 irsp->ulpStatus, irsp->un.ulpWord[4],
1785 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001786 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001787 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1788 "0103 PRLI completes to NPort x%x "
1789 "Data: x%x x%x x%x x%x\n",
1790 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1791 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001792
James Smart2e0fef82007-06-17 19:56:36 -05001793 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001794 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001795 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001796 goto out;
1797
1798 if (irsp->ulpStatus) {
1799 /* Check for retry */
1800 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1801 /* ELS command is being retried */
1802 goto out;
1803 }
1804 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001805 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1806 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1807 ndlp->nlp_DID, irsp->ulpStatus,
1808 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001809 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001810 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001811 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001812 else
James Smart2e0fef82007-06-17 19:56:36 -05001813 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001814 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001815 } else
dea31012005-04-17 16:05:31 -05001816 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001817 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001818 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001819out:
1820 lpfc_els_free_iocb(phba, cmdiocb);
1821 return;
1822}
1823
James Smarte59058c2008-08-24 21:49:00 -04001824/**
James Smart3621a712009-04-06 18:47:14 -04001825 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001826 * @vport: pointer to a host virtual N_Port data structure.
1827 * @ndlp: pointer to a node-list data structure.
1828 * @retry: number of retries to the command IOCB.
1829 *
1830 * This routine issues a Process Login (PRLI) ELS command for the
1831 * @vport. The PRLI service parameters are set up in the payload of the
1832 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1833 * is put to the IOCB completion callback func field before invoking the
1834 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1835 *
1836 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1837 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1838 * will be stored into the context1 field of the IOCB for the completion
1839 * callback function to the PRLI ELS command.
1840 *
1841 * Return code
1842 * 0 - successfully issued prli iocb command for @vport
1843 * 1 - failed to issue prli iocb command for @vport
1844 **/
dea31012005-04-17 16:05:31 -05001845int
James Smart2e0fef82007-06-17 19:56:36 -05001846lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001847 uint8_t retry)
1848{
James Smart2e0fef82007-06-17 19:56:36 -05001849 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1850 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001851 PRLI *npr;
1852 IOCB_t *icmd;
1853 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001854 uint8_t *pcmd;
1855 uint16_t cmdsize;
1856
James Smart92d7f7b2007-06-17 19:56:38 -05001857 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001858 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1859 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001860 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001861 return 1;
dea31012005-04-17 16:05:31 -05001862
1863 icmd = &elsiocb->iocb;
1864 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1865
1866 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001867 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001868 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001869 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001870
1871 /* For PRLI, remainder of payload is PRLI parameter page */
1872 npr = (PRLI *) pcmd;
1873 /*
1874 * If our firmware version is 3.20 or later,
1875 * set the following bits for FC-TAPE support.
1876 */
1877 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1878 npr->ConfmComplAllowed = 1;
1879 npr->Retry = 1;
1880 npr->TaskRetryIdReq = 1;
1881 }
1882 npr->estabImagePair = 1;
1883 npr->readXferRdyDis = 1;
1884
1885 /* For FCP support */
1886 npr->prliType = PRLI_FCP_TYPE;
1887 npr->initiatorFunc = 1;
1888
James Smart858c9f62007-06-17 19:56:39 -05001889 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1890 "Issue PRLI: did:x%x",
1891 ndlp->nlp_DID, 0, 0);
1892
dea31012005-04-17 16:05:31 -05001893 phba->fc_stat.elsXmitPRLI++;
1894 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001895 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001896 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001897 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001898 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1899 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001900 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001901 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001902 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001903 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001904 return 1;
dea31012005-04-17 16:05:31 -05001905 }
James Smart2e0fef82007-06-17 19:56:36 -05001906 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001907 return 0;
dea31012005-04-17 16:05:31 -05001908}
1909
James Smarte59058c2008-08-24 21:49:00 -04001910/**
James Smart3621a712009-04-06 18:47:14 -04001911 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001912 * @vport: pointer to a host virtual N_Port data structure.
1913 *
1914 * This routine performs Registration State Change Notification (RSCN)
1915 * discovery for a @vport. If the @vport's node port recovery count is not
1916 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1917 * the nodes that need recovery. If none of the PLOGI were needed through
1918 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1919 * invoked to check and handle possible more RSCN came in during the period
1920 * of processing the current ones.
1921 **/
1922static void
1923lpfc_rscn_disc(struct lpfc_vport *vport)
1924{
1925 lpfc_can_disctmo(vport);
1926
1927 /* RSCN discovery */
1928 /* go thru NPR nodes and issue ELS PLOGIs */
1929 if (vport->fc_npr_cnt)
1930 if (lpfc_els_disc_plogi(vport))
1931 return;
1932
1933 lpfc_end_rscn(vport);
1934}
1935
1936/**
James Smart3621a712009-04-06 18:47:14 -04001937 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001938 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1939 *
1940 * This function is called when the final ADISC is completed during discovery.
1941 * This function handles clearing link attention or issuing reg_vpi depending
1942 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1943 * discovery.
1944 * This function is called with no locks held.
1945 **/
1946static void
1947lpfc_adisc_done(struct lpfc_vport *vport)
1948{
1949 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1950 struct lpfc_hba *phba = vport->phba;
1951
1952 /*
1953 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1954 * and continue discovery.
1955 */
1956 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001957 !(vport->fc_flag & FC_RSCN_MODE) &&
1958 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001959 lpfc_issue_reg_vpi(phba, vport);
1960 return;
1961 }
1962 /*
1963 * For SLI2, we need to set port_state to READY
1964 * and continue discovery.
1965 */
1966 if (vport->port_state < LPFC_VPORT_READY) {
1967 /* If we get here, there is nothing to ADISC */
1968 if (vport->port_type == LPFC_PHYSICAL_PORT)
1969 lpfc_issue_clear_la(phba, vport);
1970 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1971 vport->num_disc_nodes = 0;
1972 /* go thru NPR list, issue ELS PLOGIs */
1973 if (vport->fc_npr_cnt)
1974 lpfc_els_disc_plogi(vport);
1975 if (!vport->num_disc_nodes) {
1976 spin_lock_irq(shost->host_lock);
1977 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1978 spin_unlock_irq(shost->host_lock);
1979 lpfc_can_disctmo(vport);
1980 lpfc_end_rscn(vport);
1981 }
1982 }
1983 vport->port_state = LPFC_VPORT_READY;
1984 } else
1985 lpfc_rscn_disc(vport);
1986}
1987
1988/**
James Smart3621a712009-04-06 18:47:14 -04001989 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001990 * @vport: pointer to a host virtual N_Port data structure.
1991 *
1992 * This routine determines whether there are more ndlps on a @vport
1993 * node list need to have Address Discover (ADISC) issued. If so, it will
1994 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1995 * remaining nodes which need to have ADISC sent.
1996 **/
James Smart0ff10d42008-01-11 01:52:36 -05001997void
James Smart2e0fef82007-06-17 19:56:36 -05001998lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001999{
2000 int sentadisc;
2001
James Smart2e0fef82007-06-17 19:56:36 -05002002 if (vport->num_disc_nodes)
2003 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002004 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002005 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2006 "0210 Continue discovery with %d ADISCs to go "
2007 "Data: x%x x%x x%x\n",
2008 vport->num_disc_nodes, vport->fc_adisc_cnt,
2009 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002010 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002011 if (vport->fc_flag & FC_NLP_MORE) {
2012 lpfc_set_disctmo(vport);
2013 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2014 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002015 }
James Smart90160e02008-08-24 21:49:45 -04002016 if (!vport->num_disc_nodes)
2017 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002018 return;
2019}
2020
James Smarte59058c2008-08-24 21:49:00 -04002021/**
James Smart3621a712009-04-06 18:47:14 -04002022 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002023 * @phba: pointer to lpfc hba data structure.
2024 * @cmdiocb: pointer to lpfc command iocb data structure.
2025 * @rspiocb: pointer to lpfc response iocb data structure.
2026 *
2027 * This routine is the completion function for issuing the Address Discover
2028 * (ADISC) command. It first checks to see whether link went down during
2029 * the discovery process. If so, the node will be marked as node port
2030 * recovery for issuing discover IOCB by the link attention handler and
2031 * exit. Otherwise, the response status is checked. If error was reported
2032 * in the response status, the ADISC command shall be retried by invoking
2033 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2034 * the response status, the state machine is invoked to set transition
2035 * with respect to NLP_EVT_CMPL_ADISC event.
2036 **/
dea31012005-04-17 16:05:31 -05002037static void
James Smart2e0fef82007-06-17 19:56:36 -05002038lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2039 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002040{
James Smart2e0fef82007-06-17 19:56:36 -05002041 struct lpfc_vport *vport = cmdiocb->vport;
2042 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002043 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002044 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002045 int disc;
dea31012005-04-17 16:05:31 -05002046
2047 /* we pass cmdiocb to state machine which needs rspiocb as well */
2048 cmdiocb->context_un.rsp_iocb = rspiocb;
2049
2050 irsp = &(rspiocb->iocb);
2051 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002052
James Smart858c9f62007-06-17 19:56:39 -05002053 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2054 "ADISC cmpl: status:x%x/x%x did:x%x",
2055 irsp->ulpStatus, irsp->un.ulpWord[4],
2056 ndlp->nlp_DID);
2057
dea31012005-04-17 16:05:31 -05002058 /* Since ndlp can be freed in the disc state machine, note if this node
2059 * is being used during discovery.
2060 */
James Smart2e0fef82007-06-17 19:56:36 -05002061 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002062 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002063 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002064 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002065 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002066 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2067 "0104 ADISC completes to NPort x%x "
2068 "Data: x%x x%x x%x x%x x%x\n",
2069 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2070 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002071 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002072 if (lpfc_els_chk_latt(vport)) {
2073 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002074 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002075 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002076 goto out;
2077 }
2078
2079 if (irsp->ulpStatus) {
2080 /* Check for retry */
2081 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2082 /* ELS command is being retried */
2083 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002084 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002085 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002086 spin_unlock_irq(shost->host_lock);
2087 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002088 }
2089 goto out;
2090 }
2091 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002092 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2093 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2094 ndlp->nlp_DID, irsp->ulpStatus,
2095 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002096 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002097 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002098 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002099 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002100 } else
dea31012005-04-17 16:05:31 -05002101 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002102 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002103 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002104
James Smart90160e02008-08-24 21:49:45 -04002105 /* Check to see if there are more ADISCs to be sent */
2106 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002107 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002108out:
2109 lpfc_els_free_iocb(phba, cmdiocb);
2110 return;
2111}
2112
James Smarte59058c2008-08-24 21:49:00 -04002113/**
James Smart3621a712009-04-06 18:47:14 -04002114 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002115 * @vport: pointer to a virtual N_Port data structure.
2116 * @ndlp: pointer to a node-list data structure.
2117 * @retry: number of retries to the command IOCB.
2118 *
2119 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2120 * @vport. It prepares the payload of the ADISC ELS command, updates the
2121 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2122 * to issue the ADISC ELS command.
2123 *
2124 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2125 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2126 * will be stored into the context1 field of the IOCB for the completion
2127 * callback function to the ADISC ELS command.
2128 *
2129 * Return code
2130 * 0 - successfully issued adisc
2131 * 1 - failed to issue adisc
2132 **/
dea31012005-04-17 16:05:31 -05002133int
James Smart2e0fef82007-06-17 19:56:36 -05002134lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002135 uint8_t retry)
2136{
James Smart2e0fef82007-06-17 19:56:36 -05002137 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2138 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002139 ADISC *ap;
2140 IOCB_t *icmd;
2141 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002142 uint8_t *pcmd;
2143 uint16_t cmdsize;
2144
James Smart92d7f7b2007-06-17 19:56:38 -05002145 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002146 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2147 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002148 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002149 return 1;
dea31012005-04-17 16:05:31 -05002150
2151 icmd = &elsiocb->iocb;
2152 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2153
2154 /* For ADISC request, remainder of payload is service parameters */
2155 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002156 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002157
2158 /* Fill in ADISC payload */
2159 ap = (ADISC *) pcmd;
2160 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002161 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2162 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002163 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002164
James Smart858c9f62007-06-17 19:56:39 -05002165 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2166 "Issue ADISC: did:x%x",
2167 ndlp->nlp_DID, 0, 0);
2168
dea31012005-04-17 16:05:31 -05002169 phba->fc_stat.elsXmitADISC++;
2170 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002171 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002172 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002173 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002174 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2175 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002177 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002179 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002180 return 1;
dea31012005-04-17 16:05:31 -05002181 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002182 return 0;
dea31012005-04-17 16:05:31 -05002183}
2184
James Smarte59058c2008-08-24 21:49:00 -04002185/**
James Smart3621a712009-04-06 18:47:14 -04002186 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002187 * @phba: pointer to lpfc hba data structure.
2188 * @cmdiocb: pointer to lpfc command iocb data structure.
2189 * @rspiocb: pointer to lpfc response iocb data structure.
2190 *
2191 * This routine is the completion function for issuing the ELS Logout (LOGO)
2192 * command. If no error status was reported from the LOGO response, the
2193 * state machine of the associated ndlp shall be invoked for transition with
2194 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2195 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2196 **/
dea31012005-04-17 16:05:31 -05002197static void
James Smart2e0fef82007-06-17 19:56:36 -05002198lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2199 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002200{
James Smart2e0fef82007-06-17 19:56:36 -05002201 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2202 struct lpfc_vport *vport = ndlp->vport;
2203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002204 IOCB_t *irsp;
2205 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002206
2207 psli = &phba->sli;
2208 /* we pass cmdiocb to state machine which needs rspiocb as well */
2209 cmdiocb->context_un.rsp_iocb = rspiocb;
2210
2211 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002212 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002213 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002214 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002215
James Smart858c9f62007-06-17 19:56:39 -05002216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2217 "LOGO cmpl: status:x%x/x%x did:x%x",
2218 irsp->ulpStatus, irsp->un.ulpWord[4],
2219 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002220 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002221 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2222 "0105 LOGO completes to NPort x%x "
2223 "Data: x%x x%x x%x x%x\n",
2224 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2225 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002226 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002227 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002228 goto out;
2229
James Smart92d7f7b2007-06-17 19:56:38 -05002230 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2231 /* NLP_EVT_DEVICE_RM should unregister the RPI
2232 * which should abort all outstanding IOs.
2233 */
2234 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2235 NLP_EVT_DEVICE_RM);
2236 goto out;
2237 }
2238
dea31012005-04-17 16:05:31 -05002239 if (irsp->ulpStatus) {
2240 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002241 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002242 /* ELS command is being retried */
2243 goto out;
dea31012005-04-17 16:05:31 -05002244 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002245 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2246 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2247 ndlp->nlp_DID, irsp->ulpStatus,
2248 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002249 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002250 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002251 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002252 else
James Smart2e0fef82007-06-17 19:56:36 -05002253 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002254 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002255 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002256 /* Good status, call state machine.
2257 * This will unregister the rpi if needed.
2258 */
James Smart2e0fef82007-06-17 19:56:36 -05002259 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002260 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002261out:
2262 lpfc_els_free_iocb(phba, cmdiocb);
2263 return;
2264}
2265
James Smarte59058c2008-08-24 21:49:00 -04002266/**
James Smart3621a712009-04-06 18:47:14 -04002267 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002268 * @vport: pointer to a virtual N_Port data structure.
2269 * @ndlp: pointer to a node-list data structure.
2270 * @retry: number of retries to the command IOCB.
2271 *
2272 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2273 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2274 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2275 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2276 *
2277 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2278 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2279 * will be stored into the context1 field of the IOCB for the completion
2280 * callback function to the LOGO ELS command.
2281 *
2282 * Return code
2283 * 0 - successfully issued logo
2284 * 1 - failed to issue logo
2285 **/
dea31012005-04-17 16:05:31 -05002286int
James Smart2e0fef82007-06-17 19:56:36 -05002287lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002288 uint8_t retry)
2289{
James Smart2e0fef82007-06-17 19:56:36 -05002290 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2291 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002292 IOCB_t *icmd;
2293 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002294 uint8_t *pcmd;
2295 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002296 int rc;
dea31012005-04-17 16:05:31 -05002297
James Smart98c9ea52007-10-27 13:37:33 -04002298 spin_lock_irq(shost->host_lock);
2299 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2300 spin_unlock_irq(shost->host_lock);
2301 return 0;
2302 }
2303 spin_unlock_irq(shost->host_lock);
2304
James Smart92d7f7b2007-06-17 19:56:38 -05002305 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002306 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2307 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002308 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002309 return 1;
dea31012005-04-17 16:05:31 -05002310
2311 icmd = &elsiocb->iocb;
2312 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2313 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002314 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002315
2316 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002317 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002318 pcmd += sizeof(uint32_t);
2319 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002320
James Smart858c9f62007-06-17 19:56:39 -05002321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2322 "Issue LOGO: did:x%x",
2323 ndlp->nlp_DID, 0, 0);
2324
dea31012005-04-17 16:05:31 -05002325 phba->fc_stat.elsXmitLOGO++;
2326 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002327 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002328 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002329 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002330 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002331
2332 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002333 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002334 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002335 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002336 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002337 return 1;
dea31012005-04-17 16:05:31 -05002338 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002339 return 0;
dea31012005-04-17 16:05:31 -05002340}
2341
James Smarte59058c2008-08-24 21:49:00 -04002342/**
James Smart3621a712009-04-06 18:47:14 -04002343 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002344 * @phba: pointer to lpfc hba data structure.
2345 * @cmdiocb: pointer to lpfc command iocb data structure.
2346 * @rspiocb: pointer to lpfc response iocb data structure.
2347 *
2348 * This routine is a generic completion callback function for ELS commands.
2349 * Specifically, it is the callback function which does not need to perform
2350 * any command specific operations. It is currently used by the ELS command
2351 * issuing routines for the ELS State Change Request (SCR),
2352 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2353 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2354 * certain debug loggings, this callback function simply invokes the
2355 * lpfc_els_chk_latt() routine to check whether link went down during the
2356 * discovery process.
2357 **/
dea31012005-04-17 16:05:31 -05002358static void
James Smart2e0fef82007-06-17 19:56:36 -05002359lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2360 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002361{
James Smart2e0fef82007-06-17 19:56:36 -05002362 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002363 IOCB_t *irsp;
2364
2365 irsp = &rspiocb->iocb;
2366
James Smart858c9f62007-06-17 19:56:39 -05002367 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2368 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2369 irsp->ulpStatus, irsp->un.ulpWord[4],
2370 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002371 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002372 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2373 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2374 irsp->ulpIoTag, irsp->ulpStatus,
2375 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002376 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002377 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002378 lpfc_els_free_iocb(phba, cmdiocb);
2379 return;
2380}
2381
James Smarte59058c2008-08-24 21:49:00 -04002382/**
James Smart3621a712009-04-06 18:47:14 -04002383 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002384 * @vport: pointer to a host virtual N_Port data structure.
2385 * @nportid: N_Port identifier to the remote node.
2386 * @retry: number of retries to the command IOCB.
2387 *
2388 * This routine issues a State Change Request (SCR) to a fabric node
2389 * on a @vport. The remote node @nportid is passed into the function. It
2390 * first search the @vport node list to find the matching ndlp. If no such
2391 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2392 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2393 * routine is invoked to send the SCR IOCB.
2394 *
2395 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2396 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2397 * will be stored into the context1 field of the IOCB for the completion
2398 * callback function to the SCR ELS command.
2399 *
2400 * Return code
2401 * 0 - Successfully issued scr command
2402 * 1 - Failed to issue scr command
2403 **/
dea31012005-04-17 16:05:31 -05002404int
James Smart2e0fef82007-06-17 19:56:36 -05002405lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002406{
James Smart2e0fef82007-06-17 19:56:36 -05002407 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002408 IOCB_t *icmd;
2409 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002410 struct lpfc_sli *psli;
2411 uint8_t *pcmd;
2412 uint16_t cmdsize;
2413 struct lpfc_nodelist *ndlp;
2414
2415 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002416 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002417
James Smarte47c9092008-02-08 18:49:26 -05002418 ndlp = lpfc_findnode_did(vport, nportid);
2419 if (!ndlp) {
2420 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2421 if (!ndlp)
2422 return 1;
2423 lpfc_nlp_init(vport, ndlp, nportid);
2424 lpfc_enqueue_node(vport, ndlp);
2425 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2426 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2427 if (!ndlp)
2428 return 1;
2429 }
dea31012005-04-17 16:05:31 -05002430
James Smart2e0fef82007-06-17 19:56:36 -05002431 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2432 ndlp->nlp_DID, ELS_CMD_SCR);
2433
James Smart488d1462006-03-07 15:02:37 -05002434 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002435 /* This will trigger the release of the node just
2436 * allocated
2437 */
James Smart329f9bc2007-04-25 09:53:01 -04002438 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002439 return 1;
dea31012005-04-17 16:05:31 -05002440 }
2441
2442 icmd = &elsiocb->iocb;
2443 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2444
2445 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002446 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002447
2448 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002449 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002450 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2451
James Smart858c9f62007-06-17 19:56:39 -05002452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2453 "Issue SCR: did:x%x",
2454 ndlp->nlp_DID, 0, 0);
2455
dea31012005-04-17 16:05:31 -05002456 phba->fc_stat.elsXmitSCR++;
2457 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002458 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2459 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002460 /* The additional lpfc_nlp_put will cause the following
2461 * lpfc_els_free_iocb routine to trigger the rlease of
2462 * the node.
2463 */
James Smart329f9bc2007-04-25 09:53:01 -04002464 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002465 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002466 return 1;
dea31012005-04-17 16:05:31 -05002467 }
James Smartfa4066b2008-01-11 01:53:27 -05002468 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2469 * trigger the release of node.
2470 */
James Smart329f9bc2007-04-25 09:53:01 -04002471 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002472 return 0;
dea31012005-04-17 16:05:31 -05002473}
2474
James Smarte59058c2008-08-24 21:49:00 -04002475/**
James Smart3621a712009-04-06 18:47:14 -04002476 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002477 * @vport: pointer to a host virtual N_Port data structure.
2478 * @nportid: N_Port identifier to the remote node.
2479 * @retry: number of retries to the command IOCB.
2480 *
2481 * This routine issues a Fibre Channel Address Resolution Response
2482 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2483 * is passed into the function. It first search the @vport node list to find
2484 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2485 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2486 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2487 *
2488 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2489 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2490 * will be stored into the context1 field of the IOCB for the completion
2491 * callback function to the PARPR ELS command.
2492 *
2493 * Return code
2494 * 0 - Successfully issued farpr command
2495 * 1 - Failed to issue farpr command
2496 **/
dea31012005-04-17 16:05:31 -05002497static int
James Smart2e0fef82007-06-17 19:56:36 -05002498lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002499{
James Smart2e0fef82007-06-17 19:56:36 -05002500 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002501 IOCB_t *icmd;
2502 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002503 struct lpfc_sli *psli;
2504 FARP *fp;
2505 uint8_t *pcmd;
2506 uint32_t *lp;
2507 uint16_t cmdsize;
2508 struct lpfc_nodelist *ondlp;
2509 struct lpfc_nodelist *ndlp;
2510
2511 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002512 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002513
James Smarte47c9092008-02-08 18:49:26 -05002514 ndlp = lpfc_findnode_did(vport, nportid);
2515 if (!ndlp) {
2516 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2517 if (!ndlp)
2518 return 1;
2519 lpfc_nlp_init(vport, ndlp, nportid);
2520 lpfc_enqueue_node(vport, ndlp);
2521 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2522 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2523 if (!ndlp)
2524 return 1;
2525 }
James Smart2e0fef82007-06-17 19:56:36 -05002526
2527 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2528 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002529 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002530 /* This will trigger the release of the node just
2531 * allocated
2532 */
James Smart329f9bc2007-04-25 09:53:01 -04002533 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002534 return 1;
dea31012005-04-17 16:05:31 -05002535 }
2536
2537 icmd = &elsiocb->iocb;
2538 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2539
2540 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002541 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002542
2543 /* Fill in FARPR payload */
2544 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002545 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002546 lp = (uint32_t *) pcmd;
2547 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002548 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002549 fp->Rflags = 0;
2550 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2551
James Smart92d7f7b2007-06-17 19:56:38 -05002552 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2553 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002554 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002555 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002556 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002557 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002558 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002559 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002560 }
2561
James Smart858c9f62007-06-17 19:56:39 -05002562 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2563 "Issue FARPR: did:x%x",
2564 ndlp->nlp_DID, 0, 0);
2565
dea31012005-04-17 16:05:31 -05002566 phba->fc_stat.elsXmitFARPR++;
2567 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002568 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2569 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002570 /* The additional lpfc_nlp_put will cause the following
2571 * lpfc_els_free_iocb routine to trigger the release of
2572 * the node.
2573 */
James Smart329f9bc2007-04-25 09:53:01 -04002574 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002575 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002576 return 1;
dea31012005-04-17 16:05:31 -05002577 }
James Smartfa4066b2008-01-11 01:53:27 -05002578 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2579 * trigger the release of the node.
2580 */
James Smart329f9bc2007-04-25 09:53:01 -04002581 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002582 return 0;
dea31012005-04-17 16:05:31 -05002583}
2584
James Smarte59058c2008-08-24 21:49:00 -04002585/**
James Smart3621a712009-04-06 18:47:14 -04002586 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002587 * @vport: pointer to a host virtual N_Port data structure.
2588 * @nlp: pointer to a node-list data structure.
2589 *
2590 * This routine cancels the timer with a delayed IOCB-command retry for
2591 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2592 * removes the ELS retry event if it presents. In addition, if the
2593 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2594 * commands are sent for the @vport's nodes that require issuing discovery
2595 * ADISC.
2596 **/
dea31012005-04-17 16:05:31 -05002597void
James Smart2e0fef82007-06-17 19:56:36 -05002598lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002599{
James Smart2e0fef82007-06-17 19:56:36 -05002600 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002601 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002602
James Smart0d2b6b82008-06-14 22:52:47 -04002603 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2604 return;
James Smart2e0fef82007-06-17 19:56:36 -05002605 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002606 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002607 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002608 del_timer_sync(&nlp->nlp_delayfunc);
2609 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002610 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002611 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002612 /* Decrement nlp reference count held for the delayed retry */
2613 evtp = &nlp->els_retry_evt;
2614 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2615 }
James Smartfdcebe22006-03-07 15:04:01 -05002616 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002617 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002618 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002619 spin_unlock_irq(shost->host_lock);
2620 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002621 if (vport->port_state < LPFC_VPORT_READY) {
2622 /* Check if there are more ADISCs to be sent */
2623 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002624 } else {
2625 /* Check if there are more PLOGIs to be sent */
2626 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002627 if (vport->num_disc_nodes == 0) {
2628 spin_lock_irq(shost->host_lock);
2629 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2630 spin_unlock_irq(shost->host_lock);
2631 lpfc_can_disctmo(vport);
2632 lpfc_end_rscn(vport);
2633 }
James Smartfdcebe22006-03-07 15:04:01 -05002634 }
2635 }
2636 }
2637 return;
2638}
2639
James Smarte59058c2008-08-24 21:49:00 -04002640/**
James Smart3621a712009-04-06 18:47:14 -04002641 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002642 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2643 *
2644 * This routine is invoked by the ndlp delayed-function timer to check
2645 * whether there is any pending ELS retry event(s) with the node. If not, it
2646 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2647 * adds the delayed events to the HBA work list and invokes the
2648 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2649 * event. Note that lpfc_nlp_get() is called before posting the event to
2650 * the work list to hold reference count of ndlp so that it guarantees the
2651 * reference to ndlp will still be available when the worker thread gets
2652 * to the event associated with the ndlp.
2653 **/
James Smartfdcebe22006-03-07 15:04:01 -05002654void
dea31012005-04-17 16:05:31 -05002655lpfc_els_retry_delay(unsigned long ptr)
2656{
James Smart2e0fef82007-06-17 19:56:36 -05002657 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2658 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002659 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002660 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002661 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002662
James Smart92d7f7b2007-06-17 19:56:38 -05002663 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002664 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002665 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002666 return;
2667 }
2668
James Smartfa4066b2008-01-11 01:53:27 -05002669 /* We need to hold the node by incrementing the reference
2670 * count until the queued work is done
2671 */
2672 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002673 if (evtp->evt_arg1) {
2674 evtp->evt = LPFC_EVT_ELS_RETRY;
2675 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002676 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002677 }
James Smart92d7f7b2007-06-17 19:56:38 -05002678 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002679 return;
2680}
2681
James Smarte59058c2008-08-24 21:49:00 -04002682/**
James Smart3621a712009-04-06 18:47:14 -04002683 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002684 * @ndlp: pointer to a node-list data structure.
2685 *
2686 * This routine is the worker-thread handler for processing the @ndlp delayed
2687 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2688 * the last ELS command from the associated ndlp and invokes the proper ELS
2689 * function according to the delayed ELS command to retry the command.
2690 **/
dea31012005-04-17 16:05:31 -05002691void
2692lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2693{
James Smart2e0fef82007-06-17 19:56:36 -05002694 struct lpfc_vport *vport = ndlp->vport;
2695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2696 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002697
James Smart2e0fef82007-06-17 19:56:36 -05002698 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002699 did = ndlp->nlp_DID;
2700 cmd = ndlp->nlp_last_elscmd;
2701 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002702
2703 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002704 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002705 return;
2706 }
2707
2708 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002709 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002710 /*
2711 * If a discovery event readded nlp_delayfunc after timer
2712 * firing and before processing the timer, cancel the
2713 * nlp_delayfunc.
2714 */
2715 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002716 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002717 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002718
2719 switch (cmd) {
2720 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002721 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002722 break;
2723 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002724 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002725 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002727 }
dea31012005-04-17 16:05:31 -05002728 break;
2729 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002730 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002731 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002732 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002733 }
dea31012005-04-17 16:05:31 -05002734 break;
2735 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002736 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002737 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002739 }
dea31012005-04-17 16:05:31 -05002740 break;
2741 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002742 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002743 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002745 }
dea31012005-04-17 16:05:31 -05002746 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002747 case ELS_CMD_FDISC:
James Smartfedd3b72011-02-16 12:39:24 -05002748 if (!(vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI))
2749 lpfc_issue_els_fdisc(vport, ndlp, retry);
James Smart92d7f7b2007-06-17 19:56:38 -05002750 break;
dea31012005-04-17 16:05:31 -05002751 }
2752 return;
2753}
2754
James Smarte59058c2008-08-24 21:49:00 -04002755/**
James Smart3621a712009-04-06 18:47:14 -04002756 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002757 * @phba: pointer to lpfc hba data structure.
2758 * @cmdiocb: pointer to lpfc command iocb data structure.
2759 * @rspiocb: pointer to lpfc response iocb data structure.
2760 *
2761 * This routine makes a retry decision on an ELS command IOCB, which has
2762 * failed. The following ELS IOCBs use this function for retrying the command
2763 * when previously issued command responsed with error status: FLOGI, PLOGI,
2764 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2765 * returned error status, it makes the decision whether a retry shall be
2766 * issued for the command, and whether a retry shall be made immediately or
2767 * delayed. In the former case, the corresponding ELS command issuing-function
2768 * is called to retry the command. In the later case, the ELS command shall
2769 * be posted to the ndlp delayed event and delayed function timer set to the
2770 * ndlp for the delayed command issusing.
2771 *
2772 * Return code
2773 * 0 - No retry of els command is made
2774 * 1 - Immediate or delayed retry of els command is made
2775 **/
dea31012005-04-17 16:05:31 -05002776static int
James Smart2e0fef82007-06-17 19:56:36 -05002777lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2778 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002779{
James Smart2e0fef82007-06-17 19:56:36 -05002780 struct lpfc_vport *vport = cmdiocb->vport;
2781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2782 IOCB_t *irsp = &rspiocb->iocb;
2783 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2784 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002785 uint32_t *elscmd;
2786 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002787 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002788 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002789 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002790 uint32_t did;
dea31012005-04-17 16:05:31 -05002791
James Smart488d1462006-03-07 15:02:37 -05002792
dea31012005-04-17 16:05:31 -05002793 /* Note: context2 may be 0 for internal driver abort
2794 * of delays ELS command.
2795 */
2796
2797 if (pcmd && pcmd->virt) {
2798 elscmd = (uint32_t *) (pcmd->virt);
2799 cmd = *elscmd++;
2800 }
2801
James Smarte47c9092008-02-08 18:49:26 -05002802 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002803 did = ndlp->nlp_DID;
2804 else {
2805 /* We should only hit this case for retrying PLOGI */
2806 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002807 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002808 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2809 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002810 return 1;
2811 }
2812
James Smart858c9f62007-06-17 19:56:39 -05002813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2814 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2815 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2816
dea31012005-04-17 16:05:31 -05002817 switch (irsp->ulpStatus) {
2818 case IOSTAT_FCP_RSP_ERROR:
dea31012005-04-17 16:05:31 -05002819 break;
James Smart1151e3e2011-02-16 12:39:35 -05002820 case IOSTAT_REMOTE_STOP:
2821 if (phba->sli_rev == LPFC_SLI_REV4) {
2822 /* This IO was aborted by the target, we don't
2823 * know the rxid and because we did not send the
2824 * ABTS we cannot generate and RRQ.
2825 */
2826 lpfc_set_rrq_active(phba, ndlp,
2827 cmdiocb->sli4_xritag, 0, 0);
2828 }
2829 break;
dea31012005-04-17 16:05:31 -05002830 case IOSTAT_LOCAL_REJECT:
2831 switch ((irsp->un.ulpWord[4] & 0xff)) {
2832 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002833 if (cmd == ELS_CMD_FLOGI) {
2834 if (PCI_DEVICE_ID_HORNET ==
2835 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002836 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002837 phba->pport->fc_myDID = 0;
2838 phba->alpa_map[0] = 0;
2839 phba->alpa_map[1] = 0;
2840 }
2841 }
James Smart2e0fef82007-06-17 19:56:36 -05002842 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002843 delay = 1000;
dea31012005-04-17 16:05:31 -05002844 retry = 1;
2845 break;
2846
James Smart92d7f7b2007-06-17 19:56:38 -05002847 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002848 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2849 "0124 Retry illegal cmd x%x "
2850 "retry:x%x delay:x%x\n",
2851 cmd, cmdiocb->retry, delay);
2852 retry = 1;
2853 /* All command's retry policy */
2854 maxretry = 8;
2855 if (cmdiocb->retry > 2)
2856 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002857 break;
2858
dea31012005-04-17 16:05:31 -05002859 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002860 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002861 retry = 1;
2862 if (cmdiocb->retry > 100)
2863 delay = 100;
2864 maxretry = 250;
2865 break;
2866
2867 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002868 delay = 100;
dea31012005-04-17 16:05:31 -05002869 retry = 1;
2870 break;
2871
James Smart858c9f62007-06-17 19:56:39 -05002872 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002873 case IOERR_INVALID_RPI:
2874 retry = 1;
2875 break;
2876 }
2877 break;
2878
2879 case IOSTAT_NPORT_RJT:
2880 case IOSTAT_FABRIC_RJT:
2881 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2882 retry = 1;
2883 break;
2884 }
2885 break;
2886
2887 case IOSTAT_NPORT_BSY:
2888 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002889 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002890 retry = 1;
2891 break;
2892
2893 case IOSTAT_LS_RJT:
2894 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2895 /* Added for Vendor specifc support
2896 * Just keep retrying for these Rsn / Exp codes
2897 */
2898 switch (stat.un.b.lsRjtRsnCode) {
2899 case LSRJT_UNABLE_TPC:
2900 if (stat.un.b.lsRjtRsnCodeExp ==
2901 LSEXP_CMD_IN_PROGRESS) {
2902 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002903 delay = 1000;
dea31012005-04-17 16:05:31 -05002904 maxretry = 48;
2905 }
2906 retry = 1;
2907 break;
2908 }
James Smartffc95492010-06-07 15:23:17 -04002909 if (stat.un.b.lsRjtRsnCodeExp ==
2910 LSEXP_CANT_GIVE_DATA) {
2911 if (cmd == ELS_CMD_PLOGI) {
2912 delay = 1000;
2913 maxretry = 48;
2914 }
2915 retry = 1;
2916 break;
2917 }
dea31012005-04-17 16:05:31 -05002918 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002919 delay = 1000;
dea31012005-04-17 16:05:31 -05002920 maxretry = lpfc_max_els_tries + 1;
2921 retry = 1;
2922 break;
2923 }
James Smart92d7f7b2007-06-17 19:56:38 -05002924 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2925 (cmd == ELS_CMD_FDISC) &&
2926 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002927 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2928 "0125 FDISC Failed (x%x). "
2929 "Fabric out of resources\n",
2930 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002931 lpfc_vport_set_state(vport,
2932 FC_VPORT_NO_FABRIC_RSCS);
2933 }
dea31012005-04-17 16:05:31 -05002934 break;
2935
2936 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002937 if ((cmd == ELS_CMD_PLOGI) ||
2938 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002939 delay = 1000;
dea31012005-04-17 16:05:31 -05002940 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002941 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002942 /* FDISC retry policy */
2943 maxretry = 48;
2944 if (cmdiocb->retry >= 32)
2945 delay = 1000;
dea31012005-04-17 16:05:31 -05002946 }
2947 retry = 1;
2948 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002949
2950 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002951 /* There are some cases where switches return this
2952 * error when they are not ready and should be returning
2953 * Logical Busy. We should delay every time.
2954 */
2955 if (cmd == ELS_CMD_FDISC &&
2956 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2957 maxretry = 3;
2958 delay = 1000;
2959 retry = 1;
2960 break;
2961 }
James Smart92d7f7b2007-06-17 19:56:38 -05002962 case LSRJT_PROTOCOL_ERR:
2963 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2964 (cmd == ELS_CMD_FDISC) &&
2965 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2966 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2967 ) {
James Smarte8b62012007-08-02 11:10:09 -04002968 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002969 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002970 "Fabric Detected Bad WWN\n",
2971 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002972 lpfc_vport_set_state(vport,
2973 FC_VPORT_FABRIC_REJ_WWN);
2974 }
2975 break;
dea31012005-04-17 16:05:31 -05002976 }
2977 break;
2978
2979 case IOSTAT_INTERMED_RSP:
2980 case IOSTAT_BA_RJT:
2981 break;
2982
2983 default:
2984 break;
2985 }
2986
James Smart488d1462006-03-07 15:02:37 -05002987 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002988 retry = 1;
dea31012005-04-17 16:05:31 -05002989
James Smart695a8142010-01-26 23:08:03 -05002990 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05002991 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002992 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002993 /* FLOGI retry policy */
2994 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002995 /* retry forever */
2996 maxretry = 0;
2997 if (cmdiocb->retry >= 100)
2998 delay = 5000;
2999 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04003000 delay = 1000;
3001 }
3002
James Smart6669f9b2009-10-02 15:16:45 -04003003 cmdiocb->retry++;
3004 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05003005 phba->fc_stat.elsRetryExceeded++;
3006 retry = 0;
3007 }
3008
James Smarted957682007-06-17 19:56:37 -05003009 if ((vport->load_flag & FC_UNLOADING) != 0)
3010 retry = 0;
3011
dea31012005-04-17 16:05:31 -05003012 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003013 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3014 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3015 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3016 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3017 "2849 Stop retry ELS command "
3018 "x%x to remote NPORT x%x, "
3019 "Data: x%x x%x\n", cmd, did,
3020 cmdiocb->retry, delay);
3021 return 0;
3022 }
3023 }
dea31012005-04-17 16:05:31 -05003024
3025 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003026 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3027 "0107 Retry ELS command x%x to remote "
3028 "NPORT x%x Data: x%x x%x\n",
3029 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003030
James Smart858c9f62007-06-17 19:56:39 -05003031 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3032 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3033 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3034 /* Don't reset timer for no resources */
3035
dea31012005-04-17 16:05:31 -05003036 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003037 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003038 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003039 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003040 }
3041
3042 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003043 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003044 phba->fc_stat.elsDelayRetry++;
3045 ndlp->nlp_retry = cmdiocb->retry;
3046
James Smart92d7f7b2007-06-17 19:56:38 -05003047 /* delay is specified in milliseconds */
3048 mod_timer(&ndlp->nlp_delayfunc,
3049 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003050 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003051 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003052 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003053
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003054 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003055 if (cmd == ELS_CMD_PRLI)
3056 lpfc_nlp_set_state(vport, ndlp,
3057 NLP_STE_REG_LOGIN_ISSUE);
3058 else
3059 lpfc_nlp_set_state(vport, ndlp,
3060 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003061 ndlp->nlp_last_elscmd = cmd;
3062
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003063 return 1;
dea31012005-04-17 16:05:31 -05003064 }
3065 switch (cmd) {
3066 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003067 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003068 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003069 case ELS_CMD_FDISC:
3070 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3071 return 1;
dea31012005-04-17 16:05:31 -05003072 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003073 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003074 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003075 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003076 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003077 }
James Smart2e0fef82007-06-17 19:56:36 -05003078 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003079 return 1;
dea31012005-04-17 16:05:31 -05003080 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003081 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3083 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003084 return 1;
dea31012005-04-17 16:05:31 -05003085 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003086 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003087 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3088 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003089 return 1;
dea31012005-04-17 16:05:31 -05003090 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003091 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003092 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3093 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003094 return 1;
dea31012005-04-17 16:05:31 -05003095 }
3096 }
dea31012005-04-17 16:05:31 -05003097 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003098 if (logerr) {
3099 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3100 "0137 No retry ELS command x%x to remote "
3101 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3102 cmd, did, irsp->ulpStatus,
3103 irsp->un.ulpWord[4]);
3104 }
3105 else {
3106 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003107 "0108 No retry ELS command x%x to remote "
3108 "NPORT x%x Retried:%d Error:x%x/%x\n",
3109 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3110 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003111 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003112 return 0;
dea31012005-04-17 16:05:31 -05003113}
3114
James Smarte59058c2008-08-24 21:49:00 -04003115/**
James Smart3621a712009-04-06 18:47:14 -04003116 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003117 * @phba: pointer to lpfc hba data structure.
3118 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3119 *
3120 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3121 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3122 * checks to see whether there is a lpfc DMA buffer associated with the
3123 * response of the command IOCB. If so, it will be released before releasing
3124 * the lpfc DMA buffer associated with the IOCB itself.
3125 *
3126 * Return code
3127 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3128 **/
James Smart09372822008-01-11 01:52:54 -05003129static int
James Smart87af33f2007-10-27 13:37:43 -04003130lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3131{
3132 struct lpfc_dmabuf *buf_ptr;
3133
James Smarte59058c2008-08-24 21:49:00 -04003134 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003135 if (!list_empty(&buf_ptr1->list)) {
3136 list_remove_head(&buf_ptr1->list, buf_ptr,
3137 struct lpfc_dmabuf,
3138 list);
3139 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3140 kfree(buf_ptr);
3141 }
3142 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3143 kfree(buf_ptr1);
3144 return 0;
3145}
3146
James Smarte59058c2008-08-24 21:49:00 -04003147/**
James Smart3621a712009-04-06 18:47:14 -04003148 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003149 * @phba: pointer to lpfc hba data structure.
3150 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3151 *
3152 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3153 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3154 * pool.
3155 *
3156 * Return code
3157 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3158 **/
James Smart09372822008-01-11 01:52:54 -05003159static int
James Smart87af33f2007-10-27 13:37:43 -04003160lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3161{
3162 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3163 kfree(buf_ptr);
3164 return 0;
3165}
3166
James Smarte59058c2008-08-24 21:49:00 -04003167/**
James Smart3621a712009-04-06 18:47:14 -04003168 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003169 * @phba: pointer to lpfc hba data structure.
3170 * @elsiocb: pointer to lpfc els command iocb data structure.
3171 *
3172 * This routine frees a command IOCB and its associated resources. The
3173 * command IOCB data structure contains the reference to various associated
3174 * resources, these fields must be set to NULL if the associated reference
3175 * not present:
3176 * context1 - reference to ndlp
3177 * context2 - reference to cmd
3178 * context2->next - reference to rsp
3179 * context3 - reference to bpl
3180 *
3181 * It first properly decrements the reference count held on ndlp for the
3182 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3183 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3184 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3185 * adds the DMA buffer the @phba data structure for the delayed release.
3186 * If reference to the Buffer Pointer List (BPL) is present, the
3187 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3188 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3189 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3190 *
3191 * Return code
3192 * 0 - Success (currently, always return 0)
3193 **/
James Smart87af33f2007-10-27 13:37:43 -04003194int
James Smart329f9bc2007-04-25 09:53:01 -04003195lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003196{
3197 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003198 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003199
James Smarta8adb832007-10-27 13:37:53 -04003200 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3201 if (ndlp) {
3202 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3203 lpfc_nlp_put(ndlp);
3204
3205 /* If the ndlp is not being used by another discovery
3206 * thread, free it.
3207 */
3208 if (!lpfc_nlp_not_used(ndlp)) {
3209 /* If ndlp is being used by another discovery
3210 * thread, just clear NLP_DEFER_RM
3211 */
3212 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3213 }
3214 }
3215 else
3216 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003217 elsiocb->context1 = NULL;
3218 }
dea31012005-04-17 16:05:31 -05003219 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3220 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003221 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3222 /* Firmware could still be in progress of DMAing
3223 * payload, so don't free data buffer till after
3224 * a hbeat.
3225 */
3226 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3227 buf_ptr = elsiocb->context2;
3228 elsiocb->context2 = NULL;
3229 if (buf_ptr) {
3230 buf_ptr1 = NULL;
3231 spin_lock_irq(&phba->hbalock);
3232 if (!list_empty(&buf_ptr->list)) {
3233 list_remove_head(&buf_ptr->list,
3234 buf_ptr1, struct lpfc_dmabuf,
3235 list);
3236 INIT_LIST_HEAD(&buf_ptr1->list);
3237 list_add_tail(&buf_ptr1->list,
3238 &phba->elsbuf);
3239 phba->elsbuf_cnt++;
3240 }
3241 INIT_LIST_HEAD(&buf_ptr->list);
3242 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3243 phba->elsbuf_cnt++;
3244 spin_unlock_irq(&phba->hbalock);
3245 }
3246 } else {
3247 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3248 lpfc_els_free_data(phba, buf_ptr1);
3249 }
dea31012005-04-17 16:05:31 -05003250 }
3251
3252 if (elsiocb->context3) {
3253 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003254 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003255 }
James Bottomley604a3e32005-10-29 10:28:33 -05003256 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003257 return 0;
3258}
3259
James Smarte59058c2008-08-24 21:49:00 -04003260/**
James Smart3621a712009-04-06 18:47:14 -04003261 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003262 * @phba: pointer to lpfc hba data structure.
3263 * @cmdiocb: pointer to lpfc command iocb data structure.
3264 * @rspiocb: pointer to lpfc response iocb data structure.
3265 *
3266 * This routine is the completion callback function to the Logout (LOGO)
3267 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3268 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3269 * release the ndlp if it has the last reference remaining (reference count
3270 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3271 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3272 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3273 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3274 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3275 * IOCB data structure.
3276 **/
dea31012005-04-17 16:05:31 -05003277static void
James Smart2e0fef82007-06-17 19:56:36 -05003278lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3279 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003280{
James Smart2e0fef82007-06-17 19:56:36 -05003281 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3282 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003283 IOCB_t *irsp;
3284
3285 irsp = &rspiocb->iocb;
3286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3287 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3288 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003289 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003290 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3291 "0109 ACC to LOGO completes to NPort x%x "
3292 "Data: x%x x%x x%x\n",
3293 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3294 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003295
3296 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3297 /* NPort Recovery mode or node is just allocated */
3298 if (!lpfc_nlp_not_used(ndlp)) {
3299 /* If the ndlp is being used by another discovery
3300 * thread, just unregister the RPI.
3301 */
3302 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003303 } else {
3304 /* Indicate the node has already released, should
3305 * not reference to it from within lpfc_els_free_iocb.
3306 */
3307 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003308 }
dea31012005-04-17 16:05:31 -05003309 }
3310 lpfc_els_free_iocb(phba, cmdiocb);
3311 return;
3312}
3313
James Smarte59058c2008-08-24 21:49:00 -04003314/**
James Smart3621a712009-04-06 18:47:14 -04003315 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003316 * @phba: pointer to lpfc hba data structure.
3317 * @pmb: pointer to the driver internal queue element for mailbox command.
3318 *
3319 * This routine is the completion callback function for unregister default
3320 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3321 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3322 * decrements the ndlp reference count held for this completion callback
3323 * function. After that, it invokes the lpfc_nlp_not_used() to check
3324 * whether there is only one reference left on the ndlp. If so, it will
3325 * perform one more decrement and trigger the release of the ndlp.
3326 **/
James Smart858c9f62007-06-17 19:56:39 -05003327void
3328lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3329{
3330 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3331 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3332
3333 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003334 pmb->context2 = NULL;
3335
James Smart858c9f62007-06-17 19:56:39 -05003336 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3337 kfree(mp);
3338 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003339 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003340 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003341 /* This is the end of the default RPI cleanup logic for this
3342 * ndlp. If no other discovery threads are using this ndlp.
3343 * we should free all resources associated with it.
3344 */
3345 lpfc_nlp_not_used(ndlp);
3346 }
James Smart3772a992009-05-22 14:50:54 -04003347
James Smart858c9f62007-06-17 19:56:39 -05003348 return;
3349}
3350
James Smarte59058c2008-08-24 21:49:00 -04003351/**
James Smart3621a712009-04-06 18:47:14 -04003352 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003353 * @phba: pointer to lpfc hba data structure.
3354 * @cmdiocb: pointer to lpfc command iocb data structure.
3355 * @rspiocb: pointer to lpfc response iocb data structure.
3356 *
3357 * This routine is the completion callback function for ELS Response IOCB
3358 * command. In normal case, this callback function just properly sets the
3359 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3360 * field in the command IOCB is not NULL, the referred mailbox command will
3361 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3362 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3363 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3364 * routine shall be invoked trying to release the ndlp if no other threads
3365 * are currently referring it.
3366 **/
dea31012005-04-17 16:05:31 -05003367static void
James Smart858c9f62007-06-17 19:56:39 -05003368lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003369 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003370{
James Smart2e0fef82007-06-17 19:56:36 -05003371 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3372 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3373 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003374 IOCB_t *irsp;
3375 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003376 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003377 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003378 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003379
James Smart33ccf8d2006-08-17 11:57:58 -04003380 irsp = &rspiocb->iocb;
3381
dea31012005-04-17 16:05:31 -05003382 if (cmdiocb->context_un.mbox)
3383 mbox = cmdiocb->context_un.mbox;
3384
James Smartfa4066b2008-01-11 01:53:27 -05003385 /* First determine if this is a LS_RJT cmpl. Note, this callback
3386 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3387 */
James Smart87af33f2007-10-27 13:37:43 -04003388 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003389 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3390 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003391 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003392 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003393 */
3394 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3395 ls_rjt = 1;
3396 }
3397
dea31012005-04-17 16:05:31 -05003398 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003399 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003400 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003401 mp = (struct lpfc_dmabuf *) mbox->context1;
3402 if (mp) {
3403 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3404 kfree(mp);
3405 }
James Smart329f9bc2007-04-25 09:53:01 -04003406 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003407 }
James Smart58da1ff2008-04-07 10:15:56 -04003408 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3409 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003410 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003411 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003412 /* Indicate the node has already released,
3413 * should not reference to it from within
3414 * the routine lpfc_els_free_iocb.
3415 */
3416 cmdiocb->context1 = NULL;
3417 }
dea31012005-04-17 16:05:31 -05003418 goto out;
3419 }
3420
James Smart858c9f62007-06-17 19:56:39 -05003421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003422 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003423 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003424 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003425 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003426 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3427 "0110 ELS response tag x%x completes "
3428 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3429 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3430 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3431 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3432 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003433 if (mbox) {
3434 if ((rspiocb->iocb.ulpStatus == 0)
3435 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003436 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003437 /* Increment reference count to ndlp to hold the
3438 * reference to ndlp for the callback function.
3439 */
James Smart329f9bc2007-04-25 09:53:01 -04003440 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003441 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003442 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3443 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3444 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3445 }
3446 else {
3447 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3448 ndlp->nlp_prev_state = ndlp->nlp_state;
3449 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003450 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003451 }
James Smart0b727fe2007-10-27 13:37:25 -04003452 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003453 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003454 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003455 else
3456 /* Decrement the ndlp reference count we
3457 * set for this failed mailbox command.
3458 */
3459 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003460
3461 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3462 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3463 "0138 ELS rsp: Cannot issue reg_login for x%x "
3464 "Data: x%x x%x x%x\n",
3465 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3466 ndlp->nlp_rpi);
3467
James Smartfa4066b2008-01-11 01:53:27 -05003468 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003469 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003470 /* Indicate node has already been released,
3471 * should not reference to it from within
3472 * the routine lpfc_els_free_iocb.
3473 */
3474 cmdiocb->context1 = NULL;
3475 }
dea31012005-04-17 16:05:31 -05003476 } else {
James Smart858c9f62007-06-17 19:56:39 -05003477 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3478 if (!lpfc_error_lost_link(irsp) &&
3479 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003480 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003481 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003482 /* Indicate node has already been
3483 * released, should not reference
3484 * to it from within the routine
3485 * lpfc_els_free_iocb.
3486 */
3487 cmdiocb->context1 = NULL;
3488 }
dea31012005-04-17 16:05:31 -05003489 }
3490 }
James Smart14691152006-12-02 13:34:28 -05003491 mp = (struct lpfc_dmabuf *) mbox->context1;
3492 if (mp) {
3493 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3494 kfree(mp);
3495 }
3496 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003497 }
3498out:
James Smart58da1ff2008-04-07 10:15:56 -04003499 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003500 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003501 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003502 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003503
3504 /* If the node is not being used by another discovery thread,
3505 * and we are sending a reject, we are done with it.
3506 * Release driver reference count here and free associated
3507 * resources.
3508 */
3509 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003510 if (lpfc_nlp_not_used(ndlp))
3511 /* Indicate node has already been released,
3512 * should not reference to it from within
3513 * the routine lpfc_els_free_iocb.
3514 */
3515 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003516 }
James Smart87af33f2007-10-27 13:37:43 -04003517
dea31012005-04-17 16:05:31 -05003518 lpfc_els_free_iocb(phba, cmdiocb);
3519 return;
3520}
3521
James Smarte59058c2008-08-24 21:49:00 -04003522/**
James Smart3621a712009-04-06 18:47:14 -04003523 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003524 * @vport: pointer to a host virtual N_Port data structure.
3525 * @flag: the els command code to be accepted.
3526 * @oldiocb: pointer to the original lpfc command iocb data structure.
3527 * @ndlp: pointer to a node-list data structure.
3528 * @mbox: pointer to the driver internal queue element for mailbox command.
3529 *
3530 * This routine prepares and issues an Accept (ACC) response IOCB
3531 * command. It uses the @flag to properly set up the IOCB field for the
3532 * specific ACC response command to be issued and invokes the
3533 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3534 * @mbox pointer is passed in, it will be put into the context_un.mbox
3535 * field of the IOCB for the completion callback function to issue the
3536 * mailbox command to the HBA later when callback is invoked.
3537 *
3538 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3539 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3540 * will be stored into the context1 field of the IOCB for the completion
3541 * callback function to the corresponding response ELS IOCB command.
3542 *
3543 * Return code
3544 * 0 - Successfully issued acc response
3545 * 1 - Failed to issue acc response
3546 **/
dea31012005-04-17 16:05:31 -05003547int
James Smart2e0fef82007-06-17 19:56:36 -05003548lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3549 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003550 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003551{
James Smart2e0fef82007-06-17 19:56:36 -05003552 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3553 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003554 IOCB_t *icmd;
3555 IOCB_t *oldcmd;
3556 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003557 struct lpfc_sli *psli;
3558 uint8_t *pcmd;
3559 uint16_t cmdsize;
3560 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003561 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003562
3563 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003564 oldcmd = &oldiocb->iocb;
3565
3566 switch (flag) {
3567 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003568 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003569 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3570 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003571 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003572 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003573 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003574 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003575 return 1;
dea31012005-04-17 16:05:31 -05003576 }
James Smart2e0fef82007-06-17 19:56:36 -05003577
dea31012005-04-17 16:05:31 -05003578 icmd = &elsiocb->iocb;
3579 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3580 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3581 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003582 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003583
3584 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3585 "Issue ACC: did:x%x flg:x%x",
3586 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003587 break;
3588 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003589 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003590 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3591 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003592 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003593 return 1;
James Smart488d1462006-03-07 15:02:37 -05003594
dea31012005-04-17 16:05:31 -05003595 icmd = &elsiocb->iocb;
3596 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3597 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3598
3599 if (mbox)
3600 elsiocb->context_un.mbox = mbox;
3601
3602 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003603 pcmd += sizeof(uint32_t);
3604 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003605
3606 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3607 "Issue ACC PLOGI: did:x%x flg:x%x",
3608 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003609 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003610 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003611 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003612 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003613 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3614 if (!elsiocb)
3615 return 1;
3616
3617 icmd = &elsiocb->iocb;
3618 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3619 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3620
3621 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003622 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003623 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3624 els_pkt_ptr = (ELS_PKT *) pcmd;
3625 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003626
3627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3628 "Issue ACC PRLO: did:x%x flg:x%x",
3629 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003630 break;
dea31012005-04-17 16:05:31 -05003631 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003632 return 1;
dea31012005-04-17 16:05:31 -05003633 }
dea31012005-04-17 16:05:31 -05003634 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003635 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3636 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3637 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3638 elsiocb->iotag, elsiocb->iocb.ulpContext,
3639 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3640 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003641 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003642 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003643 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003644 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003645 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3646 } else {
James Smart858c9f62007-06-17 19:56:39 -05003647 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003648 }
3649
3650 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003651 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003652 if (rc == IOCB_ERROR) {
3653 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003654 return 1;
dea31012005-04-17 16:05:31 -05003655 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003656 return 0;
dea31012005-04-17 16:05:31 -05003657}
3658
James Smarte59058c2008-08-24 21:49:00 -04003659/**
James Smart3621a712009-04-06 18:47:14 -04003660 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003661 * @vport: pointer to a virtual N_Port data structure.
3662 * @rejectError:
3663 * @oldiocb: pointer to the original lpfc command iocb data structure.
3664 * @ndlp: pointer to a node-list data structure.
3665 * @mbox: pointer to the driver internal queue element for mailbox command.
3666 *
3667 * This routine prepares and issue an Reject (RJT) response IOCB
3668 * command. If a @mbox pointer is passed in, it will be put into the
3669 * context_un.mbox field of the IOCB for the completion callback function
3670 * to issue to the HBA later.
3671 *
3672 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3673 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3674 * will be stored into the context1 field of the IOCB for the completion
3675 * callback function to the reject response ELS IOCB command.
3676 *
3677 * Return code
3678 * 0 - Successfully issued reject response
3679 * 1 - Failed to issue reject response
3680 **/
dea31012005-04-17 16:05:31 -05003681int
James Smart2e0fef82007-06-17 19:56:36 -05003682lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003683 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3684 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003685{
James Smart2e0fef82007-06-17 19:56:36 -05003686 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003687 IOCB_t *icmd;
3688 IOCB_t *oldcmd;
3689 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003690 struct lpfc_sli *psli;
3691 uint8_t *pcmd;
3692 uint16_t cmdsize;
3693 int rc;
3694
3695 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003696 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003697 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3698 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003699 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003700 return 1;
dea31012005-04-17 16:05:31 -05003701
3702 icmd = &elsiocb->iocb;
3703 oldcmd = &oldiocb->iocb;
3704 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3705 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3706
3707 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003708 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003709 *((uint32_t *) (pcmd)) = rejectError;
3710
James Smart51ef4c22007-08-02 11:10:31 -04003711 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003712 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003713
dea31012005-04-17 16:05:31 -05003714 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003715 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3716 "0129 Xmit ELS RJT x%x response tag x%x "
3717 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3718 "rpi x%x\n",
3719 rejectError, elsiocb->iotag,
3720 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3721 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003722 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3723 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3724 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3725
dea31012005-04-17 16:05:31 -05003726 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003727 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003728 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003729
dea31012005-04-17 16:05:31 -05003730 if (rc == IOCB_ERROR) {
3731 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003732 return 1;
dea31012005-04-17 16:05:31 -05003733 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003734 return 0;
dea31012005-04-17 16:05:31 -05003735}
3736
James Smarte59058c2008-08-24 21:49:00 -04003737/**
James Smart3621a712009-04-06 18:47:14 -04003738 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003739 * @vport: pointer to a virtual N_Port data structure.
3740 * @oldiocb: pointer to the original lpfc command iocb data structure.
3741 * @ndlp: pointer to a node-list data structure.
3742 *
3743 * This routine prepares and issues an Accept (ACC) response to Address
3744 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3745 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3746 *
3747 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3748 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3749 * will be stored into the context1 field of the IOCB for the completion
3750 * callback function to the ADISC Accept response ELS IOCB command.
3751 *
3752 * Return code
3753 * 0 - Successfully issued acc adisc response
3754 * 1 - Failed to issue adisc acc response
3755 **/
dea31012005-04-17 16:05:31 -05003756int
James Smart2e0fef82007-06-17 19:56:36 -05003757lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3758 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003759{
James Smart2e0fef82007-06-17 19:56:36 -05003760 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003761 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003762 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003763 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003764 uint8_t *pcmd;
3765 uint16_t cmdsize;
3766 int rc;
3767
James Smart92d7f7b2007-06-17 19:56:38 -05003768 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003769 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3770 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003771 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003772 return 1;
dea31012005-04-17 16:05:31 -05003773
dea31012005-04-17 16:05:31 -05003774 icmd = &elsiocb->iocb;
3775 oldcmd = &oldiocb->iocb;
3776 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003777
3778 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003779 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3780 "0130 Xmit ADISC ACC response iotag x%x xri: "
3781 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3782 elsiocb->iotag, elsiocb->iocb.ulpContext,
3783 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3784 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003785 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3786
3787 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003788 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003789
3790 ap = (ADISC *) (pcmd);
3791 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003792 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3793 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003794 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003795
James Smart858c9f62007-06-17 19:56:39 -05003796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3797 "Issue ACC ADISC: did:x%x flg:x%x",
3798 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3799
dea31012005-04-17 16:05:31 -05003800 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003801 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003802 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003803 if (rc == IOCB_ERROR) {
3804 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003805 return 1;
dea31012005-04-17 16:05:31 -05003806 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003807 return 0;
dea31012005-04-17 16:05:31 -05003808}
3809
James Smarte59058c2008-08-24 21:49:00 -04003810/**
James Smart3621a712009-04-06 18:47:14 -04003811 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003812 * @vport: pointer to a virtual N_Port data structure.
3813 * @oldiocb: pointer to the original lpfc command iocb data structure.
3814 * @ndlp: pointer to a node-list data structure.
3815 *
3816 * This routine prepares and issues an Accept (ACC) response to Process
3817 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3818 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3819 *
3820 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3821 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3822 * will be stored into the context1 field of the IOCB for the completion
3823 * callback function to the PRLI Accept response ELS IOCB command.
3824 *
3825 * Return code
3826 * 0 - Successfully issued acc prli response
3827 * 1 - Failed to issue acc prli response
3828 **/
dea31012005-04-17 16:05:31 -05003829int
James Smart2e0fef82007-06-17 19:56:36 -05003830lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003831 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 PRLI *npr;
3835 lpfc_vpd_t *vpd;
3836 IOCB_t *icmd;
3837 IOCB_t *oldcmd;
3838 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003839 struct lpfc_sli *psli;
3840 uint8_t *pcmd;
3841 uint16_t cmdsize;
3842 int rc;
3843
3844 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003845
James Smart92d7f7b2007-06-17 19:56:38 -05003846 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003847 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003848 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003849 if (!elsiocb)
3850 return 1;
dea31012005-04-17 16:05:31 -05003851
dea31012005-04-17 16:05:31 -05003852 icmd = &elsiocb->iocb;
3853 oldcmd = &oldiocb->iocb;
3854 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003855 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003856 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3857 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3858 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3859 elsiocb->iotag, elsiocb->iocb.ulpContext,
3860 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3861 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003862 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3863
3864 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003865 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003866
3867 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003868 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003869
3870 npr = (PRLI *) pcmd;
3871 vpd = &phba->vpd;
3872 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003873 * If the remote port is a target and our firmware version is 3.20 or
3874 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003875 */
James Smart0d2b6b82008-06-14 22:52:47 -04003876 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3877 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003878 npr->ConfmComplAllowed = 1;
3879 npr->Retry = 1;
3880 npr->TaskRetryIdReq = 1;
3881 }
3882
3883 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3884 npr->estabImagePair = 1;
3885 npr->readXferRdyDis = 1;
3886 npr->ConfmComplAllowed = 1;
3887
3888 npr->prliType = PRLI_FCP_TYPE;
3889 npr->initiatorFunc = 1;
3890
James Smart858c9f62007-06-17 19:56:39 -05003891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3892 "Issue ACC PRLI: did:x%x flg:x%x",
3893 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3894
dea31012005-04-17 16:05:31 -05003895 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003896 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003897
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 Smart3621a712009-04-06 18:47:14 -04003907 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003908 * @vport: pointer to a virtual N_Port data structure.
3909 * @format: rnid command format.
3910 * @oldiocb: pointer to the original lpfc command iocb data structure.
3911 * @ndlp: pointer to a node-list data structure.
3912 *
3913 * This routine issues a Request Node Identification Data (RNID) Accept
3914 * (ACC) response. It constructs the RNID ACC response command according to
3915 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3916 * issue the response. Note that this command does not need to hold the ndlp
3917 * reference count for the callback. So, the ndlp reference count taken by
3918 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3919 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3920 * there is no ndlp reference available.
3921 *
3922 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3923 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3924 * will be stored into the context1 field of the IOCB for the completion
3925 * callback function. However, for the RNID Accept Response ELS command,
3926 * this is undone later by this routine after the IOCB is allocated.
3927 *
3928 * Return code
3929 * 0 - Successfully issued acc rnid response
3930 * 1 - Failed to issue acc rnid response
3931 **/
dea31012005-04-17 16:05:31 -05003932static int
James Smart2e0fef82007-06-17 19:56:36 -05003933lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003934 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003935{
James Smart2e0fef82007-06-17 19:56:36 -05003936 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003937 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003938 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003939 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003940 struct lpfc_sli *psli;
3941 uint8_t *pcmd;
3942 uint16_t cmdsize;
3943 int rc;
3944
3945 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003946 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3947 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003948 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003949 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003950
James Smart2e0fef82007-06-17 19:56:36 -05003951 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3952 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003953 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003954 return 1;
dea31012005-04-17 16:05:31 -05003955
dea31012005-04-17 16:05:31 -05003956 icmd = &elsiocb->iocb;
3957 oldcmd = &oldiocb->iocb;
3958 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003959 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003960 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3961 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3962 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003963 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003964 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003965 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003966
James Smart92d7f7b2007-06-17 19:56:38 -05003967 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003968 rn = (RNID *) (pcmd);
3969 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003970 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3971 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3972 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003973 switch (format) {
3974 case 0:
3975 rn->SpecificLen = 0;
3976 break;
3977 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003978 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003979 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003980 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003981 rn->un.topologyDisc.unitType = RNID_HBA;
3982 rn->un.topologyDisc.physPort = 0;
3983 rn->un.topologyDisc.attachedNodes = 0;
3984 break;
3985 default:
3986 rn->CommonLen = 0;
3987 rn->SpecificLen = 0;
3988 break;
3989 }
3990
James Smart858c9f62007-06-17 19:56:39 -05003991 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3992 "Issue ACC RNID: did:x%x flg:x%x",
3993 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3994
dea31012005-04-17 16:05:31 -05003995 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003996 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003997 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003998 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3999 * it could be freed */
4000
James Smart3772a992009-05-22 14:50:54 -04004001 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05004002 if (rc == IOCB_ERROR) {
4003 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004004 return 1;
dea31012005-04-17 16:05:31 -05004005 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004006 return 0;
dea31012005-04-17 16:05:31 -05004007}
4008
James Smarte59058c2008-08-24 21:49:00 -04004009/**
James Smart19ca7602010-11-20 23:11:55 -05004010 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4011 * @vport: pointer to a virtual N_Port data structure.
4012 * @iocb: pointer to the lpfc command iocb data structure.
4013 * @ndlp: pointer to a node-list data structure.
4014 *
4015 * Return
4016 **/
4017static void
4018lpfc_els_clear_rrq(struct lpfc_vport *vport,
4019 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4020{
4021 struct lpfc_hba *phba = vport->phba;
4022 uint8_t *pcmd;
4023 struct RRQ *rrq;
4024 uint16_t rxid;
James Smart1151e3e2011-02-16 12:39:35 -05004025 uint16_t xri;
James Smart19ca7602010-11-20 23:11:55 -05004026 struct lpfc_node_rrq *prrq;
4027
4028
4029 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4030 pcmd += sizeof(uint32_t);
4031 rrq = (struct RRQ *)pcmd;
James Smart1151e3e2011-02-16 12:39:35 -05004032 rrq->rrq_exchg = be32_to_cpu(rrq->rrq_exchg);
4033 rxid = be16_to_cpu(bf_get(rrq_rxid, rrq));
James Smart19ca7602010-11-20 23:11:55 -05004034
4035 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4036 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4037 " x%x x%x\n",
James Smart1151e3e2011-02-16 12:39:35 -05004038 be32_to_cpu(bf_get(rrq_did, rrq)),
4039 be16_to_cpu(bf_get(rrq_oxid, rrq)),
James Smart19ca7602010-11-20 23:11:55 -05004040 rxid,
4041 iocb->iotag, iocb->iocb.ulpContext);
4042
4043 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4044 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4045 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
James Smart1151e3e2011-02-16 12:39:35 -05004046 if (vport->fc_myDID == be32_to_cpu(bf_get(rrq_did, rrq)))
4047 xri = be16_to_cpu(bf_get(rrq_oxid, rrq));
4048 else
4049 xri = rxid;
4050 prrq = lpfc_get_active_rrq(vport, xri, ndlp->nlp_DID);
James Smart19ca7602010-11-20 23:11:55 -05004051 if (prrq)
James Smart1151e3e2011-02-16 12:39:35 -05004052 lpfc_clr_rrq_active(phba, xri, prrq);
James Smart19ca7602010-11-20 23:11:55 -05004053 return;
4054}
4055
4056/**
James Smart12265f62010-10-22 11:05:53 -04004057 * lpfc_els_rsp_echo_acc - Issue echo acc response
4058 * @vport: pointer to a virtual N_Port data structure.
4059 * @data: pointer to echo data to return in the accept.
4060 * @oldiocb: pointer to the original lpfc command iocb data structure.
4061 * @ndlp: pointer to a node-list data structure.
4062 *
4063 * Return code
4064 * 0 - Successfully issued acc echo response
4065 * 1 - Failed to issue acc echo response
4066 **/
4067static int
4068lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4069 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4070{
4071 struct lpfc_hba *phba = vport->phba;
4072 struct lpfc_iocbq *elsiocb;
4073 struct lpfc_sli *psli;
4074 uint8_t *pcmd;
4075 uint16_t cmdsize;
4076 int rc;
4077
4078 psli = &phba->sli;
4079 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4080
4081 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4082 ndlp->nlp_DID, ELS_CMD_ACC);
4083 if (!elsiocb)
4084 return 1;
4085
4086 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4087 /* Xmit ECHO ACC response tag <ulpIoTag> */
4088 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4089 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4090 elsiocb->iotag, elsiocb->iocb.ulpContext);
4091 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4092 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4093 pcmd += sizeof(uint32_t);
4094 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4095
4096 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4097 "Issue ACC ECHO: did:x%x flg:x%x",
4098 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4099
4100 phba->fc_stat.elsXmitACC++;
4101 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4102 lpfc_nlp_put(ndlp);
4103 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4104 * it could be freed */
4105
4106 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4107 if (rc == IOCB_ERROR) {
4108 lpfc_els_free_iocb(phba, elsiocb);
4109 return 1;
4110 }
4111 return 0;
4112}
4113
4114/**
James Smart3621a712009-04-06 18:47:14 -04004115 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004116 * @vport: pointer to a host virtual N_Port data structure.
4117 *
4118 * This routine issues Address Discover (ADISC) ELS commands to those
4119 * N_Ports which are in node port recovery state and ADISC has not been issued
4120 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4121 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4122 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4123 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4124 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4125 * IOCBs quit for later pick up. On the other hand, after walking through
4126 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4127 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4128 * no more ADISC need to be sent.
4129 *
4130 * Return code
4131 * The number of N_Ports with adisc issued.
4132 **/
dea31012005-04-17 16:05:31 -05004133int
James Smart2e0fef82007-06-17 19:56:36 -05004134lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004135{
James Smart2e0fef82007-06-17 19:56:36 -05004136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004137 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004138 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004139
James Smart685f0bf2007-04-25 09:53:08 -04004140 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004141 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004142 if (!NLP_CHK_NODE_ACT(ndlp))
4143 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004144 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4145 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4146 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004147 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004148 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004149 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004150 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004151 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4152 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004153 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004154 vport->num_disc_nodes++;
4155 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004156 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004157 spin_lock_irq(shost->host_lock);
4158 vport->fc_flag |= FC_NLP_MORE;
4159 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004160 break;
dea31012005-04-17 16:05:31 -05004161 }
4162 }
4163 }
4164 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004165 spin_lock_irq(shost->host_lock);
4166 vport->fc_flag &= ~FC_NLP_MORE;
4167 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004168 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004169 return sentadisc;
dea31012005-04-17 16:05:31 -05004170}
4171
James Smarte59058c2008-08-24 21:49:00 -04004172/**
James Smart3621a712009-04-06 18:47:14 -04004173 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004174 * @vport: pointer to a host virtual N_Port data structure.
4175 *
4176 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4177 * which are in node port recovery state, with a @vport. Each time an ELS
4178 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4179 * the per @vport number of discover count (num_disc_nodes) shall be
4180 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4181 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4182 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4183 * later pick up. On the other hand, after walking through all the ndlps with
4184 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4185 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4186 * PLOGI need to be sent.
4187 *
4188 * Return code
4189 * The number of N_Ports with plogi issued.
4190 **/
dea31012005-04-17 16:05:31 -05004191int
James Smart2e0fef82007-06-17 19:56:36 -05004192lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004193{
James Smart2e0fef82007-06-17 19:56:36 -05004194 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004195 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004196 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004197
James Smart2e0fef82007-06-17 19:56:36 -05004198 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4199 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004200 if (!NLP_CHK_NODE_ACT(ndlp))
4201 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004202 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4203 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4204 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4205 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4206 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004207 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4208 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004209 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004210 vport->num_disc_nodes++;
4211 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004212 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004213 spin_lock_irq(shost->host_lock);
4214 vport->fc_flag |= FC_NLP_MORE;
4215 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004216 break;
dea31012005-04-17 16:05:31 -05004217 }
4218 }
4219 }
James Smart87af33f2007-10-27 13:37:43 -04004220 if (sentplogi) {
4221 lpfc_set_disctmo(vport);
4222 }
4223 else {
James Smart2e0fef82007-06-17 19:56:36 -05004224 spin_lock_irq(shost->host_lock);
4225 vport->fc_flag &= ~FC_NLP_MORE;
4226 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004227 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004228 return sentplogi;
dea31012005-04-17 16:05:31 -05004229}
4230
James Smarte59058c2008-08-24 21:49:00 -04004231/**
James Smart3621a712009-04-06 18:47:14 -04004232 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004233 * @vport: pointer to a host virtual N_Port data structure.
4234 *
4235 * This routine cleans up any Registration State Change Notification
4236 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4237 * @vport together with the host_lock is used to prevent multiple thread
4238 * trying to access the RSCN array on a same @vport at the same time.
4239 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004240void
James Smart2e0fef82007-06-17 19:56:36 -05004241lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004242{
James Smart2e0fef82007-06-17 19:56:36 -05004243 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4244 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004245 int i;
4246
James Smart7f5f3d02008-02-08 18:50:14 -05004247 spin_lock_irq(shost->host_lock);
4248 if (vport->fc_rscn_flush) {
4249 /* Another thread is walking fc_rscn_id_list on this vport */
4250 spin_unlock_irq(shost->host_lock);
4251 return;
4252 }
4253 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4254 vport->fc_rscn_flush = 1;
4255 spin_unlock_irq(shost->host_lock);
4256
James Smart2e0fef82007-06-17 19:56:36 -05004257 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004258 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004259 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004260 }
James Smart2e0fef82007-06-17 19:56:36 -05004261 spin_lock_irq(shost->host_lock);
4262 vport->fc_rscn_id_cnt = 0;
4263 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4264 spin_unlock_irq(shost->host_lock);
4265 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004266 /* Indicate we are done walking this fc_rscn_id_list */
4267 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004268}
4269
James Smarte59058c2008-08-24 21:49:00 -04004270/**
James Smart3621a712009-04-06 18:47:14 -04004271 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004272 * @vport: pointer to a host virtual N_Port data structure.
4273 * @did: remote destination port identifier.
4274 *
4275 * This routine checks whether there is any pending Registration State
4276 * Configuration Notification (RSCN) to a @did on @vport.
4277 *
4278 * Return code
4279 * None zero - The @did matched with a pending rscn
4280 * 0 - not able to match @did with a pending rscn
4281 **/
dea31012005-04-17 16:05:31 -05004282int
James Smart2e0fef82007-06-17 19:56:36 -05004283lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004284{
4285 D_ID ns_did;
4286 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004287 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004288 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004289 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004290
4291 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004292
4293 /* Never match fabric nodes for RSCNs */
4294 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004295 return 0;
dea31012005-04-17 16:05:31 -05004296
4297 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004298 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004299 return did;
dea31012005-04-17 16:05:31 -05004300
James Smart7f5f3d02008-02-08 18:50:14 -05004301 spin_lock_irq(shost->host_lock);
4302 if (vport->fc_rscn_flush) {
4303 /* Another thread is walking fc_rscn_id_list on this vport */
4304 spin_unlock_irq(shost->host_lock);
4305 return 0;
4306 }
4307 /* Indicate we are walking fc_rscn_id_list on this vport */
4308 vport->fc_rscn_flush = 1;
4309 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004310 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004311 lp = vport->fc_rscn_id_list[i]->virt;
4312 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4313 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004314 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004315 rscn_did.un.word = be32_to_cpu(*lp++);
4316 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004317 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4318 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004319 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4320 && (ns_did.un.b.area == rscn_did.un.b.area)
4321 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004322 goto return_did_out;
dea31012005-04-17 16:05:31 -05004323 break;
James Smarteaf15d52008-12-04 22:39:29 -05004324 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004325 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4326 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004327 goto return_did_out;
dea31012005-04-17 16:05:31 -05004328 break;
James Smarteaf15d52008-12-04 22:39:29 -05004329 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004330 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004331 goto return_did_out;
dea31012005-04-17 16:05:31 -05004332 break;
James Smarteaf15d52008-12-04 22:39:29 -05004333 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004334 goto return_did_out;
dea31012005-04-17 16:05:31 -05004335 }
4336 }
James Smart92d7f7b2007-06-17 19:56:38 -05004337 }
James Smart7f5f3d02008-02-08 18:50:14 -05004338 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4339 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004340 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004341return_did_out:
4342 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4343 vport->fc_rscn_flush = 0;
4344 return did;
dea31012005-04-17 16:05:31 -05004345}
4346
James Smarte59058c2008-08-24 21:49:00 -04004347/**
James Smart3621a712009-04-06 18:47:14 -04004348 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004349 * @vport: pointer to a host virtual N_Port data structure.
4350 *
4351 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4352 * state machine for a @vport's nodes that are with pending RSCN (Registration
4353 * State Change Notification).
4354 *
4355 * Return code
4356 * 0 - Successful (currently alway return 0)
4357 **/
dea31012005-04-17 16:05:31 -05004358static int
James Smart2e0fef82007-06-17 19:56:36 -05004359lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004360{
James Smart685f0bf2007-04-25 09:53:08 -04004361 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004362
James Smart0d2b6b82008-06-14 22:52:47 -04004363 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004364 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004365 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004366 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4367 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004368 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004369 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004370 NLP_EVT_DEVICE_RECOVERY);
4371 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004372 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004373 return 0;
dea31012005-04-17 16:05:31 -05004374}
4375
James Smarte59058c2008-08-24 21:49:00 -04004376/**
James Smart3621a712009-04-06 18:47:14 -04004377 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004378 * @vport: pointer to a host virtual N_Port data structure.
4379 * @cmdiocb: pointer to lpfc command iocb data structure.
4380 *
4381 * lpfc_send_rscn_event sends an RSCN netlink event to management
4382 * applications.
4383 */
4384static void
4385lpfc_send_rscn_event(struct lpfc_vport *vport,
4386 struct lpfc_iocbq *cmdiocb)
4387{
4388 struct lpfc_dmabuf *pcmd;
4389 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4390 uint32_t *payload_ptr;
4391 uint32_t payload_len;
4392 struct lpfc_rscn_event_header *rscn_event_data;
4393
4394 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4395 payload_ptr = (uint32_t *) pcmd->virt;
4396 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4397
4398 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4399 payload_len, GFP_KERNEL);
4400 if (!rscn_event_data) {
4401 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4402 "0147 Failed to allocate memory for RSCN event\n");
4403 return;
4404 }
4405 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4406 rscn_event_data->payload_length = payload_len;
4407 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4408 payload_len);
4409
4410 fc_host_post_vendor_event(shost,
4411 fc_get_event_number(),
4412 sizeof(struct lpfc_els_event_header) + payload_len,
4413 (char *)rscn_event_data,
4414 LPFC_NL_VENDOR_ID);
4415
4416 kfree(rscn_event_data);
4417}
4418
4419/**
James Smart3621a712009-04-06 18:47:14 -04004420 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004421 * @vport: pointer to a host virtual N_Port data structure.
4422 * @cmdiocb: pointer to lpfc command iocb data structure.
4423 * @ndlp: pointer to a node-list data structure.
4424 *
4425 * This routine processes an unsolicited RSCN (Registration State Change
4426 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4427 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4428 * discover state machine is about to begin discovery, it just accepts the
4429 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4430 * contains N_Port IDs for other vports on this HBA, it just accepts the
4431 * RSCN and ignore processing it. If the state machine is in the recovery
4432 * state, the fc_rscn_id_list of this @vport is walked and the
4433 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4434 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4435 * routine is invoked to handle the RSCN event.
4436 *
4437 * Return code
4438 * 0 - Just sent the acc response
4439 * 1 - Sent the acc response and waited for name server completion
4440 **/
dea31012005-04-17 16:05:31 -05004441static int
James Smart2e0fef82007-06-17 19:56:36 -05004442lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004443 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004444{
James Smart2e0fef82007-06-17 19:56:36 -05004445 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4446 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004447 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004448 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004449 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004450 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004451 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004452 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004453 int i;
dea31012005-04-17 16:05:31 -05004454
4455 icmd = &cmdiocb->iocb;
4456 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4457 lp = (uint32_t *) pcmd->virt;
4458
James Smart92d7f7b2007-06-17 19:56:38 -05004459 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4460 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004461 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004462 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4463 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004464 vport->fc_flag, payload_len, *lp,
4465 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004466
4467 /* Send an RSCN event to the management application */
4468 lpfc_send_rscn_event(vport, cmdiocb);
4469
James Smartd2873e42006-08-18 17:46:43 -04004470 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004471 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004472 FCH_EVT_RSCN, lp[i]);
4473
dea31012005-04-17 16:05:31 -05004474 /* If we are about to begin discovery, just ACC the RSCN.
4475 * Discovery processing will satisfy it.
4476 */
James Smart2e0fef82007-06-17 19:56:36 -05004477 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4479 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4480 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4481
James Smart51ef4c22007-08-02 11:10:31 -04004482 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004483 return 0;
dea31012005-04-17 16:05:31 -05004484 }
4485
James Smart92d7f7b2007-06-17 19:56:38 -05004486 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4487 * just ACC and ignore it.
4488 */
4489 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004490 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004491 i = payload_len;
4492 datap = lp;
4493 while (i > 0) {
4494 nportid = *datap++;
4495 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4496 i -= sizeof(uint32_t);
4497 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004498 if (lpfc_find_vport_by_did(phba, nportid))
4499 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004500 }
4501 if (rscn_id == hba_id) {
4502 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004503 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004504 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004505 "Data: x%x x%x x%x x%x\n",
4506 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004507 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004508 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4509 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4510 ndlp->nlp_DID, vport->port_state,
4511 ndlp->nlp_flag);
4512
James Smart92d7f7b2007-06-17 19:56:38 -05004513 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004514 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004515 return 0;
4516 }
4517 }
4518
James Smart7f5f3d02008-02-08 18:50:14 -05004519 spin_lock_irq(shost->host_lock);
4520 if (vport->fc_rscn_flush) {
4521 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004522 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004523 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004524 /* Send back ACC */
4525 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004526 return 0;
4527 }
4528 /* Indicate we are walking fc_rscn_id_list on this vport */
4529 vport->fc_rscn_flush = 1;
4530 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004531 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004532 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004533 /* If we are already processing an RSCN, save the received
4534 * RSCN payload buffer, cmdiocb->context2 to process later.
4535 */
James Smart2e0fef82007-06-17 19:56:36 -05004536 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004537 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4538 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4539 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4540
James Smart09372822008-01-11 01:52:54 -05004541 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004542 vport->fc_flag |= FC_RSCN_DEFERRED;
4543 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004544 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004545 vport->fc_flag |= FC_RSCN_MODE;
4546 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004547 if (rscn_cnt) {
4548 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4549 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4550 }
4551 if ((rscn_cnt) &&
4552 (payload_len + length <= LPFC_BPL_SIZE)) {
4553 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004554 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004555 memcpy(((uint8_t *)cmd) + length, lp,
4556 payload_len);
4557 } else {
4558 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4559 vport->fc_rscn_id_cnt++;
4560 /* If we zero, cmdiocb->context2, the calling
4561 * routine will not try to free it.
4562 */
4563 cmdiocb->context2 = NULL;
4564 }
dea31012005-04-17 16:05:31 -05004565 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004566 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4567 "0235 Deferred RSCN "
4568 "Data: x%x x%x x%x\n",
4569 vport->fc_rscn_id_cnt, vport->fc_flag,
4570 vport->port_state);
dea31012005-04-17 16:05:31 -05004571 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004572 vport->fc_flag |= FC_RSCN_DISCOVERY;
4573 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004574 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004575 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4576 "0234 ReDiscovery RSCN "
4577 "Data: x%x x%x x%x\n",
4578 vport->fc_rscn_id_cnt, vport->fc_flag,
4579 vport->port_state);
dea31012005-04-17 16:05:31 -05004580 }
James Smart7f5f3d02008-02-08 18:50:14 -05004581 /* Indicate we are done walking fc_rscn_id_list on this vport */
4582 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004583 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004584 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004585 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004586 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004587 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004588 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004589 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004590 return 0;
dea31012005-04-17 16:05:31 -05004591 }
James Smart858c9f62007-06-17 19:56:39 -05004592 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4593 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4594 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4595
James Smart2e0fef82007-06-17 19:56:36 -05004596 spin_lock_irq(shost->host_lock);
4597 vport->fc_flag |= FC_RSCN_MODE;
4598 spin_unlock_irq(shost->host_lock);
4599 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004600 /* Indicate we are done walking fc_rscn_id_list on this vport */
4601 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004602 /*
4603 * If we zero, cmdiocb->context2, the calling routine will
4604 * not try to free it.
4605 */
4606 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004607 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004608 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004609 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004610 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004611 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004612 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004613}
4614
James Smarte59058c2008-08-24 21:49:00 -04004615/**
James Smart3621a712009-04-06 18:47:14 -04004616 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004617 * @vport: pointer to a host virtual N_Port data structure.
4618 *
4619 * This routine handles the Registration State Configuration Notification
4620 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4621 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4622 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4623 * NameServer shall be issued. If CT command to the NameServer fails to be
4624 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4625 * RSCN activities with the @vport.
4626 *
4627 * Return code
4628 * 0 - Cleaned up rscn on the @vport
4629 * 1 - Wait for plogi to name server before proceed
4630 **/
dea31012005-04-17 16:05:31 -05004631int
James Smart2e0fef82007-06-17 19:56:36 -05004632lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004633{
4634 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004635 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004636
James Smart92d7f7b2007-06-17 19:56:38 -05004637 /* Ignore RSCN if the port is being torn down. */
4638 if (vport->load_flag & FC_UNLOADING) {
4639 lpfc_els_flush_rscn(vport);
4640 return 0;
4641 }
4642
dea31012005-04-17 16:05:31 -05004643 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004644 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004645
4646 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004647 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4648 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4649 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4650 vport->port_state);
dea31012005-04-17 16:05:31 -05004651
4652 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004653 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004654 vport->num_disc_nodes = 0;
4655
James Smart2e0fef82007-06-17 19:56:36 -05004656 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004657 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4658 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004659 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004660 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004661 /* Wait for NameServer query cmpl before we can
4662 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004663 return 1;
dea31012005-04-17 16:05:31 -05004664 } else {
4665 /* If login to NameServer does not exist, issue one */
4666 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004667 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004668 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004669 /* Wait for NameServer login cmpl before we can
4670 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004671 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004672
James Smarte47c9092008-02-08 18:49:26 -05004673 if (ndlp) {
4674 ndlp = lpfc_enable_node(vport, ndlp,
4675 NLP_STE_PLOGI_ISSUE);
4676 if (!ndlp) {
4677 lpfc_els_flush_rscn(vport);
4678 return 0;
4679 }
4680 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004681 } else {
James Smarte47c9092008-02-08 18:49:26 -05004682 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4683 if (!ndlp) {
4684 lpfc_els_flush_rscn(vport);
4685 return 0;
4686 }
James Smart2e0fef82007-06-17 19:56:36 -05004687 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004688 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004689 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004690 }
James Smarte47c9092008-02-08 18:49:26 -05004691 ndlp->nlp_type |= NLP_FABRIC;
4692 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4693 /* Wait for NameServer login cmpl before we can
4694 * continue
4695 */
4696 return 1;
dea31012005-04-17 16:05:31 -05004697 }
4698
James Smart2e0fef82007-06-17 19:56:36 -05004699 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004700 return 0;
dea31012005-04-17 16:05:31 -05004701}
4702
James Smarte59058c2008-08-24 21:49:00 -04004703/**
James Smart3621a712009-04-06 18:47:14 -04004704 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004705 * @vport: pointer to a host virtual N_Port data structure.
4706 * @cmdiocb: pointer to lpfc command iocb data structure.
4707 * @ndlp: pointer to a node-list data structure.
4708 *
4709 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4710 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4711 * point topology. As an unsolicited FLOGI should not be received in a loop
4712 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4713 * lpfc_check_sparm() routine is invoked to check the parameters in the
4714 * unsolicited FLOGI. If parameters validation failed, the routine
4715 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4716 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4717 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4718 * will initiate PLOGI. The higher lexicographical value party shall has
4719 * higher priority (as the winning port) and will initiate PLOGI and
4720 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4721 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4722 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4723 *
4724 * Return code
4725 * 0 - Successfully processed the unsolicited flogi
4726 * 1 - Failed to process the unsolicited flogi
4727 **/
dea31012005-04-17 16:05:31 -05004728static int
James Smart2e0fef82007-06-17 19:56:36 -05004729lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004730 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004731{
James Smart2e0fef82007-06-17 19:56:36 -05004732 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4733 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004734 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4735 uint32_t *lp = (uint32_t *) pcmd->virt;
4736 IOCB_t *icmd = &cmdiocb->iocb;
4737 struct serv_parm *sp;
4738 LPFC_MBOXQ_t *mbox;
4739 struct ls_rjt stat;
4740 uint32_t cmd, did;
4741 int rc;
4742
4743 cmd = *lp++;
4744 sp = (struct serv_parm *) lp;
4745
4746 /* FLOGI received */
4747
James Smart2e0fef82007-06-17 19:56:36 -05004748 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004749
James Smart76a95d72010-11-20 23:11:48 -05004750 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004751 /* We should never receive a FLOGI in loop mode, ignore it */
4752 did = icmd->un.elsreq64.remoteID;
4753
4754 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4755 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004756 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4757 "0113 An FLOGI ELS command x%x was "
4758 "received from DID x%x in Loop Mode\n",
4759 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004760 return 1;
dea31012005-04-17 16:05:31 -05004761 }
4762
4763 did = Fabric_DID;
4764
James Smart341af102010-01-26 23:07:37 -05004765 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004766 /* For a FLOGI we accept, then if our portname is greater
4767 * then the remote portname we initiate Nport login.
4768 */
4769
James Smart2e0fef82007-06-17 19:56:36 -05004770 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004771 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004772
4773 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004774 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4775 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004776 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004777
dea31012005-04-17 16:05:31 -05004778 lpfc_linkdown(phba);
4779 lpfc_init_link(phba, mbox,
4780 phba->cfg_topology,
4781 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004782 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004783 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004784 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004785 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004786 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004787 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004788 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004789 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004790 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004791 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004792 spin_lock_irq(shost->host_lock);
4793 vport->fc_flag |= FC_PT2PT_PLOGI;
4794 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004795 }
James Smart2e0fef82007-06-17 19:56:36 -05004796 spin_lock_irq(shost->host_lock);
4797 vport->fc_flag |= FC_PT2PT;
4798 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4799 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004800 } else {
4801 /* Reject this request because invalid parameters */
4802 stat.un.b.lsRjtRsvd0 = 0;
4803 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4804 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4805 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004806 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4807 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004808 return 1;
dea31012005-04-17 16:05:31 -05004809 }
4810
4811 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004812 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004813
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004814 return 0;
dea31012005-04-17 16:05:31 -05004815}
4816
James Smarte59058c2008-08-24 21:49:00 -04004817/**
James Smart3621a712009-04-06 18:47:14 -04004818 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004819 * @vport: pointer to a host virtual N_Port data structure.
4820 * @cmdiocb: pointer to lpfc command iocb data structure.
4821 * @ndlp: pointer to a node-list data structure.
4822 *
4823 * This routine processes Request Node Identification Data (RNID) IOCB
4824 * received as an ELS unsolicited event. Only when the RNID specified format
4825 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4826 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4827 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4828 * rejected by invoking the lpfc_els_rsp_reject() routine.
4829 *
4830 * Return code
4831 * 0 - Successfully processed rnid iocb (currently always return 0)
4832 **/
dea31012005-04-17 16:05:31 -05004833static int
James Smart2e0fef82007-06-17 19:56:36 -05004834lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4835 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004836{
4837 struct lpfc_dmabuf *pcmd;
4838 uint32_t *lp;
4839 IOCB_t *icmd;
4840 RNID *rn;
4841 struct ls_rjt stat;
4842 uint32_t cmd, did;
4843
4844 icmd = &cmdiocb->iocb;
4845 did = icmd->un.elsreq64.remoteID;
4846 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4847 lp = (uint32_t *) pcmd->virt;
4848
4849 cmd = *lp++;
4850 rn = (RNID *) lp;
4851
4852 /* RNID received */
4853
4854 switch (rn->Format) {
4855 case 0:
4856 case RNID_TOPOLOGY_DISC:
4857 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004858 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004859 break;
4860 default:
4861 /* Reject this request because format not supported */
4862 stat.un.b.lsRjtRsvd0 = 0;
4863 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4864 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4865 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004866 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4867 NULL);
dea31012005-04-17 16:05:31 -05004868 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004869 return 0;
dea31012005-04-17 16:05:31 -05004870}
4871
James Smarte59058c2008-08-24 21:49:00 -04004872/**
James Smart12265f62010-10-22 11:05:53 -04004873 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4874 * @vport: pointer to a host virtual N_Port data structure.
4875 * @cmdiocb: pointer to lpfc command iocb data structure.
4876 * @ndlp: pointer to a node-list data structure.
4877 *
4878 * Return code
4879 * 0 - Successfully processed echo iocb (currently always return 0)
4880 **/
4881static int
4882lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4883 struct lpfc_nodelist *ndlp)
4884{
4885 uint8_t *pcmd;
4886
4887 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4888
4889 /* skip over first word of echo command to find echo data */
4890 pcmd += sizeof(uint32_t);
4891
4892 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4893 return 0;
4894}
4895
4896/**
James Smart3621a712009-04-06 18:47:14 -04004897 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004898 * @vport: pointer to a host virtual N_Port data structure.
4899 * @cmdiocb: pointer to lpfc command iocb data structure.
4900 * @ndlp: pointer to a node-list data structure.
4901 *
4902 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4903 * received as an ELS unsolicited event. Currently, this function just invokes
4904 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4905 *
4906 * Return code
4907 * 0 - Successfully processed lirr iocb (currently always return 0)
4908 **/
dea31012005-04-17 16:05:31 -05004909static int
James Smart2e0fef82007-06-17 19:56:36 -05004910lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4911 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004912{
4913 struct ls_rjt stat;
4914
4915 /* For now, unconditionally reject this command */
4916 stat.un.b.lsRjtRsvd0 = 0;
4917 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4918 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4919 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004920 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004921 return 0;
4922}
4923
James Smarte59058c2008-08-24 21:49:00 -04004924/**
James Smart5ffc2662009-11-18 15:39:44 -05004925 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4926 * @vport: pointer to a host virtual N_Port data structure.
4927 * @cmdiocb: pointer to lpfc command iocb data structure.
4928 * @ndlp: pointer to a node-list data structure.
4929 *
4930 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4931 * received as an ELS unsolicited event. A request to RRQ shall only
4932 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4933 * Nx_Port N_Port_ID of the target Exchange is the same as the
4934 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4935 * not accepted, an LS_RJT with reason code "Unable to perform
4936 * command request" and reason code explanation "Invalid Originator
4937 * S_ID" shall be returned. For now, we just unconditionally accept
4938 * RRQ from the target.
4939 **/
4940static void
4941lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4942 struct lpfc_nodelist *ndlp)
4943{
4944 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05004945 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4946 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05004947}
4948
4949/**
James Smart12265f62010-10-22 11:05:53 -04004950 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4951 * @phba: pointer to lpfc hba data structure.
4952 * @pmb: pointer to the driver internal queue element for mailbox command.
4953 *
4954 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4955 * mailbox command. This callback function is to actually send the Accept
4956 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4957 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4958 * mailbox command, constructs the RPS response with the link statistics
4959 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4960 * response to the RPS.
4961 *
4962 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4963 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4964 * will be stored into the context1 field of the IOCB for the completion
4965 * callback function to the RPS Accept Response ELS IOCB command.
4966 *
4967 **/
4968static void
4969lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4970{
4971 MAILBOX_t *mb;
4972 IOCB_t *icmd;
4973 struct RLS_RSP *rls_rsp;
4974 uint8_t *pcmd;
4975 struct lpfc_iocbq *elsiocb;
4976 struct lpfc_nodelist *ndlp;
4977 uint16_t xri;
4978 uint32_t cmdsize;
4979
4980 mb = &pmb->u.mb;
4981
4982 ndlp = (struct lpfc_nodelist *) pmb->context2;
4983 xri = (uint16_t) ((unsigned long)(pmb->context1));
4984 pmb->context1 = NULL;
4985 pmb->context2 = NULL;
4986
4987 if (mb->mbxStatus) {
4988 mempool_free(pmb, phba->mbox_mem_pool);
4989 return;
4990 }
4991
4992 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4993 mempool_free(pmb, phba->mbox_mem_pool);
4994 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4995 lpfc_max_els_tries, ndlp,
4996 ndlp->nlp_DID, ELS_CMD_ACC);
4997
4998 /* Decrement the ndlp reference count from previous mbox command */
4999 lpfc_nlp_put(ndlp);
5000
5001 if (!elsiocb)
5002 return;
5003
5004 icmd = &elsiocb->iocb;
5005 icmd->ulpContext = xri;
5006
5007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5008 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5009 pcmd += sizeof(uint32_t); /* Skip past command */
5010 rls_rsp = (struct RLS_RSP *)pcmd;
5011
5012 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5013 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5014 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5015 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5016 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5017 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5018
5019 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5020 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5021 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5022 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5023 elsiocb->iotag, elsiocb->iocb.ulpContext,
5024 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5025 ndlp->nlp_rpi);
5026 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5027 phba->fc_stat.elsXmitACC++;
5028 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5029 lpfc_els_free_iocb(phba, elsiocb);
5030}
5031
5032/**
James Smart3621a712009-04-06 18:47:14 -04005033 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005034 * @phba: pointer to lpfc hba data structure.
5035 * @pmb: pointer to the driver internal queue element for mailbox command.
5036 *
5037 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5038 * mailbox command. This callback function is to actually send the Accept
5039 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5040 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5041 * mailbox command, constructs the RPS response with the link statistics
5042 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5043 * response to the RPS.
5044 *
5045 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5046 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5047 * will be stored into the context1 field of the IOCB for the completion
5048 * callback function to the RPS Accept Response ELS IOCB command.
5049 *
5050 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005051static void
James Smart329f9bc2007-04-25 09:53:01 -04005052lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005053{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005054 MAILBOX_t *mb;
5055 IOCB_t *icmd;
5056 RPS_RSP *rps_rsp;
5057 uint8_t *pcmd;
5058 struct lpfc_iocbq *elsiocb;
5059 struct lpfc_nodelist *ndlp;
5060 uint16_t xri, status;
5061 uint32_t cmdsize;
5062
James Smart04c68492009-05-22 14:52:52 -04005063 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005064
5065 ndlp = (struct lpfc_nodelist *) pmb->context2;
5066 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07005067 pmb->context1 = NULL;
5068 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005069
5070 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005071 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005072 return;
5073 }
5074
5075 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005076 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005077 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5078 lpfc_max_els_tries, ndlp,
5079 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005080
5081 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005082 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005083
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005084 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005085 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005086
5087 icmd = &elsiocb->iocb;
5088 icmd->ulpContext = xri;
5089
5090 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5091 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005092 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005093 rps_rsp = (RPS_RSP *)pcmd;
5094
James Smart76a95d72010-11-20 23:11:48 -05005095 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005096 status = 0x10;
5097 else
5098 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005099 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005100 status |= 0x4;
5101
5102 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005103 rps_rsp->portStatus = cpu_to_be16(status);
5104 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5105 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5106 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5107 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5108 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5109 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005110 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005111 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5112 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5113 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5114 elsiocb->iotag, elsiocb->iocb.ulpContext,
5115 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5116 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005117 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005118 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005119 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005120 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005121 return;
5122}
5123
James Smarte59058c2008-08-24 21:49:00 -04005124/**
James Smart12265f62010-10-22 11:05:53 -04005125 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5126 * @vport: pointer to a host virtual N_Port data structure.
5127 * @cmdiocb: pointer to lpfc command iocb data structure.
5128 * @ndlp: pointer to a node-list data structure.
5129 *
5130 * This routine processes Read Port Status (RPL) IOCB received as an
5131 * ELS unsolicited event. It first checks the remote port state. If the
5132 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5133 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5134 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5135 * for reading the HBA link statistics. It is for the callback function,
5136 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5137 * to actually sending out RPL Accept (ACC) response.
5138 *
5139 * Return codes
5140 * 0 - Successfully processed rls iocb (currently always return 0)
5141 **/
5142static int
5143lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5144 struct lpfc_nodelist *ndlp)
5145{
5146 struct lpfc_hba *phba = vport->phba;
5147 LPFC_MBOXQ_t *mbox;
5148 struct lpfc_dmabuf *pcmd;
5149 struct ls_rjt stat;
5150
5151 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5152 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5153 /* reject the unsolicited RPS request and done with it */
5154 goto reject_out;
5155
5156 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5157
5158 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5159 if (mbox) {
5160 lpfc_read_lnk_stat(phba, mbox);
5161 mbox->context1 =
5162 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5163 mbox->context2 = lpfc_nlp_get(ndlp);
5164 mbox->vport = vport;
5165 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5166 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5167 != MBX_NOT_FINISHED)
5168 /* Mbox completion will send ELS Response */
5169 return 0;
5170 /* Decrement reference count used for the failed mbox
5171 * command.
5172 */
5173 lpfc_nlp_put(ndlp);
5174 mempool_free(mbox, phba->mbox_mem_pool);
5175 }
5176reject_out:
5177 /* issue rejection response */
5178 stat.un.b.lsRjtRsvd0 = 0;
5179 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5180 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5181 stat.un.b.vendorUnique = 0;
5182 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5183 return 0;
5184}
5185
5186/**
5187 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5188 * @vport: pointer to a host virtual N_Port data structure.
5189 * @cmdiocb: pointer to lpfc command iocb data structure.
5190 * @ndlp: pointer to a node-list data structure.
5191 *
5192 * This routine processes Read Timout Value (RTV) IOCB received as an
5193 * ELS unsolicited event. It first checks the remote port state. If the
5194 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5195 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5196 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5197 * Value (RTV) unsolicited IOCB event.
5198 *
5199 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5200 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5201 * will be stored into the context1 field of the IOCB for the completion
5202 * callback function to the RPS Accept Response ELS IOCB command.
5203 *
5204 * Return codes
5205 * 0 - Successfully processed rtv iocb (currently always return 0)
5206 **/
5207static int
5208lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5209 struct lpfc_nodelist *ndlp)
5210{
5211 struct lpfc_hba *phba = vport->phba;
5212 struct ls_rjt stat;
5213 struct RTV_RSP *rtv_rsp;
5214 uint8_t *pcmd;
5215 struct lpfc_iocbq *elsiocb;
5216 uint32_t cmdsize;
5217
5218
5219 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5220 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5221 /* reject the unsolicited RPS request and done with it */
5222 goto reject_out;
5223
5224 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5225 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5226 lpfc_max_els_tries, ndlp,
5227 ndlp->nlp_DID, ELS_CMD_ACC);
5228
5229 if (!elsiocb)
5230 return 1;
5231
5232 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5233 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5234 pcmd += sizeof(uint32_t); /* Skip past command */
5235
5236 /* use the command's xri in the response */
5237 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5238
5239 rtv_rsp = (struct RTV_RSP *)pcmd;
5240
5241 /* populate RTV payload */
5242 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5243 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5244 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5245 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5246 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5247
5248 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5249 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5250 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5251 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5252 "Data: x%x x%x x%x\n",
5253 elsiocb->iotag, elsiocb->iocb.ulpContext,
5254 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5255 ndlp->nlp_rpi,
5256 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5257 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5258 phba->fc_stat.elsXmitACC++;
5259 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5260 lpfc_els_free_iocb(phba, elsiocb);
5261 return 0;
5262
5263reject_out:
5264 /* issue rejection response */
5265 stat.un.b.lsRjtRsvd0 = 0;
5266 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5267 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5268 stat.un.b.vendorUnique = 0;
5269 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5270 return 0;
5271}
5272
5273/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005274 * @vport: pointer to a host virtual N_Port data structure.
5275 * @cmdiocb: pointer to lpfc command iocb data structure.
5276 * @ndlp: pointer to a node-list data structure.
5277 *
5278 * This routine processes Read Port Status (RPS) IOCB received as an
5279 * ELS unsolicited event. It first checks the remote port state. If the
5280 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5281 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5282 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5283 * for reading the HBA link statistics. It is for the callback function,
5284 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5285 * to actually sending out RPS Accept (ACC) response.
5286 *
5287 * Return codes
5288 * 0 - Successfully processed rps iocb (currently always return 0)
5289 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005290static int
James Smart2e0fef82007-06-17 19:56:36 -05005291lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5292 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005293{
James Smart2e0fef82007-06-17 19:56:36 -05005294 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005295 uint32_t *lp;
5296 uint8_t flag;
5297 LPFC_MBOXQ_t *mbox;
5298 struct lpfc_dmabuf *pcmd;
5299 RPS *rps;
5300 struct ls_rjt stat;
5301
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005302 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005303 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5304 /* reject the unsolicited RPS request and done with it */
5305 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005306
5307 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5308 lp = (uint32_t *) pcmd->virt;
5309 flag = (be32_to_cpu(*lp++) & 0xf);
5310 rps = (RPS *) lp;
5311
5312 if ((flag == 0) ||
5313 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005314 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005315 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005316
James Smart92d7f7b2007-06-17 19:56:38 -05005317 printk("Fix me....\n");
5318 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005319 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5320 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005321 lpfc_read_lnk_stat(phba, mbox);
5322 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005323 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005324 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005325 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005326 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005327 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005328 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005329 /* Mbox completion will send ELS Response */
5330 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005331 /* Decrement reference count used for the failed mbox
5332 * command.
5333 */
James Smart329f9bc2007-04-25 09:53:01 -04005334 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005335 mempool_free(mbox, phba->mbox_mem_pool);
5336 }
5337 }
James Smart90160e02008-08-24 21:49:45 -04005338
5339reject_out:
5340 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005341 stat.un.b.lsRjtRsvd0 = 0;
5342 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5343 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5344 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005345 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005346 return 0;
5347}
5348
James Smart19ca7602010-11-20 23:11:55 -05005349/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5350 * @vport: pointer to a host virtual N_Port data structure.
5351 * @ndlp: pointer to a node-list data structure.
5352 * @did: DID of the target.
5353 * @rrq: Pointer to the rrq struct.
5354 *
5355 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5356 * Successful the the completion handler will clear the RRQ.
5357 *
5358 * Return codes
5359 * 0 - Successfully sent rrq els iocb.
5360 * 1 - Failed to send rrq els iocb.
5361 **/
5362static int
5363lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5364 uint32_t did, struct lpfc_node_rrq *rrq)
5365{
5366 struct lpfc_hba *phba = vport->phba;
5367 struct RRQ *els_rrq;
5368 IOCB_t *icmd;
5369 struct lpfc_iocbq *elsiocb;
5370 uint8_t *pcmd;
5371 uint16_t cmdsize;
5372 int ret;
5373
5374
5375 if (ndlp != rrq->ndlp)
5376 ndlp = rrq->ndlp;
5377 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5378 return 1;
5379
5380 /* If ndlp is not NULL, we will bump the reference count on it */
5381 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5382 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5383 ELS_CMD_RRQ);
5384 if (!elsiocb)
5385 return 1;
5386
5387 icmd = &elsiocb->iocb;
5388 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5389
5390 /* For RRQ request, remainder of payload is Exchange IDs */
5391 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5392 pcmd += sizeof(uint32_t);
5393 els_rrq = (struct RRQ *) pcmd;
5394
5395 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5396 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5397 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5398 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5399 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5400
5401
5402 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5403 "Issue RRQ: did:x%x",
5404 did, rrq->xritag, rrq->rxid);
5405 elsiocb->context_un.rrq = rrq;
5406 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5407 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5408
5409 if (ret == IOCB_ERROR) {
5410 lpfc_els_free_iocb(phba, elsiocb);
5411 return 1;
5412 }
5413 return 0;
5414}
5415
5416/**
5417 * lpfc_send_rrq - Sends ELS RRQ if needed.
5418 * @phba: pointer to lpfc hba data structure.
5419 * @rrq: pointer to the active rrq.
5420 *
5421 * This routine will call the lpfc_issue_els_rrq if the rrq is
5422 * still active for the xri. If this function returns a failure then
5423 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5424 *
5425 * Returns 0 Success.
5426 * 1 Failure.
5427 **/
5428int
5429lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5430{
5431 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5432 rrq->nlp_DID);
5433 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5434 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5435 rrq->nlp_DID, rrq);
5436 else
5437 return 1;
5438}
5439
James Smarte59058c2008-08-24 21:49:00 -04005440/**
James Smart3621a712009-04-06 18:47:14 -04005441 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005442 * @vport: pointer to a host virtual N_Port data structure.
5443 * @cmdsize: size of the ELS command.
5444 * @oldiocb: pointer to the original lpfc command iocb data structure.
5445 * @ndlp: pointer to a node-list data structure.
5446 *
5447 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5448 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5449 *
5450 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5451 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5452 * will be stored into the context1 field of the IOCB for the completion
5453 * callback function to the RPL Accept Response ELS command.
5454 *
5455 * Return code
5456 * 0 - Successfully issued ACC RPL ELS command
5457 * 1 - Failed to issue ACC RPL ELS command
5458 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005459static int
James Smart2e0fef82007-06-17 19:56:36 -05005460lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5461 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005462{
James Smart2e0fef82007-06-17 19:56:36 -05005463 struct lpfc_hba *phba = vport->phba;
5464 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005465 RPL_RSP rpl_rsp;
5466 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005467 uint8_t *pcmd;
5468
James Smart2e0fef82007-06-17 19:56:36 -05005469 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5470 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005471
James Smart488d1462006-03-07 15:02:37 -05005472 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005473 return 1;
James Smart488d1462006-03-07 15:02:37 -05005474
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005475 icmd = &elsiocb->iocb;
5476 oldcmd = &oldiocb->iocb;
5477 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5478
5479 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5480 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005481 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005482 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5483 pcmd += sizeof(uint16_t);
5484
5485 /* Setup the RPL ACC payload */
5486 rpl_rsp.listLen = be32_to_cpu(1);
5487 rpl_rsp.index = 0;
5488 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005489 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5490 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005491 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005492 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005493 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005494 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5495 "0120 Xmit ELS RPL ACC response tag x%x "
5496 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5497 "rpi x%x\n",
5498 elsiocb->iotag, elsiocb->iocb.ulpContext,
5499 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5500 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005501 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005502 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005503 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5504 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005505 lpfc_els_free_iocb(phba, elsiocb);
5506 return 1;
5507 }
5508 return 0;
5509}
5510
James Smarte59058c2008-08-24 21:49:00 -04005511/**
James Smart3621a712009-04-06 18:47:14 -04005512 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005513 * @vport: pointer to a host virtual N_Port data structure.
5514 * @cmdiocb: pointer to lpfc command iocb data structure.
5515 * @ndlp: pointer to a node-list data structure.
5516 *
5517 * This routine processes Read Port List (RPL) IOCB received as an ELS
5518 * unsolicited event. It first checks the remote port state. If the remote
5519 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5520 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5521 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5522 * to accept the RPL.
5523 *
5524 * Return code
5525 * 0 - Successfully processed rpl iocb (currently always return 0)
5526 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005527static int
James Smart2e0fef82007-06-17 19:56:36 -05005528lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5529 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005530{
5531 struct lpfc_dmabuf *pcmd;
5532 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005533 uint32_t maxsize;
5534 uint16_t cmdsize;
5535 RPL *rpl;
5536 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005537
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005538 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5539 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005540 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005541 stat.un.b.lsRjtRsvd0 = 0;
5542 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5543 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5544 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005545 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5546 NULL);
James Smart90160e02008-08-24 21:49:45 -04005547 /* rejected the unsolicited RPL request and done with it */
5548 return 0;
dea31012005-04-17 16:05:31 -05005549 }
5550
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005551 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5552 lp = (uint32_t *) pcmd->virt;
5553 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005554 maxsize = be32_to_cpu(rpl->maxsize);
5555
5556 /* We support only one port */
5557 if ((rpl->index == 0) &&
5558 ((maxsize == 0) ||
5559 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5560 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005561 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005562 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5563 }
James Smart2e0fef82007-06-17 19:56:36 -05005564 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005565
5566 return 0;
5567}
5568
James Smarte59058c2008-08-24 21:49:00 -04005569/**
James Smart3621a712009-04-06 18:47:14 -04005570 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005571 * @vport: pointer to a virtual N_Port data structure.
5572 * @cmdiocb: pointer to lpfc command iocb data structure.
5573 * @ndlp: pointer to a node-list data structure.
5574 *
5575 * This routine processes Fibre Channel Address Resolution Protocol
5576 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5577 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5578 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5579 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5580 * remote PortName is compared against the FC PortName stored in the @vport
5581 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5582 * compared against the FC NodeName stored in the @vport data structure.
5583 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5584 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5585 * invoked to send out FARP Response to the remote node. Before sending the
5586 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5587 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5588 * routine is invoked to log into the remote port first.
5589 *
5590 * Return code
5591 * 0 - Either the FARP Match Mode not supported or successfully processed
5592 **/
dea31012005-04-17 16:05:31 -05005593static int
James Smart2e0fef82007-06-17 19:56:36 -05005594lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5595 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005596{
5597 struct lpfc_dmabuf *pcmd;
5598 uint32_t *lp;
5599 IOCB_t *icmd;
5600 FARP *fp;
5601 uint32_t cmd, cnt, did;
5602
5603 icmd = &cmdiocb->iocb;
5604 did = icmd->un.elsreq64.remoteID;
5605 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5606 lp = (uint32_t *) pcmd->virt;
5607
5608 cmd = *lp++;
5609 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005610 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005611 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5612 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005613 /* We will only support match on WWPN or WWNN */
5614 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005615 return 0;
dea31012005-04-17 16:05:31 -05005616 }
5617
5618 cnt = 0;
5619 /* If this FARP command is searching for my portname */
5620 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005621 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005622 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005623 cnt = 1;
5624 }
5625
5626 /* If this FARP command is searching for my nodename */
5627 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005628 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005629 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005630 cnt = 1;
5631 }
5632
5633 if (cnt) {
5634 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5635 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5636 /* Log back into the node before sending the FARP. */
5637 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005638 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005639 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005640 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005641 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005642 }
5643
5644 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005645 if (fp->Rflags & FARP_REQUEST_FARPR)
5646 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005647 }
5648 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005649 return 0;
dea31012005-04-17 16:05:31 -05005650}
5651
James Smarte59058c2008-08-24 21:49:00 -04005652/**
James Smart3621a712009-04-06 18:47:14 -04005653 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005654 * @vport: pointer to a host virtual N_Port data structure.
5655 * @cmdiocb: pointer to lpfc command iocb data structure.
5656 * @ndlp: pointer to a node-list data structure.
5657 *
5658 * This routine processes Fibre Channel Address Resolution Protocol
5659 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5660 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5661 * the FARP response request.
5662 *
5663 * Return code
5664 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5665 **/
dea31012005-04-17 16:05:31 -05005666static int
James Smart2e0fef82007-06-17 19:56:36 -05005667lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5668 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005669{
5670 struct lpfc_dmabuf *pcmd;
5671 uint32_t *lp;
5672 IOCB_t *icmd;
5673 uint32_t cmd, did;
5674
5675 icmd = &cmdiocb->iocb;
5676 did = icmd->un.elsreq64.remoteID;
5677 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5678 lp = (uint32_t *) pcmd->virt;
5679
5680 cmd = *lp++;
5681 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005682 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5683 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005684 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005685 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005686
5687 return 0;
5688}
5689
James Smarte59058c2008-08-24 21:49:00 -04005690/**
James Smart3621a712009-04-06 18:47:14 -04005691 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005692 * @vport: pointer to a host virtual N_Port data structure.
5693 * @cmdiocb: pointer to lpfc command iocb data structure.
5694 * @fan_ndlp: pointer to a node-list data structure.
5695 *
5696 * This routine processes a Fabric Address Notification (FAN) IOCB
5697 * command received as an ELS unsolicited event. The FAN ELS command will
5698 * only be processed on a physical port (i.e., the @vport represents the
5699 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5700 * compared against those in the phba data structure. If any of those is
5701 * different, the lpfc_initial_flogi() routine is invoked to initialize
5702 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5703 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5704 * is invoked to register login to the fabric.
5705 *
5706 * Return code
5707 * 0 - Successfully processed fan iocb (currently always return 0).
5708 **/
dea31012005-04-17 16:05:31 -05005709static int
James Smart2e0fef82007-06-17 19:56:36 -05005710lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5711 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005712{
James Smart2e0fef82007-06-17 19:56:36 -05005713 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005714 uint32_t *lp;
5715 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005716
James Smart0d2b6b82008-06-14 22:52:47 -04005717 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5718 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5719 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005720 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005721 if ((vport == phba->pport) &&
5722 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005723 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005724 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005725 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005726 sizeof(struct lpfc_name)))) {
5727 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005728 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005729 } else {
5730 /* FAN verified - skip FLOGI */
5731 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005732 if (phba->sli_rev < LPFC_SLI_REV4)
5733 lpfc_issue_fabric_reglogin(vport);
5734 else
5735 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005736 }
dea31012005-04-17 16:05:31 -05005737 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005738 return 0;
dea31012005-04-17 16:05:31 -05005739}
5740
James Smarte59058c2008-08-24 21:49:00 -04005741/**
James Smart3621a712009-04-06 18:47:14 -04005742 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005743 * @ptr: holder for the timer function associated data.
5744 *
5745 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5746 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5747 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5748 * up the worker thread. It is for the worker thread to invoke the routine
5749 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5750 **/
dea31012005-04-17 16:05:31 -05005751void
5752lpfc_els_timeout(unsigned long ptr)
5753{
James Smart2e0fef82007-06-17 19:56:36 -05005754 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5755 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005756 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005757 unsigned long iflag;
5758
James Smart2e0fef82007-06-17 19:56:36 -05005759 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005760 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5761 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005762 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005763 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005764
James Smart5e9d9b82008-06-14 22:52:53 -04005765 if (!tmo_posted)
5766 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005767 return;
5768}
5769
James Smart2a9bf3d2010-06-07 15:24:45 -04005770
James Smarte59058c2008-08-24 21:49:00 -04005771/**
James Smart3621a712009-04-06 18:47:14 -04005772 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005773 * @vport: pointer to a virtual N_Port data structure.
5774 *
5775 * This routine is the actual handler function that processes an ELS timeout
5776 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5777 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5778 * invoking the lpfc_sli_issue_abort_iotag() routine.
5779 **/
dea31012005-04-17 16:05:31 -05005780void
James Smart2e0fef82007-06-17 19:56:36 -05005781lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005782{
James Smart2e0fef82007-06-17 19:56:36 -05005783 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005784 struct lpfc_sli_ring *pring;
5785 struct lpfc_iocbq *tmp_iocb, *piocb;
5786 IOCB_t *cmd = NULL;
5787 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005788 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005789 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005790 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005791 LIST_HEAD(txcmplq_completions);
5792 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005793
James Smart2a9bf3d2010-06-07 15:24:45 -04005794
dea31012005-04-17 16:05:31 -05005795 timeout = (uint32_t)(phba->fc_ratov << 1);
5796
5797 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005798
James Smart2a9bf3d2010-06-07 15:24:45 -04005799 spin_lock_irq(&phba->hbalock);
5800 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5801 spin_unlock_irq(&phba->hbalock);
5802
5803 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005804 cmd = &piocb->iocb;
5805
James Smart2e0fef82007-06-17 19:56:36 -05005806 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5807 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5808 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005809 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005810
5811 if (piocb->vport != vport)
5812 continue;
5813
dea31012005-04-17 16:05:31 -05005814 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005815 if (pcmd)
5816 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005817
James Smart92d7f7b2007-06-17 19:56:38 -05005818 if (els_command == ELS_CMD_FARP ||
5819 els_command == ELS_CMD_FARPR ||
5820 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005821 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005822
dea31012005-04-17 16:05:31 -05005823 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005824 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005825 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005826 else
dea31012005-04-17 16:05:31 -05005827 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005828 continue;
5829 }
5830
James Smart2e0fef82007-06-17 19:56:36 -05005831 remote_ID = 0xffffffff;
5832 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005833 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005834 else {
5835 struct lpfc_nodelist *ndlp;
5836 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005837 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005838 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005839 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005840 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005841 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005842 spin_lock_irq(&phba->hbalock);
5843 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005844 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005845
James Smart2a9bf3d2010-06-07 15:24:45 -04005846 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5847 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5848 "0127 ELS timeout Data: x%x x%x x%x "
5849 "x%x\n", els_command,
5850 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5851 spin_lock_irq(&phba->hbalock);
5852 list_del_init(&piocb->dlist);
5853 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5854 spin_unlock_irq(&phba->hbalock);
5855 }
5856
James Smart2e0fef82007-06-17 19:56:36 -05005857 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5858 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005859}
5860
James Smarte59058c2008-08-24 21:49:00 -04005861/**
James Smart3621a712009-04-06 18:47:14 -04005862 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005863 * @vport: pointer to a host virtual N_Port data structure.
5864 *
5865 * This routine is used to clean up all the outstanding ELS commands on a
5866 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5867 * routine. After that, it walks the ELS transmit queue to remove all the
5868 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5869 * the IOCBs with a non-NULL completion callback function, the callback
5870 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5871 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5872 * callback function, the IOCB will simply be released. Finally, it walks
5873 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5874 * completion queue IOCB that is associated with the @vport and is not
5875 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5876 * part of the discovery state machine) out to HBA by invoking the
5877 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5878 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5879 * the IOCBs are aborted when this function returns.
5880 **/
dea31012005-04-17 16:05:31 -05005881void
James Smart2e0fef82007-06-17 19:56:36 -05005882lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005883{
James Smart2534ba72007-04-25 09:52:20 -04005884 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005885 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005886 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005887 struct lpfc_iocbq *tmp_iocb, *piocb;
5888 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005889
5890 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005891
James Smart2e0fef82007-06-17 19:56:36 -05005892 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005893 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5894 cmd = &piocb->iocb;
5895
5896 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5897 continue;
5898 }
5899
5900 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005901 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5902 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5903 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5904 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005905 continue;
dea31012005-04-17 16:05:31 -05005906
James Smart2e0fef82007-06-17 19:56:36 -05005907 if (piocb->vport != vport)
5908 continue;
5909
James Smart2534ba72007-04-25 09:52:20 -04005910 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005911 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005912 }
5913
5914 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005915 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5916 continue;
5917 }
dea31012005-04-17 16:05:31 -05005918
James Smart2e0fef82007-06-17 19:56:36 -05005919 if (piocb->vport != vport)
5920 continue;
5921
James Smart07951072007-04-25 09:51:38 -04005922 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005923 }
James Smart2e0fef82007-06-17 19:56:36 -05005924 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005925
James Smarta257bf92009-04-06 18:48:10 -04005926 /* Cancell all the IOCBs from the completions list */
5927 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5928 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005929
dea31012005-04-17 16:05:31 -05005930 return;
5931}
5932
James Smarte59058c2008-08-24 21:49:00 -04005933/**
James Smart3621a712009-04-06 18:47:14 -04005934 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005935 * @phba: pointer to lpfc hba data structure.
5936 *
5937 * This routine is used to clean up all the outstanding ELS commands on a
5938 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5939 * routine. After that, it walks the ELS transmit queue to remove all the
5940 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5941 * the IOCBs with the completion callback function associated, the callback
5942 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5943 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5944 * callback function associated, the IOCB will simply be released. Finally,
5945 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5946 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5947 * management plane IOCBs that are not part of the discovery state machine)
5948 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5949 **/
James Smart549e55c2007-08-02 11:09:51 -04005950void
5951lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5952{
5953 LIST_HEAD(completions);
5954 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5955 struct lpfc_iocbq *tmp_iocb, *piocb;
5956 IOCB_t *cmd = NULL;
5957
5958 lpfc_fabric_abort_hba(phba);
5959 spin_lock_irq(&phba->hbalock);
5960 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5961 cmd = &piocb->iocb;
5962 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5963 continue;
5964 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5965 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5966 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5967 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5968 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5969 continue;
5970 list_move_tail(&piocb->list, &completions);
5971 pring->txq_cnt--;
5972 }
5973 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5974 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5975 continue;
5976 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5977 }
5978 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005979
5980 /* Cancel all the IOCBs from the completions list */
5981 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5982 IOERR_SLI_ABORTED);
5983
James Smart549e55c2007-08-02 11:09:51 -04005984 return;
5985}
5986
James Smarte59058c2008-08-24 21:49:00 -04005987/**
James Smart3621a712009-04-06 18:47:14 -04005988 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005989 * @phba: Pointer to hba context object.
5990 * @cmdiocbp: Pointer to command iocb which reported error.
5991 * @rspiocbp: Pointer to response iocb which reported error.
5992 *
5993 * This function sends an event when there is an ELS command
5994 * failure.
5995 **/
5996void
5997lpfc_send_els_failure_event(struct lpfc_hba *phba,
5998 struct lpfc_iocbq *cmdiocbp,
5999 struct lpfc_iocbq *rspiocbp)
6000{
6001 struct lpfc_vport *vport = cmdiocbp->vport;
6002 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6003 struct lpfc_lsrjt_event lsrjt_event;
6004 struct lpfc_fabric_event_header fabric_event;
6005 struct ls_rjt stat;
6006 struct lpfc_nodelist *ndlp;
6007 uint32_t *pcmd;
6008
6009 ndlp = cmdiocbp->context1;
6010 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6011 return;
6012
6013 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6014 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6015 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6016 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6017 sizeof(struct lpfc_name));
6018 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6019 sizeof(struct lpfc_name));
6020 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6021 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006022 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006023 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6024 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6025 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6026 fc_host_post_vendor_event(shost,
6027 fc_get_event_number(),
6028 sizeof(lsrjt_event),
6029 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006030 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006031 return;
6032 }
6033 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6034 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6035 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6036 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6037 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6038 else
6039 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6040 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6041 sizeof(struct lpfc_name));
6042 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6043 sizeof(struct lpfc_name));
6044 fc_host_post_vendor_event(shost,
6045 fc_get_event_number(),
6046 sizeof(fabric_event),
6047 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006048 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006049 return;
6050 }
6051
6052}
6053
6054/**
James Smart3621a712009-04-06 18:47:14 -04006055 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006056 * @vport: Pointer to vport object.
6057 * @ndlp: Pointer FC node object.
6058 * @cmd: ELS command code.
6059 *
6060 * This function posts an event when there is an incoming
6061 * unsolicited ELS command.
6062 **/
6063static void
6064lpfc_send_els_event(struct lpfc_vport *vport,
6065 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006066 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006067{
James Smartddcc50f2008-12-04 22:38:46 -05006068 struct lpfc_els_event_header *els_data = NULL;
6069 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6071
James Smartddcc50f2008-12-04 22:38:46 -05006072 if (*payload == ELS_CMD_LOGO) {
6073 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6074 if (!logo_data) {
6075 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6076 "0148 Failed to allocate memory "
6077 "for LOGO event\n");
6078 return;
6079 }
6080 els_data = &logo_data->header;
6081 } else {
6082 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6083 GFP_KERNEL);
6084 if (!els_data) {
6085 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6086 "0149 Failed to allocate memory "
6087 "for ELS event\n");
6088 return;
6089 }
6090 }
6091 els_data->event_type = FC_REG_ELS_EVENT;
6092 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006093 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006094 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006095 break;
6096 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006097 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006098 break;
6099 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006100 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6101 break;
6102 case ELS_CMD_LOGO:
6103 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6104 /* Copy the WWPN in the LOGO payload */
6105 memcpy(logo_data->logo_wwpn, &payload[2],
6106 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006107 break;
6108 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006109 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006110 return;
6111 }
James Smartddcc50f2008-12-04 22:38:46 -05006112 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6113 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6114 if (*payload == ELS_CMD_LOGO) {
6115 fc_host_post_vendor_event(shost,
6116 fc_get_event_number(),
6117 sizeof(struct lpfc_logo_event),
6118 (char *)logo_data,
6119 LPFC_NL_VENDOR_ID);
6120 kfree(logo_data);
6121 } else {
6122 fc_host_post_vendor_event(shost,
6123 fc_get_event_number(),
6124 sizeof(struct lpfc_els_event_header),
6125 (char *)els_data,
6126 LPFC_NL_VENDOR_ID);
6127 kfree(els_data);
6128 }
James Smartea2151b2008-09-07 11:52:10 -04006129
6130 return;
6131}
6132
6133
6134/**
James Smart3621a712009-04-06 18:47:14 -04006135 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006136 * @phba: pointer to lpfc hba data structure.
6137 * @pring: pointer to a SLI ring.
6138 * @vport: pointer to a host virtual N_Port data structure.
6139 * @elsiocb: pointer to lpfc els command iocb data structure.
6140 *
6141 * This routine is used for processing the IOCB associated with a unsolicited
6142 * event. It first determines whether there is an existing ndlp that matches
6143 * the DID from the unsolicited IOCB. If not, it will create a new one with
6144 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6145 * IOCB is then used to invoke the proper routine and to set up proper state
6146 * of the discovery state machine.
6147 **/
James Smarted957682007-06-17 19:56:37 -05006148static void
6149lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006150 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006151{
James Smart87af33f2007-10-27 13:37:43 -04006152 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006153 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006154 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006155 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006156 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006157 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006158
James Smarte47c9092008-02-08 18:49:26 -05006159 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006160 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006161
dea31012005-04-17 16:05:31 -05006162 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006163 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6164 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006165 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006166 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006167
James Smart858c9f62007-06-17 19:56:39 -05006168 did = icmd->un.rcvels.remoteID;
6169 if (icmd->ulpStatus) {
6170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6171 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6172 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006173 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006174 }
dea31012005-04-17 16:05:31 -05006175
6176 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006177 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006178 goto dropit;
dea31012005-04-17 16:05:31 -05006179
James Smartc8685952009-11-18 15:39:16 -05006180 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006181 if (vport->load_flag & FC_UNLOADING)
6182 goto dropit;
6183
James Smart2e0fef82007-06-17 19:56:36 -05006184 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006185 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006186 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006187 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006188 if (!ndlp)
dea31012005-04-17 16:05:31 -05006189 goto dropit;
dea31012005-04-17 16:05:31 -05006190
James Smart2e0fef82007-06-17 19:56:36 -05006191 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006192 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006193 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006194 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006195 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006196 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6197 ndlp = lpfc_enable_node(vport, ndlp,
6198 NLP_STE_UNUSED_NODE);
6199 if (!ndlp)
6200 goto dropit;
6201 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6202 newnode = 1;
6203 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6204 ndlp->nlp_type |= NLP_FABRIC;
6205 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6206 /* This is similar to the new node path */
6207 ndlp = lpfc_nlp_get(ndlp);
6208 if (!ndlp)
6209 goto dropit;
6210 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6211 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006212 }
dea31012005-04-17 16:05:31 -05006213
6214 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006215
James Smart329f9bc2007-04-25 09:53:01 -04006216 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006217 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006218
6219 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6220 cmd &= ELS_CMD_MASK;
6221 }
6222 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006223 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6224 "0112 ELS command x%x received from NPORT x%x "
6225 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006226 switch (cmd) {
6227 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6229 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6230 did, vport->port_state, ndlp->nlp_flag);
6231
dea31012005-04-17 16:05:31 -05006232 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006233 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6234
James Smartddcc50f2008-12-04 22:38:46 -05006235 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05006236 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006237 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6238 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6239 rjt_err = LSRJT_UNABLE_TPC;
6240 break;
6241 }
6242 /* We get here, and drop thru, if we are PT2PT with
6243 * another NPort and the other side has initiated
6244 * the PLOGI before responding to our FLOGI.
6245 */
dea31012005-04-17 16:05:31 -05006246 }
James Smart87af33f2007-10-27 13:37:43 -04006247
6248 shost = lpfc_shost_from_vport(vport);
6249 spin_lock_irq(shost->host_lock);
6250 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6251 spin_unlock_irq(shost->host_lock);
6252
James Smart2e0fef82007-06-17 19:56:36 -05006253 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6254 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006255
dea31012005-04-17 16:05:31 -05006256 break;
6257 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6259 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6260 did, vport->port_state, ndlp->nlp_flag);
6261
dea31012005-04-17 16:05:31 -05006262 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006263 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006264 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006265 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006266 break;
6267 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6269 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6270 did, vport->port_state, ndlp->nlp_flag);
6271
dea31012005-04-17 16:05:31 -05006272 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006273 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006274 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006275 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006276 break;
6277 }
James Smart2e0fef82007-06-17 19:56:36 -05006278 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006279 break;
6280 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006281 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6282 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6283 did, vport->port_state, ndlp->nlp_flag);
6284
dea31012005-04-17 16:05:31 -05006285 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006286 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006287 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006288 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006289 break;
6290 }
James Smart2e0fef82007-06-17 19:56:36 -05006291 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006292 break;
6293 case ELS_CMD_RSCN:
6294 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006295 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006296 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006297 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006298 break;
6299 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6301 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6302 did, vport->port_state, ndlp->nlp_flag);
6303
James Smartddcc50f2008-12-04 22:38:46 -05006304 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006305 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006306 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006307 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006308 break;
6309 }
James Smart2e0fef82007-06-17 19:56:36 -05006310 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6311 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006312 break;
6313 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006314 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6315 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6316 did, vport->port_state, ndlp->nlp_flag);
6317
dea31012005-04-17 16:05:31 -05006318 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006319 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006320 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006321 break;
6322 }
James Smart2e0fef82007-06-17 19:56:36 -05006323 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6324 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006325 break;
6326 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006327 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6328 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6329 did, vport->port_state, ndlp->nlp_flag);
6330
dea31012005-04-17 16:05:31 -05006331 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006332 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006333 break;
6334 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6336 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6337 did, vport->port_state, ndlp->nlp_flag);
6338
dea31012005-04-17 16:05:31 -05006339 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006340 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006341 break;
6342 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6344 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6345 did, vport->port_state, ndlp->nlp_flag);
6346
dea31012005-04-17 16:05:31 -05006347 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006348 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006349 break;
dea31012005-04-17 16:05:31 -05006350 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6352 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6353 did, vport->port_state, ndlp->nlp_flag);
6354
dea31012005-04-17 16:05:31 -05006355 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006356 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006357 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006358 break;
6359 }
James Smart2e0fef82007-06-17 19:56:36 -05006360 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006361 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006362 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006363 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6364 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6365 did, vport->port_state, ndlp->nlp_flag);
6366
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006367 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006368 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006369 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006370 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006371 break;
James Smart12265f62010-10-22 11:05:53 -04006372 case ELS_CMD_RLS:
6373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6374 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6375 did, vport->port_state, ndlp->nlp_flag);
6376
6377 phba->fc_stat.elsRcvRLS++;
6378 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6379 if (newnode)
6380 lpfc_nlp_put(ndlp);
6381 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006382 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006383 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6384 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6385 did, vport->port_state, ndlp->nlp_flag);
6386
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006387 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006388 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006389 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006390 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006391 break;
6392 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006393 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6394 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6395 did, vport->port_state, ndlp->nlp_flag);
6396
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006397 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006398 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006399 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006400 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006401 break;
dea31012005-04-17 16:05:31 -05006402 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6404 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6405 did, vport->port_state, ndlp->nlp_flag);
6406
dea31012005-04-17 16:05:31 -05006407 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006408 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006409 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006410 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006411 break;
James Smart12265f62010-10-22 11:05:53 -04006412 case ELS_CMD_RTV:
6413 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6414 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6415 did, vport->port_state, ndlp->nlp_flag);
6416 phba->fc_stat.elsRcvRTV++;
6417 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6418 if (newnode)
6419 lpfc_nlp_put(ndlp);
6420 break;
James Smart5ffc2662009-11-18 15:39:44 -05006421 case ELS_CMD_RRQ:
6422 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6423 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6424 did, vport->port_state, ndlp->nlp_flag);
6425
6426 phba->fc_stat.elsRcvRRQ++;
6427 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6428 if (newnode)
6429 lpfc_nlp_put(ndlp);
6430 break;
James Smart12265f62010-10-22 11:05:53 -04006431 case ELS_CMD_ECHO:
6432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6433 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6434 did, vport->port_state, ndlp->nlp_flag);
6435
6436 phba->fc_stat.elsRcvECHO++;
6437 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6438 if (newnode)
6439 lpfc_nlp_put(ndlp);
6440 break;
dea31012005-04-17 16:05:31 -05006441 default:
James Smart858c9f62007-06-17 19:56:39 -05006442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6443 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6444 cmd, did, vport->port_state);
6445
dea31012005-04-17 16:05:31 -05006446 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006447 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006448
6449 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006450 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6451 "0115 Unknown ELS command x%x "
6452 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006453 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006454 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006455 break;
6456 }
6457
6458 /* check if need to LS_RJT received ELS cmd */
6459 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006460 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006461 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006462 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006463 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6464 NULL);
dea31012005-04-17 16:05:31 -05006465 }
6466
James Smartd7c255b2008-08-24 21:50:00 -04006467 lpfc_nlp_put(elsiocb->context1);
6468 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006469 return;
6470
6471dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006472 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006473 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6474 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006475 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006476 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006477 phba->fc_stat.elsRcvDrop++;
6478}
6479
James Smarte59058c2008-08-24 21:49:00 -04006480/**
James Smart3621a712009-04-06 18:47:14 -04006481 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006482 * @phba: pointer to lpfc hba data structure.
6483 * @vpi: host virtual N_Port identifier.
6484 *
6485 * This routine finds a vport on a HBA (referred by @phba) through a
6486 * @vpi. The function walks the HBA's vport list and returns the address
6487 * of the vport with the matching @vpi.
6488 *
6489 * Return code
6490 * NULL - No vport with the matching @vpi found
6491 * Otherwise - Address to the vport with the matching @vpi.
6492 **/
James Smart6669f9b2009-10-02 15:16:45 -04006493struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006494lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6495{
6496 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006497 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006498
James Smart549e55c2007-08-02 11:09:51 -04006499 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006500 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006501 if (vport->vpi == vpi) {
6502 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006503 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006504 }
James Smart92d7f7b2007-06-17 19:56:38 -05006505 }
James Smart549e55c2007-08-02 11:09:51 -04006506 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006507 return NULL;
6508}
James Smarted957682007-06-17 19:56:37 -05006509
James Smarte59058c2008-08-24 21:49:00 -04006510/**
James Smart3621a712009-04-06 18:47:14 -04006511 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006512 * @phba: pointer to lpfc hba data structure.
6513 * @pring: pointer to a SLI ring.
6514 * @elsiocb: pointer to lpfc els iocb data structure.
6515 *
6516 * This routine is used to process an unsolicited event received from a SLI
6517 * (Service Level Interface) ring. The actual processing of the data buffer
6518 * associated with the unsolicited event is done by invoking the routine
6519 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6520 * SLI ring on which the unsolicited event was received.
6521 **/
James Smarted957682007-06-17 19:56:37 -05006522void
6523lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6524 struct lpfc_iocbq *elsiocb)
6525{
6526 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006527 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006528 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006529 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6530 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006531
James Smartd7c255b2008-08-24 21:50:00 -04006532 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006533 elsiocb->context2 = NULL;
6534 elsiocb->context3 = NULL;
6535
6536 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6537 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6538 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6539 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006540 phba->fc_stat.NoRcvBuf++;
6541 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006542 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006543 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006544 return;
6545 }
6546
James Smart92d7f7b2007-06-17 19:56:38 -05006547 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6548 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6549 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6550 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6551 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006552 else
6553 vport = lpfc_find_vport_by_vpid(phba,
6554 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006555 }
James Smart7f5f3d02008-02-08 18:50:14 -05006556 /* If there are no BDEs associated
6557 * with this IOCB, there is nothing to do.
6558 */
James Smarted957682007-06-17 19:56:37 -05006559 if (icmd->ulpBdeCount == 0)
6560 return;
6561
James Smart7f5f3d02008-02-08 18:50:14 -05006562 /* type of ELS cmd is first 32bit word
6563 * in packet
6564 */
James Smarted957682007-06-17 19:56:37 -05006565 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006566 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006567 } else {
6568 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6569 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006570 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6571 paddr);
James Smarted957682007-06-17 19:56:37 -05006572 }
6573
James Smart92d7f7b2007-06-17 19:56:38 -05006574 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6575 /*
6576 * The different unsolicited event handlers would tell us
6577 * if they are done with "mp" by setting context2 to NULL.
6578 */
dea31012005-04-17 16:05:31 -05006579 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006580 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6581 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006582 }
James Smarted957682007-06-17 19:56:37 -05006583
6584 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006585 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006586 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006587 elsiocb->context2 = bdeBuf2;
6588 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006589 /* free mp if we are done with it */
6590 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006591 lpfc_in_buf_free(phba, elsiocb->context2);
6592 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006593 }
dea31012005-04-17 16:05:31 -05006594 }
dea31012005-04-17 16:05:31 -05006595}
James Smart92d7f7b2007-06-17 19:56:38 -05006596
James Smarte59058c2008-08-24 21:49:00 -04006597/**
James Smart3621a712009-04-06 18:47:14 -04006598 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006599 * @phba: pointer to lpfc hba data structure.
6600 * @vport: pointer to a virtual N_Port data structure.
6601 *
6602 * This routine issues a Port Login (PLOGI) to the Name Server with
6603 * State Change Request (SCR) for a @vport. This routine will create an
6604 * ndlp for the Name Server associated to the @vport if such node does
6605 * not already exist. The PLOGI to Name Server is issued by invoking the
6606 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6607 * (FDMI) is configured to the @vport, a FDMI node will be created and
6608 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6609 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006610void
6611lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6612{
6613 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6614
6615 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6616 if (!ndlp) {
6617 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6618 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006619 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006620 lpfc_disc_start(vport);
6621 return;
6622 }
6623 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006624 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6625 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006626 return;
6627 }
6628 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006629 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6630 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6631 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006632 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006633 lpfc_disc_start(vport);
6634 return;
6635 }
6636 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6637 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6638 "0348 NameServer login: node freed\n");
6639 return;
6640 }
James Smart92d7f7b2007-06-17 19:56:38 -05006641 }
James Smart58da1ff2008-04-07 10:15:56 -04006642 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006643
6644 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6645
6646 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6647 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006648 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6649 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006650 return;
6651 }
6652
James Smart3de2a652007-08-02 11:09:59 -04006653 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006654 /* If this is the first time, allocate an ndlp and initialize
6655 * it. Otherwise, make sure the node is enabled and then do the
6656 * login.
6657 */
6658 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6659 if (!ndlp_fdmi) {
6660 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6661 GFP_KERNEL);
6662 if (ndlp_fdmi) {
6663 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6664 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6665 } else
6666 return;
6667 }
6668 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6669 ndlp_fdmi = lpfc_enable_node(vport,
6670 ndlp_fdmi,
6671 NLP_STE_NPR_NODE);
6672
James Smart92d7f7b2007-06-17 19:56:38 -05006673 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006674 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006675 NLP_STE_PLOGI_ISSUE);
6676 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006677 }
6678 }
James Smart92d7f7b2007-06-17 19:56:38 -05006679}
6680
James Smarte59058c2008-08-24 21:49:00 -04006681/**
James Smart3621a712009-04-06 18:47:14 -04006682 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006683 * @phba: pointer to lpfc hba data structure.
6684 * @pmb: pointer to the driver internal queue element for mailbox command.
6685 *
6686 * This routine is the completion callback function to register new vport
6687 * mailbox command. If the new vport mailbox command completes successfully,
6688 * the fabric registration login shall be performed on physical port (the
6689 * new vport created is actually a physical port, with VPI 0) or the port
6690 * login to Name Server for State Change Request (SCR) will be performed
6691 * on virtual port (real virtual port, with VPI greater than 0).
6692 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006693static void
6694lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6695{
6696 struct lpfc_vport *vport = pmb->vport;
6697 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6698 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006699 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006700 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006701
James Smart09372822008-01-11 01:52:54 -05006702 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006703 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006704 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006705
6706 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006707 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006708 "0915 Register VPI failed : Status: x%x"
6709 " upd bit: x%x \n", mb->mbxStatus,
6710 mb->un.varRegVpi.upd);
6711 if (phba->sli_rev == LPFC_SLI_REV4 &&
6712 mb->un.varRegVpi.upd)
6713 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006714
6715 switch (mb->mbxStatus) {
6716 case 0x11: /* unsupported feature */
6717 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006718 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006719 /* giving up on vport registration */
6720 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6721 spin_lock_irq(shost->host_lock);
6722 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6723 spin_unlock_irq(shost->host_lock);
6724 lpfc_can_disctmo(vport);
6725 break;
James Smart695a8142010-01-26 23:08:03 -05006726 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6727 case 0x20:
6728 spin_lock_irq(shost->host_lock);
6729 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6730 spin_unlock_irq(shost->host_lock);
6731 lpfc_init_vpi(phba, pmb, vport->vpi);
6732 pmb->vport = vport;
6733 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6734 rc = lpfc_sli_issue_mbox(phba, pmb,
6735 MBX_NOWAIT);
6736 if (rc == MBX_NOT_FINISHED) {
6737 lpfc_printf_vlog(vport,
6738 KERN_ERR, LOG_MBOX,
6739 "2732 Failed to issue INIT_VPI"
6740 " mailbox command\n");
6741 } else {
6742 lpfc_nlp_put(ndlp);
6743 return;
6744 }
6745
James Smart92d7f7b2007-06-17 19:56:38 -05006746 default:
6747 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006748 if (phba->sli_rev == LPFC_SLI_REV4)
6749 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006750 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006751 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006752 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006753 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006754 if (vport->port_type == LPFC_PHYSICAL_PORT
6755 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006756 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006757 else
6758 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006759 break;
6760 }
James Smart92d7f7b2007-06-17 19:56:38 -05006761 } else {
James Smart695a8142010-01-26 23:08:03 -05006762 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006763 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006764 spin_unlock_irq(shost->host_lock);
6765 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006766 if (phba->sli_rev < LPFC_SLI_REV4)
6767 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006768 else {
James Smartfc2b9892010-02-26 14:15:29 -05006769 /*
6770 * If the physical port is instantiated using
6771 * FDISC, do not start vport discovery.
6772 */
6773 if (vport->port_state != LPFC_FDISC)
6774 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006775 lpfc_do_scr_ns_plogi(phba, vport);
6776 }
6777 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006778 lpfc_do_scr_ns_plogi(phba, vport);
6779 }
James Smart38b92ef2010-08-04 16:11:39 -04006780mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006781 /* Now, we decrement the ndlp reference count held for this
6782 * callback function
6783 */
6784 lpfc_nlp_put(ndlp);
6785
James Smart92d7f7b2007-06-17 19:56:38 -05006786 mempool_free(pmb, phba->mbox_mem_pool);
6787 return;
6788}
6789
James Smarte59058c2008-08-24 21:49:00 -04006790/**
James Smart3621a712009-04-06 18:47:14 -04006791 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006792 * @phba: pointer to lpfc hba data structure.
6793 * @vport: pointer to a host virtual N_Port data structure.
6794 * @ndlp: pointer to a node-list data structure.
6795 *
6796 * This routine registers the @vport as a new virtual port with a HBA.
6797 * It is done through a registering vpi mailbox command.
6798 **/
James Smart695a8142010-01-26 23:08:03 -05006799void
James Smart92d7f7b2007-06-17 19:56:38 -05006800lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6801 struct lpfc_nodelist *ndlp)
6802{
James Smart09372822008-01-11 01:52:54 -05006803 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006804 LPFC_MBOXQ_t *mbox;
6805
6806 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6807 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006808 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006809 mbox->vport = vport;
6810 mbox->context2 = lpfc_nlp_get(ndlp);
6811 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006812 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006813 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006814 /* mailbox command not success, decrement ndlp
6815 * reference count for this command
6816 */
6817 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006818 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006819
James Smarte8b62012007-08-02 11:10:09 -04006820 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6821 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006822 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006823 }
6824 } else {
James Smarte8b62012007-08-02 11:10:09 -04006825 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6826 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006827 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006828 }
James Smartfa4066b2008-01-11 01:53:27 -05006829 return;
6830
6831mbox_err_exit:
6832 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6833 spin_lock_irq(shost->host_lock);
6834 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6835 spin_unlock_irq(shost->host_lock);
6836 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006837}
6838
James Smarte59058c2008-08-24 21:49:00 -04006839/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006840 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006841 * @phba: pointer to lpfc hba data structure.
6842 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006843 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006844 **/
6845void
James Smart0c9ab6f2010-02-26 14:15:57 -05006846lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006847{
6848 struct lpfc_vport **vports;
6849 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006850 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006851 int i;
James Smart695a8142010-01-26 23:08:03 -05006852
6853 /* Treat this failure as linkdown for all vports */
6854 link_state = phba->link_state;
6855 lpfc_linkdown(phba);
6856 phba->link_state = link_state;
6857
6858 vports = lpfc_create_vport_work_array(phba);
6859
6860 if (vports) {
6861 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6862 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6863 if (ndlp)
6864 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6865 lpfc_els_flush_cmd(vports[i]);
6866 }
6867 lpfc_destroy_vport_work_array(phba, vports);
6868 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006869}
6870
6871/**
6872 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6873 * @phba: pointer to lpfc hba data structure.
6874 *
6875 * This routine abort all pending discovery commands and
6876 * start a timer to retry FLOGI for the physical port
6877 * discovery.
6878 **/
6879void
6880lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6881{
6882 struct lpfc_nodelist *ndlp;
6883 struct Scsi_Host *shost;
6884
6885 /* Cancel the all vports retry delay retry timers */
6886 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006887
6888 /* If fabric require FLOGI, then re-instantiate physical login */
6889 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6890 if (!ndlp)
6891 return;
6892
James Smart695a8142010-01-26 23:08:03 -05006893 shost = lpfc_shost_from_vport(phba->pport);
6894 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6895 spin_lock_irq(shost->host_lock);
6896 ndlp->nlp_flag |= NLP_DELAY_TMO;
6897 spin_unlock_irq(shost->host_lock);
6898 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6899 phba->pport->port_state = LPFC_FLOGI;
6900 return;
6901}
6902
6903/**
6904 * lpfc_fabric_login_reqd - Check if FLOGI required.
6905 * @phba: pointer to lpfc hba data structure.
6906 * @cmdiocb: pointer to FDISC command iocb.
6907 * @rspiocb: pointer to FDISC response iocb.
6908 *
6909 * This routine checks if a FLOGI is reguired for FDISC
6910 * to succeed.
6911 **/
6912static int
6913lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6914 struct lpfc_iocbq *cmdiocb,
6915 struct lpfc_iocbq *rspiocb)
6916{
6917
6918 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6919 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6920 return 0;
6921 else
6922 return 1;
6923}
6924
6925/**
James Smart3621a712009-04-06 18:47:14 -04006926 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006927 * @phba: pointer to lpfc hba data structure.
6928 * @cmdiocb: pointer to lpfc command iocb data structure.
6929 * @rspiocb: pointer to lpfc response iocb data structure.
6930 *
6931 * This routine is the completion callback function to a Fabric Discover
6932 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6933 * single threaded, each FDISC completion callback function will reset
6934 * the discovery timer for all vports such that the timers will not get
6935 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6936 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6937 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6938 * assigned to the vport has been changed with the completion of the FDISC
6939 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6940 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6941 * routine is invoked to register new vport with the HBA. Otherwise, the
6942 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6943 * Server for State Change Request (SCR).
6944 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006945static void
6946lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6947 struct lpfc_iocbq *rspiocb)
6948{
6949 struct lpfc_vport *vport = cmdiocb->vport;
6950 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6951 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6952 struct lpfc_nodelist *np;
6953 struct lpfc_nodelist *next_np;
6954 IOCB_t *irsp = &rspiocb->iocb;
6955 struct lpfc_iocbq *piocb;
6956
James Smarte8b62012007-08-02 11:10:09 -04006957 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6958 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6959 irsp->ulpStatus, irsp->un.ulpWord[4],
6960 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006961 /* Since all FDISCs are being single threaded, we
6962 * must reset the discovery timer for ALL vports
6963 * waiting to send FDISC when one completes.
6964 */
6965 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6966 lpfc_set_disctmo(piocb->vport);
6967 }
6968
James Smart858c9f62007-06-17 19:56:39 -05006969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6970 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6971 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6972
James Smart92d7f7b2007-06-17 19:56:38 -05006973 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006974
6975 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6976 lpfc_retry_pport_discovery(phba);
6977 goto out;
6978 }
6979
James Smart92d7f7b2007-06-17 19:56:38 -05006980 /* Check for retry */
6981 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6982 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006983 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006984 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006985 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006986 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006987 goto fdisc_failed;
6988 }
James Smartd7c255b2008-08-24 21:50:00 -04006989 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006990 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006991 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006992 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05006993 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04006994 vport->fc_flag |= FC_PUBLIC_LOOP;
6995 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006996
James Smartd7c255b2008-08-24 21:50:00 -04006997 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6998 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6999 if ((vport->fc_prevDID != vport->fc_myDID) &&
7000 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7001 /* If our NportID changed, we need to ensure all
7002 * remaining NPORTs get unreg_login'ed so we can
7003 * issue unreg_vpi.
7004 */
7005 list_for_each_entry_safe(np, next_np,
7006 &vport->fc_nodes, nlp_listp) {
7007 if (!NLP_CHK_NODE_ACT(ndlp) ||
7008 (np->nlp_state != NLP_STE_NPR_NODE) ||
7009 !(np->nlp_flag & NLP_NPR_ADISC))
7010 continue;
James Smart09372822008-01-11 01:52:54 -05007011 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007012 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007013 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007014 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007015 }
James Smart78730cf2010-04-06 15:06:30 -04007016 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007017
7018 if (phba->sli_rev == LPFC_SLI_REV4)
7019 lpfc_sli4_unreg_all_rpis(vport);
7020
James Smartd7c255b2008-08-24 21:50:00 -04007021 lpfc_mbx_unreg_vpi(vport);
7022 spin_lock_irq(shost->host_lock);
7023 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007024 if (phba->sli_rev == LPFC_SLI_REV4)
7025 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007026 else
7027 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007028 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007029 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7030 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7031 /*
7032 * Driver needs to re-reg VPI in order for f/w
7033 * to update the MAC address.
7034 */
7035 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007036 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007037 }
7038
James Smartecfd03c2010-02-12 14:41:27 -05007039 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7040 lpfc_issue_init_vpi(vport);
7041 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007042 lpfc_register_new_vport(phba, vport, ndlp);
7043 else
7044 lpfc_do_scr_ns_plogi(phba, vport);
7045 goto out;
7046fdisc_failed:
7047 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7048 /* Cancel discovery timer */
7049 lpfc_can_disctmo(vport);
7050 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007051out:
7052 lpfc_els_free_iocb(phba, cmdiocb);
7053}
7054
James Smarte59058c2008-08-24 21:49:00 -04007055/**
James Smart3621a712009-04-06 18:47:14 -04007056 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007057 * @vport: pointer to a virtual N_Port data structure.
7058 * @ndlp: pointer to a node-list data structure.
7059 * @retry: number of retries to the command IOCB.
7060 *
7061 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7062 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7063 * routine to issue the IOCB, which makes sure only one outstanding fabric
7064 * IOCB will be sent off HBA at any given time.
7065 *
7066 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7067 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7068 * will be stored into the context1 field of the IOCB for the completion
7069 * callback function to the FDISC ELS command.
7070 *
7071 * Return code
7072 * 0 - Successfully issued fdisc iocb command
7073 * 1 - Failed to issue fdisc iocb command
7074 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007075static int
James Smart92d7f7b2007-06-17 19:56:38 -05007076lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7077 uint8_t retry)
7078{
7079 struct lpfc_hba *phba = vport->phba;
7080 IOCB_t *icmd;
7081 struct lpfc_iocbq *elsiocb;
7082 struct serv_parm *sp;
7083 uint8_t *pcmd;
7084 uint16_t cmdsize;
7085 int did = ndlp->nlp_DID;
7086 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007087
James Smart5ffc2662009-11-18 15:39:44 -05007088 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007089 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7090 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7091 ELS_CMD_FDISC);
7092 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007093 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007094 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7095 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007096 return 1;
7097 }
7098
7099 icmd = &elsiocb->iocb;
7100 icmd->un.elsreq64.myID = 0;
7101 icmd->un.elsreq64.fl = 1;
7102
James Smart40426292010-12-15 17:58:10 -05007103 if ((phba->sli_rev == LPFC_SLI_REV4) &&
7104 (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) ==
7105 LPFC_SLI_INTF_IF_TYPE_0)) {
James Smartf1126682009-06-10 17:22:44 -04007106 /* FDISC needs to be 1 for WQE VPI */
7107 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7108 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7109 /* Set the ulpContext to the vpi */
7110 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
7111 } else {
7112 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7113 icmd->ulpCt_h = 1;
7114 icmd->ulpCt_l = 0;
7115 }
James Smart92d7f7b2007-06-17 19:56:38 -05007116
7117 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7118 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7119 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7120 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7121 sp = (struct serv_parm *) pcmd;
7122 /* Setup CSPs accordingly for Fabric */
7123 sp->cmn.e_d_tov = 0;
7124 sp->cmn.w2.r_a_tov = 0;
7125 sp->cls1.classValid = 0;
7126 sp->cls2.seqDelivery = 1;
7127 sp->cls3.seqDelivery = 1;
7128
7129 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7130 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7131 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7132 pcmd += sizeof(uint32_t); /* Port Name */
7133 memcpy(pcmd, &vport->fc_portname, 8);
7134 pcmd += sizeof(uint32_t); /* Node Name */
7135 pcmd += sizeof(uint32_t); /* Node Name */
7136 memcpy(pcmd, &vport->fc_nodename, 8);
7137
7138 lpfc_set_disctmo(vport);
7139
7140 phba->fc_stat.elsXmitFDISC++;
7141 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7142
James Smart858c9f62007-06-17 19:56:39 -05007143 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7144 "Issue FDISC: did:x%x",
7145 did, 0, 0);
7146
James Smart92d7f7b2007-06-17 19:56:38 -05007147 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7148 if (rc == IOCB_ERROR) {
7149 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007150 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007151 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7152 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007153 return 1;
7154 }
7155 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007156 return 0;
7157}
7158
James Smarte59058c2008-08-24 21:49:00 -04007159/**
James Smart3621a712009-04-06 18:47:14 -04007160 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007161 * @phba: pointer to lpfc hba data structure.
7162 * @cmdiocb: pointer to lpfc command iocb data structure.
7163 * @rspiocb: pointer to lpfc response iocb data structure.
7164 *
7165 * This routine is the completion callback function to the issuing of a LOGO
7166 * ELS command off a vport. It frees the command IOCB and then decrement the
7167 * reference count held on ndlp for this completion function, indicating that
7168 * the reference to the ndlp is no long needed. Note that the
7169 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7170 * callback function and an additional explicit ndlp reference decrementation
7171 * will trigger the actual release of the ndlp.
7172 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007173static void
7174lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7175 struct lpfc_iocbq *rspiocb)
7176{
7177 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007178 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007179 struct lpfc_nodelist *ndlp;
7180 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007181
7182 irsp = &rspiocb->iocb;
7183 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7184 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7185 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007186
7187 lpfc_els_free_iocb(phba, cmdiocb);
7188 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007189
7190 /* Trigger the release of the ndlp after logo */
7191 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007192}
7193
James Smarte59058c2008-08-24 21:49:00 -04007194/**
James Smart3621a712009-04-06 18:47:14 -04007195 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007196 * @vport: pointer to a virtual N_Port data structure.
7197 * @ndlp: pointer to a node-list data structure.
7198 *
7199 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7200 *
7201 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7202 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7203 * will be stored into the context1 field of the IOCB for the completion
7204 * callback function to the LOGO ELS command.
7205 *
7206 * Return codes
7207 * 0 - Successfully issued logo off the @vport
7208 * 1 - Failed to issue logo off the @vport
7209 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007210int
7211lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7212{
7213 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7214 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007215 IOCB_t *icmd;
7216 struct lpfc_iocbq *elsiocb;
7217 uint8_t *pcmd;
7218 uint16_t cmdsize;
7219
7220 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7221 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7222 ELS_CMD_LOGO);
7223 if (!elsiocb)
7224 return 1;
7225
7226 icmd = &elsiocb->iocb;
7227 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7228 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7229 pcmd += sizeof(uint32_t);
7230
7231 /* Fill in LOGO payload */
7232 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7233 pcmd += sizeof(uint32_t);
7234 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7235
James Smart858c9f62007-06-17 19:56:39 -05007236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7237 "Issue LOGO npiv did:x%x flg:x%x",
7238 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7239
James Smart92d7f7b2007-06-17 19:56:38 -05007240 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7241 spin_lock_irq(shost->host_lock);
7242 ndlp->nlp_flag |= NLP_LOGO_SND;
7243 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007244 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7245 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007246 spin_lock_irq(shost->host_lock);
7247 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7248 spin_unlock_irq(shost->host_lock);
7249 lpfc_els_free_iocb(phba, elsiocb);
7250 return 1;
7251 }
7252 return 0;
7253}
7254
James Smarte59058c2008-08-24 21:49:00 -04007255/**
James Smart3621a712009-04-06 18:47:14 -04007256 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007257 * @ptr: holder for the timer function associated data.
7258 *
7259 * This routine is invoked by the fabric iocb block timer after
7260 * timeout. It posts the fabric iocb block timeout event by setting the
7261 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7262 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7263 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7264 * posted event WORKER_FABRIC_BLOCK_TMO.
7265 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007266void
7267lpfc_fabric_block_timeout(unsigned long ptr)
7268{
7269 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7270 unsigned long iflags;
7271 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007272
James Smart92d7f7b2007-06-17 19:56:38 -05007273 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7274 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7275 if (!tmo_posted)
7276 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7277 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7278
James Smart5e9d9b82008-06-14 22:52:53 -04007279 if (!tmo_posted)
7280 lpfc_worker_wake_up(phba);
7281 return;
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_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007286 * @phba: pointer to lpfc hba data structure.
7287 *
7288 * This routine issues one fabric iocb from the driver internal list to
7289 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7290 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7291 * remove one pending fabric iocb from the driver internal list and invokes
7292 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7293 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007294static void
7295lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7296{
7297 struct lpfc_iocbq *iocb;
7298 unsigned long iflags;
7299 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007300 IOCB_t *cmd;
7301
7302repeat:
7303 iocb = NULL;
7304 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007305 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007306 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7307 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7308 list);
7309 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007310 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007311 atomic_inc(&phba->fabric_iocb_count);
7312 }
7313 spin_unlock_irqrestore(&phba->hbalock, iflags);
7314 if (iocb) {
7315 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7316 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7317 iocb->iocb_flag |= LPFC_IO_FABRIC;
7318
James Smart858c9f62007-06-17 19:56:39 -05007319 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7320 "Fabric sched1: ste:x%x",
7321 iocb->vport->port_state, 0, 0);
7322
James Smart3772a992009-05-22 14:50:54 -04007323 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007324
7325 if (ret == IOCB_ERROR) {
7326 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7327 iocb->fabric_iocb_cmpl = NULL;
7328 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7329 cmd = &iocb->iocb;
7330 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7331 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7332 iocb->iocb_cmpl(phba, iocb, iocb);
7333
7334 atomic_dec(&phba->fabric_iocb_count);
7335 goto repeat;
7336 }
7337 }
7338
7339 return;
7340}
7341
James Smarte59058c2008-08-24 21:49:00 -04007342/**
James Smart3621a712009-04-06 18:47:14 -04007343 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007344 * @phba: pointer to lpfc hba data structure.
7345 *
7346 * This routine unblocks the issuing fabric iocb command. The function
7347 * will clear the fabric iocb block bit and then invoke the routine
7348 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7349 * from the driver internal fabric iocb list.
7350 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007351void
7352lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7353{
7354 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7355
7356 lpfc_resume_fabric_iocbs(phba);
7357 return;
7358}
7359
James Smarte59058c2008-08-24 21:49:00 -04007360/**
James Smart3621a712009-04-06 18:47:14 -04007361 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007362 * @phba: pointer to lpfc hba data structure.
7363 *
7364 * This routine blocks the issuing fabric iocb for a specified amount of
7365 * time (currently 100 ms). This is done by set the fabric iocb block bit
7366 * and set up a timeout timer for 100ms. When the block bit is set, no more
7367 * fabric iocb will be issued out of the HBA.
7368 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007369static void
7370lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7371{
7372 int blocked;
7373
7374 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007375 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007376 if (!blocked)
7377 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7378
7379 return;
7380}
7381
James Smarte59058c2008-08-24 21:49:00 -04007382/**
James Smart3621a712009-04-06 18:47:14 -04007383 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007384 * @phba: pointer to lpfc hba data structure.
7385 * @cmdiocb: pointer to lpfc command iocb data structure.
7386 * @rspiocb: pointer to lpfc response iocb data structure.
7387 *
7388 * This routine is the callback function that is put to the fabric iocb's
7389 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7390 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7391 * function first restores and invokes the original iocb's callback function
7392 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7393 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7394 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007395static void
7396lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7397 struct lpfc_iocbq *rspiocb)
7398{
7399 struct ls_rjt stat;
7400
7401 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7402 BUG();
7403
7404 switch (rspiocb->iocb.ulpStatus) {
7405 case IOSTAT_NPORT_RJT:
7406 case IOSTAT_FABRIC_RJT:
7407 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7408 lpfc_block_fabric_iocbs(phba);
7409 }
7410 break;
7411
7412 case IOSTAT_NPORT_BSY:
7413 case IOSTAT_FABRIC_BSY:
7414 lpfc_block_fabric_iocbs(phba);
7415 break;
7416
7417 case IOSTAT_LS_RJT:
7418 stat.un.lsRjtError =
7419 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7420 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7421 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7422 lpfc_block_fabric_iocbs(phba);
7423 break;
7424 }
7425
7426 if (atomic_read(&phba->fabric_iocb_count) == 0)
7427 BUG();
7428
7429 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7430 cmdiocb->fabric_iocb_cmpl = NULL;
7431 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7432 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7433
7434 atomic_dec(&phba->fabric_iocb_count);
7435 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007436 /* Post any pending iocbs to HBA */
7437 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007438 }
7439}
7440
James Smarte59058c2008-08-24 21:49:00 -04007441/**
James Smart3621a712009-04-06 18:47:14 -04007442 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007443 * @phba: pointer to lpfc hba data structure.
7444 * @iocb: pointer to lpfc command iocb data structure.
7445 *
7446 * This routine is used as the top-level API for issuing a fabric iocb command
7447 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7448 * function makes sure that only one fabric bound iocb will be outstanding at
7449 * any given time. As such, this function will first check to see whether there
7450 * is already an outstanding fabric iocb on the wire. If so, it will put the
7451 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7452 * issued later. Otherwise, it will issue the iocb on the wire and update the
7453 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7454 *
7455 * Note, this implementation has a potential sending out fabric IOCBs out of
7456 * order. The problem is caused by the construction of the "ready" boolen does
7457 * not include the condition that the internal fabric IOCB list is empty. As
7458 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7459 * ahead of the fabric IOCBs in the internal list.
7460 *
7461 * Return code
7462 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7463 * IOCB_ERROR - failed to issue fabric iocb
7464 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007465static int
James Smart92d7f7b2007-06-17 19:56:38 -05007466lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7467{
7468 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007469 int ready;
7470 int ret;
7471
7472 if (atomic_read(&phba->fabric_iocb_count) > 1)
7473 BUG();
7474
7475 spin_lock_irqsave(&phba->hbalock, iflags);
7476 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7477 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7478
James Smart7f5f3d02008-02-08 18:50:14 -05007479 if (ready)
7480 /* Increment fabric iocb count to hold the position */
7481 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007482 spin_unlock_irqrestore(&phba->hbalock, iflags);
7483 if (ready) {
7484 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7485 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7486 iocb->iocb_flag |= LPFC_IO_FABRIC;
7487
James Smart858c9f62007-06-17 19:56:39 -05007488 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7489 "Fabric sched2: ste:x%x",
7490 iocb->vport->port_state, 0, 0);
7491
James Smart3772a992009-05-22 14:50:54 -04007492 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007493
7494 if (ret == IOCB_ERROR) {
7495 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7496 iocb->fabric_iocb_cmpl = NULL;
7497 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7498 atomic_dec(&phba->fabric_iocb_count);
7499 }
7500 } else {
7501 spin_lock_irqsave(&phba->hbalock, iflags);
7502 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7503 spin_unlock_irqrestore(&phba->hbalock, iflags);
7504 ret = IOCB_SUCCESS;
7505 }
7506 return ret;
7507}
7508
James Smarte59058c2008-08-24 21:49:00 -04007509/**
James Smart3621a712009-04-06 18:47:14 -04007510 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007511 * @vport: pointer to a virtual N_Port data structure.
7512 *
7513 * This routine aborts all the IOCBs associated with a @vport from the
7514 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7515 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7516 * list, removes each IOCB associated with the @vport off the list, set the
7517 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7518 * associated with the IOCB.
7519 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007520static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007521{
7522 LIST_HEAD(completions);
7523 struct lpfc_hba *phba = vport->phba;
7524 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007525
7526 spin_lock_irq(&phba->hbalock);
7527 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7528 list) {
7529
7530 if (piocb->vport != vport)
7531 continue;
7532
7533 list_move_tail(&piocb->list, &completions);
7534 }
7535 spin_unlock_irq(&phba->hbalock);
7536
James Smarta257bf92009-04-06 18:48:10 -04007537 /* Cancel all the IOCBs from the completions list */
7538 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7539 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007540}
7541
James Smarte59058c2008-08-24 21:49:00 -04007542/**
James Smart3621a712009-04-06 18:47:14 -04007543 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007544 * @ndlp: pointer to a node-list data structure.
7545 *
7546 * This routine aborts all the IOCBs associated with an @ndlp from the
7547 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7548 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7549 * list, removes each IOCB associated with the @ndlp off the list, set the
7550 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7551 * associated with the IOCB.
7552 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007553void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7554{
7555 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007556 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007557 struct lpfc_iocbq *tmp_iocb, *piocb;
7558 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007559
7560 spin_lock_irq(&phba->hbalock);
7561 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7562 list) {
7563 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7564
7565 list_move_tail(&piocb->list, &completions);
7566 }
7567 }
7568 spin_unlock_irq(&phba->hbalock);
7569
James Smarta257bf92009-04-06 18:48:10 -04007570 /* Cancel all the IOCBs from the completions list */
7571 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7572 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007573}
7574
James Smarte59058c2008-08-24 21:49:00 -04007575/**
James Smart3621a712009-04-06 18:47:14 -04007576 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007577 * @phba: pointer to lpfc hba data structure.
7578 *
7579 * This routine aborts all the IOCBs currently on the driver internal
7580 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7581 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7582 * list, removes IOCBs off the list, set the status feild to
7583 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7584 * the IOCB.
7585 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007586void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7587{
7588 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007589
7590 spin_lock_irq(&phba->hbalock);
7591 list_splice_init(&phba->fabric_iocb_list, &completions);
7592 spin_unlock_irq(&phba->hbalock);
7593
James Smarta257bf92009-04-06 18:48:10 -04007594 /* Cancel all the IOCBs from the completions list */
7595 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7596 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007597}
James Smart6fb120a2009-05-22 14:52:59 -04007598
7599/**
James Smart1151e3e2011-02-16 12:39:35 -05007600 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7601 * @vport: pointer to lpfc vport data structure.
7602 *
7603 * This routine is invoked by the vport cleanup for deletions and the cleanup
7604 * for an ndlp on removal.
7605 **/
7606void
7607lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *vport)
7608{
7609 struct lpfc_hba *phba = vport->phba;
7610 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7611 unsigned long iflag = 0;
7612
7613 spin_lock_irqsave(&phba->hbalock, iflag);
7614 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7615 list_for_each_entry_safe(sglq_entry, sglq_next,
7616 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7617 if (sglq_entry->ndlp && sglq_entry->ndlp->vport == vport)
7618 sglq_entry->ndlp = NULL;
7619 }
7620 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7621 spin_unlock_irqrestore(&phba->hbalock, iflag);
7622 return;
7623}
7624
7625/**
James Smart6fb120a2009-05-22 14:52:59 -04007626 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7627 * @phba: pointer to lpfc hba data structure.
7628 * @axri: pointer to the els xri abort wcqe structure.
7629 *
7630 * This routine is invoked by the worker thread to process a SLI4 slow-path
7631 * ELS aborted xri.
7632 **/
7633void
7634lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7635 struct sli4_wcqe_xri_aborted *axri)
7636{
7637 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007638 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7639
James Smart6fb120a2009-05-22 14:52:59 -04007640 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7641 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007642 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007643 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007644
James Smart0f65ff62010-02-26 14:14:23 -05007645 spin_lock_irqsave(&phba->hbalock, iflag);
7646 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007647 list_for_each_entry_safe(sglq_entry, sglq_next,
7648 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7649 if (sglq_entry->sli4_xritag == xri) {
7650 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007651 ndlp = sglq_entry->ndlp;
7652 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007653 list_add_tail(&sglq_entry->list,
7654 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007655 sglq_entry->state = SGL_FREED;
7656 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007657 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007658 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007659
7660 /* Check if TXQ queue needs to be serviced */
7661 if (pring->txq_cnt)
7662 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007663 return;
7664 }
7665 }
James Smart0f65ff62010-02-26 14:14:23 -05007666 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7667 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7668 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7669 spin_unlock_irqrestore(&phba->hbalock, iflag);
7670 return;
7671 }
7672 sglq_entry->state = SGL_XRI_ABORTED;
7673 spin_unlock_irqrestore(&phba->hbalock, iflag);
7674 return;
James Smart6fb120a2009-05-22 14:52:59 -04007675}