blob: 0705ad86538f785a55fe87d7c89c5e6d7543a817 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
James Smartda0436e2009-05-22 14:51:39 -040032#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050033#include "lpfc_hw.h"
34#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040035#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_scsi.h"
39#include "lpfc.h"
40#include "lpfc_logmsg.h"
41#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050042#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050043#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050044
45static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050047static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010049static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
James Smart3621a712009-04-06 18:47:14 -040058 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040059 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040087 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
dea31012005-04-17 16:05:31 -050089 return 0;
90
91 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050092 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050093
94 if (!(ha_copy & HA_LATT))
95 return 0;
96
97 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040098 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500102
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
108 */
James Smart2e0fef82007-06-17 19:56:36 -0500109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500112
James Smart92d7f7b2007-06-17 19:56:38 -0500113 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500115
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500116 return 1;
dea31012005-04-17 16:05:31 -0500117}
118
James Smarte59058c2008-08-24 21:49:00 -0400119/**
James Smart3621a712009-04-06 18:47:14 -0400120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
128 *
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
142 *
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
146 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400147struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500148lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500152{
James Smart2e0fef82007-06-17 19:56:36 -0500153 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400154 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
158
dea31012005-04-17 16:05:31 -0500159
James Smart2e0fef82007-06-17 19:56:36 -0500160 if (!lpfc_is_link_up(phba))
161 return NULL;
dea31012005-04-17 16:05:31 -0500162
dea31012005-04-17 16:05:31 -0500163 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400164 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500165
166 if (elsiocb == NULL)
167 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500168
James Smart0c287582009-06-10 17:22:56 -0400169 /*
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
172 */
173 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
James Smartf0d9bcc2010-10-22 11:07:09 -0400180 elsiocb->iocb_flag |=
181 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500182 & LPFC_FIP_ELS_ID_MASK);
183 break;
184 case ELS_CMD_FDISC:
James Smartf0d9bcc2010-10-22 11:07:09 -0400185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_LOGO:
James Smartf0d9bcc2010-10-22 11:07:09 -0400190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
James Smartc8685952009-11-18 15:39:16 -0500192 & LPFC_FIP_ELS_ID_MASK);
193 break;
194 }
James Smart0c287582009-06-10 17:22:56 -0400195 else
James Smartc8685952009-11-18 15:39:16 -0500196 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400197
dea31012005-04-17 16:05:31 -0500198 icmd = &elsiocb->iocb;
199
200 /* fill in BDEs for command */
201 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400202 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
203 if (pcmd)
204 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500205 if (!pcmd || !pcmd->virt)
206 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500207
208 INIT_LIST_HEAD(&pcmd->list);
209
210 /* Allocate buffer for response payload */
211 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500212 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500213 if (prsp)
214 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
215 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500216 if (!prsp || !prsp->virt)
217 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500218 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500219 } else
dea31012005-04-17 16:05:31 -0500220 prsp = NULL;
dea31012005-04-17 16:05:31 -0500221
222 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500223 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500224 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500225 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
226 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500227 if (!pbuflist || !pbuflist->virt)
228 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500229
230 INIT_LIST_HEAD(&pbuflist->list);
231
232 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
233 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400234 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500235 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500236 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500238 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400239 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500240 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500241 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500242 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
243 }
dea31012005-04-17 16:05:31 -0500244 icmd->ulpBdeCount = 1;
245 icmd->ulpLe = 1;
246 icmd->ulpClass = CLASS3;
247
James Smart92d7f7b2007-06-17 19:56:38 -0500248 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
249 icmd->un.elsreq64.myID = vport->fc_myDID;
250
251 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400252 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500253 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500254 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
255 if (elscmd == ELS_CMD_ECHO)
256 icmd->ulpCt_l = 0; /* context = invalid RPI */
257 else
258 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500259 }
260
dea31012005-04-17 16:05:31 -0500261 bpl = (struct ulp_bde64 *) pbuflist->virt;
262 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
263 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
264 bpl->tus.f.bdeSize = cmdSize;
265 bpl->tus.f.bdeFlags = 0;
266 bpl->tus.w = le32_to_cpu(bpl->tus.w);
267
268 if (expectRsp) {
269 bpl++;
270 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
271 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
272 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400273 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500274 bpl->tus.w = le32_to_cpu(bpl->tus.w);
275 }
276
James Smartfa4066b2008-01-11 01:53:27 -0500277 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400278 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500279 if (!elsiocb->context1)
280 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400281 elsiocb->context2 = pcmd;
282 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500283 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500284 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500285 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
286
287 if (prsp) {
288 list_add(&prsp->list, &pcmd->list);
289 }
dea31012005-04-17 16:05:31 -0500290 if (expectRsp) {
291 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
293 "0116 Xmit ELS command x%x to remote "
294 "NPORT x%x I/O tag: x%x, port state: x%x\n",
295 elscmd, did, elsiocb->iotag,
296 vport->port_state);
dea31012005-04-17 16:05:31 -0500297 } else {
298 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400299 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
300 "0117 Xmit ELS response x%x to remote "
301 "NPORT x%x I/O tag: x%x, size: x%x\n",
302 elscmd, ndlp->nlp_DID, elsiocb->iotag,
303 cmdSize);
dea31012005-04-17 16:05:31 -0500304 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500305 return elsiocb;
dea31012005-04-17 16:05:31 -0500306
James Smartfa4066b2008-01-11 01:53:27 -0500307els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500308 if (expectRsp)
309 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500310 kfree(pbuflist);
311
312els_iocb_free_prsp_exit:
313 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
314 kfree(prsp);
315
316els_iocb_free_pcmb_exit:
317 kfree(pcmd);
318 lpfc_sli_release_iocbq(phba, elsiocb);
319 return NULL;
320}
dea31012005-04-17 16:05:31 -0500321
James Smarte59058c2008-08-24 21:49:00 -0400322/**
James Smart3621a712009-04-06 18:47:14 -0400323 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400324 * @vport: pointer to a host virtual N_Port data structure.
325 *
326 * This routine issues a fabric registration login for a @vport. An
327 * active ndlp node with Fabric_DID must already exist for this @vport.
328 * The routine invokes two mailbox commands to carry out fabric registration
329 * login through the HBA firmware: the first mailbox command requests the
330 * HBA to perform link configuration for the @vport; and the second mailbox
331 * command requests the HBA to perform the actual fabric registration login
332 * with the @vport.
333 *
334 * Return code
335 * 0 - successfully issued fabric registration login for @vport
336 * -ENXIO -- failed to issue fabric registration login for @vport
337 **/
James Smart3772a992009-05-22 14:50:54 -0400338int
James Smart92d7f7b2007-06-17 19:56:38 -0500339lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
340{
341 struct lpfc_hba *phba = vport->phba;
342 LPFC_MBOXQ_t *mbox;
343 struct lpfc_dmabuf *mp;
344 struct lpfc_nodelist *ndlp;
345 struct serv_parm *sp;
346 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400347 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500348
349 sp = &phba->fc_fabparam;
350 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500351 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400352 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500353 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400354 }
James Smart92d7f7b2007-06-17 19:56:38 -0500355
356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400357 if (!mbox) {
358 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500359 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400360 }
James Smart92d7f7b2007-06-17 19:56:38 -0500361
362 vport->port_state = LPFC_FABRIC_CFG_LINK;
363 lpfc_config_link(phba, mbox);
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 mbox->vport = vport;
366
James Smart0b727fe2007-10-27 13:37:25 -0400367 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400368 if (rc == MBX_NOT_FINISHED) {
369 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500370 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400371 }
James Smart92d7f7b2007-06-17 19:56:38 -0500372
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400374 if (!mbox) {
375 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500376 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400377 }
James Smart3772a992009-05-22 14:50:54 -0400378 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400379 if (rc) {
380 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500381 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400382 }
James Smart92d7f7b2007-06-17 19:56:38 -0500383
384 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
385 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500386 /* increment the reference count on ndlp to hold reference
387 * for the callback routine.
388 */
James Smart92d7f7b2007-06-17 19:56:38 -0500389 mbox->context2 = lpfc_nlp_get(ndlp);
390
James Smart0b727fe2007-10-27 13:37:25 -0400391 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400392 if (rc == MBX_NOT_FINISHED) {
393 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500394 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400395 }
James Smart92d7f7b2007-06-17 19:56:38 -0500396
397 return 0;
398
399fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500400 /* decrement the reference count on ndlp just incremented
401 * for the failed mbox command.
402 */
James Smart92d7f7b2007-06-17 19:56:38 -0500403 lpfc_nlp_put(ndlp);
404 mp = (struct lpfc_dmabuf *) mbox->context1;
405 lpfc_mbuf_free(phba, mp->virt, mp->phys);
406 kfree(mp);
407fail_free_mbox:
408 mempool_free(mbox, phba->mbox_mem_pool);
409
410fail:
411 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400412 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400413 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500414 return -ENXIO;
415}
416
James Smarte59058c2008-08-24 21:49:00 -0400417/**
James Smart6fb120a2009-05-22 14:52:59 -0400418 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
419 * @vport: pointer to a host virtual N_Port data structure.
420 *
421 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
422 * the @vport. This mailbox command is necessary for FCoE only.
423 *
424 * Return code
425 * 0 - successfully issued REG_VFI for @vport
426 * A failure code otherwise.
427 **/
428static int
429lpfc_issue_reg_vfi(struct lpfc_vport *vport)
430{
431 struct lpfc_hba *phba = vport->phba;
432 LPFC_MBOXQ_t *mboxq;
433 struct lpfc_nodelist *ndlp;
434 struct serv_parm *sp;
435 struct lpfc_dmabuf *dmabuf;
436 int rc = 0;
437
438 sp = &phba->fc_fabparam;
439 ndlp = lpfc_findnode_did(vport, Fabric_DID);
440 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
441 rc = -ENODEV;
442 goto fail;
443 }
444
445 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
446 if (!dmabuf) {
447 rc = -ENOMEM;
448 goto fail;
449 }
450 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
451 if (!dmabuf->virt) {
452 rc = -ENOMEM;
453 goto fail_free_dmabuf;
454 }
455 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
456 if (!mboxq) {
457 rc = -ENOMEM;
458 goto fail_free_coherent;
459 }
460 vport->port_state = LPFC_FABRIC_CFG_LINK;
461 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
462 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
463 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
464 mboxq->vport = vport;
465 mboxq->context1 = dmabuf;
466 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
467 if (rc == MBX_NOT_FINISHED) {
468 rc = -ENXIO;
469 goto fail_free_mbox;
470 }
471 return 0;
472
473fail_free_mbox:
474 mempool_free(mboxq, phba->mbox_mem_pool);
475fail_free_coherent:
476 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
477fail_free_dmabuf:
478 kfree(dmabuf);
479fail:
480 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
482 "0289 Issue Register VFI failed: Err %d\n", rc);
483 return rc;
484}
485
486/**
James Smart3621a712009-04-06 18:47:14 -0400487 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400488 * @vport: pointer to a host virtual N_Port data structure.
489 * @ndlp: pointer to a node-list data structure.
490 * @sp: pointer to service parameter data structure.
491 * @irsp: pointer to the IOCB within the lpfc response IOCB.
492 *
493 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
494 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
495 * port in a fabric topology. It properly sets up the parameters to the @ndlp
496 * from the IOCB response. It also check the newly assigned N_Port ID to the
497 * @vport against the previously assigned N_Port ID. If it is different from
498 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
499 * is invoked on all the remaining nodes with the @vport to unregister the
500 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
501 * is invoked to register login to the fabric.
502 *
503 * Return code
504 * 0 - Success (currently, always return 0)
505 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500506static int
James Smart2e0fef82007-06-17 19:56:36 -0500507lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
508 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500509{
James Smart2e0fef82007-06-17 19:56:36 -0500510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
511 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500512 struct lpfc_nodelist *np;
513 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500514
James Smart2e0fef82007-06-17 19:56:36 -0500515 spin_lock_irq(shost->host_lock);
516 vport->fc_flag |= FC_FABRIC;
517 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500518
519 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
520 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
521 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
522
James Smart12265f62010-10-22 11:05:53 -0400523 phba->fc_edtovResol = sp->cmn.edtovResolution;
dea31012005-04-17 16:05:31 -0500524 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
525
James Smart76a95d72010-11-20 23:11:48 -0500526 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500527 spin_lock_irq(shost->host_lock);
528 vport->fc_flag |= FC_PUBLIC_LOOP;
529 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500530 }
531
James Smart2e0fef82007-06-17 19:56:36 -0500532 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500533 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500534 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500535 ndlp->nlp_class_sup = 0;
536 if (sp->cls1.classValid)
537 ndlp->nlp_class_sup |= FC_COS_CLASS1;
538 if (sp->cls2.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS2;
540 if (sp->cls3.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS3;
542 if (sp->cls4.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS4;
544 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
545 sp->cmn.bbRcvSizeLsb;
546 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
547
James Smart92d7f7b2007-06-17 19:56:38 -0500548 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
549 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400550 lpfc_printf_vlog(vport, KERN_WARNING,
551 LOG_ELS | LOG_VPORT,
552 "1816 FLOGI NPIV supported, "
553 "response data 0x%x\n",
554 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500555 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500556 } else {
557 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400558 to call reg_vnpid atleast for the physcial host */
559 lpfc_printf_vlog(vport, KERN_WARNING,
560 LOG_ELS | LOG_VPORT,
561 "1817 Fabric does not support NPIV "
562 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500563 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
564 }
565 }
566
567 if ((vport->fc_prevDID != vport->fc_myDID) &&
568 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
569
570 /* If our NportID changed, we need to ensure all
571 * remaining NPORTs get unreg_login'ed.
572 */
573 list_for_each_entry_safe(np, next_np,
574 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400575 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500576 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500577 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
578 !(np->nlp_flag & NLP_NPR_ADISC))
579 continue;
580 spin_lock_irq(shost->host_lock);
581 np->nlp_flag &= ~NLP_NPR_ADISC;
582 spin_unlock_irq(shost->host_lock);
583 lpfc_unreg_rpi(vport, np);
584 }
James Smart78730cf2010-04-06 15:06:30 -0400585 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -0400586
587 if (phba->sli_rev == LPFC_SLI_REV4)
588 lpfc_sli4_unreg_all_rpis(vport);
589
James Smart92d7f7b2007-06-17 19:56:38 -0500590 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
591 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500592 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500593 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500594 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500595 }
James Smartecfd03c2010-02-12 14:41:27 -0500596 /*
597 * If VPI is unreged, driver need to do INIT_VPI
598 * before re-registering
599 */
600 if (phba->sli_rev == LPFC_SLI_REV4) {
601 spin_lock_irq(shost->host_lock);
602 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
603 spin_unlock_irq(shost->host_lock);
604 }
James Smart38b92ef2010-08-04 16:11:39 -0400605 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
606 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
607 /*
608 * Driver needs to re-reg VPI in order for f/w
609 * to update the MAC address.
610 */
611 lpfc_register_new_vport(phba, vport, ndlp);
612 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500613 }
614
James Smart6fb120a2009-05-22 14:52:59 -0400615 if (phba->sli_rev < LPFC_SLI_REV4) {
616 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
617 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
618 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
619 lpfc_register_new_vport(phba, vport, ndlp);
620 else
621 lpfc_issue_fabric_reglogin(vport);
622 } else {
623 ndlp->nlp_type |= NLP_FABRIC;
624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500625 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
626 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400627 lpfc_start_fdiscs(phba);
628 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500629 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500630 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500631 else
James Smart6fb120a2009-05-22 14:52:59 -0400632 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500633 }
dea31012005-04-17 16:05:31 -0500634 return 0;
dea31012005-04-17 16:05:31 -0500635}
James Smarte59058c2008-08-24 21:49:00 -0400636/**
James Smart3621a712009-04-06 18:47:14 -0400637 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
641 *
642 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
643 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
644 * in a point-to-point topology. First, the @vport's N_Port Name is compared
645 * with the received N_Port Name: if the @vport's N_Port Name is greater than
646 * the received N_Port Name lexicographically, this node shall assign local
647 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
648 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
649 * this node shall just wait for the remote node to issue PLOGI and assign
650 * N_Port IDs.
651 *
652 * Return code
653 * 0 - Success
654 * -ENXIO - Fail
655 **/
dea31012005-04-17 16:05:31 -0500656static int
James Smart2e0fef82007-06-17 19:56:36 -0500657lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500659{
James Smart2e0fef82007-06-17 19:56:36 -0500660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500662 LPFC_MBOXQ_t *mbox;
663 int rc;
664
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
667 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500668
669 phba->fc_edtov = FF_DEF_EDTOV;
670 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500671 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500672 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500673 if (rc >= 0) {
674 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_PT2PT_PLOGI;
677 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500678
679 /*
680 * N_Port ID cannot be 0, set our to LocalID the other
681 * side will be RemoteID.
682 */
683
684 /* not equal */
685 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500686 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500687
688 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
689 if (!mbox)
690 goto fail;
691
692 lpfc_config_link(phba, mbox);
693
694 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500695 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400696 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500697 if (rc == MBX_NOT_FINISHED) {
698 mempool_free(mbox, phba->mbox_mem_pool);
699 goto fail;
700 }
James Smarte47c9092008-02-08 18:49:26 -0500701 /* Decrement ndlp reference count indicating that ndlp can be
702 * safely released when other references to it are done.
703 */
James Smart329f9bc2007-04-25 09:53:01 -0400704 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500705
James Smart2e0fef82007-06-17 19:56:36 -0500706 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500707 if (!ndlp) {
708 /*
709 * Cannot find existing Fabric ndlp, so allocate a
710 * new one
711 */
712 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
713 if (!ndlp)
714 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500715 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500716 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
717 ndlp = lpfc_enable_node(vport, ndlp,
718 NLP_STE_UNUSED_NODE);
719 if(!ndlp)
720 goto fail;
dea31012005-04-17 16:05:31 -0500721 }
722
723 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500724 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500725 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500726 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500727 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
729 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500730 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500731 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500732 } else
733 /* This side will wait for the PLOGI, decrement ndlp reference
734 * count indicating that ndlp can be released when other
735 * references to it are done.
736 */
James Smart329f9bc2007-04-25 09:53:01 -0400737 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500738
James Smart09372822008-01-11 01:52:54 -0500739 /* If we are pt2pt with another NPort, force NPIV off! */
740 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
741
James Smart2e0fef82007-06-17 19:56:36 -0500742 spin_lock_irq(shost->host_lock);
743 vport->fc_flag |= FC_PT2PT;
744 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500745
746 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500747 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500748 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500749fail:
dea31012005-04-17 16:05:31 -0500750 return -ENXIO;
751}
752
James Smarte59058c2008-08-24 21:49:00 -0400753/**
James Smart3621a712009-04-06 18:47:14 -0400754 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400755 * @phba: pointer to lpfc hba data structure.
756 * @cmdiocb: pointer to lpfc command iocb data structure.
757 * @rspiocb: pointer to lpfc response iocb data structure.
758 *
759 * This routine is the top-level completion callback function for issuing
760 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
761 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
762 * retry has been made (either immediately or delayed with lpfc_els_retry()
763 * returning 1), the command IOCB will be released and function returned.
764 * If the retry attempt has been given up (possibly reach the maximum
765 * number of retries), one additional decrement of ndlp reference shall be
766 * invoked before going out after releasing the command IOCB. This will
767 * actually release the remote node (Note, lpfc_els_free_iocb() will also
768 * invoke one decrement of ndlp reference count). If no error reported in
769 * the IOCB status, the command Port ID field is used to determine whether
770 * this is a point-to-point topology or a fabric topology: if the Port ID
771 * field is assigned, it is a fabric topology; otherwise, it is a
772 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
773 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
774 * specific topology completion conditions.
775 **/
dea31012005-04-17 16:05:31 -0500776static void
James Smart329f9bc2007-04-25 09:53:01 -0400777lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
778 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500779{
James Smart2e0fef82007-06-17 19:56:36 -0500780 struct lpfc_vport *vport = cmdiocb->vport;
781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500782 IOCB_t *irsp = &rspiocb->iocb;
783 struct lpfc_nodelist *ndlp = cmdiocb->context1;
784 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
785 struct serv_parm *sp;
James Smart0c9ab6f2010-02-26 14:15:57 -0500786 uint16_t fcf_index;
dea31012005-04-17 16:05:31 -0500787 int rc;
788
789 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500790 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500791 /* One additional decrement on node reference count to
792 * trigger the release of the node
793 */
James Smart329f9bc2007-04-25 09:53:01 -0400794 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500795 goto out;
796 }
797
James Smart858c9f62007-06-17 19:56:39 -0500798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
799 "FLOGI cmpl: status:x%x/x%x state:x%x",
800 irsp->ulpStatus, irsp->un.ulpWord[4],
801 vport->port_state);
802
dea31012005-04-17 16:05:31 -0500803 if (irsp->ulpStatus) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500804 /*
James Smarta93ff372010-10-22 11:06:08 -0400805 * In case of FIP mode, perform roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -0500806 * due to new FCF discovery
807 */
808 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smartdbb6b3a2010-06-08 18:31:37 -0400809 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
810 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
811 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
James Smart0c9ab6f2010-02-26 14:15:57 -0500812 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400813 "2611 FLOGI failed on FCF (x%x), "
814 "status:x%x/x%x, tmo:x%x, perform "
815 "roundrobin FCF failover\n",
James Smart38b92ef2010-08-04 16:11:39 -0400816 phba->fcf.current_rec.fcf_indx,
817 irsp->ulpStatus, irsp->un.ulpWord[4],
818 irsp->ulpTimeout);
James Smart0c9ab6f2010-02-26 14:15:57 -0500819 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
James Smarta93ff372010-10-22 11:06:08 -0400820 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
821 if (rc)
822 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500823 }
824
James Smart38b92ef2010-08-04 16:11:39 -0400825 /* FLOGI failure */
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
827 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
828 irsp->ulpStatus, irsp->un.ulpWord[4],
829 irsp->ulpTimeout);
830
dea31012005-04-17 16:05:31 -0500831 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500832 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500833 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500834
James Smart76a95d72010-11-20 23:11:48 -0500835 /* FLOGI failure */
836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
837 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
838 irsp->ulpStatus, irsp->un.ulpWord[4],
839 irsp->ulpTimeout);
840
dea31012005-04-17 16:05:31 -0500841 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500842 spin_lock_irq(shost->host_lock);
843 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
844 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500845
James Smart329f9bc2007-04-25 09:53:01 -0400846 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500847 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
848 * alpa map would take too long otherwise.
849 */
850 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400851 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
James Smart76a95d72010-11-20 23:11:48 -0500852 if ((phba->sli_rev == LPFC_SLI_REV4) &&
853 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
854 (vport->fc_prevDID != vport->fc_myDID))) {
855 if (vport->fc_flag & FC_VFI_REGISTERED)
856 lpfc_sli4_unreg_all_rpis(vport);
857 lpfc_issue_reg_vfi(vport);
858 lpfc_nlp_put(ndlp);
859 goto out;
860 }
dea31012005-04-17 16:05:31 -0500861 }
dea31012005-04-17 16:05:31 -0500862 goto flogifail;
863 }
James Smart695a8142010-01-26 23:08:03 -0500864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -0400866 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smart695a8142010-01-26 23:08:03 -0500867 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500868
869 /*
870 * The FLogI succeeded. Sync the data for the CPU before
871 * accessing it.
872 */
873 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
874
875 sp = prsp->virt + sizeof(uint32_t);
876
877 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200879 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400880 "Data: x%x x%x x%x x%x\n",
881 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
882 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500883
James Smart2e0fef82007-06-17 19:56:36 -0500884 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500885 /*
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
888 */
889 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500890 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
James Smart76a95d72010-11-20 23:11:48 -0500891 else if (!(phba->hba_flag & HBA_FCOE_MODE))
James Smart2e0fef82007-06-17 19:56:36 -0500892 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
James Smartdbb6b3a2010-06-08 18:31:37 -0400893 else {
894 lpfc_printf_vlog(vport, KERN_ERR,
895 LOG_FIP | LOG_ELS,
896 "2831 FLOGI response with cleared Fabric "
897 "bit fcf_index 0x%x "
898 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
899 "Fabric Name "
900 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
901 phba->fcf.current_rec.fcf_indx,
902 phba->fcf.current_rec.switch_name[0],
903 phba->fcf.current_rec.switch_name[1],
904 phba->fcf.current_rec.switch_name[2],
905 phba->fcf.current_rec.switch_name[3],
906 phba->fcf.current_rec.switch_name[4],
907 phba->fcf.current_rec.switch_name[5],
908 phba->fcf.current_rec.switch_name[6],
909 phba->fcf.current_rec.switch_name[7],
910 phba->fcf.current_rec.fabric_name[0],
911 phba->fcf.current_rec.fabric_name[1],
912 phba->fcf.current_rec.fabric_name[2],
913 phba->fcf.current_rec.fabric_name[3],
914 phba->fcf.current_rec.fabric_name[4],
915 phba->fcf.current_rec.fabric_name[5],
916 phba->fcf.current_rec.fabric_name[6],
917 phba->fcf.current_rec.fabric_name[7]);
918 lpfc_nlp_put(ndlp);
919 spin_lock_irq(&phba->hbalock);
920 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400921 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smartdbb6b3a2010-06-08 18:31:37 -0400922 spin_unlock_irq(&phba->hbalock);
923 goto out;
924 }
James Smart0c9ab6f2010-02-26 14:15:57 -0500925 if (!rc) {
926 /* Mark the FCF discovery process done */
James Smart999d8132010-03-15 11:24:56 -0400927 if (phba->hba_flag & HBA_FIP_SUPPORT)
928 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
929 LOG_ELS,
James Smarta93ff372010-10-22 11:06:08 -0400930 "2769 FLOGI to FCF (x%x) "
931 "completed successfully\n",
James Smart999d8132010-03-15 11:24:56 -0400932 phba->fcf.current_rec.fcf_indx);
James Smart0c9ab6f2010-02-26 14:15:57 -0500933 spin_lock_irq(&phba->hbalock);
934 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -0400935 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
James Smart0c9ab6f2010-02-26 14:15:57 -0500936 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500937 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -0500938 }
dea31012005-04-17 16:05:31 -0500939 }
940
941flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400942 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500943
James Smart858c9f62007-06-17 19:56:39 -0500944 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500945 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500946 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500947
948 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500949 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400950 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
951 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
952 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
953 (phba->link_state != LPFC_CLEAR_LA)) {
954 /* If FLOGI failed enable link interrupt. */
955 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500956 }
dea31012005-04-17 16:05:31 -0500957out:
958 lpfc_els_free_iocb(phba, cmdiocb);
959}
960
James Smarte59058c2008-08-24 21:49:00 -0400961/**
James Smart3621a712009-04-06 18:47:14 -0400962 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400963 * @vport: pointer to a host virtual N_Port data structure.
964 * @ndlp: pointer to a node-list data structure.
965 * @retry: number of retries to the command IOCB.
966 *
967 * This routine issues a Fabric Login (FLOGI) Request ELS command
968 * for a @vport. The initiator service parameters are put into the payload
969 * of the FLOGI Request IOCB and the top-level callback function pointer
970 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
971 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
972 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
973 *
974 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
975 * will be incremented by 1 for holding the ndlp and the reference to ndlp
976 * will be stored into the context1 field of the IOCB for the completion
977 * callback function to the FLOGI ELS command.
978 *
979 * Return code
980 * 0 - successfully issued flogi iocb for @vport
981 * 1 - failed to issue flogi iocb for @vport
982 **/
dea31012005-04-17 16:05:31 -0500983static int
James Smart2e0fef82007-06-17 19:56:36 -0500984lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500985 uint8_t retry)
986{
James Smart2e0fef82007-06-17 19:56:36 -0500987 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500988 struct serv_parm *sp;
989 IOCB_t *icmd;
990 struct lpfc_iocbq *elsiocb;
991 struct lpfc_sli_ring *pring;
992 uint8_t *pcmd;
993 uint16_t cmdsize;
994 uint32_t tmo;
995 int rc;
996
997 pring = &phba->sli.ring[LPFC_ELS_RING];
998
James Smart92d7f7b2007-06-17 19:56:38 -0500999 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -05001000 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1001 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -05001002
James Smart488d1462006-03-07 15:02:37 -05001003 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001004 return 1;
dea31012005-04-17 16:05:31 -05001005
1006 icmd = &elsiocb->iocb;
1007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1008
1009 /* For FLOGI request, remainder of payload is service parameters */
1010 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001011 pcmd += sizeof(uint32_t);
1012 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001013 sp = (struct serv_parm *) pcmd;
1014
1015 /* Setup CSPs accordingly for Fabric */
1016 sp->cmn.e_d_tov = 0;
1017 sp->cmn.w2.r_a_tov = 0;
1018 sp->cls1.classValid = 0;
1019 sp->cls2.seqDelivery = 1;
1020 sp->cls3.seqDelivery = 1;
1021 if (sp->cmn.fcphLow < FC_PH3)
1022 sp->cmn.fcphLow = FC_PH3;
1023 if (sp->cmn.fcphHigh < FC_PH3)
1024 sp->cmn.fcphHigh = FC_PH3;
1025
James Smart6fb120a2009-05-22 14:52:59 -04001026 if (phba->sli_rev == LPFC_SLI_REV4) {
1027 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1028 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1029 /* FLOGI needs to be 3 for WQE FCFI */
1030 /* Set the fcfi to the fcfi we registered with */
1031 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1032 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05001033 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001034 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1035 icmd->ulpCt_h = 1;
1036 icmd->ulpCt_l = 0;
1037 }
1038
James Smart76a95d72010-11-20 23:11:48 -05001039 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
James Smart858c9f62007-06-17 19:56:39 -05001040 icmd->un.elsreq64.myID = 0;
1041 icmd->un.elsreq64.fl = 1;
1042 }
1043
dea31012005-04-17 16:05:31 -05001044 tmo = phba->fc_ratov;
1045 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001046 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001047 phba->fc_ratov = tmo;
1048
1049 phba->fc_stat.elsXmitFLOGI++;
1050 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -05001051
1052 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1053 "Issue FLOGI: opt:x%x",
1054 phba->sli3_options, 0, 0);
1055
James Smart92d7f7b2007-06-17 19:56:38 -05001056 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001057 if (rc == IOCB_ERROR) {
1058 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001059 return 1;
dea31012005-04-17 16:05:31 -05001060 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001061 return 0;
dea31012005-04-17 16:05:31 -05001062}
1063
James Smarte59058c2008-08-24 21:49:00 -04001064/**
James Smart3621a712009-04-06 18:47:14 -04001065 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -04001066 * @phba: pointer to lpfc hba data structure.
1067 *
1068 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1069 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1070 * list and issues an abort IOCB commond on each outstanding IOCB that
1071 * contains a active Fabric_DID ndlp. Note that this function is to issue
1072 * the abort IOCB command on all the outstanding IOCBs, thus when this
1073 * function returns, it does not guarantee all the IOCBs are actually aborted.
1074 *
1075 * Return code
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08001076 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
James Smarte59058c2008-08-24 21:49:00 -04001077 **/
dea31012005-04-17 16:05:31 -05001078int
James Smart2e0fef82007-06-17 19:56:36 -05001079lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05001080{
1081 struct lpfc_sli_ring *pring;
1082 struct lpfc_iocbq *iocb, *next_iocb;
1083 struct lpfc_nodelist *ndlp;
1084 IOCB_t *icmd;
1085
1086 /* Abort outstanding I/O on NPort <nlp_DID> */
1087 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -04001088 "0201 Abort outstanding I/O on NPort x%x\n",
1089 Fabric_DID);
dea31012005-04-17 16:05:31 -05001090
1091 pring = &phba->sli.ring[LPFC_ELS_RING];
1092
1093 /*
1094 * Check the txcmplq for an iocb that matches the nport the driver is
1095 * searching for.
1096 */
James Smart2e0fef82007-06-17 19:56:36 -05001097 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001098 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1099 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001100 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1101 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001102 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001103 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1104 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001105 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001106 }
1107 }
James Smart2e0fef82007-06-17 19:56:36 -05001108 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001109
1110 return 0;
1111}
1112
James Smarte59058c2008-08-24 21:49:00 -04001113/**
James Smart3621a712009-04-06 18:47:14 -04001114 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001115 * @vport: pointer to a host virtual N_Port data structure.
1116 *
1117 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1118 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1119 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1120 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1121 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1122 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1123 * @vport.
1124 *
1125 * Return code
1126 * 0 - failed to issue initial flogi for @vport
1127 * 1 - successfully issued initial flogi for @vport
1128 **/
dea31012005-04-17 16:05:31 -05001129int
James Smart2e0fef82007-06-17 19:56:36 -05001130lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001131{
James Smart2e0fef82007-06-17 19:56:36 -05001132 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001133 struct lpfc_nodelist *ndlp;
1134
James Smart98c9ea52007-10-27 13:37:33 -04001135 vport->port_state = LPFC_FLOGI;
1136 lpfc_set_disctmo(vport);
1137
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001138 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001139 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001140 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001141 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001142 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1143 if (!ndlp)
1144 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001145 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001146 /* Set the node type */
1147 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001148 /* Put ndlp onto node list */
1149 lpfc_enqueue_node(vport, ndlp);
1150 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1151 /* re-setup ndlp without removing from node list */
1152 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1153 if (!ndlp)
1154 return 0;
dea31012005-04-17 16:05:31 -05001155 }
James Smart87af33f2007-10-27 13:37:43 -04001156
James Smart5ac6b302010-10-22 11:05:36 -04001157 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001158 /* This decrement of reference count to node shall kick off
1159 * the release of the node.
1160 */
James Smart329f9bc2007-04-25 09:53:01 -04001161 lpfc_nlp_put(ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04001162 return 0;
1163 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001164 return 1;
dea31012005-04-17 16:05:31 -05001165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
James Smart3621a712009-04-06 18:47:14 -04001168 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001169 * @vport: pointer to a host virtual N_Port data structure.
1170 *
1171 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1172 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1173 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1174 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1175 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1176 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1177 * @vport.
1178 *
1179 * Return code
1180 * 0 - failed to issue initial fdisc for @vport
1181 * 1 - successfully issued initial fdisc for @vport
1182 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001183int
1184lpfc_initial_fdisc(struct lpfc_vport *vport)
1185{
1186 struct lpfc_hba *phba = vport->phba;
1187 struct lpfc_nodelist *ndlp;
1188
1189 /* First look for the Fabric ndlp */
1190 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1191 if (!ndlp) {
1192 /* Cannot find existing Fabric ndlp, so allocate a new one */
1193 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1194 if (!ndlp)
1195 return 0;
1196 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001197 /* Put ndlp onto node list */
1198 lpfc_enqueue_node(vport, ndlp);
1199 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1200 /* re-setup ndlp without removing from node list */
1201 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1202 if (!ndlp)
1203 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001204 }
James Smarte47c9092008-02-08 18:49:26 -05001205
James Smart92d7f7b2007-06-17 19:56:38 -05001206 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001207 /* decrement node reference count to trigger the release of
1208 * the node.
1209 */
James Smart92d7f7b2007-06-17 19:56:38 -05001210 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001211 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001212 }
1213 return 1;
1214}
James Smart87af33f2007-10-27 13:37:43 -04001215
James Smarte59058c2008-08-24 21:49:00 -04001216/**
James Smart3621a712009-04-06 18:47:14 -04001217 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001218 * @vport: pointer to a host virtual N_Port data structure.
1219 *
1220 * This routine checks whether there are more remaining Port Logins
1221 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1222 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1223 * to issue ELS PLOGIs up to the configured discover threads with the
1224 * @vport (@vport->cfg_discovery_threads). The function also decrement
1225 * the @vport's num_disc_node by 1 if it is not already 0.
1226 **/
James Smart87af33f2007-10-27 13:37:43 -04001227void
James Smart2e0fef82007-06-17 19:56:36 -05001228lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001229{
1230 int sentplogi;
1231
James Smart2e0fef82007-06-17 19:56:36 -05001232 if (vport->num_disc_nodes)
1233 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001234
1235 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "0232 Continue discovery with %d PLOGIs to go "
1238 "Data: x%x x%x x%x\n",
1239 vport->num_disc_nodes, vport->fc_plogi_cnt,
1240 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001241 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001242 if (vport->fc_flag & FC_NLP_MORE)
1243 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1244 sentplogi = lpfc_els_disc_plogi(vport);
1245
dea31012005-04-17 16:05:31 -05001246 return;
1247}
1248
James Smarte59058c2008-08-24 21:49:00 -04001249/**
James Smart3621a712009-04-06 18:47:14 -04001250 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001251 * @phba: pointer to lpfc hba data structure.
1252 * @prsp: pointer to response IOCB payload.
1253 * @ndlp: pointer to a node-list data structure.
1254 *
1255 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1256 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1257 * The following cases are considered N_Port confirmed:
1258 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1259 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1260 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1261 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1262 * 1) if there is a node on vport list other than the @ndlp with the same
1263 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1264 * on that node to release the RPI associated with the node; 2) if there is
1265 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1266 * into, a new node shall be allocated (or activated). In either case, the
1267 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1268 * be released and the new_ndlp shall be put on to the vport node list and
1269 * its pointer returned as the confirmed node.
1270 *
1271 * Note that before the @ndlp got "released", the keepDID from not-matching
1272 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1273 * of the @ndlp. This is because the release of @ndlp is actually to put it
1274 * into an inactive state on the vport node list and the vport node list
1275 * management algorithm does not allow two node with a same DID.
1276 *
1277 * Return code
1278 * pointer to the PLOGI N_Port @ndlp
1279 **/
James Smart488d1462006-03-07 15:02:37 -05001280static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001281lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001282 struct lpfc_nodelist *ndlp)
1283{
James Smart2e0fef82007-06-17 19:56:36 -05001284 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001285 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001286 struct lpfc_rport_data *rdata;
1287 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001288 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001289 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001290 uint32_t rc, keepDID = 0;
James Smart38b92ef2010-08-04 16:11:39 -04001291 int put_node;
1292 int put_rport;
James Smart19ca7602010-11-20 23:11:55 -05001293 struct lpfc_node_rrqs rrq;
James Smart488d1462006-03-07 15:02:37 -05001294
James Smart2fb9bd82006-12-02 13:33:57 -05001295 /* Fabric nodes can have the same WWPN so we don't bother searching
1296 * by WWPN. Just return the ndlp that was given to us.
1297 */
1298 if (ndlp->nlp_type & NLP_FABRIC)
1299 return ndlp;
1300
James Smart92d7f7b2007-06-17 19:56:38 -05001301 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001302 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001303
James Smart685f0bf2007-04-25 09:53:08 -04001304 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001305 * we have for that ndlp. If not, we have some work to do.
1306 */
James Smart2e0fef82007-06-17 19:56:36 -05001307 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001308
James Smarte47c9092008-02-08 18:49:26 -05001309 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001310 return ndlp;
James Smart19ca7602010-11-20 23:11:55 -05001311 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
James Smart488d1462006-03-07 15:02:37 -05001312
1313 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001314 rc = memcmp(&ndlp->nlp_portname, name,
1315 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001316 if (!rc)
1317 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001318 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1319 if (!new_ndlp)
1320 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001321 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001322 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001323 rc = memcmp(&ndlp->nlp_portname, name,
1324 sizeof(struct lpfc_name));
1325 if (!rc)
1326 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001327 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1328 NLP_STE_UNUSED_NODE);
1329 if (!new_ndlp)
1330 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001331 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001332 if (phba->sli_rev == LPFC_SLI_REV4)
1333 memcpy(&rrq.xri_bitmap,
1334 &new_ndlp->active_rrqs.xri_bitmap,
1335 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1336 } else {
James Smart58da1ff2008-04-07 10:15:56 -04001337 keepDID = new_ndlp->nlp_DID;
James Smart19ca7602010-11-20 23:11:55 -05001338 if (phba->sli_rev == LPFC_SLI_REV4)
1339 memcpy(&rrq.xri_bitmap,
1340 &new_ndlp->active_rrqs.xri_bitmap,
1341 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1342 }
James Smart488d1462006-03-07 15:02:37 -05001343
James Smart2e0fef82007-06-17 19:56:36 -05001344 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001345 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001346 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart19ca7602010-11-20 23:11:55 -05001347 if (phba->sli_rev == LPFC_SLI_REV4)
1348 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1349 &ndlp->active_rrqs.xri_bitmap,
1350 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart0ff10d42008-01-11 01:52:36 -05001351
1352 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1353 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1354 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1355
James Smarte47c9092008-02-08 18:49:26 -05001356 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001357 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001358
James Smart2e0fef82007-06-17 19:56:36 -05001359 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001360 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1361 /* The new_ndlp is replacing ndlp totally, so we need
1362 * to put ndlp on UNUSED list and try to free it.
1363 */
James Smart0ff10d42008-01-11 01:52:36 -05001364
1365 /* Fix up the rport accordingly */
1366 rport = ndlp->rport;
1367 if (rport) {
1368 rdata = rport->dd_data;
1369 if (rdata->pnode == ndlp) {
1370 lpfc_nlp_put(ndlp);
1371 ndlp->rport = NULL;
1372 rdata->pnode = lpfc_nlp_get(new_ndlp);
1373 new_ndlp->rport = rport;
1374 }
1375 new_ndlp->nlp_type = ndlp->nlp_type;
1376 }
James Smart58da1ff2008-04-07 10:15:56 -04001377 /* We shall actually free the ndlp with both nlp_DID and
1378 * nlp_portname fields equals 0 to avoid any ndlp on the
1379 * nodelist never to be used.
1380 */
1381 if (ndlp->nlp_DID == 0) {
1382 spin_lock_irq(&phba->ndlp_lock);
1383 NLP_SET_FREE_REQ(ndlp);
1384 spin_unlock_irq(&phba->ndlp_lock);
1385 }
James Smart0ff10d42008-01-11 01:52:36 -05001386
James Smart58da1ff2008-04-07 10:15:56 -04001387 /* Two ndlps cannot have the same did on the nodelist */
1388 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001389 if (phba->sli_rev == LPFC_SLI_REV4)
1390 memcpy(&ndlp->active_rrqs.xri_bitmap,
1391 &rrq.xri_bitmap,
1392 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001393 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001394 }
James Smart92795652006-07-06 15:50:02 -04001395 else {
James Smart2e0fef82007-06-17 19:56:36 -05001396 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001397 /* Two ndlps cannot have the same did */
1398 ndlp->nlp_DID = keepDID;
James Smart19ca7602010-11-20 23:11:55 -05001399 if (phba->sli_rev == LPFC_SLI_REV4)
1400 memcpy(&ndlp->active_rrqs.xri_bitmap,
1401 &rrq.xri_bitmap,
1402 sizeof(ndlp->active_rrqs.xri_bitmap));
James Smart2e0fef82007-06-17 19:56:36 -05001403 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart38b92ef2010-08-04 16:11:39 -04001404 /* Since we are swapping the ndlp passed in with the new one
1405 * and the did has already been swapped, copy over the
1406 * state and names.
1407 */
1408 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1409 sizeof(struct lpfc_name));
1410 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1411 sizeof(struct lpfc_name));
1412 new_ndlp->nlp_state = ndlp->nlp_state;
1413 /* Fix up the rport accordingly */
1414 rport = ndlp->rport;
1415 if (rport) {
1416 rdata = rport->dd_data;
1417 put_node = rdata->pnode != NULL;
1418 put_rport = ndlp->rport != NULL;
1419 rdata->pnode = NULL;
1420 ndlp->rport = NULL;
1421 if (put_node)
1422 lpfc_nlp_put(ndlp);
1423 if (put_rport)
1424 put_device(&rport->dev);
1425 }
James Smart92795652006-07-06 15:50:02 -04001426 }
James Smart488d1462006-03-07 15:02:37 -05001427 return new_ndlp;
1428}
1429
James Smarte59058c2008-08-24 21:49:00 -04001430/**
James Smart3621a712009-04-06 18:47:14 -04001431 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001432 * @vport: pointer to a host virtual N_Port data structure.
1433 *
1434 * This routine checks whether more Registration State Change
1435 * Notifications (RSCNs) came in while the discovery state machine was in
1436 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1437 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1438 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1439 * handling the RSCNs.
1440 **/
James Smart87af33f2007-10-27 13:37:43 -04001441void
1442lpfc_end_rscn(struct lpfc_vport *vport)
1443{
1444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1445
1446 if (vport->fc_flag & FC_RSCN_MODE) {
1447 /*
1448 * Check to see if more RSCNs came in while we were
1449 * processing this one.
1450 */
1451 if (vport->fc_rscn_id_cnt ||
1452 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1453 lpfc_els_handle_rscn(vport);
1454 else {
1455 spin_lock_irq(shost->host_lock);
1456 vport->fc_flag &= ~FC_RSCN_MODE;
1457 spin_unlock_irq(shost->host_lock);
1458 }
1459 }
1460}
1461
James Smarte59058c2008-08-24 21:49:00 -04001462/**
James Smart19ca7602010-11-20 23:11:55 -05001463 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1464 * @phba: pointer to lpfc hba data structure.
1465 * @cmdiocb: pointer to lpfc command iocb data structure.
1466 * @rspiocb: pointer to lpfc response iocb data structure.
1467 *
1468 * This routine will call the clear rrq function to free the rrq and
1469 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1470 * exist then the clear_rrq is still called because the rrq needs to
1471 * be freed.
1472 **/
1473
1474static void
1475lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1476 struct lpfc_iocbq *rspiocb)
1477{
1478 struct lpfc_vport *vport = cmdiocb->vport;
1479 IOCB_t *irsp;
1480 struct lpfc_nodelist *ndlp;
1481 struct lpfc_node_rrq *rrq;
1482
1483 /* we pass cmdiocb to state machine which needs rspiocb as well */
1484 rrq = cmdiocb->context_un.rrq;
1485 cmdiocb->context_un.rsp_iocb = rspiocb;
1486
1487 irsp = &rspiocb->iocb;
1488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1489 "RRQ cmpl: status:x%x/x%x did:x%x",
1490 irsp->ulpStatus, irsp->un.ulpWord[4],
1491 irsp->un.elsreq64.remoteID);
1492
1493 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1494 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1495 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1496 "2882 RRQ completes to NPort x%x "
1497 "with no ndlp. Data: x%x x%x x%x\n",
1498 irsp->un.elsreq64.remoteID,
1499 irsp->ulpStatus, irsp->un.ulpWord[4],
1500 irsp->ulpIoTag);
1501 goto out;
1502 }
1503
1504 /* rrq completes to NPort <nlp_DID> */
1505 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1506 "2880 RRQ completes to NPort x%x "
1507 "Data: x%x x%x x%x x%x x%x\n",
1508 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1509 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1510
1511 if (irsp->ulpStatus) {
1512 /* Check for retry */
1513 /* RRQ failed Don't print the vport to vport rjts */
1514 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1515 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1516 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1517 (phba)->pport->cfg_log_verbose & LOG_ELS)
1518 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1519 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1520 ndlp->nlp_DID, irsp->ulpStatus,
1521 irsp->un.ulpWord[4]);
1522 }
1523out:
1524 if (rrq)
1525 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1526 lpfc_els_free_iocb(phba, cmdiocb);
1527 return;
1528}
1529/**
James Smart3621a712009-04-06 18:47:14 -04001530 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001531 * @phba: pointer to lpfc hba data structure.
1532 * @cmdiocb: pointer to lpfc command iocb data structure.
1533 * @rspiocb: pointer to lpfc response iocb data structure.
1534 *
1535 * This routine is the completion callback function for issuing the Port
1536 * Login (PLOGI) command. For PLOGI completion, there must be an active
1537 * ndlp on the vport node list that matches the remote node ID from the
1538 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1539 * ignored and command IOCB released. The PLOGI response IOCB status is
1540 * checked for error conditons. If there is error status reported, PLOGI
1541 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1542 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1543 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1544 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1545 * there are additional N_Port nodes with the vport that need to perform
1546 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1547 * PLOGIs.
1548 **/
dea31012005-04-17 16:05:31 -05001549static void
James Smart2e0fef82007-06-17 19:56:36 -05001550lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1551 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001552{
James Smart2e0fef82007-06-17 19:56:36 -05001553 struct lpfc_vport *vport = cmdiocb->vport;
1554 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001555 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001556 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001557 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001558 int disc, rc, did, type;
1559
dea31012005-04-17 16:05:31 -05001560 /* we pass cmdiocb to state machine which needs rspiocb as well */
1561 cmdiocb->context_un.rsp_iocb = rspiocb;
1562
1563 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1565 "PLOGI cmpl: status:x%x/x%x did:x%x",
1566 irsp->ulpStatus, irsp->un.ulpWord[4],
1567 irsp->un.elsreq64.remoteID);
1568
James Smart2e0fef82007-06-17 19:56:36 -05001569 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001570 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001571 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1572 "0136 PLOGI completes to NPort x%x "
1573 "with no ndlp. Data: x%x x%x x%x\n",
1574 irsp->un.elsreq64.remoteID,
1575 irsp->ulpStatus, irsp->un.ulpWord[4],
1576 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001577 goto out;
James Smarted957682007-06-17 19:56:37 -05001578 }
dea31012005-04-17 16:05:31 -05001579
1580 /* Since ndlp can be freed in the disc state machine, note if this node
1581 * is being used during discovery.
1582 */
James Smart2e0fef82007-06-17 19:56:36 -05001583 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001584 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001585 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001586 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001587 rc = 0;
1588
1589 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001590 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1591 "0102 PLOGI completes to NPort x%x "
1592 "Data: x%x x%x x%x x%x x%x\n",
1593 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1594 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001595 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001596 if (lpfc_els_chk_latt(vport)) {
1597 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001598 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001599 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001600 goto out;
1601 }
1602
1603 /* ndlp could be freed in DSM, save these values now */
1604 type = ndlp->nlp_type;
1605 did = ndlp->nlp_DID;
1606
1607 if (irsp->ulpStatus) {
1608 /* Check for retry */
1609 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1610 /* ELS command is being retried */
1611 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001612 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001613 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001614 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001615 }
1616 goto out;
1617 }
James Smart2a9bf3d2010-06-07 15:24:45 -04001618 /* PLOGI failed Don't print the vport to vport rjts */
1619 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1620 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1621 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1622 (phba)->pport->cfg_log_verbose & LOG_ELS)
1623 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smarte40a02c2010-02-26 14:13:54 -05001624 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1625 ndlp->nlp_DID, irsp->ulpStatus,
1626 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001627 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001628 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001629 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001630 else
James Smart2e0fef82007-06-17 19:56:36 -05001631 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001632 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001633 } else {
1634 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001635 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001636 cmdiocb->context2)->list.next,
1637 struct lpfc_dmabuf, list);
1638 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001639 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001640 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001641 }
1642
James Smart2e0fef82007-06-17 19:56:36 -05001643 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001644 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001645 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001646
James Smart2e0fef82007-06-17 19:56:36 -05001647 if (vport->num_disc_nodes == 0) {
1648 spin_lock_irq(shost->host_lock);
1649 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1650 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001651
James Smart2e0fef82007-06-17 19:56:36 -05001652 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001653 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001654 }
1655 }
1656
1657out:
1658 lpfc_els_free_iocb(phba, cmdiocb);
1659 return;
1660}
1661
James Smarte59058c2008-08-24 21:49:00 -04001662/**
James Smart3621a712009-04-06 18:47:14 -04001663 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001664 * @vport: pointer to a host virtual N_Port data structure.
1665 * @did: destination port identifier.
1666 * @retry: number of retries to the command IOCB.
1667 *
1668 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1669 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1670 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1671 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1672 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1673 *
1674 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1675 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1676 * will be stored into the context1 field of the IOCB for the completion
1677 * callback function to the PLOGI ELS command.
1678 *
1679 * Return code
1680 * 0 - Successfully issued a plogi for @vport
1681 * 1 - failed to issue a plogi for @vport
1682 **/
dea31012005-04-17 16:05:31 -05001683int
James Smart2e0fef82007-06-17 19:56:36 -05001684lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001685{
James Smart2e0fef82007-06-17 19:56:36 -05001686 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001687 struct serv_parm *sp;
1688 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001689 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001690 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001691 struct lpfc_sli *psli;
1692 uint8_t *pcmd;
1693 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001694 int ret;
dea31012005-04-17 16:05:31 -05001695
1696 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001697
James Smart98c9ea52007-10-27 13:37:33 -04001698 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001699 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1700 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001701
James Smarte47c9092008-02-08 18:49:26 -05001702 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001703 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001704 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001705 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001706 if (!elsiocb)
1707 return 1;
dea31012005-04-17 16:05:31 -05001708
1709 icmd = &elsiocb->iocb;
1710 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1711
1712 /* For PLOGI request, remainder of payload is service parameters */
1713 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001714 pcmd += sizeof(uint32_t);
1715 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001716 sp = (struct serv_parm *) pcmd;
1717
James Smart5ac6b302010-10-22 11:05:36 -04001718 /*
1719 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1720 * to device on remote loops work.
1721 */
1722 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1723 sp->cmn.altBbCredit = 1;
1724
dea31012005-04-17 16:05:31 -05001725 if (sp->cmn.fcphLow < FC_PH_4_3)
1726 sp->cmn.fcphLow = FC_PH_4_3;
1727
1728 if (sp->cmn.fcphHigh < FC_PH3)
1729 sp->cmn.fcphHigh = FC_PH3;
1730
James Smart858c9f62007-06-17 19:56:39 -05001731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1732 "Issue PLOGI: did:x%x",
1733 did, 0, 0);
1734
dea31012005-04-17 16:05:31 -05001735 phba->fc_stat.elsXmitPLOGI++;
1736 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001737 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001738
1739 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001740 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001741 return 1;
dea31012005-04-17 16:05:31 -05001742 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001743 return 0;
dea31012005-04-17 16:05:31 -05001744}
1745
James Smarte59058c2008-08-24 21:49:00 -04001746/**
James Smart3621a712009-04-06 18:47:14 -04001747 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001748 * @phba: pointer to lpfc hba data structure.
1749 * @cmdiocb: pointer to lpfc command iocb data structure.
1750 * @rspiocb: pointer to lpfc response iocb data structure.
1751 *
1752 * This routine is the completion callback function for a Process Login
1753 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1754 * status. If there is error status reported, PRLI retry shall be attempted
1755 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1756 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1757 * ndlp to mark the PRLI completion.
1758 **/
dea31012005-04-17 16:05:31 -05001759static void
James Smart2e0fef82007-06-17 19:56:36 -05001760lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1761 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001762{
James Smart2e0fef82007-06-17 19:56:36 -05001763 struct lpfc_vport *vport = cmdiocb->vport;
1764 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001765 IOCB_t *irsp;
1766 struct lpfc_sli *psli;
1767 struct lpfc_nodelist *ndlp;
1768
1769 psli = &phba->sli;
1770 /* we pass cmdiocb to state machine which needs rspiocb as well */
1771 cmdiocb->context_un.rsp_iocb = rspiocb;
1772
1773 irsp = &(rspiocb->iocb);
1774 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001775 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001776 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001777 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001778
James Smart858c9f62007-06-17 19:56:39 -05001779 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1780 "PRLI cmpl: status:x%x/x%x did:x%x",
1781 irsp->ulpStatus, irsp->un.ulpWord[4],
1782 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001783 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1785 "0103 PRLI completes to NPort x%x "
1786 "Data: x%x x%x x%x x%x\n",
1787 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1788 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001789
James Smart2e0fef82007-06-17 19:56:36 -05001790 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001791 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001792 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001793 goto out;
1794
1795 if (irsp->ulpStatus) {
1796 /* Check for retry */
1797 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1798 /* ELS command is being retried */
1799 goto out;
1800 }
1801 /* PRLI failed */
James Smarte40a02c2010-02-26 14:13:54 -05001802 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1803 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1804 ndlp->nlp_DID, irsp->ulpStatus,
1805 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05001806 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001807 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001808 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001809 else
James Smart2e0fef82007-06-17 19:56:36 -05001810 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001811 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001812 } else
dea31012005-04-17 16:05:31 -05001813 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001814 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001815 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001816out:
1817 lpfc_els_free_iocb(phba, cmdiocb);
1818 return;
1819}
1820
James Smarte59058c2008-08-24 21:49:00 -04001821/**
James Smart3621a712009-04-06 18:47:14 -04001822 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001823 * @vport: pointer to a host virtual N_Port data structure.
1824 * @ndlp: pointer to a node-list data structure.
1825 * @retry: number of retries to the command IOCB.
1826 *
1827 * This routine issues a Process Login (PRLI) ELS command for the
1828 * @vport. The PRLI service parameters are set up in the payload of the
1829 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1830 * is put to the IOCB completion callback func field before invoking the
1831 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1832 *
1833 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1834 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1835 * will be stored into the context1 field of the IOCB for the completion
1836 * callback function to the PRLI ELS command.
1837 *
1838 * Return code
1839 * 0 - successfully issued prli iocb command for @vport
1840 * 1 - failed to issue prli iocb command for @vport
1841 **/
dea31012005-04-17 16:05:31 -05001842int
James Smart2e0fef82007-06-17 19:56:36 -05001843lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001844 uint8_t retry)
1845{
James Smart2e0fef82007-06-17 19:56:36 -05001846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1847 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001848 PRLI *npr;
1849 IOCB_t *icmd;
1850 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001851 uint8_t *pcmd;
1852 uint16_t cmdsize;
1853
James Smart92d7f7b2007-06-17 19:56:38 -05001854 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001855 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1856 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001857 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001858 return 1;
dea31012005-04-17 16:05:31 -05001859
1860 icmd = &elsiocb->iocb;
1861 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1862
1863 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001864 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001865 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001866 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001867
1868 /* For PRLI, remainder of payload is PRLI parameter page */
1869 npr = (PRLI *) pcmd;
1870 /*
1871 * If our firmware version is 3.20 or later,
1872 * set the following bits for FC-TAPE support.
1873 */
1874 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1875 npr->ConfmComplAllowed = 1;
1876 npr->Retry = 1;
1877 npr->TaskRetryIdReq = 1;
1878 }
1879 npr->estabImagePair = 1;
1880 npr->readXferRdyDis = 1;
1881
1882 /* For FCP support */
1883 npr->prliType = PRLI_FCP_TYPE;
1884 npr->initiatorFunc = 1;
1885
James Smart858c9f62007-06-17 19:56:39 -05001886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1887 "Issue PRLI: did:x%x",
1888 ndlp->nlp_DID, 0, 0);
1889
dea31012005-04-17 16:05:31 -05001890 phba->fc_stat.elsXmitPRLI++;
1891 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001892 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001893 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001894 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001895 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1896 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001897 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001898 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001899 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001900 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001901 return 1;
dea31012005-04-17 16:05:31 -05001902 }
James Smart2e0fef82007-06-17 19:56:36 -05001903 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001904 return 0;
dea31012005-04-17 16:05:31 -05001905}
1906
James Smarte59058c2008-08-24 21:49:00 -04001907/**
James Smart3621a712009-04-06 18:47:14 -04001908 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001909 * @vport: pointer to a host virtual N_Port data structure.
1910 *
1911 * This routine performs Registration State Change Notification (RSCN)
1912 * discovery for a @vport. If the @vport's node port recovery count is not
1913 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1914 * the nodes that need recovery. If none of the PLOGI were needed through
1915 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1916 * invoked to check and handle possible more RSCN came in during the period
1917 * of processing the current ones.
1918 **/
1919static void
1920lpfc_rscn_disc(struct lpfc_vport *vport)
1921{
1922 lpfc_can_disctmo(vport);
1923
1924 /* RSCN discovery */
1925 /* go thru NPR nodes and issue ELS PLOGIs */
1926 if (vport->fc_npr_cnt)
1927 if (lpfc_els_disc_plogi(vport))
1928 return;
1929
1930 lpfc_end_rscn(vport);
1931}
1932
1933/**
James Smart3621a712009-04-06 18:47:14 -04001934 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001935 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1936 *
1937 * This function is called when the final ADISC is completed during discovery.
1938 * This function handles clearing link attention or issuing reg_vpi depending
1939 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1940 * discovery.
1941 * This function is called with no locks held.
1942 **/
1943static void
1944lpfc_adisc_done(struct lpfc_vport *vport)
1945{
1946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1947 struct lpfc_hba *phba = vport->phba;
1948
1949 /*
1950 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1951 * and continue discovery.
1952 */
1953 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001954 !(vport->fc_flag & FC_RSCN_MODE) &&
1955 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001956 lpfc_issue_reg_vpi(phba, vport);
1957 return;
1958 }
1959 /*
1960 * For SLI2, we need to set port_state to READY
1961 * and continue discovery.
1962 */
1963 if (vport->port_state < LPFC_VPORT_READY) {
1964 /* If we get here, there is nothing to ADISC */
1965 if (vport->port_type == LPFC_PHYSICAL_PORT)
1966 lpfc_issue_clear_la(phba, vport);
1967 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1968 vport->num_disc_nodes = 0;
1969 /* go thru NPR list, issue ELS PLOGIs */
1970 if (vport->fc_npr_cnt)
1971 lpfc_els_disc_plogi(vport);
1972 if (!vport->num_disc_nodes) {
1973 spin_lock_irq(shost->host_lock);
1974 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1975 spin_unlock_irq(shost->host_lock);
1976 lpfc_can_disctmo(vport);
1977 lpfc_end_rscn(vport);
1978 }
1979 }
1980 vport->port_state = LPFC_VPORT_READY;
1981 } else
1982 lpfc_rscn_disc(vport);
1983}
1984
1985/**
James Smart3621a712009-04-06 18:47:14 -04001986 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001987 * @vport: pointer to a host virtual N_Port data structure.
1988 *
1989 * This routine determines whether there are more ndlps on a @vport
1990 * node list need to have Address Discover (ADISC) issued. If so, it will
1991 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1992 * remaining nodes which need to have ADISC sent.
1993 **/
James Smart0ff10d42008-01-11 01:52:36 -05001994void
James Smart2e0fef82007-06-17 19:56:36 -05001995lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001996{
1997 int sentadisc;
1998
James Smart2e0fef82007-06-17 19:56:36 -05001999 if (vport->num_disc_nodes)
2000 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05002001 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04002002 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2003 "0210 Continue discovery with %d ADISCs to go "
2004 "Data: x%x x%x x%x\n",
2005 vport->num_disc_nodes, vport->fc_adisc_cnt,
2006 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05002007 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05002008 if (vport->fc_flag & FC_NLP_MORE) {
2009 lpfc_set_disctmo(vport);
2010 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2011 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002012 }
James Smart90160e02008-08-24 21:49:45 -04002013 if (!vport->num_disc_nodes)
2014 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05002015 return;
2016}
2017
James Smarte59058c2008-08-24 21:49:00 -04002018/**
James Smart3621a712009-04-06 18:47:14 -04002019 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04002020 * @phba: pointer to lpfc hba data structure.
2021 * @cmdiocb: pointer to lpfc command iocb data structure.
2022 * @rspiocb: pointer to lpfc response iocb data structure.
2023 *
2024 * This routine is the completion function for issuing the Address Discover
2025 * (ADISC) command. It first checks to see whether link went down during
2026 * the discovery process. If so, the node will be marked as node port
2027 * recovery for issuing discover IOCB by the link attention handler and
2028 * exit. Otherwise, the response status is checked. If error was reported
2029 * in the response status, the ADISC command shall be retried by invoking
2030 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2031 * the response status, the state machine is invoked to set transition
2032 * with respect to NLP_EVT_CMPL_ADISC event.
2033 **/
dea31012005-04-17 16:05:31 -05002034static void
James Smart2e0fef82007-06-17 19:56:36 -05002035lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2036 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002037{
James Smart2e0fef82007-06-17 19:56:36 -05002038 struct lpfc_vport *vport = cmdiocb->vport;
2039 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002040 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002041 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002042 int disc;
dea31012005-04-17 16:05:31 -05002043
2044 /* we pass cmdiocb to state machine which needs rspiocb as well */
2045 cmdiocb->context_un.rsp_iocb = rspiocb;
2046
2047 irsp = &(rspiocb->iocb);
2048 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05002049
James Smart858c9f62007-06-17 19:56:39 -05002050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2051 "ADISC cmpl: status:x%x/x%x did:x%x",
2052 irsp->ulpStatus, irsp->un.ulpWord[4],
2053 ndlp->nlp_DID);
2054
dea31012005-04-17 16:05:31 -05002055 /* Since ndlp can be freed in the disc state machine, note if this node
2056 * is being used during discovery.
2057 */
James Smart2e0fef82007-06-17 19:56:36 -05002058 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002059 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002060 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05002061 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002062 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2064 "0104 ADISC completes to NPort x%x "
2065 "Data: x%x x%x x%x x%x x%x\n",
2066 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2067 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002068 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002069 if (lpfc_els_chk_latt(vport)) {
2070 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002071 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002072 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002073 goto out;
2074 }
2075
2076 if (irsp->ulpStatus) {
2077 /* Check for retry */
2078 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2079 /* ELS command is being retried */
2080 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05002081 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002082 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002083 spin_unlock_irq(shost->host_lock);
2084 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002085 }
2086 goto out;
2087 }
2088 /* ADISC failed */
James Smarte40a02c2010-02-26 14:13:54 -05002089 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2090 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2091 ndlp->nlp_DID, irsp->ulpStatus,
2092 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002093 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05002094 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05002095 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05002096 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05002097 } else
dea31012005-04-17 16:05:31 -05002098 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05002099 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05002100 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05002101
James Smart90160e02008-08-24 21:49:45 -04002102 /* Check to see if there are more ADISCs to be sent */
2103 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05002104 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05002105out:
2106 lpfc_els_free_iocb(phba, cmdiocb);
2107 return;
2108}
2109
James Smarte59058c2008-08-24 21:49:00 -04002110/**
James Smart3621a712009-04-06 18:47:14 -04002111 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002112 * @vport: pointer to a virtual N_Port data structure.
2113 * @ndlp: pointer to a node-list data structure.
2114 * @retry: number of retries to the command IOCB.
2115 *
2116 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2117 * @vport. It prepares the payload of the ADISC ELS command, updates the
2118 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2119 * to issue the ADISC ELS command.
2120 *
2121 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2122 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2123 * will be stored into the context1 field of the IOCB for the completion
2124 * callback function to the ADISC ELS command.
2125 *
2126 * Return code
2127 * 0 - successfully issued adisc
2128 * 1 - failed to issue adisc
2129 **/
dea31012005-04-17 16:05:31 -05002130int
James Smart2e0fef82007-06-17 19:56:36 -05002131lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002132 uint8_t retry)
2133{
James Smart2e0fef82007-06-17 19:56:36 -05002134 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2135 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002136 ADISC *ap;
2137 IOCB_t *icmd;
2138 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002139 uint8_t *pcmd;
2140 uint16_t cmdsize;
2141
James Smart92d7f7b2007-06-17 19:56:38 -05002142 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05002143 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2144 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05002145 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002146 return 1;
dea31012005-04-17 16:05:31 -05002147
2148 icmd = &elsiocb->iocb;
2149 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2150
2151 /* For ADISC request, remainder of payload is service parameters */
2152 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05002153 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002154
2155 /* Fill in ADISC payload */
2156 ap = (ADISC *) pcmd;
2157 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002158 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2159 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002160 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002161
James Smart858c9f62007-06-17 19:56:39 -05002162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2163 "Issue ADISC: did:x%x",
2164 ndlp->nlp_DID, 0, 0);
2165
dea31012005-04-17 16:05:31 -05002166 phba->fc_stat.elsXmitADISC++;
2167 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05002168 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002169 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002170 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002171 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2172 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002173 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002174 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002175 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002176 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002177 return 1;
dea31012005-04-17 16:05:31 -05002178 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002179 return 0;
dea31012005-04-17 16:05:31 -05002180}
2181
James Smarte59058c2008-08-24 21:49:00 -04002182/**
James Smart3621a712009-04-06 18:47:14 -04002183 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04002184 * @phba: pointer to lpfc hba data structure.
2185 * @cmdiocb: pointer to lpfc command iocb data structure.
2186 * @rspiocb: pointer to lpfc response iocb data structure.
2187 *
2188 * This routine is the completion function for issuing the ELS Logout (LOGO)
2189 * command. If no error status was reported from the LOGO response, the
2190 * state machine of the associated ndlp shall be invoked for transition with
2191 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2192 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2193 **/
dea31012005-04-17 16:05:31 -05002194static void
James Smart2e0fef82007-06-17 19:56:36 -05002195lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2196 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002197{
James Smart2e0fef82007-06-17 19:56:36 -05002198 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2199 struct lpfc_vport *vport = ndlp->vport;
2200 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002201 IOCB_t *irsp;
2202 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05002203
2204 psli = &phba->sli;
2205 /* we pass cmdiocb to state machine which needs rspiocb as well */
2206 cmdiocb->context_un.rsp_iocb = rspiocb;
2207
2208 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002209 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002210 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002211 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002212
James Smart858c9f62007-06-17 19:56:39 -05002213 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2214 "LOGO cmpl: status:x%x/x%x did:x%x",
2215 irsp->ulpStatus, irsp->un.ulpWord[4],
2216 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002217 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002218 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2219 "0105 LOGO completes to NPort x%x "
2220 "Data: x%x x%x x%x x%x\n",
2221 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2222 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05002223 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002224 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05002225 goto out;
2226
James Smart92d7f7b2007-06-17 19:56:38 -05002227 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2228 /* NLP_EVT_DEVICE_RM should unregister the RPI
2229 * which should abort all outstanding IOs.
2230 */
2231 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2232 NLP_EVT_DEVICE_RM);
2233 goto out;
2234 }
2235
dea31012005-04-17 16:05:31 -05002236 if (irsp->ulpStatus) {
2237 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002238 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002239 /* ELS command is being retried */
2240 goto out;
dea31012005-04-17 16:05:31 -05002241 /* LOGO failed */
James Smarte40a02c2010-02-26 14:13:54 -05002242 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2243 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2244 ndlp->nlp_DID, irsp->ulpStatus,
2245 irsp->un.ulpWord[4]);
dea31012005-04-17 16:05:31 -05002246 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002247 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002248 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002249 else
James Smart2e0fef82007-06-17 19:56:36 -05002250 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002251 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002252 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002253 /* Good status, call state machine.
2254 * This will unregister the rpi if needed.
2255 */
James Smart2e0fef82007-06-17 19:56:36 -05002256 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002257 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002258out:
2259 lpfc_els_free_iocb(phba, cmdiocb);
2260 return;
2261}
2262
James Smarte59058c2008-08-24 21:49:00 -04002263/**
James Smart3621a712009-04-06 18:47:14 -04002264 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002265 * @vport: pointer to a virtual N_Port data structure.
2266 * @ndlp: pointer to a node-list data structure.
2267 * @retry: number of retries to the command IOCB.
2268 *
2269 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2270 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2271 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2272 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2273 *
2274 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2275 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2276 * will be stored into the context1 field of the IOCB for the completion
2277 * callback function to the LOGO ELS command.
2278 *
2279 * Return code
2280 * 0 - successfully issued logo
2281 * 1 - failed to issue logo
2282 **/
dea31012005-04-17 16:05:31 -05002283int
James Smart2e0fef82007-06-17 19:56:36 -05002284lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002285 uint8_t retry)
2286{
James Smart2e0fef82007-06-17 19:56:36 -05002287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2288 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002289 IOCB_t *icmd;
2290 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002291 uint8_t *pcmd;
2292 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002293 int rc;
dea31012005-04-17 16:05:31 -05002294
James Smart98c9ea52007-10-27 13:37:33 -04002295 spin_lock_irq(shost->host_lock);
2296 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2297 spin_unlock_irq(shost->host_lock);
2298 return 0;
2299 }
2300 spin_unlock_irq(shost->host_lock);
2301
James Smart92d7f7b2007-06-17 19:56:38 -05002302 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002303 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2304 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002305 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002306 return 1;
dea31012005-04-17 16:05:31 -05002307
2308 icmd = &elsiocb->iocb;
2309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2310 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002311 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002312
2313 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002314 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002315 pcmd += sizeof(uint32_t);
2316 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002317
James Smart858c9f62007-06-17 19:56:39 -05002318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2319 "Issue LOGO: did:x%x",
2320 ndlp->nlp_DID, 0, 0);
2321
dea31012005-04-17 16:05:31 -05002322 phba->fc_stat.elsXmitLOGO++;
2323 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002324 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002325 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002326 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002327 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002328
2329 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002330 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002331 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002332 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002333 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002334 return 1;
dea31012005-04-17 16:05:31 -05002335 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002336 return 0;
dea31012005-04-17 16:05:31 -05002337}
2338
James Smarte59058c2008-08-24 21:49:00 -04002339/**
James Smart3621a712009-04-06 18:47:14 -04002340 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002341 * @phba: pointer to lpfc hba data structure.
2342 * @cmdiocb: pointer to lpfc command iocb data structure.
2343 * @rspiocb: pointer to lpfc response iocb data structure.
2344 *
2345 * This routine is a generic completion callback function for ELS commands.
2346 * Specifically, it is the callback function which does not need to perform
2347 * any command specific operations. It is currently used by the ELS command
2348 * issuing routines for the ELS State Change Request (SCR),
2349 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2350 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2351 * certain debug loggings, this callback function simply invokes the
2352 * lpfc_els_chk_latt() routine to check whether link went down during the
2353 * discovery process.
2354 **/
dea31012005-04-17 16:05:31 -05002355static void
James Smart2e0fef82007-06-17 19:56:36 -05002356lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2357 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002358{
James Smart2e0fef82007-06-17 19:56:36 -05002359 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002360 IOCB_t *irsp;
2361
2362 irsp = &rspiocb->iocb;
2363
James Smart858c9f62007-06-17 19:56:39 -05002364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2365 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2366 irsp->ulpStatus, irsp->un.ulpWord[4],
2367 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002368 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2370 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2371 irsp->ulpIoTag, irsp->ulpStatus,
2372 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002373 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002374 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002375 lpfc_els_free_iocb(phba, cmdiocb);
2376 return;
2377}
2378
James Smarte59058c2008-08-24 21:49:00 -04002379/**
James Smart3621a712009-04-06 18:47:14 -04002380 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002381 * @vport: pointer to a host virtual N_Port data structure.
2382 * @nportid: N_Port identifier to the remote node.
2383 * @retry: number of retries to the command IOCB.
2384 *
2385 * This routine issues a State Change Request (SCR) to a fabric node
2386 * on a @vport. The remote node @nportid is passed into the function. It
2387 * first search the @vport node list to find the matching ndlp. If no such
2388 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2389 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2390 * routine is invoked to send the SCR IOCB.
2391 *
2392 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2393 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2394 * will be stored into the context1 field of the IOCB for the completion
2395 * callback function to the SCR ELS command.
2396 *
2397 * Return code
2398 * 0 - Successfully issued scr command
2399 * 1 - Failed to issue scr command
2400 **/
dea31012005-04-17 16:05:31 -05002401int
James Smart2e0fef82007-06-17 19:56:36 -05002402lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002403{
James Smart2e0fef82007-06-17 19:56:36 -05002404 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002405 IOCB_t *icmd;
2406 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002407 struct lpfc_sli *psli;
2408 uint8_t *pcmd;
2409 uint16_t cmdsize;
2410 struct lpfc_nodelist *ndlp;
2411
2412 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002413 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002414
James Smarte47c9092008-02-08 18:49:26 -05002415 ndlp = lpfc_findnode_did(vport, nportid);
2416 if (!ndlp) {
2417 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2418 if (!ndlp)
2419 return 1;
2420 lpfc_nlp_init(vport, ndlp, nportid);
2421 lpfc_enqueue_node(vport, ndlp);
2422 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2423 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2424 if (!ndlp)
2425 return 1;
2426 }
dea31012005-04-17 16:05:31 -05002427
James Smart2e0fef82007-06-17 19:56:36 -05002428 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2429 ndlp->nlp_DID, ELS_CMD_SCR);
2430
James Smart488d1462006-03-07 15:02:37 -05002431 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002432 /* This will trigger the release of the node just
2433 * allocated
2434 */
James Smart329f9bc2007-04-25 09:53:01 -04002435 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002436 return 1;
dea31012005-04-17 16:05:31 -05002437 }
2438
2439 icmd = &elsiocb->iocb;
2440 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2441
2442 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002443 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002444
2445 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002446 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002447 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2448
James Smart858c9f62007-06-17 19:56:39 -05002449 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2450 "Issue SCR: did:x%x",
2451 ndlp->nlp_DID, 0, 0);
2452
dea31012005-04-17 16:05:31 -05002453 phba->fc_stat.elsXmitSCR++;
2454 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002455 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2456 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002457 /* The additional lpfc_nlp_put will cause the following
2458 * lpfc_els_free_iocb routine to trigger the rlease of
2459 * the node.
2460 */
James Smart329f9bc2007-04-25 09:53:01 -04002461 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002462 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002463 return 1;
dea31012005-04-17 16:05:31 -05002464 }
James Smartfa4066b2008-01-11 01:53:27 -05002465 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2466 * trigger the release of node.
2467 */
James Smart329f9bc2007-04-25 09:53:01 -04002468 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002469 return 0;
dea31012005-04-17 16:05:31 -05002470}
2471
James Smarte59058c2008-08-24 21:49:00 -04002472/**
James Smart3621a712009-04-06 18:47:14 -04002473 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002474 * @vport: pointer to a host virtual N_Port data structure.
2475 * @nportid: N_Port identifier to the remote node.
2476 * @retry: number of retries to the command IOCB.
2477 *
2478 * This routine issues a Fibre Channel Address Resolution Response
2479 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2480 * is passed into the function. It first search the @vport node list to find
2481 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2482 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2483 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2484 *
2485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2487 * will be stored into the context1 field of the IOCB for the completion
2488 * callback function to the PARPR ELS command.
2489 *
2490 * Return code
2491 * 0 - Successfully issued farpr command
2492 * 1 - Failed to issue farpr command
2493 **/
dea31012005-04-17 16:05:31 -05002494static int
James Smart2e0fef82007-06-17 19:56:36 -05002495lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002496{
James Smart2e0fef82007-06-17 19:56:36 -05002497 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002498 IOCB_t *icmd;
2499 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002500 struct lpfc_sli *psli;
2501 FARP *fp;
2502 uint8_t *pcmd;
2503 uint32_t *lp;
2504 uint16_t cmdsize;
2505 struct lpfc_nodelist *ondlp;
2506 struct lpfc_nodelist *ndlp;
2507
2508 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002509 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002510
James Smarte47c9092008-02-08 18:49:26 -05002511 ndlp = lpfc_findnode_did(vport, nportid);
2512 if (!ndlp) {
2513 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2514 if (!ndlp)
2515 return 1;
2516 lpfc_nlp_init(vport, ndlp, nportid);
2517 lpfc_enqueue_node(vport, ndlp);
2518 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2519 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2520 if (!ndlp)
2521 return 1;
2522 }
James Smart2e0fef82007-06-17 19:56:36 -05002523
2524 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2525 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002526 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002527 /* This will trigger the release of the node just
2528 * allocated
2529 */
James Smart329f9bc2007-04-25 09:53:01 -04002530 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002531 return 1;
dea31012005-04-17 16:05:31 -05002532 }
2533
2534 icmd = &elsiocb->iocb;
2535 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2536
2537 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002538 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002539
2540 /* Fill in FARPR payload */
2541 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002542 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002543 lp = (uint32_t *) pcmd;
2544 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002545 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002546 fp->Rflags = 0;
2547 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2548
James Smart92d7f7b2007-06-17 19:56:38 -05002549 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2550 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002551 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002552 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002553 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002554 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002555 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002556 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002557 }
2558
James Smart858c9f62007-06-17 19:56:39 -05002559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2560 "Issue FARPR: did:x%x",
2561 ndlp->nlp_DID, 0, 0);
2562
dea31012005-04-17 16:05:31 -05002563 phba->fc_stat.elsXmitFARPR++;
2564 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002565 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2566 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002567 /* The additional lpfc_nlp_put will cause the following
2568 * lpfc_els_free_iocb routine to trigger the release of
2569 * the node.
2570 */
James Smart329f9bc2007-04-25 09:53:01 -04002571 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002572 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002573 return 1;
dea31012005-04-17 16:05:31 -05002574 }
James Smartfa4066b2008-01-11 01:53:27 -05002575 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2576 * trigger the release of the node.
2577 */
James Smart329f9bc2007-04-25 09:53:01 -04002578 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002579 return 0;
dea31012005-04-17 16:05:31 -05002580}
2581
James Smarte59058c2008-08-24 21:49:00 -04002582/**
James Smart3621a712009-04-06 18:47:14 -04002583 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002584 * @vport: pointer to a host virtual N_Port data structure.
2585 * @nlp: pointer to a node-list data structure.
2586 *
2587 * This routine cancels the timer with a delayed IOCB-command retry for
2588 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2589 * removes the ELS retry event if it presents. In addition, if the
2590 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2591 * commands are sent for the @vport's nodes that require issuing discovery
2592 * ADISC.
2593 **/
dea31012005-04-17 16:05:31 -05002594void
James Smart2e0fef82007-06-17 19:56:36 -05002595lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002596{
James Smart2e0fef82007-06-17 19:56:36 -05002597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002598 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002599
James Smart0d2b6b82008-06-14 22:52:47 -04002600 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2601 return;
James Smart2e0fef82007-06-17 19:56:36 -05002602 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002603 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002604 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002605 del_timer_sync(&nlp->nlp_delayfunc);
2606 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002607 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002608 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002609 /* Decrement nlp reference count held for the delayed retry */
2610 evtp = &nlp->els_retry_evt;
2611 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2612 }
James Smartfdcebe22006-03-07 15:04:01 -05002613 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002614 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002615 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002616 spin_unlock_irq(shost->host_lock);
2617 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002618 if (vport->port_state < LPFC_VPORT_READY) {
2619 /* Check if there are more ADISCs to be sent */
2620 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002621 } else {
2622 /* Check if there are more PLOGIs to be sent */
2623 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002624 if (vport->num_disc_nodes == 0) {
2625 spin_lock_irq(shost->host_lock);
2626 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2627 spin_unlock_irq(shost->host_lock);
2628 lpfc_can_disctmo(vport);
2629 lpfc_end_rscn(vport);
2630 }
James Smartfdcebe22006-03-07 15:04:01 -05002631 }
2632 }
2633 }
2634 return;
2635}
2636
James Smarte59058c2008-08-24 21:49:00 -04002637/**
James Smart3621a712009-04-06 18:47:14 -04002638 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002639 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2640 *
2641 * This routine is invoked by the ndlp delayed-function timer to check
2642 * whether there is any pending ELS retry event(s) with the node. If not, it
2643 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2644 * adds the delayed events to the HBA work list and invokes the
2645 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2646 * event. Note that lpfc_nlp_get() is called before posting the event to
2647 * the work list to hold reference count of ndlp so that it guarantees the
2648 * reference to ndlp will still be available when the worker thread gets
2649 * to the event associated with the ndlp.
2650 **/
James Smartfdcebe22006-03-07 15:04:01 -05002651void
dea31012005-04-17 16:05:31 -05002652lpfc_els_retry_delay(unsigned long ptr)
2653{
James Smart2e0fef82007-06-17 19:56:36 -05002654 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2655 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002656 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002657 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002658 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002659
James Smart92d7f7b2007-06-17 19:56:38 -05002660 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002661 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002662 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002663 return;
2664 }
2665
James Smartfa4066b2008-01-11 01:53:27 -05002666 /* We need to hold the node by incrementing the reference
2667 * count until the queued work is done
2668 */
2669 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002670 if (evtp->evt_arg1) {
2671 evtp->evt = LPFC_EVT_ELS_RETRY;
2672 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002673 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002674 }
James Smart92d7f7b2007-06-17 19:56:38 -05002675 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002676 return;
2677}
2678
James Smarte59058c2008-08-24 21:49:00 -04002679/**
James Smart3621a712009-04-06 18:47:14 -04002680 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002681 * @ndlp: pointer to a node-list data structure.
2682 *
2683 * This routine is the worker-thread handler for processing the @ndlp delayed
2684 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2685 * the last ELS command from the associated ndlp and invokes the proper ELS
2686 * function according to the delayed ELS command to retry the command.
2687 **/
dea31012005-04-17 16:05:31 -05002688void
2689lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2690{
James Smart2e0fef82007-06-17 19:56:36 -05002691 struct lpfc_vport *vport = ndlp->vport;
2692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2693 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002694
James Smart2e0fef82007-06-17 19:56:36 -05002695 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002696 did = ndlp->nlp_DID;
2697 cmd = ndlp->nlp_last_elscmd;
2698 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002699
2700 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002701 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002702 return;
2703 }
2704
2705 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002706 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002707 /*
2708 * If a discovery event readded nlp_delayfunc after timer
2709 * firing and before processing the timer, cancel the
2710 * nlp_delayfunc.
2711 */
2712 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002713 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002714 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002715
2716 switch (cmd) {
2717 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002718 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002719 break;
2720 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002721 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002722 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002724 }
dea31012005-04-17 16:05:31 -05002725 break;
2726 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002727 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002728 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002730 }
dea31012005-04-17 16:05:31 -05002731 break;
2732 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002733 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002734 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002735 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002736 }
dea31012005-04-17 16:05:31 -05002737 break;
2738 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002739 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002740 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002741 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002742 }
dea31012005-04-17 16:05:31 -05002743 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002744 case ELS_CMD_FDISC:
2745 lpfc_issue_els_fdisc(vport, ndlp, retry);
2746 break;
dea31012005-04-17 16:05:31 -05002747 }
2748 return;
2749}
2750
James Smarte59058c2008-08-24 21:49:00 -04002751/**
James Smart3621a712009-04-06 18:47:14 -04002752 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002753 * @phba: pointer to lpfc hba data structure.
2754 * @cmdiocb: pointer to lpfc command iocb data structure.
2755 * @rspiocb: pointer to lpfc response iocb data structure.
2756 *
2757 * This routine makes a retry decision on an ELS command IOCB, which has
2758 * failed. The following ELS IOCBs use this function for retrying the command
2759 * when previously issued command responsed with error status: FLOGI, PLOGI,
2760 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2761 * returned error status, it makes the decision whether a retry shall be
2762 * issued for the command, and whether a retry shall be made immediately or
2763 * delayed. In the former case, the corresponding ELS command issuing-function
2764 * is called to retry the command. In the later case, the ELS command shall
2765 * be posted to the ndlp delayed event and delayed function timer set to the
2766 * ndlp for the delayed command issusing.
2767 *
2768 * Return code
2769 * 0 - No retry of els command is made
2770 * 1 - Immediate or delayed retry of els command is made
2771 **/
dea31012005-04-17 16:05:31 -05002772static int
James Smart2e0fef82007-06-17 19:56:36 -05002773lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2774 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002775{
James Smart2e0fef82007-06-17 19:56:36 -05002776 struct lpfc_vport *vport = cmdiocb->vport;
2777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2778 IOCB_t *irsp = &rspiocb->iocb;
2779 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2780 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002781 uint32_t *elscmd;
2782 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002783 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002784 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002785 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002786 uint32_t did;
dea31012005-04-17 16:05:31 -05002787
James Smart488d1462006-03-07 15:02:37 -05002788
dea31012005-04-17 16:05:31 -05002789 /* Note: context2 may be 0 for internal driver abort
2790 * of delays ELS command.
2791 */
2792
2793 if (pcmd && pcmd->virt) {
2794 elscmd = (uint32_t *) (pcmd->virt);
2795 cmd = *elscmd++;
2796 }
2797
James Smarte47c9092008-02-08 18:49:26 -05002798 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002799 did = ndlp->nlp_DID;
2800 else {
2801 /* We should only hit this case for retrying PLOGI */
2802 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002803 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002804 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2805 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002806 return 1;
2807 }
2808
James Smart858c9f62007-06-17 19:56:39 -05002809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2810 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2811 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2812
dea31012005-04-17 16:05:31 -05002813 switch (irsp->ulpStatus) {
2814 case IOSTAT_FCP_RSP_ERROR:
2815 case IOSTAT_REMOTE_STOP:
2816 break;
2817
2818 case IOSTAT_LOCAL_REJECT:
2819 switch ((irsp->un.ulpWord[4] & 0xff)) {
2820 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002821 if (cmd == ELS_CMD_FLOGI) {
2822 if (PCI_DEVICE_ID_HORNET ==
2823 phba->pcidev->device) {
James Smart76a95d72010-11-20 23:11:48 -05002824 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
James Smarteaf15d52008-12-04 22:39:29 -05002825 phba->pport->fc_myDID = 0;
2826 phba->alpa_map[0] = 0;
2827 phba->alpa_map[1] = 0;
2828 }
2829 }
James Smart2e0fef82007-06-17 19:56:36 -05002830 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002831 delay = 1000;
dea31012005-04-17 16:05:31 -05002832 retry = 1;
2833 break;
2834
James Smart92d7f7b2007-06-17 19:56:38 -05002835 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2837 "0124 Retry illegal cmd x%x "
2838 "retry:x%x delay:x%x\n",
2839 cmd, cmdiocb->retry, delay);
2840 retry = 1;
2841 /* All command's retry policy */
2842 maxretry = 8;
2843 if (cmdiocb->retry > 2)
2844 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002845 break;
2846
dea31012005-04-17 16:05:31 -05002847 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002848 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002849 retry = 1;
2850 if (cmdiocb->retry > 100)
2851 delay = 100;
2852 maxretry = 250;
2853 break;
2854
2855 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002856 delay = 100;
dea31012005-04-17 16:05:31 -05002857 retry = 1;
2858 break;
2859
James Smart858c9f62007-06-17 19:56:39 -05002860 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002861 case IOERR_INVALID_RPI:
2862 retry = 1;
2863 break;
2864 }
2865 break;
2866
2867 case IOSTAT_NPORT_RJT:
2868 case IOSTAT_FABRIC_RJT:
2869 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2870 retry = 1;
2871 break;
2872 }
2873 break;
2874
2875 case IOSTAT_NPORT_BSY:
2876 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002877 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002878 retry = 1;
2879 break;
2880
2881 case IOSTAT_LS_RJT:
2882 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2883 /* Added for Vendor specifc support
2884 * Just keep retrying for these Rsn / Exp codes
2885 */
2886 switch (stat.un.b.lsRjtRsnCode) {
2887 case LSRJT_UNABLE_TPC:
2888 if (stat.un.b.lsRjtRsnCodeExp ==
2889 LSEXP_CMD_IN_PROGRESS) {
2890 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002891 delay = 1000;
dea31012005-04-17 16:05:31 -05002892 maxretry = 48;
2893 }
2894 retry = 1;
2895 break;
2896 }
James Smartffc95492010-06-07 15:23:17 -04002897 if (stat.un.b.lsRjtRsnCodeExp ==
2898 LSEXP_CANT_GIVE_DATA) {
2899 if (cmd == ELS_CMD_PLOGI) {
2900 delay = 1000;
2901 maxretry = 48;
2902 }
2903 retry = 1;
2904 break;
2905 }
dea31012005-04-17 16:05:31 -05002906 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002907 delay = 1000;
dea31012005-04-17 16:05:31 -05002908 maxretry = lpfc_max_els_tries + 1;
2909 retry = 1;
2910 break;
2911 }
James Smart92d7f7b2007-06-17 19:56:38 -05002912 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2913 (cmd == ELS_CMD_FDISC) &&
2914 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002915 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2916 "0125 FDISC Failed (x%x). "
2917 "Fabric out of resources\n",
2918 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002919 lpfc_vport_set_state(vport,
2920 FC_VPORT_NO_FABRIC_RSCS);
2921 }
dea31012005-04-17 16:05:31 -05002922 break;
2923
2924 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002925 if ((cmd == ELS_CMD_PLOGI) ||
2926 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002927 delay = 1000;
dea31012005-04-17 16:05:31 -05002928 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002929 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002930 /* FDISC retry policy */
2931 maxretry = 48;
2932 if (cmdiocb->retry >= 32)
2933 delay = 1000;
dea31012005-04-17 16:05:31 -05002934 }
2935 retry = 1;
2936 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002937
2938 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002939 /* There are some cases where switches return this
2940 * error when they are not ready and should be returning
2941 * Logical Busy. We should delay every time.
2942 */
2943 if (cmd == ELS_CMD_FDISC &&
2944 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2945 maxretry = 3;
2946 delay = 1000;
2947 retry = 1;
2948 break;
2949 }
James Smart92d7f7b2007-06-17 19:56:38 -05002950 case LSRJT_PROTOCOL_ERR:
2951 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2952 (cmd == ELS_CMD_FDISC) &&
2953 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2954 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2955 ) {
James Smarte8b62012007-08-02 11:10:09 -04002956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002957 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002958 "Fabric Detected Bad WWN\n",
2959 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002960 lpfc_vport_set_state(vport,
2961 FC_VPORT_FABRIC_REJ_WWN);
2962 }
2963 break;
dea31012005-04-17 16:05:31 -05002964 }
2965 break;
2966
2967 case IOSTAT_INTERMED_RSP:
2968 case IOSTAT_BA_RJT:
2969 break;
2970
2971 default:
2972 break;
2973 }
2974
James Smart488d1462006-03-07 15:02:37 -05002975 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002976 retry = 1;
dea31012005-04-17 16:05:31 -05002977
James Smart695a8142010-01-26 23:08:03 -05002978 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart76a95d72010-11-20 23:11:48 -05002979 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002980 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002981 /* FLOGI retry policy */
2982 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002983 /* retry forever */
2984 maxretry = 0;
2985 if (cmdiocb->retry >= 100)
2986 delay = 5000;
2987 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002988 delay = 1000;
2989 }
2990
James Smart6669f9b2009-10-02 15:16:45 -04002991 cmdiocb->retry++;
2992 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002993 phba->fc_stat.elsRetryExceeded++;
2994 retry = 0;
2995 }
2996
James Smarted957682007-06-17 19:56:37 -05002997 if ((vport->load_flag & FC_UNLOADING) != 0)
2998 retry = 0;
2999
dea31012005-04-17 16:05:31 -05003000 if (retry) {
James Smart38b92ef2010-08-04 16:11:39 -04003001 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3002 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3003 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3004 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3005 "2849 Stop retry ELS command "
3006 "x%x to remote NPORT x%x, "
3007 "Data: x%x x%x\n", cmd, did,
3008 cmdiocb->retry, delay);
3009 return 0;
3010 }
3011 }
dea31012005-04-17 16:05:31 -05003012
3013 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003014 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3015 "0107 Retry ELS command x%x to remote "
3016 "NPORT x%x Data: x%x x%x\n",
3017 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05003018
James Smart858c9f62007-06-17 19:56:39 -05003019 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3020 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3021 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3022 /* Don't reset timer for no resources */
3023
dea31012005-04-17 16:05:31 -05003024 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05003025 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05003026 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05003027 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003028 }
3029
3030 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04003031 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05003032 phba->fc_stat.elsDelayRetry++;
3033 ndlp->nlp_retry = cmdiocb->retry;
3034
James Smart92d7f7b2007-06-17 19:56:38 -05003035 /* delay is specified in milliseconds */
3036 mod_timer(&ndlp->nlp_delayfunc,
3037 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05003038 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003039 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05003040 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003041
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003042 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05003043 if (cmd == ELS_CMD_PRLI)
3044 lpfc_nlp_set_state(vport, ndlp,
3045 NLP_STE_REG_LOGIN_ISSUE);
3046 else
3047 lpfc_nlp_set_state(vport, ndlp,
3048 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003049 ndlp->nlp_last_elscmd = cmd;
3050
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003051 return 1;
dea31012005-04-17 16:05:31 -05003052 }
3053 switch (cmd) {
3054 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05003055 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003056 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003057 case ELS_CMD_FDISC:
3058 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3059 return 1;
dea31012005-04-17 16:05:31 -05003060 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04003061 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05003062 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003063 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003064 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003065 }
James Smart2e0fef82007-06-17 19:56:36 -05003066 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003067 return 1;
dea31012005-04-17 16:05:31 -05003068 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003069 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003070 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3071 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003072 return 1;
dea31012005-04-17 16:05:31 -05003073 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003074 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003075 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3076 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003077 return 1;
dea31012005-04-17 16:05:31 -05003078 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003079 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003080 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3081 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003082 return 1;
dea31012005-04-17 16:05:31 -05003083 }
3084 }
dea31012005-04-17 16:05:31 -05003085 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04003086 if (logerr) {
3087 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3088 "0137 No retry ELS command x%x to remote "
3089 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3090 cmd, did, irsp->ulpStatus,
3091 irsp->un.ulpWord[4]);
3092 }
3093 else {
3094 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04003095 "0108 No retry ELS command x%x to remote "
3096 "NPORT x%x Retried:%d Error:x%x/%x\n",
3097 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3098 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04003099 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003100 return 0;
dea31012005-04-17 16:05:31 -05003101}
3102
James Smarte59058c2008-08-24 21:49:00 -04003103/**
James Smart3621a712009-04-06 18:47:14 -04003104 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04003105 * @phba: pointer to lpfc hba data structure.
3106 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3107 *
3108 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3109 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3110 * checks to see whether there is a lpfc DMA buffer associated with the
3111 * response of the command IOCB. If so, it will be released before releasing
3112 * the lpfc DMA buffer associated with the IOCB itself.
3113 *
3114 * Return code
3115 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3116 **/
James Smart09372822008-01-11 01:52:54 -05003117static int
James Smart87af33f2007-10-27 13:37:43 -04003118lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3119{
3120 struct lpfc_dmabuf *buf_ptr;
3121
James Smarte59058c2008-08-24 21:49:00 -04003122 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04003123 if (!list_empty(&buf_ptr1->list)) {
3124 list_remove_head(&buf_ptr1->list, buf_ptr,
3125 struct lpfc_dmabuf,
3126 list);
3127 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3128 kfree(buf_ptr);
3129 }
3130 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3131 kfree(buf_ptr1);
3132 return 0;
3133}
3134
James Smarte59058c2008-08-24 21:49:00 -04003135/**
James Smart3621a712009-04-06 18:47:14 -04003136 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04003137 * @phba: pointer to lpfc hba data structure.
3138 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3139 *
3140 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3141 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3142 * pool.
3143 *
3144 * Return code
3145 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3146 **/
James Smart09372822008-01-11 01:52:54 -05003147static int
James Smart87af33f2007-10-27 13:37:43 -04003148lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3149{
3150 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3151 kfree(buf_ptr);
3152 return 0;
3153}
3154
James Smarte59058c2008-08-24 21:49:00 -04003155/**
James Smart3621a712009-04-06 18:47:14 -04003156 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04003157 * @phba: pointer to lpfc hba data structure.
3158 * @elsiocb: pointer to lpfc els command iocb data structure.
3159 *
3160 * This routine frees a command IOCB and its associated resources. The
3161 * command IOCB data structure contains the reference to various associated
3162 * resources, these fields must be set to NULL if the associated reference
3163 * not present:
3164 * context1 - reference to ndlp
3165 * context2 - reference to cmd
3166 * context2->next - reference to rsp
3167 * context3 - reference to bpl
3168 *
3169 * It first properly decrements the reference count held on ndlp for the
3170 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3171 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3172 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3173 * adds the DMA buffer the @phba data structure for the delayed release.
3174 * If reference to the Buffer Pointer List (BPL) is present, the
3175 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3176 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3177 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3178 *
3179 * Return code
3180 * 0 - Success (currently, always return 0)
3181 **/
James Smart87af33f2007-10-27 13:37:43 -04003182int
James Smart329f9bc2007-04-25 09:53:01 -04003183lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003184{
3185 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04003186 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003187
James Smarta8adb832007-10-27 13:37:53 -04003188 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3189 if (ndlp) {
3190 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3191 lpfc_nlp_put(ndlp);
3192
3193 /* If the ndlp is not being used by another discovery
3194 * thread, free it.
3195 */
3196 if (!lpfc_nlp_not_used(ndlp)) {
3197 /* If ndlp is being used by another discovery
3198 * thread, just clear NLP_DEFER_RM
3199 */
3200 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3201 }
3202 }
3203 else
3204 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04003205 elsiocb->context1 = NULL;
3206 }
dea31012005-04-17 16:05:31 -05003207 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3208 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05003209 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3210 /* Firmware could still be in progress of DMAing
3211 * payload, so don't free data buffer till after
3212 * a hbeat.
3213 */
3214 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3215 buf_ptr = elsiocb->context2;
3216 elsiocb->context2 = NULL;
3217 if (buf_ptr) {
3218 buf_ptr1 = NULL;
3219 spin_lock_irq(&phba->hbalock);
3220 if (!list_empty(&buf_ptr->list)) {
3221 list_remove_head(&buf_ptr->list,
3222 buf_ptr1, struct lpfc_dmabuf,
3223 list);
3224 INIT_LIST_HEAD(&buf_ptr1->list);
3225 list_add_tail(&buf_ptr1->list,
3226 &phba->elsbuf);
3227 phba->elsbuf_cnt++;
3228 }
3229 INIT_LIST_HEAD(&buf_ptr->list);
3230 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3231 phba->elsbuf_cnt++;
3232 spin_unlock_irq(&phba->hbalock);
3233 }
3234 } else {
3235 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3236 lpfc_els_free_data(phba, buf_ptr1);
3237 }
dea31012005-04-17 16:05:31 -05003238 }
3239
3240 if (elsiocb->context3) {
3241 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04003242 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05003243 }
James Bottomley604a3e32005-10-29 10:28:33 -05003244 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05003245 return 0;
3246}
3247
James Smarte59058c2008-08-24 21:49:00 -04003248/**
James Smart3621a712009-04-06 18:47:14 -04003249 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04003250 * @phba: pointer to lpfc hba data structure.
3251 * @cmdiocb: pointer to lpfc command iocb data structure.
3252 * @rspiocb: pointer to lpfc response iocb data structure.
3253 *
3254 * This routine is the completion callback function to the Logout (LOGO)
3255 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3256 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3257 * release the ndlp if it has the last reference remaining (reference count
3258 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3259 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3260 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3261 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3262 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3263 * IOCB data structure.
3264 **/
dea31012005-04-17 16:05:31 -05003265static void
James Smart2e0fef82007-06-17 19:56:36 -05003266lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3267 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003268{
James Smart2e0fef82007-06-17 19:56:36 -05003269 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3270 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003271 IOCB_t *irsp;
3272
3273 irsp = &rspiocb->iocb;
3274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3275 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3276 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003277 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003278 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3279 "0109 ACC to LOGO completes to NPort x%x "
3280 "Data: x%x x%x x%x\n",
3281 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3282 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003283
3284 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3285 /* NPort Recovery mode or node is just allocated */
3286 if (!lpfc_nlp_not_used(ndlp)) {
3287 /* If the ndlp is being used by another discovery
3288 * thread, just unregister the RPI.
3289 */
3290 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003291 } else {
3292 /* Indicate the node has already released, should
3293 * not reference to it from within lpfc_els_free_iocb.
3294 */
3295 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003296 }
dea31012005-04-17 16:05:31 -05003297 }
3298 lpfc_els_free_iocb(phba, cmdiocb);
3299 return;
3300}
3301
James Smarte59058c2008-08-24 21:49:00 -04003302/**
James Smart3621a712009-04-06 18:47:14 -04003303 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003304 * @phba: pointer to lpfc hba data structure.
3305 * @pmb: pointer to the driver internal queue element for mailbox command.
3306 *
3307 * This routine is the completion callback function for unregister default
3308 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3309 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3310 * decrements the ndlp reference count held for this completion callback
3311 * function. After that, it invokes the lpfc_nlp_not_used() to check
3312 * whether there is only one reference left on the ndlp. If so, it will
3313 * perform one more decrement and trigger the release of the ndlp.
3314 **/
James Smart858c9f62007-06-17 19:56:39 -05003315void
3316lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3317{
3318 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3319 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3320
James Smart6fb120a2009-05-22 14:52:59 -04003321 /*
3322 * This routine is used to register and unregister in previous SLI
3323 * modes.
3324 */
3325 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3326 (phba->sli_rev == LPFC_SLI_REV4))
3327 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3328
James Smart858c9f62007-06-17 19:56:39 -05003329 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003330 pmb->context2 = NULL;
3331
James Smart858c9f62007-06-17 19:56:39 -05003332 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3333 kfree(mp);
3334 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003335 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003336 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003337 /* This is the end of the default RPI cleanup logic for this
3338 * ndlp. If no other discovery threads are using this ndlp.
3339 * we should free all resources associated with it.
3340 */
3341 lpfc_nlp_not_used(ndlp);
3342 }
James Smart3772a992009-05-22 14:50:54 -04003343
James Smart858c9f62007-06-17 19:56:39 -05003344 return;
3345}
3346
James Smarte59058c2008-08-24 21:49:00 -04003347/**
James Smart3621a712009-04-06 18:47:14 -04003348 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003349 * @phba: pointer to lpfc hba data structure.
3350 * @cmdiocb: pointer to lpfc command iocb data structure.
3351 * @rspiocb: pointer to lpfc response iocb data structure.
3352 *
3353 * This routine is the completion callback function for ELS Response IOCB
3354 * command. In normal case, this callback function just properly sets the
3355 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3356 * field in the command IOCB is not NULL, the referred mailbox command will
3357 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3358 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3359 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3360 * routine shall be invoked trying to release the ndlp if no other threads
3361 * are currently referring it.
3362 **/
dea31012005-04-17 16:05:31 -05003363static void
James Smart858c9f62007-06-17 19:56:39 -05003364lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003365 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003366{
James Smart2e0fef82007-06-17 19:56:36 -05003367 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3368 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3369 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003370 IOCB_t *irsp;
3371 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003372 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003373 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003374 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003375
James Smart33ccf8d2006-08-17 11:57:58 -04003376 irsp = &rspiocb->iocb;
3377
dea31012005-04-17 16:05:31 -05003378 if (cmdiocb->context_un.mbox)
3379 mbox = cmdiocb->context_un.mbox;
3380
James Smartfa4066b2008-01-11 01:53:27 -05003381 /* First determine if this is a LS_RJT cmpl. Note, this callback
3382 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3383 */
James Smart87af33f2007-10-27 13:37:43 -04003384 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003385 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3386 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003387 /* A LS_RJT associated with Default RPI cleanup has its own
Daniel Mack3ad2f3f2010-02-03 08:01:28 +08003388 * separate code path.
James Smart87af33f2007-10-27 13:37:43 -04003389 */
3390 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3391 ls_rjt = 1;
3392 }
3393
dea31012005-04-17 16:05:31 -05003394 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003395 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003396 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003397 mp = (struct lpfc_dmabuf *) mbox->context1;
3398 if (mp) {
3399 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3400 kfree(mp);
3401 }
James Smart329f9bc2007-04-25 09:53:01 -04003402 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003403 }
James Smart58da1ff2008-04-07 10:15:56 -04003404 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3405 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003406 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003407 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003408 /* Indicate the node has already released,
3409 * should not reference to it from within
3410 * the routine lpfc_els_free_iocb.
3411 */
3412 cmdiocb->context1 = NULL;
3413 }
dea31012005-04-17 16:05:31 -05003414 goto out;
3415 }
3416
James Smart858c9f62007-06-17 19:56:39 -05003417 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003418 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003419 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003420 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003421 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003422 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3423 "0110 ELS response tag x%x completes "
3424 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3425 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3426 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3427 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3428 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003429 if (mbox) {
3430 if ((rspiocb->iocb.ulpStatus == 0)
3431 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003432 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003433 /* Increment reference count to ndlp to hold the
3434 * reference to ndlp for the callback function.
3435 */
James Smart329f9bc2007-04-25 09:53:01 -04003436 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003437 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003438 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3439 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3440 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3441 }
3442 else {
3443 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3444 ndlp->nlp_prev_state = ndlp->nlp_state;
3445 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003446 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003447 }
James Smart0b727fe2007-10-27 13:37:25 -04003448 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003449 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003450 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003451 else
3452 /* Decrement the ndlp reference count we
3453 * set for this failed mailbox command.
3454 */
3455 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003456
3457 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3458 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3459 "0138 ELS rsp: Cannot issue reg_login for x%x "
3460 "Data: x%x x%x x%x\n",
3461 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3462 ndlp->nlp_rpi);
3463
James Smartfa4066b2008-01-11 01:53:27 -05003464 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003465 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003466 /* Indicate node has already been released,
3467 * should not reference to it from within
3468 * the routine lpfc_els_free_iocb.
3469 */
3470 cmdiocb->context1 = NULL;
3471 }
dea31012005-04-17 16:05:31 -05003472 } else {
James Smart858c9f62007-06-17 19:56:39 -05003473 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3474 if (!lpfc_error_lost_link(irsp) &&
3475 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003476 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003477 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003478 /* Indicate node has already been
3479 * released, should not reference
3480 * to it from within the routine
3481 * lpfc_els_free_iocb.
3482 */
3483 cmdiocb->context1 = NULL;
3484 }
dea31012005-04-17 16:05:31 -05003485 }
3486 }
James Smart14691152006-12-02 13:34:28 -05003487 mp = (struct lpfc_dmabuf *) mbox->context1;
3488 if (mp) {
3489 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3490 kfree(mp);
3491 }
3492 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003493 }
3494out:
James Smart58da1ff2008-04-07 10:15:56 -04003495 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003496 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003497 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003498 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003499
3500 /* If the node is not being used by another discovery thread,
3501 * and we are sending a reject, we are done with it.
3502 * Release driver reference count here and free associated
3503 * resources.
3504 */
3505 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003506 if (lpfc_nlp_not_used(ndlp))
3507 /* Indicate node has already been released,
3508 * should not reference to it from within
3509 * the routine lpfc_els_free_iocb.
3510 */
3511 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003512 }
James Smart87af33f2007-10-27 13:37:43 -04003513
dea31012005-04-17 16:05:31 -05003514 lpfc_els_free_iocb(phba, cmdiocb);
3515 return;
3516}
3517
James Smarte59058c2008-08-24 21:49:00 -04003518/**
James Smart3621a712009-04-06 18:47:14 -04003519 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003520 * @vport: pointer to a host virtual N_Port data structure.
3521 * @flag: the els command code to be accepted.
3522 * @oldiocb: pointer to the original lpfc command iocb data structure.
3523 * @ndlp: pointer to a node-list data structure.
3524 * @mbox: pointer to the driver internal queue element for mailbox command.
3525 *
3526 * This routine prepares and issues an Accept (ACC) response IOCB
3527 * command. It uses the @flag to properly set up the IOCB field for the
3528 * specific ACC response command to be issued and invokes the
3529 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3530 * @mbox pointer is passed in, it will be put into the context_un.mbox
3531 * field of the IOCB for the completion callback function to issue the
3532 * mailbox command to the HBA later when callback is invoked.
3533 *
3534 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3535 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3536 * will be stored into the context1 field of the IOCB for the completion
3537 * callback function to the corresponding response ELS IOCB command.
3538 *
3539 * Return code
3540 * 0 - Successfully issued acc response
3541 * 1 - Failed to issue acc response
3542 **/
dea31012005-04-17 16:05:31 -05003543int
James Smart2e0fef82007-06-17 19:56:36 -05003544lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3545 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003546 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003547{
James Smart2e0fef82007-06-17 19:56:36 -05003548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3549 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003550 IOCB_t *icmd;
3551 IOCB_t *oldcmd;
3552 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003553 struct lpfc_sli *psli;
3554 uint8_t *pcmd;
3555 uint16_t cmdsize;
3556 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003557 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003558
3559 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003560 oldcmd = &oldiocb->iocb;
3561
3562 switch (flag) {
3563 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003564 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003565 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3566 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003567 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003568 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003569 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003570 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003571 return 1;
dea31012005-04-17 16:05:31 -05003572 }
James Smart2e0fef82007-06-17 19:56:36 -05003573
dea31012005-04-17 16:05:31 -05003574 icmd = &elsiocb->iocb;
3575 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3576 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3577 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003578 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003579
3580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3581 "Issue ACC: did:x%x flg:x%x",
3582 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003583 break;
3584 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003585 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003586 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3587 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003588 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003589 return 1;
James Smart488d1462006-03-07 15:02:37 -05003590
dea31012005-04-17 16:05:31 -05003591 icmd = &elsiocb->iocb;
3592 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3593 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3594
3595 if (mbox)
3596 elsiocb->context_un.mbox = mbox;
3597
3598 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003599 pcmd += sizeof(uint32_t);
3600 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003601
3602 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3603 "Issue ACC PLOGI: did:x%x flg:x%x",
3604 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003605 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003606 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003607 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003608 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003609 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3610 if (!elsiocb)
3611 return 1;
3612
3613 icmd = &elsiocb->iocb;
3614 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3615 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3616
3617 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003618 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003619 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3620 els_pkt_ptr = (ELS_PKT *) pcmd;
3621 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003622
3623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3624 "Issue ACC PRLO: did:x%x flg:x%x",
3625 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003626 break;
dea31012005-04-17 16:05:31 -05003627 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003628 return 1;
dea31012005-04-17 16:05:31 -05003629 }
dea31012005-04-17 16:05:31 -05003630 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003631 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3632 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3633 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3634 elsiocb->iotag, elsiocb->iocb.ulpContext,
3635 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3636 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003637 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003638 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003639 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003640 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003641 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3642 } else {
James Smart858c9f62007-06-17 19:56:39 -05003643 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003644 }
3645
3646 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003647 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003648 if (rc == IOCB_ERROR) {
3649 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003650 return 1;
dea31012005-04-17 16:05:31 -05003651 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003652 return 0;
dea31012005-04-17 16:05:31 -05003653}
3654
James Smarte59058c2008-08-24 21:49:00 -04003655/**
James Smart3621a712009-04-06 18:47:14 -04003656 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003657 * @vport: pointer to a virtual N_Port data structure.
3658 * @rejectError:
3659 * @oldiocb: pointer to the original lpfc command iocb data structure.
3660 * @ndlp: pointer to a node-list data structure.
3661 * @mbox: pointer to the driver internal queue element for mailbox command.
3662 *
3663 * This routine prepares and issue an Reject (RJT) response IOCB
3664 * command. If a @mbox pointer is passed in, it will be put into the
3665 * context_un.mbox field of the IOCB for the completion callback function
3666 * to issue to the HBA later.
3667 *
3668 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3669 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3670 * will be stored into the context1 field of the IOCB for the completion
3671 * callback function to the reject response ELS IOCB command.
3672 *
3673 * Return code
3674 * 0 - Successfully issued reject response
3675 * 1 - Failed to issue reject response
3676 **/
dea31012005-04-17 16:05:31 -05003677int
James Smart2e0fef82007-06-17 19:56:36 -05003678lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003679 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3680 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003681{
James Smart2e0fef82007-06-17 19:56:36 -05003682 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003683 IOCB_t *icmd;
3684 IOCB_t *oldcmd;
3685 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003686 struct lpfc_sli *psli;
3687 uint8_t *pcmd;
3688 uint16_t cmdsize;
3689 int rc;
3690
3691 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003692 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003693 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3694 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003695 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003696 return 1;
dea31012005-04-17 16:05:31 -05003697
3698 icmd = &elsiocb->iocb;
3699 oldcmd = &oldiocb->iocb;
3700 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3701 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3702
3703 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003704 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003705 *((uint32_t *) (pcmd)) = rejectError;
3706
James Smart51ef4c22007-08-02 11:10:31 -04003707 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003708 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003709
dea31012005-04-17 16:05:31 -05003710 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003711 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3712 "0129 Xmit ELS RJT x%x response tag x%x "
3713 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3714 "rpi x%x\n",
3715 rejectError, elsiocb->iotag,
3716 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3717 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3719 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3720 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3721
dea31012005-04-17 16:05:31 -05003722 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003723 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003724 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003725
dea31012005-04-17 16:05:31 -05003726 if (rc == IOCB_ERROR) {
3727 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003728 return 1;
dea31012005-04-17 16:05:31 -05003729 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003730 return 0;
dea31012005-04-17 16:05:31 -05003731}
3732
James Smarte59058c2008-08-24 21:49:00 -04003733/**
James Smart3621a712009-04-06 18:47:14 -04003734 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003735 * @vport: pointer to a virtual N_Port data structure.
3736 * @oldiocb: pointer to the original lpfc command iocb data structure.
3737 * @ndlp: pointer to a node-list data structure.
3738 *
3739 * This routine prepares and issues an Accept (ACC) response to Address
3740 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3741 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3742 *
3743 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3744 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3745 * will be stored into the context1 field of the IOCB for the completion
3746 * callback function to the ADISC Accept response ELS IOCB command.
3747 *
3748 * Return code
3749 * 0 - Successfully issued acc adisc response
3750 * 1 - Failed to issue adisc acc response
3751 **/
dea31012005-04-17 16:05:31 -05003752int
James Smart2e0fef82007-06-17 19:56:36 -05003753lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3754 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003755{
James Smart2e0fef82007-06-17 19:56:36 -05003756 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003757 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003758 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003759 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003760 uint8_t *pcmd;
3761 uint16_t cmdsize;
3762 int rc;
3763
James Smart92d7f7b2007-06-17 19:56:38 -05003764 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003765 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3766 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003767 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003768 return 1;
dea31012005-04-17 16:05:31 -05003769
dea31012005-04-17 16:05:31 -05003770 icmd = &elsiocb->iocb;
3771 oldcmd = &oldiocb->iocb;
3772 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003773
3774 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3776 "0130 Xmit ADISC ACC response iotag x%x xri: "
3777 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3778 elsiocb->iotag, elsiocb->iocb.ulpContext,
3779 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3780 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003781 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3782
3783 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003784 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003785
3786 ap = (ADISC *) (pcmd);
3787 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003788 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3789 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003790 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003791
James Smart858c9f62007-06-17 19:56:39 -05003792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3793 "Issue ACC ADISC: did:x%x flg:x%x",
3794 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3795
dea31012005-04-17 16:05:31 -05003796 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003797 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003798 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003799 if (rc == IOCB_ERROR) {
3800 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003801 return 1;
dea31012005-04-17 16:05:31 -05003802 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003803 return 0;
dea31012005-04-17 16:05:31 -05003804}
3805
James Smarte59058c2008-08-24 21:49:00 -04003806/**
James Smart3621a712009-04-06 18:47:14 -04003807 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003808 * @vport: pointer to a virtual N_Port data structure.
3809 * @oldiocb: pointer to the original lpfc command iocb data structure.
3810 * @ndlp: pointer to a node-list data structure.
3811 *
3812 * This routine prepares and issues an Accept (ACC) response to Process
3813 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3814 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3815 *
3816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3818 * will be stored into the context1 field of the IOCB for the completion
3819 * callback function to the PRLI Accept response ELS IOCB command.
3820 *
3821 * Return code
3822 * 0 - Successfully issued acc prli response
3823 * 1 - Failed to issue acc prli response
3824 **/
dea31012005-04-17 16:05:31 -05003825int
James Smart2e0fef82007-06-17 19:56:36 -05003826lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003827 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003828{
James Smart2e0fef82007-06-17 19:56:36 -05003829 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003830 PRLI *npr;
3831 lpfc_vpd_t *vpd;
3832 IOCB_t *icmd;
3833 IOCB_t *oldcmd;
3834 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003835 struct lpfc_sli *psli;
3836 uint8_t *pcmd;
3837 uint16_t cmdsize;
3838 int rc;
3839
3840 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003841
James Smart92d7f7b2007-06-17 19:56:38 -05003842 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003843 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003844 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003845 if (!elsiocb)
3846 return 1;
dea31012005-04-17 16:05:31 -05003847
dea31012005-04-17 16:05:31 -05003848 icmd = &elsiocb->iocb;
3849 oldcmd = &oldiocb->iocb;
3850 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003851 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003852 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3853 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3854 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3855 elsiocb->iotag, elsiocb->iocb.ulpContext,
3856 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3857 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003858 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3859
3860 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003861 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003862
3863 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003864 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003865
3866 npr = (PRLI *) pcmd;
3867 vpd = &phba->vpd;
3868 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003869 * If the remote port is a target and our firmware version is 3.20 or
3870 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003871 */
James Smart0d2b6b82008-06-14 22:52:47 -04003872 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3873 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003874 npr->ConfmComplAllowed = 1;
3875 npr->Retry = 1;
3876 npr->TaskRetryIdReq = 1;
3877 }
3878
3879 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3880 npr->estabImagePair = 1;
3881 npr->readXferRdyDis = 1;
3882 npr->ConfmComplAllowed = 1;
3883
3884 npr->prliType = PRLI_FCP_TYPE;
3885 npr->initiatorFunc = 1;
3886
James Smart858c9f62007-06-17 19:56:39 -05003887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3888 "Issue ACC PRLI: did:x%x flg:x%x",
3889 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3890
dea31012005-04-17 16:05:31 -05003891 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003892 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003893
James Smart3772a992009-05-22 14:50:54 -04003894 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003895 if (rc == IOCB_ERROR) {
3896 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003897 return 1;
dea31012005-04-17 16:05:31 -05003898 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003899 return 0;
dea31012005-04-17 16:05:31 -05003900}
3901
James Smarte59058c2008-08-24 21:49:00 -04003902/**
James Smart3621a712009-04-06 18:47:14 -04003903 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003904 * @vport: pointer to a virtual N_Port data structure.
3905 * @format: rnid command format.
3906 * @oldiocb: pointer to the original lpfc command iocb data structure.
3907 * @ndlp: pointer to a node-list data structure.
3908 *
3909 * This routine issues a Request Node Identification Data (RNID) Accept
3910 * (ACC) response. It constructs the RNID ACC response command according to
3911 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3912 * issue the response. Note that this command does not need to hold the ndlp
3913 * reference count for the callback. So, the ndlp reference count taken by
3914 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3915 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3916 * there is no ndlp reference available.
3917 *
3918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3920 * will be stored into the context1 field of the IOCB for the completion
3921 * callback function. However, for the RNID Accept Response ELS command,
3922 * this is undone later by this routine after the IOCB is allocated.
3923 *
3924 * Return code
3925 * 0 - Successfully issued acc rnid response
3926 * 1 - Failed to issue acc rnid response
3927 **/
dea31012005-04-17 16:05:31 -05003928static int
James Smart2e0fef82007-06-17 19:56:36 -05003929lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003930 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003931{
James Smart2e0fef82007-06-17 19:56:36 -05003932 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003933 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003934 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003935 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003936 struct lpfc_sli *psli;
3937 uint8_t *pcmd;
3938 uint16_t cmdsize;
3939 int rc;
3940
3941 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003942 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3943 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003944 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003945 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003946
James Smart2e0fef82007-06-17 19:56:36 -05003947 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3948 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003949 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003950 return 1;
dea31012005-04-17 16:05:31 -05003951
dea31012005-04-17 16:05:31 -05003952 icmd = &elsiocb->iocb;
3953 oldcmd = &oldiocb->iocb;
3954 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003955 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003956 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3957 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3958 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003959 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003960 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003961 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003962
James Smart92d7f7b2007-06-17 19:56:38 -05003963 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003964 rn = (RNID *) (pcmd);
3965 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003966 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3967 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3968 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003969 switch (format) {
3970 case 0:
3971 rn->SpecificLen = 0;
3972 break;
3973 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003974 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003975 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003976 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003977 rn->un.topologyDisc.unitType = RNID_HBA;
3978 rn->un.topologyDisc.physPort = 0;
3979 rn->un.topologyDisc.attachedNodes = 0;
3980 break;
3981 default:
3982 rn->CommonLen = 0;
3983 rn->SpecificLen = 0;
3984 break;
3985 }
3986
James Smart858c9f62007-06-17 19:56:39 -05003987 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3988 "Issue ACC RNID: did:x%x flg:x%x",
3989 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3990
dea31012005-04-17 16:05:31 -05003991 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003992 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003993 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003994 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3995 * it could be freed */
3996
James Smart3772a992009-05-22 14:50:54 -04003997 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003998 if (rc == IOCB_ERROR) {
3999 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004000 return 1;
dea31012005-04-17 16:05:31 -05004001 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004002 return 0;
dea31012005-04-17 16:05:31 -05004003}
4004
James Smarte59058c2008-08-24 21:49:00 -04004005/**
James Smart19ca7602010-11-20 23:11:55 -05004006 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4007 * @vport: pointer to a virtual N_Port data structure.
4008 * @iocb: pointer to the lpfc command iocb data structure.
4009 * @ndlp: pointer to a node-list data structure.
4010 *
4011 * Return
4012 **/
4013static void
4014lpfc_els_clear_rrq(struct lpfc_vport *vport,
4015 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4016{
4017 struct lpfc_hba *phba = vport->phba;
4018 uint8_t *pcmd;
4019 struct RRQ *rrq;
4020 uint16_t rxid;
4021 struct lpfc_node_rrq *prrq;
4022
4023
4024 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4025 pcmd += sizeof(uint32_t);
4026 rrq = (struct RRQ *)pcmd;
4027 rxid = bf_get(rrq_oxid, rrq);
4028
4029 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4030 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4031 " x%x x%x\n",
4032 bf_get(rrq_did, rrq),
4033 bf_get(rrq_oxid, rrq),
4034 rxid,
4035 iocb->iotag, iocb->iocb.ulpContext);
4036
4037 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4038 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4039 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4040 prrq = lpfc_get_active_rrq(vport, rxid, ndlp->nlp_DID);
4041 if (prrq)
4042 lpfc_clr_rrq_active(phba, rxid, prrq);
4043 return;
4044}
4045
4046/**
James Smart12265f62010-10-22 11:05:53 -04004047 * lpfc_els_rsp_echo_acc - Issue echo acc response
4048 * @vport: pointer to a virtual N_Port data structure.
4049 * @data: pointer to echo data to return in the accept.
4050 * @oldiocb: pointer to the original lpfc command iocb data structure.
4051 * @ndlp: pointer to a node-list data structure.
4052 *
4053 * Return code
4054 * 0 - Successfully issued acc echo response
4055 * 1 - Failed to issue acc echo response
4056 **/
4057static int
4058lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4059 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4060{
4061 struct lpfc_hba *phba = vport->phba;
4062 struct lpfc_iocbq *elsiocb;
4063 struct lpfc_sli *psli;
4064 uint8_t *pcmd;
4065 uint16_t cmdsize;
4066 int rc;
4067
4068 psli = &phba->sli;
4069 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4070
4071 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4072 ndlp->nlp_DID, ELS_CMD_ACC);
4073 if (!elsiocb)
4074 return 1;
4075
4076 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4077 /* Xmit ECHO ACC response tag <ulpIoTag> */
4078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4079 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4080 elsiocb->iotag, elsiocb->iocb.ulpContext);
4081 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4082 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4083 pcmd += sizeof(uint32_t);
4084 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4085
4086 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4087 "Issue ACC ECHO: did:x%x flg:x%x",
4088 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4089
4090 phba->fc_stat.elsXmitACC++;
4091 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4092 lpfc_nlp_put(ndlp);
4093 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4094 * it could be freed */
4095
4096 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4097 if (rc == IOCB_ERROR) {
4098 lpfc_els_free_iocb(phba, elsiocb);
4099 return 1;
4100 }
4101 return 0;
4102}
4103
4104/**
James Smart3621a712009-04-06 18:47:14 -04004105 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04004106 * @vport: pointer to a host virtual N_Port data structure.
4107 *
4108 * This routine issues Address Discover (ADISC) ELS commands to those
4109 * N_Ports which are in node port recovery state and ADISC has not been issued
4110 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4111 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4112 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4113 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4114 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4115 * IOCBs quit for later pick up. On the other hand, after walking through
4116 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4117 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4118 * no more ADISC need to be sent.
4119 *
4120 * Return code
4121 * The number of N_Ports with adisc issued.
4122 **/
dea31012005-04-17 16:05:31 -05004123int
James Smart2e0fef82007-06-17 19:56:36 -05004124lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004125{
James Smart2e0fef82007-06-17 19:56:36 -05004126 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004127 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004128 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05004129
James Smart685f0bf2007-04-25 09:53:08 -04004130 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05004131 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004132 if (!NLP_CHK_NODE_ACT(ndlp))
4133 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004134 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4135 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4136 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004137 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004138 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05004139 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004140 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004141 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4142 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004143 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05004144 vport->num_disc_nodes++;
4145 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004146 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004147 spin_lock_irq(shost->host_lock);
4148 vport->fc_flag |= FC_NLP_MORE;
4149 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004150 break;
dea31012005-04-17 16:05:31 -05004151 }
4152 }
4153 }
4154 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05004155 spin_lock_irq(shost->host_lock);
4156 vport->fc_flag &= ~FC_NLP_MORE;
4157 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004158 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004159 return sentadisc;
dea31012005-04-17 16:05:31 -05004160}
4161
James Smarte59058c2008-08-24 21:49:00 -04004162/**
James Smart3621a712009-04-06 18:47:14 -04004163 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04004164 * @vport: pointer to a host virtual N_Port data structure.
4165 *
4166 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4167 * which are in node port recovery state, with a @vport. Each time an ELS
4168 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4169 * the per @vport number of discover count (num_disc_nodes) shall be
4170 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4171 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4172 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4173 * later pick up. On the other hand, after walking through all the ndlps with
4174 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4175 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4176 * PLOGI need to be sent.
4177 *
4178 * Return code
4179 * The number of N_Ports with plogi issued.
4180 **/
dea31012005-04-17 16:05:31 -05004181int
James Smart2e0fef82007-06-17 19:56:36 -05004182lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004183{
James Smart2e0fef82007-06-17 19:56:36 -05004184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004185 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004186 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05004187
James Smart2e0fef82007-06-17 19:56:36 -05004188 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4189 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004190 if (!NLP_CHK_NODE_ACT(ndlp))
4191 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004192 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4193 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4194 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4195 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4196 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004197 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4198 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04004199 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05004200 vport->num_disc_nodes++;
4201 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04004202 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05004203 spin_lock_irq(shost->host_lock);
4204 vport->fc_flag |= FC_NLP_MORE;
4205 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04004206 break;
dea31012005-04-17 16:05:31 -05004207 }
4208 }
4209 }
James Smart87af33f2007-10-27 13:37:43 -04004210 if (sentplogi) {
4211 lpfc_set_disctmo(vport);
4212 }
4213 else {
James Smart2e0fef82007-06-17 19:56:36 -05004214 spin_lock_irq(shost->host_lock);
4215 vport->fc_flag &= ~FC_NLP_MORE;
4216 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004217 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004218 return sentplogi;
dea31012005-04-17 16:05:31 -05004219}
4220
James Smarte59058c2008-08-24 21:49:00 -04004221/**
James Smart3621a712009-04-06 18:47:14 -04004222 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04004223 * @vport: pointer to a host virtual N_Port data structure.
4224 *
4225 * This routine cleans up any Registration State Change Notification
4226 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4227 * @vport together with the host_lock is used to prevent multiple thread
4228 * trying to access the RSCN array on a same @vport at the same time.
4229 **/
James Smart92d7f7b2007-06-17 19:56:38 -05004230void
James Smart2e0fef82007-06-17 19:56:36 -05004231lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004232{
James Smart2e0fef82007-06-17 19:56:36 -05004233 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4234 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004235 int i;
4236
James Smart7f5f3d02008-02-08 18:50:14 -05004237 spin_lock_irq(shost->host_lock);
4238 if (vport->fc_rscn_flush) {
4239 /* Another thread is walking fc_rscn_id_list on this vport */
4240 spin_unlock_irq(shost->host_lock);
4241 return;
4242 }
4243 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4244 vport->fc_rscn_flush = 1;
4245 spin_unlock_irq(shost->host_lock);
4246
James Smart2e0fef82007-06-17 19:56:36 -05004247 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004248 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05004249 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05004250 }
James Smart2e0fef82007-06-17 19:56:36 -05004251 spin_lock_irq(shost->host_lock);
4252 vport->fc_rscn_id_cnt = 0;
4253 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4254 spin_unlock_irq(shost->host_lock);
4255 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05004256 /* Indicate we are done walking this fc_rscn_id_list */
4257 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004258}
4259
James Smarte59058c2008-08-24 21:49:00 -04004260/**
James Smart3621a712009-04-06 18:47:14 -04004261 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04004262 * @vport: pointer to a host virtual N_Port data structure.
4263 * @did: remote destination port identifier.
4264 *
4265 * This routine checks whether there is any pending Registration State
4266 * Configuration Notification (RSCN) to a @did on @vport.
4267 *
4268 * Return code
4269 * None zero - The @did matched with a pending rscn
4270 * 0 - not able to match @did with a pending rscn
4271 **/
dea31012005-04-17 16:05:31 -05004272int
James Smart2e0fef82007-06-17 19:56:36 -05004273lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004274{
4275 D_ID ns_did;
4276 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05004277 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05004278 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05004279 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004280
4281 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05004282
4283 /* Never match fabric nodes for RSCNs */
4284 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05004285 return 0;
dea31012005-04-17 16:05:31 -05004286
4287 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05004288 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004289 return did;
dea31012005-04-17 16:05:31 -05004290
James Smart7f5f3d02008-02-08 18:50:14 -05004291 spin_lock_irq(shost->host_lock);
4292 if (vport->fc_rscn_flush) {
4293 /* Another thread is walking fc_rscn_id_list on this vport */
4294 spin_unlock_irq(shost->host_lock);
4295 return 0;
4296 }
4297 /* Indicate we are walking fc_rscn_id_list on this vport */
4298 vport->fc_rscn_flush = 1;
4299 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05004300 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05004301 lp = vport->fc_rscn_id_list[i]->virt;
4302 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4303 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004304 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05004305 rscn_did.un.word = be32_to_cpu(*lp++);
4306 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05004307 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4308 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04004309 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4310 && (ns_did.un.b.area == rscn_did.un.b.area)
4311 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05004312 goto return_did_out;
dea31012005-04-17 16:05:31 -05004313 break;
James Smarteaf15d52008-12-04 22:39:29 -05004314 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05004315 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4316 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05004317 goto return_did_out;
dea31012005-04-17 16:05:31 -05004318 break;
James Smarteaf15d52008-12-04 22:39:29 -05004319 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05004320 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05004321 goto return_did_out;
dea31012005-04-17 16:05:31 -05004322 break;
James Smarteaf15d52008-12-04 22:39:29 -05004323 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05004324 goto return_did_out;
dea31012005-04-17 16:05:31 -05004325 }
4326 }
James Smart92d7f7b2007-06-17 19:56:38 -05004327 }
James Smart7f5f3d02008-02-08 18:50:14 -05004328 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4329 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004330 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05004331return_did_out:
4332 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4333 vport->fc_rscn_flush = 0;
4334 return did;
dea31012005-04-17 16:05:31 -05004335}
4336
James Smarte59058c2008-08-24 21:49:00 -04004337/**
James Smart3621a712009-04-06 18:47:14 -04004338 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04004339 * @vport: pointer to a host virtual N_Port data structure.
4340 *
4341 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4342 * state machine for a @vport's nodes that are with pending RSCN (Registration
4343 * State Change Notification).
4344 *
4345 * Return code
4346 * 0 - Successful (currently alway return 0)
4347 **/
dea31012005-04-17 16:05:31 -05004348static int
James Smart2e0fef82007-06-17 19:56:36 -05004349lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004350{
James Smart685f0bf2007-04-25 09:53:08 -04004351 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05004352
James Smart0d2b6b82008-06-14 22:52:47 -04004353 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05004354 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004355 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004356 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4357 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004358 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004359 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004360 NLP_EVT_DEVICE_RECOVERY);
4361 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004362 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004363 return 0;
dea31012005-04-17 16:05:31 -05004364}
4365
James Smarte59058c2008-08-24 21:49:00 -04004366/**
James Smart3621a712009-04-06 18:47:14 -04004367 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004368 * @vport: pointer to a host virtual N_Port data structure.
4369 * @cmdiocb: pointer to lpfc command iocb data structure.
4370 *
4371 * lpfc_send_rscn_event sends an RSCN netlink event to management
4372 * applications.
4373 */
4374static void
4375lpfc_send_rscn_event(struct lpfc_vport *vport,
4376 struct lpfc_iocbq *cmdiocb)
4377{
4378 struct lpfc_dmabuf *pcmd;
4379 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4380 uint32_t *payload_ptr;
4381 uint32_t payload_len;
4382 struct lpfc_rscn_event_header *rscn_event_data;
4383
4384 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4385 payload_ptr = (uint32_t *) pcmd->virt;
4386 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4387
4388 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4389 payload_len, GFP_KERNEL);
4390 if (!rscn_event_data) {
4391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4392 "0147 Failed to allocate memory for RSCN event\n");
4393 return;
4394 }
4395 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4396 rscn_event_data->payload_length = payload_len;
4397 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4398 payload_len);
4399
4400 fc_host_post_vendor_event(shost,
4401 fc_get_event_number(),
4402 sizeof(struct lpfc_els_event_header) + payload_len,
4403 (char *)rscn_event_data,
4404 LPFC_NL_VENDOR_ID);
4405
4406 kfree(rscn_event_data);
4407}
4408
4409/**
James Smart3621a712009-04-06 18:47:14 -04004410 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004411 * @vport: pointer to a host virtual N_Port data structure.
4412 * @cmdiocb: pointer to lpfc command iocb data structure.
4413 * @ndlp: pointer to a node-list data structure.
4414 *
4415 * This routine processes an unsolicited RSCN (Registration State Change
4416 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4417 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4418 * discover state machine is about to begin discovery, it just accepts the
4419 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4420 * contains N_Port IDs for other vports on this HBA, it just accepts the
4421 * RSCN and ignore processing it. If the state machine is in the recovery
4422 * state, the fc_rscn_id_list of this @vport is walked and the
4423 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4424 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4425 * routine is invoked to handle the RSCN event.
4426 *
4427 * Return code
4428 * 0 - Just sent the acc response
4429 * 1 - Sent the acc response and waited for name server completion
4430 **/
dea31012005-04-17 16:05:31 -05004431static int
James Smart2e0fef82007-06-17 19:56:36 -05004432lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004433 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004434{
James Smart2e0fef82007-06-17 19:56:36 -05004435 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4436 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004437 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004438 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004439 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004440 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004441 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004442 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004443 int i;
dea31012005-04-17 16:05:31 -05004444
4445 icmd = &cmdiocb->iocb;
4446 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4447 lp = (uint32_t *) pcmd->virt;
4448
James Smart92d7f7b2007-06-17 19:56:38 -05004449 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4450 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004451 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004452 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4453 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004454 vport->fc_flag, payload_len, *lp,
4455 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004456
4457 /* Send an RSCN event to the management application */
4458 lpfc_send_rscn_event(vport, cmdiocb);
4459
James Smartd2873e42006-08-18 17:46:43 -04004460 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004461 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004462 FCH_EVT_RSCN, lp[i]);
4463
dea31012005-04-17 16:05:31 -05004464 /* If we are about to begin discovery, just ACC the RSCN.
4465 * Discovery processing will satisfy it.
4466 */
James Smart2e0fef82007-06-17 19:56:36 -05004467 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004468 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4469 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4470 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4471
James Smart51ef4c22007-08-02 11:10:31 -04004472 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004473 return 0;
dea31012005-04-17 16:05:31 -05004474 }
4475
James Smart92d7f7b2007-06-17 19:56:38 -05004476 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4477 * just ACC and ignore it.
4478 */
4479 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004480 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004481 i = payload_len;
4482 datap = lp;
4483 while (i > 0) {
4484 nportid = *datap++;
4485 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4486 i -= sizeof(uint32_t);
4487 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004488 if (lpfc_find_vport_by_did(phba, nportid))
4489 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004490 }
4491 if (rscn_id == hba_id) {
4492 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004493 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004494 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004495 "Data: x%x x%x x%x x%x\n",
4496 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004497 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4499 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4500 ndlp->nlp_DID, vport->port_state,
4501 ndlp->nlp_flag);
4502
James Smart92d7f7b2007-06-17 19:56:38 -05004503 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004504 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004505 return 0;
4506 }
4507 }
4508
James Smart7f5f3d02008-02-08 18:50:14 -05004509 spin_lock_irq(shost->host_lock);
4510 if (vport->fc_rscn_flush) {
4511 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004512 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004513 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004514 /* Send back ACC */
4515 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004516 return 0;
4517 }
4518 /* Indicate we are walking fc_rscn_id_list on this vport */
4519 vport->fc_rscn_flush = 1;
4520 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004521 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004522 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004523 /* If we are already processing an RSCN, save the received
4524 * RSCN payload buffer, cmdiocb->context2 to process later.
4525 */
James Smart2e0fef82007-06-17 19:56:36 -05004526 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4528 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4529 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4530
James Smart09372822008-01-11 01:52:54 -05004531 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004532 vport->fc_flag |= FC_RSCN_DEFERRED;
4533 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004534 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004535 vport->fc_flag |= FC_RSCN_MODE;
4536 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004537 if (rscn_cnt) {
4538 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4539 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4540 }
4541 if ((rscn_cnt) &&
4542 (payload_len + length <= LPFC_BPL_SIZE)) {
4543 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004544 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004545 memcpy(((uint8_t *)cmd) + length, lp,
4546 payload_len);
4547 } else {
4548 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4549 vport->fc_rscn_id_cnt++;
4550 /* If we zero, cmdiocb->context2, the calling
4551 * routine will not try to free it.
4552 */
4553 cmdiocb->context2 = NULL;
4554 }
dea31012005-04-17 16:05:31 -05004555 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004556 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4557 "0235 Deferred RSCN "
4558 "Data: x%x x%x x%x\n",
4559 vport->fc_rscn_id_cnt, vport->fc_flag,
4560 vport->port_state);
dea31012005-04-17 16:05:31 -05004561 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004562 vport->fc_flag |= FC_RSCN_DISCOVERY;
4563 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004564 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004565 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4566 "0234 ReDiscovery RSCN "
4567 "Data: x%x x%x x%x\n",
4568 vport->fc_rscn_id_cnt, vport->fc_flag,
4569 vport->port_state);
dea31012005-04-17 16:05:31 -05004570 }
James Smart7f5f3d02008-02-08 18:50:14 -05004571 /* Indicate we are done walking fc_rscn_id_list on this vport */
4572 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004573 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004574 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004575 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004576 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004577 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004578 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004579 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004580 return 0;
dea31012005-04-17 16:05:31 -05004581 }
James Smart858c9f62007-06-17 19:56:39 -05004582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4583 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4584 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4585
James Smart2e0fef82007-06-17 19:56:36 -05004586 spin_lock_irq(shost->host_lock);
4587 vport->fc_flag |= FC_RSCN_MODE;
4588 spin_unlock_irq(shost->host_lock);
4589 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004590 /* Indicate we are done walking fc_rscn_id_list on this vport */
4591 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004592 /*
4593 * If we zero, cmdiocb->context2, the calling routine will
4594 * not try to free it.
4595 */
4596 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004597 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004598 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004599 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004600 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004601 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004602 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004603}
4604
James Smarte59058c2008-08-24 21:49:00 -04004605/**
James Smart3621a712009-04-06 18:47:14 -04004606 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004607 * @vport: pointer to a host virtual N_Port data structure.
4608 *
4609 * This routine handles the Registration State Configuration Notification
4610 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4611 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4612 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4613 * NameServer shall be issued. If CT command to the NameServer fails to be
4614 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4615 * RSCN activities with the @vport.
4616 *
4617 * Return code
4618 * 0 - Cleaned up rscn on the @vport
4619 * 1 - Wait for plogi to name server before proceed
4620 **/
dea31012005-04-17 16:05:31 -05004621int
James Smart2e0fef82007-06-17 19:56:36 -05004622lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004623{
4624 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004625 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004626
James Smart92d7f7b2007-06-17 19:56:38 -05004627 /* Ignore RSCN if the port is being torn down. */
4628 if (vport->load_flag & FC_UNLOADING) {
4629 lpfc_els_flush_rscn(vport);
4630 return 0;
4631 }
4632
dea31012005-04-17 16:05:31 -05004633 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004634 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004635
4636 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004637 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4638 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4639 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4640 vport->port_state);
dea31012005-04-17 16:05:31 -05004641
4642 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004643 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004644 vport->num_disc_nodes = 0;
4645
James Smart2e0fef82007-06-17 19:56:36 -05004646 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004647 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4648 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004649 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004650 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004651 /* Wait for NameServer query cmpl before we can
4652 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004653 return 1;
dea31012005-04-17 16:05:31 -05004654 } else {
4655 /* If login to NameServer does not exist, issue one */
4656 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004657 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004658 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004659 /* Wait for NameServer login cmpl before we can
4660 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004661 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004662
James Smarte47c9092008-02-08 18:49:26 -05004663 if (ndlp) {
4664 ndlp = lpfc_enable_node(vport, ndlp,
4665 NLP_STE_PLOGI_ISSUE);
4666 if (!ndlp) {
4667 lpfc_els_flush_rscn(vport);
4668 return 0;
4669 }
4670 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004671 } else {
James Smarte47c9092008-02-08 18:49:26 -05004672 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4673 if (!ndlp) {
4674 lpfc_els_flush_rscn(vport);
4675 return 0;
4676 }
James Smart2e0fef82007-06-17 19:56:36 -05004677 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004678 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004680 }
James Smarte47c9092008-02-08 18:49:26 -05004681 ndlp->nlp_type |= NLP_FABRIC;
4682 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4683 /* Wait for NameServer login cmpl before we can
4684 * continue
4685 */
4686 return 1;
dea31012005-04-17 16:05:31 -05004687 }
4688
James Smart2e0fef82007-06-17 19:56:36 -05004689 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004690 return 0;
dea31012005-04-17 16:05:31 -05004691}
4692
James Smarte59058c2008-08-24 21:49:00 -04004693/**
James Smart3621a712009-04-06 18:47:14 -04004694 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004695 * @vport: pointer to a host virtual N_Port data structure.
4696 * @cmdiocb: pointer to lpfc command iocb data structure.
4697 * @ndlp: pointer to a node-list data structure.
4698 *
4699 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4700 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4701 * point topology. As an unsolicited FLOGI should not be received in a loop
4702 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4703 * lpfc_check_sparm() routine is invoked to check the parameters in the
4704 * unsolicited FLOGI. If parameters validation failed, the routine
4705 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4706 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4707 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4708 * will initiate PLOGI. The higher lexicographical value party shall has
4709 * higher priority (as the winning port) and will initiate PLOGI and
4710 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4711 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4712 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4713 *
4714 * Return code
4715 * 0 - Successfully processed the unsolicited flogi
4716 * 1 - Failed to process the unsolicited flogi
4717 **/
dea31012005-04-17 16:05:31 -05004718static int
James Smart2e0fef82007-06-17 19:56:36 -05004719lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004720 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004721{
James Smart2e0fef82007-06-17 19:56:36 -05004722 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4723 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004724 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4725 uint32_t *lp = (uint32_t *) pcmd->virt;
4726 IOCB_t *icmd = &cmdiocb->iocb;
4727 struct serv_parm *sp;
4728 LPFC_MBOXQ_t *mbox;
4729 struct ls_rjt stat;
4730 uint32_t cmd, did;
4731 int rc;
4732
4733 cmd = *lp++;
4734 sp = (struct serv_parm *) lp;
4735
4736 /* FLOGI received */
4737
James Smart2e0fef82007-06-17 19:56:36 -05004738 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004739
James Smart76a95d72010-11-20 23:11:48 -05004740 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
dea31012005-04-17 16:05:31 -05004741 /* We should never receive a FLOGI in loop mode, ignore it */
4742 did = icmd->un.elsreq64.remoteID;
4743
4744 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4745 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004746 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4747 "0113 An FLOGI ELS command x%x was "
4748 "received from DID x%x in Loop Mode\n",
4749 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004750 return 1;
dea31012005-04-17 16:05:31 -05004751 }
4752
4753 did = Fabric_DID;
4754
James Smart341af102010-01-26 23:07:37 -05004755 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004756 /* For a FLOGI we accept, then if our portname is greater
4757 * then the remote portname we initiate Nport login.
4758 */
4759
James Smart2e0fef82007-06-17 19:56:36 -05004760 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004761 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004762
4763 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004764 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4765 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004766 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004767
dea31012005-04-17 16:05:31 -05004768 lpfc_linkdown(phba);
4769 lpfc_init_link(phba, mbox,
4770 phba->cfg_topology,
4771 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004772 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004773 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004774 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004775 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004776 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004777 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004778 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004779 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004780 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004781 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004782 spin_lock_irq(shost->host_lock);
4783 vport->fc_flag |= FC_PT2PT_PLOGI;
4784 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004785 }
James Smart2e0fef82007-06-17 19:56:36 -05004786 spin_lock_irq(shost->host_lock);
4787 vport->fc_flag |= FC_PT2PT;
4788 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4789 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004790 } else {
4791 /* Reject this request because invalid parameters */
4792 stat.un.b.lsRjtRsvd0 = 0;
4793 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4794 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4795 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004796 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4797 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004798 return 1;
dea31012005-04-17 16:05:31 -05004799 }
4800
4801 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004802 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004803
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004804 return 0;
dea31012005-04-17 16:05:31 -05004805}
4806
James Smarte59058c2008-08-24 21:49:00 -04004807/**
James Smart3621a712009-04-06 18:47:14 -04004808 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004809 * @vport: pointer to a host virtual N_Port data structure.
4810 * @cmdiocb: pointer to lpfc command iocb data structure.
4811 * @ndlp: pointer to a node-list data structure.
4812 *
4813 * This routine processes Request Node Identification Data (RNID) IOCB
4814 * received as an ELS unsolicited event. Only when the RNID specified format
4815 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4816 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4817 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4818 * rejected by invoking the lpfc_els_rsp_reject() routine.
4819 *
4820 * Return code
4821 * 0 - Successfully processed rnid iocb (currently always return 0)
4822 **/
dea31012005-04-17 16:05:31 -05004823static int
James Smart2e0fef82007-06-17 19:56:36 -05004824lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4825 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004826{
4827 struct lpfc_dmabuf *pcmd;
4828 uint32_t *lp;
4829 IOCB_t *icmd;
4830 RNID *rn;
4831 struct ls_rjt stat;
4832 uint32_t cmd, did;
4833
4834 icmd = &cmdiocb->iocb;
4835 did = icmd->un.elsreq64.remoteID;
4836 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4837 lp = (uint32_t *) pcmd->virt;
4838
4839 cmd = *lp++;
4840 rn = (RNID *) lp;
4841
4842 /* RNID received */
4843
4844 switch (rn->Format) {
4845 case 0:
4846 case RNID_TOPOLOGY_DISC:
4847 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004848 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004849 break;
4850 default:
4851 /* Reject this request because format not supported */
4852 stat.un.b.lsRjtRsvd0 = 0;
4853 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4854 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4855 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004856 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4857 NULL);
dea31012005-04-17 16:05:31 -05004858 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004859 return 0;
dea31012005-04-17 16:05:31 -05004860}
4861
James Smarte59058c2008-08-24 21:49:00 -04004862/**
James Smart12265f62010-10-22 11:05:53 -04004863 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4864 * @vport: pointer to a host virtual N_Port data structure.
4865 * @cmdiocb: pointer to lpfc command iocb data structure.
4866 * @ndlp: pointer to a node-list data structure.
4867 *
4868 * Return code
4869 * 0 - Successfully processed echo iocb (currently always return 0)
4870 **/
4871static int
4872lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4873 struct lpfc_nodelist *ndlp)
4874{
4875 uint8_t *pcmd;
4876
4877 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4878
4879 /* skip over first word of echo command to find echo data */
4880 pcmd += sizeof(uint32_t);
4881
4882 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4883 return 0;
4884}
4885
4886/**
James Smart3621a712009-04-06 18:47:14 -04004887 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004888 * @vport: pointer to a host virtual N_Port data structure.
4889 * @cmdiocb: pointer to lpfc command iocb data structure.
4890 * @ndlp: pointer to a node-list data structure.
4891 *
4892 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4893 * received as an ELS unsolicited event. Currently, this function just invokes
4894 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4895 *
4896 * Return code
4897 * 0 - Successfully processed lirr iocb (currently always return 0)
4898 **/
dea31012005-04-17 16:05:31 -05004899static int
James Smart2e0fef82007-06-17 19:56:36 -05004900lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4901 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004902{
4903 struct ls_rjt stat;
4904
4905 /* For now, unconditionally reject this command */
4906 stat.un.b.lsRjtRsvd0 = 0;
4907 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4908 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4909 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004910 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004911 return 0;
4912}
4913
James Smarte59058c2008-08-24 21:49:00 -04004914/**
James Smart5ffc2662009-11-18 15:39:44 -05004915 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4916 * @vport: pointer to a host virtual N_Port data structure.
4917 * @cmdiocb: pointer to lpfc command iocb data structure.
4918 * @ndlp: pointer to a node-list data structure.
4919 *
4920 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4921 * received as an ELS unsolicited event. A request to RRQ shall only
4922 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4923 * Nx_Port N_Port_ID of the target Exchange is the same as the
4924 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4925 * not accepted, an LS_RJT with reason code "Unable to perform
4926 * command request" and reason code explanation "Invalid Originator
4927 * S_ID" shall be returned. For now, we just unconditionally accept
4928 * RRQ from the target.
4929 **/
4930static void
4931lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4932 struct lpfc_nodelist *ndlp)
4933{
4934 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart19ca7602010-11-20 23:11:55 -05004935 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4936 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
James Smart5ffc2662009-11-18 15:39:44 -05004937}
4938
4939/**
James Smart12265f62010-10-22 11:05:53 -04004940 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4941 * @phba: pointer to lpfc hba data structure.
4942 * @pmb: pointer to the driver internal queue element for mailbox command.
4943 *
4944 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4945 * mailbox command. This callback function is to actually send the Accept
4946 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4947 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4948 * mailbox command, constructs the RPS response with the link statistics
4949 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4950 * response to the RPS.
4951 *
4952 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4953 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4954 * will be stored into the context1 field of the IOCB for the completion
4955 * callback function to the RPS Accept Response ELS IOCB command.
4956 *
4957 **/
4958static void
4959lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4960{
4961 MAILBOX_t *mb;
4962 IOCB_t *icmd;
4963 struct RLS_RSP *rls_rsp;
4964 uint8_t *pcmd;
4965 struct lpfc_iocbq *elsiocb;
4966 struct lpfc_nodelist *ndlp;
4967 uint16_t xri;
4968 uint32_t cmdsize;
4969
4970 mb = &pmb->u.mb;
4971
4972 ndlp = (struct lpfc_nodelist *) pmb->context2;
4973 xri = (uint16_t) ((unsigned long)(pmb->context1));
4974 pmb->context1 = NULL;
4975 pmb->context2 = NULL;
4976
4977 if (mb->mbxStatus) {
4978 mempool_free(pmb, phba->mbox_mem_pool);
4979 return;
4980 }
4981
4982 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4983 mempool_free(pmb, phba->mbox_mem_pool);
4984 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4985 lpfc_max_els_tries, ndlp,
4986 ndlp->nlp_DID, ELS_CMD_ACC);
4987
4988 /* Decrement the ndlp reference count from previous mbox command */
4989 lpfc_nlp_put(ndlp);
4990
4991 if (!elsiocb)
4992 return;
4993
4994 icmd = &elsiocb->iocb;
4995 icmd->ulpContext = xri;
4996
4997 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4998 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4999 pcmd += sizeof(uint32_t); /* Skip past command */
5000 rls_rsp = (struct RLS_RSP *)pcmd;
5001
5002 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5003 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5004 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5005 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5006 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5007 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5008
5009 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5010 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5011 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5012 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5013 elsiocb->iotag, elsiocb->iocb.ulpContext,
5014 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5015 ndlp->nlp_rpi);
5016 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5017 phba->fc_stat.elsXmitACC++;
5018 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5019 lpfc_els_free_iocb(phba, elsiocb);
5020}
5021
5022/**
James Smart3621a712009-04-06 18:47:14 -04005023 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04005024 * @phba: pointer to lpfc hba data structure.
5025 * @pmb: pointer to the driver internal queue element for mailbox command.
5026 *
5027 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5028 * mailbox command. This callback function is to actually send the Accept
5029 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5030 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5031 * mailbox command, constructs the RPS response with the link statistics
5032 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5033 * response to the RPS.
5034 *
5035 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5036 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5037 * will be stored into the context1 field of the IOCB for the completion
5038 * callback function to the RPS Accept Response ELS IOCB command.
5039 *
5040 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005041static void
James Smart329f9bc2007-04-25 09:53:01 -04005042lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005043{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005044 MAILBOX_t *mb;
5045 IOCB_t *icmd;
5046 RPS_RSP *rps_rsp;
5047 uint8_t *pcmd;
5048 struct lpfc_iocbq *elsiocb;
5049 struct lpfc_nodelist *ndlp;
5050 uint16_t xri, status;
5051 uint32_t cmdsize;
5052
James Smart04c68492009-05-22 14:52:52 -04005053 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005054
5055 ndlp = (struct lpfc_nodelist *) pmb->context2;
5056 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07005057 pmb->context1 = NULL;
5058 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005059
5060 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04005061 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005062 return;
5063 }
5064
5065 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04005066 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05005067 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5068 lpfc_max_els_tries, ndlp,
5069 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05005070
5071 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04005072 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05005073
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005074 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005075 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005076
5077 icmd = &elsiocb->iocb;
5078 icmd->ulpContext = xri;
5079
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5081 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005082 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005083 rps_rsp = (RPS_RSP *)pcmd;
5084
James Smart76a95d72010-11-20 23:11:48 -05005085 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005086 status = 0x10;
5087 else
5088 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05005089 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005090 status |= 0x4;
5091
5092 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05005093 rps_rsp->portStatus = cpu_to_be16(status);
5094 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5095 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5096 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5097 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5098 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5099 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005100 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005101 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5102 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5103 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5104 elsiocb->iotag, elsiocb->iocb.ulpContext,
5105 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5106 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005107 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005108 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005109 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005110 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005111 return;
5112}
5113
James Smarte59058c2008-08-24 21:49:00 -04005114/**
James Smart12265f62010-10-22 11:05:53 -04005115 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5116 * @vport: pointer to a host virtual N_Port data structure.
5117 * @cmdiocb: pointer to lpfc command iocb data structure.
5118 * @ndlp: pointer to a node-list data structure.
5119 *
5120 * This routine processes Read Port Status (RPL) IOCB received as an
5121 * ELS unsolicited event. It first checks the remote port state. If the
5122 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5123 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5124 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5125 * for reading the HBA link statistics. It is for the callback function,
5126 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5127 * to actually sending out RPL Accept (ACC) response.
5128 *
5129 * Return codes
5130 * 0 - Successfully processed rls iocb (currently always return 0)
5131 **/
5132static int
5133lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5134 struct lpfc_nodelist *ndlp)
5135{
5136 struct lpfc_hba *phba = vport->phba;
5137 LPFC_MBOXQ_t *mbox;
5138 struct lpfc_dmabuf *pcmd;
5139 struct ls_rjt stat;
5140
5141 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5142 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5143 /* reject the unsolicited RPS request and done with it */
5144 goto reject_out;
5145
5146 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5147
5148 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5149 if (mbox) {
5150 lpfc_read_lnk_stat(phba, mbox);
5151 mbox->context1 =
5152 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5153 mbox->context2 = lpfc_nlp_get(ndlp);
5154 mbox->vport = vport;
5155 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5156 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5157 != MBX_NOT_FINISHED)
5158 /* Mbox completion will send ELS Response */
5159 return 0;
5160 /* Decrement reference count used for the failed mbox
5161 * command.
5162 */
5163 lpfc_nlp_put(ndlp);
5164 mempool_free(mbox, phba->mbox_mem_pool);
5165 }
5166reject_out:
5167 /* issue rejection response */
5168 stat.un.b.lsRjtRsvd0 = 0;
5169 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5170 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5171 stat.un.b.vendorUnique = 0;
5172 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5173 return 0;
5174}
5175
5176/**
5177 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5178 * @vport: pointer to a host virtual N_Port data structure.
5179 * @cmdiocb: pointer to lpfc command iocb data structure.
5180 * @ndlp: pointer to a node-list data structure.
5181 *
5182 * This routine processes Read Timout Value (RTV) IOCB received as an
5183 * ELS unsolicited event. It first checks the remote port state. If the
5184 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5185 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5186 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5187 * Value (RTV) unsolicited IOCB event.
5188 *
5189 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5190 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5191 * will be stored into the context1 field of the IOCB for the completion
5192 * callback function to the RPS Accept Response ELS IOCB command.
5193 *
5194 * Return codes
5195 * 0 - Successfully processed rtv iocb (currently always return 0)
5196 **/
5197static int
5198lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5199 struct lpfc_nodelist *ndlp)
5200{
5201 struct lpfc_hba *phba = vport->phba;
5202 struct ls_rjt stat;
5203 struct RTV_RSP *rtv_rsp;
5204 uint8_t *pcmd;
5205 struct lpfc_iocbq *elsiocb;
5206 uint32_t cmdsize;
5207
5208
5209 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5210 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5211 /* reject the unsolicited RPS request and done with it */
5212 goto reject_out;
5213
5214 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5215 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5216 lpfc_max_els_tries, ndlp,
5217 ndlp->nlp_DID, ELS_CMD_ACC);
5218
5219 if (!elsiocb)
5220 return 1;
5221
5222 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5223 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5224 pcmd += sizeof(uint32_t); /* Skip past command */
5225
5226 /* use the command's xri in the response */
5227 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5228
5229 rtv_rsp = (struct RTV_RSP *)pcmd;
5230
5231 /* populate RTV payload */
5232 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5233 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5234 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5235 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5236 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5237
5238 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5239 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5240 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5241 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5242 "Data: x%x x%x x%x\n",
5243 elsiocb->iotag, elsiocb->iocb.ulpContext,
5244 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5245 ndlp->nlp_rpi,
5246 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5247 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5248 phba->fc_stat.elsXmitACC++;
5249 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5250 lpfc_els_free_iocb(phba, elsiocb);
5251 return 0;
5252
5253reject_out:
5254 /* issue rejection response */
5255 stat.un.b.lsRjtRsvd0 = 0;
5256 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5257 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5258 stat.un.b.vendorUnique = 0;
5259 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5260 return 0;
5261}
5262
5263/* lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04005264 * @vport: pointer to a host virtual N_Port data structure.
5265 * @cmdiocb: pointer to lpfc command iocb data structure.
5266 * @ndlp: pointer to a node-list data structure.
5267 *
5268 * This routine processes Read Port Status (RPS) IOCB received as an
5269 * ELS unsolicited event. It first checks the remote port state. If the
5270 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5271 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5272 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5273 * for reading the HBA link statistics. It is for the callback function,
5274 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5275 * to actually sending out RPS Accept (ACC) response.
5276 *
5277 * Return codes
5278 * 0 - Successfully processed rps iocb (currently always return 0)
5279 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005280static int
James Smart2e0fef82007-06-17 19:56:36 -05005281lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5282 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005283{
James Smart2e0fef82007-06-17 19:56:36 -05005284 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005285 uint32_t *lp;
5286 uint8_t flag;
5287 LPFC_MBOXQ_t *mbox;
5288 struct lpfc_dmabuf *pcmd;
5289 RPS *rps;
5290 struct ls_rjt stat;
5291
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005292 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04005293 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5294 /* reject the unsolicited RPS request and done with it */
5295 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005296
5297 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5298 lp = (uint32_t *) pcmd->virt;
5299 flag = (be32_to_cpu(*lp++) & 0xf);
5300 rps = (RPS *) lp;
5301
5302 if ((flag == 0) ||
5303 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05005304 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005305 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05005306
James Smart92d7f7b2007-06-17 19:56:38 -05005307 printk("Fix me....\n");
5308 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05005309 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5310 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005311 lpfc_read_lnk_stat(phba, mbox);
5312 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05005313 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04005314 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005315 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005316 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05005317 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04005318 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005319 /* Mbox completion will send ELS Response */
5320 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05005321 /* Decrement reference count used for the failed mbox
5322 * command.
5323 */
James Smart329f9bc2007-04-25 09:53:01 -04005324 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005325 mempool_free(mbox, phba->mbox_mem_pool);
5326 }
5327 }
James Smart90160e02008-08-24 21:49:45 -04005328
5329reject_out:
5330 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005331 stat.un.b.lsRjtRsvd0 = 0;
5332 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5333 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5334 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005335 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005336 return 0;
5337}
5338
James Smart19ca7602010-11-20 23:11:55 -05005339/* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5340 * @vport: pointer to a host virtual N_Port data structure.
5341 * @ndlp: pointer to a node-list data structure.
5342 * @did: DID of the target.
5343 * @rrq: Pointer to the rrq struct.
5344 *
5345 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5346 * Successful the the completion handler will clear the RRQ.
5347 *
5348 * Return codes
5349 * 0 - Successfully sent rrq els iocb.
5350 * 1 - Failed to send rrq els iocb.
5351 **/
5352static int
5353lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5354 uint32_t did, struct lpfc_node_rrq *rrq)
5355{
5356 struct lpfc_hba *phba = vport->phba;
5357 struct RRQ *els_rrq;
5358 IOCB_t *icmd;
5359 struct lpfc_iocbq *elsiocb;
5360 uint8_t *pcmd;
5361 uint16_t cmdsize;
5362 int ret;
5363
5364
5365 if (ndlp != rrq->ndlp)
5366 ndlp = rrq->ndlp;
5367 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5368 return 1;
5369
5370 /* If ndlp is not NULL, we will bump the reference count on it */
5371 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5372 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5373 ELS_CMD_RRQ);
5374 if (!elsiocb)
5375 return 1;
5376
5377 icmd = &elsiocb->iocb;
5378 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5379
5380 /* For RRQ request, remainder of payload is Exchange IDs */
5381 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5382 pcmd += sizeof(uint32_t);
5383 els_rrq = (struct RRQ *) pcmd;
5384
5385 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5386 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5387 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5388 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5389 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5390
5391
5392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5393 "Issue RRQ: did:x%x",
5394 did, rrq->xritag, rrq->rxid);
5395 elsiocb->context_un.rrq = rrq;
5396 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5397 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5398
5399 if (ret == IOCB_ERROR) {
5400 lpfc_els_free_iocb(phba, elsiocb);
5401 return 1;
5402 }
5403 return 0;
5404}
5405
5406/**
5407 * lpfc_send_rrq - Sends ELS RRQ if needed.
5408 * @phba: pointer to lpfc hba data structure.
5409 * @rrq: pointer to the active rrq.
5410 *
5411 * This routine will call the lpfc_issue_els_rrq if the rrq is
5412 * still active for the xri. If this function returns a failure then
5413 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5414 *
5415 * Returns 0 Success.
5416 * 1 Failure.
5417 **/
5418int
5419lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5420{
5421 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5422 rrq->nlp_DID);
5423 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5424 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5425 rrq->nlp_DID, rrq);
5426 else
5427 return 1;
5428}
5429
James Smarte59058c2008-08-24 21:49:00 -04005430/**
James Smart3621a712009-04-06 18:47:14 -04005431 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04005432 * @vport: pointer to a host virtual N_Port data structure.
5433 * @cmdsize: size of the ELS command.
5434 * @oldiocb: pointer to the original lpfc command iocb data structure.
5435 * @ndlp: pointer to a node-list data structure.
5436 *
5437 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5438 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5439 *
5440 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5441 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5442 * will be stored into the context1 field of the IOCB for the completion
5443 * callback function to the RPL Accept Response ELS command.
5444 *
5445 * Return code
5446 * 0 - Successfully issued ACC RPL ELS command
5447 * 1 - Failed to issue ACC RPL ELS command
5448 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05005449static int
James Smart2e0fef82007-06-17 19:56:36 -05005450lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5451 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005452{
James Smart2e0fef82007-06-17 19:56:36 -05005453 struct lpfc_hba *phba = vport->phba;
5454 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005455 RPL_RSP rpl_rsp;
5456 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005457 uint8_t *pcmd;
5458
James Smart2e0fef82007-06-17 19:56:36 -05005459 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5460 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005461
James Smart488d1462006-03-07 15:02:37 -05005462 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005463 return 1;
James Smart488d1462006-03-07 15:02:37 -05005464
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005465 icmd = &elsiocb->iocb;
5466 oldcmd = &oldiocb->iocb;
5467 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5468
5469 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5470 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05005471 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005472 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5473 pcmd += sizeof(uint16_t);
5474
5475 /* Setup the RPL ACC payload */
5476 rpl_rsp.listLen = be32_to_cpu(1);
5477 rpl_rsp.index = 0;
5478 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05005479 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5480 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005481 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005482 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005483 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04005484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5485 "0120 Xmit ELS RPL ACC response tag x%x "
5486 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5487 "rpi x%x\n",
5488 elsiocb->iotag, elsiocb->iocb.ulpContext,
5489 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5490 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05005491 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005492 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04005493 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5494 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005495 lpfc_els_free_iocb(phba, elsiocb);
5496 return 1;
5497 }
5498 return 0;
5499}
5500
James Smarte59058c2008-08-24 21:49:00 -04005501/**
James Smart3621a712009-04-06 18:47:14 -04005502 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04005503 * @vport: pointer to a host virtual N_Port data structure.
5504 * @cmdiocb: pointer to lpfc command iocb data structure.
5505 * @ndlp: pointer to a node-list data structure.
5506 *
5507 * This routine processes Read Port List (RPL) IOCB received as an ELS
5508 * unsolicited event. It first checks the remote port state. If the remote
5509 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5510 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5511 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5512 * to accept the RPL.
5513 *
5514 * Return code
5515 * 0 - Successfully processed rpl iocb (currently always return 0)
5516 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005517static int
James Smart2e0fef82007-06-17 19:56:36 -05005518lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5519 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005520{
5521 struct lpfc_dmabuf *pcmd;
5522 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005523 uint32_t maxsize;
5524 uint16_t cmdsize;
5525 RPL *rpl;
5526 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05005527
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005528 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5529 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04005530 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005531 stat.un.b.lsRjtRsvd0 = 0;
5532 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5533 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5534 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05005535 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5536 NULL);
James Smart90160e02008-08-24 21:49:45 -04005537 /* rejected the unsolicited RPL request and done with it */
5538 return 0;
dea31012005-04-17 16:05:31 -05005539 }
5540
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005541 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5542 lp = (uint32_t *) pcmd->virt;
5543 rpl = (RPL *) (lp + 1);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005544 maxsize = be32_to_cpu(rpl->maxsize);
5545
5546 /* We support only one port */
5547 if ((rpl->index == 0) &&
5548 ((maxsize == 0) ||
5549 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5550 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05005551 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005552 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5553 }
James Smart2e0fef82007-06-17 19:56:36 -05005554 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05005555
5556 return 0;
5557}
5558
James Smarte59058c2008-08-24 21:49:00 -04005559/**
James Smart3621a712009-04-06 18:47:14 -04005560 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04005561 * @vport: pointer to a virtual N_Port data structure.
5562 * @cmdiocb: pointer to lpfc command iocb data structure.
5563 * @ndlp: pointer to a node-list data structure.
5564 *
5565 * This routine processes Fibre Channel Address Resolution Protocol
5566 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5567 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5568 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5569 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5570 * remote PortName is compared against the FC PortName stored in the @vport
5571 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5572 * compared against the FC NodeName stored in the @vport data structure.
5573 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5574 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5575 * invoked to send out FARP Response to the remote node. Before sending the
5576 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5577 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5578 * routine is invoked to log into the remote port first.
5579 *
5580 * Return code
5581 * 0 - Either the FARP Match Mode not supported or successfully processed
5582 **/
dea31012005-04-17 16:05:31 -05005583static int
James Smart2e0fef82007-06-17 19:56:36 -05005584lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5585 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005586{
5587 struct lpfc_dmabuf *pcmd;
5588 uint32_t *lp;
5589 IOCB_t *icmd;
5590 FARP *fp;
5591 uint32_t cmd, cnt, did;
5592
5593 icmd = &cmdiocb->iocb;
5594 did = icmd->un.elsreq64.remoteID;
5595 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5596 lp = (uint32_t *) pcmd->virt;
5597
5598 cmd = *lp++;
5599 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05005600 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005601 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5602 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005603 /* We will only support match on WWPN or WWNN */
5604 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005605 return 0;
dea31012005-04-17 16:05:31 -05005606 }
5607
5608 cnt = 0;
5609 /* If this FARP command is searching for my portname */
5610 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05005611 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05005612 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005613 cnt = 1;
5614 }
5615
5616 /* If this FARP command is searching for my nodename */
5617 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05005618 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05005619 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05005620 cnt = 1;
5621 }
5622
5623 if (cnt) {
5624 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5625 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5626 /* Log back into the node before sending the FARP. */
5627 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005628 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05005629 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04005630 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05005631 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05005632 }
5633
5634 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05005635 if (fp->Rflags & FARP_REQUEST_FARPR)
5636 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05005637 }
5638 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005639 return 0;
dea31012005-04-17 16:05:31 -05005640}
5641
James Smarte59058c2008-08-24 21:49:00 -04005642/**
James Smart3621a712009-04-06 18:47:14 -04005643 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04005644 * @vport: pointer to a host virtual N_Port data structure.
5645 * @cmdiocb: pointer to lpfc command iocb data structure.
5646 * @ndlp: pointer to a node-list data structure.
5647 *
5648 * This routine processes Fibre Channel Address Resolution Protocol
5649 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5650 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5651 * the FARP response request.
5652 *
5653 * Return code
5654 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5655 **/
dea31012005-04-17 16:05:31 -05005656static int
James Smart2e0fef82007-06-17 19:56:36 -05005657lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5658 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05005659{
5660 struct lpfc_dmabuf *pcmd;
5661 uint32_t *lp;
5662 IOCB_t *icmd;
5663 uint32_t cmd, did;
5664
5665 icmd = &cmdiocb->iocb;
5666 did = icmd->un.elsreq64.remoteID;
5667 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5668 lp = (uint32_t *) pcmd->virt;
5669
5670 cmd = *lp++;
5671 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04005672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5673 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05005674 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04005675 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05005676
5677 return 0;
5678}
5679
James Smarte59058c2008-08-24 21:49:00 -04005680/**
James Smart3621a712009-04-06 18:47:14 -04005681 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04005682 * @vport: pointer to a host virtual N_Port data structure.
5683 * @cmdiocb: pointer to lpfc command iocb data structure.
5684 * @fan_ndlp: pointer to a node-list data structure.
5685 *
5686 * This routine processes a Fabric Address Notification (FAN) IOCB
5687 * command received as an ELS unsolicited event. The FAN ELS command will
5688 * only be processed on a physical port (i.e., the @vport represents the
5689 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5690 * compared against those in the phba data structure. If any of those is
5691 * different, the lpfc_initial_flogi() routine is invoked to initialize
5692 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5693 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5694 * is invoked to register login to the fabric.
5695 *
5696 * Return code
5697 * 0 - Successfully processed fan iocb (currently always return 0).
5698 **/
dea31012005-04-17 16:05:31 -05005699static int
James Smart2e0fef82007-06-17 19:56:36 -05005700lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5701 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005702{
James Smart2e0fef82007-06-17 19:56:36 -05005703 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005704 uint32_t *lp;
5705 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005706
James Smart0d2b6b82008-06-14 22:52:47 -04005707 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5708 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5709 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005710 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005711 if ((vport == phba->pport) &&
5712 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005713 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005714 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005715 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005716 sizeof(struct lpfc_name)))) {
5717 /* This port has switched fabrics. FLOGI is required */
James Smart76a95d72010-11-20 23:11:48 -05005718 lpfc_issue_init_vfi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005719 } else {
5720 /* FAN verified - skip FLOGI */
5721 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005722 if (phba->sli_rev < LPFC_SLI_REV4)
5723 lpfc_issue_fabric_reglogin(vport);
5724 else
5725 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005726 }
dea31012005-04-17 16:05:31 -05005727 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005728 return 0;
dea31012005-04-17 16:05:31 -05005729}
5730
James Smarte59058c2008-08-24 21:49:00 -04005731/**
James Smart3621a712009-04-06 18:47:14 -04005732 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005733 * @ptr: holder for the timer function associated data.
5734 *
5735 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5736 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5737 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5738 * up the worker thread. It is for the worker thread to invoke the routine
5739 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5740 **/
dea31012005-04-17 16:05:31 -05005741void
5742lpfc_els_timeout(unsigned long ptr)
5743{
James Smart2e0fef82007-06-17 19:56:36 -05005744 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5745 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005746 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005747 unsigned long iflag;
5748
James Smart2e0fef82007-06-17 19:56:36 -05005749 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005750 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5751 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005752 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005753 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005754
James Smart5e9d9b82008-06-14 22:52:53 -04005755 if (!tmo_posted)
5756 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005757 return;
5758}
5759
James Smart2a9bf3d2010-06-07 15:24:45 -04005760
James Smarte59058c2008-08-24 21:49:00 -04005761/**
James Smart3621a712009-04-06 18:47:14 -04005762 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005763 * @vport: pointer to a virtual N_Port data structure.
5764 *
5765 * This routine is the actual handler function that processes an ELS timeout
5766 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5767 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5768 * invoking the lpfc_sli_issue_abort_iotag() routine.
5769 **/
dea31012005-04-17 16:05:31 -05005770void
James Smart2e0fef82007-06-17 19:56:36 -05005771lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005772{
James Smart2e0fef82007-06-17 19:56:36 -05005773 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005774 struct lpfc_sli_ring *pring;
5775 struct lpfc_iocbq *tmp_iocb, *piocb;
5776 IOCB_t *cmd = NULL;
5777 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005778 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005779 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005780 uint32_t remote_ID = 0xffffffff;
James Smart2a9bf3d2010-06-07 15:24:45 -04005781 LIST_HEAD(txcmplq_completions);
5782 LIST_HEAD(abort_list);
dea31012005-04-17 16:05:31 -05005783
James Smart2a9bf3d2010-06-07 15:24:45 -04005784
dea31012005-04-17 16:05:31 -05005785 timeout = (uint32_t)(phba->fc_ratov << 1);
5786
5787 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005788
James Smart2a9bf3d2010-06-07 15:24:45 -04005789 spin_lock_irq(&phba->hbalock);
5790 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5791 spin_unlock_irq(&phba->hbalock);
5792
5793 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
dea31012005-04-17 16:05:31 -05005794 cmd = &piocb->iocb;
5795
James Smart2e0fef82007-06-17 19:56:36 -05005796 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5797 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5798 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005799 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005800
5801 if (piocb->vport != vport)
5802 continue;
5803
dea31012005-04-17 16:05:31 -05005804 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005805 if (pcmd)
5806 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005807
James Smart92d7f7b2007-06-17 19:56:38 -05005808 if (els_command == ELS_CMD_FARP ||
5809 els_command == ELS_CMD_FARPR ||
5810 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005811 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005812
dea31012005-04-17 16:05:31 -05005813 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005814 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005815 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005816 else
dea31012005-04-17 16:05:31 -05005817 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005818 continue;
5819 }
5820
James Smart2e0fef82007-06-17 19:56:36 -05005821 remote_ID = 0xffffffff;
5822 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005823 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005824 else {
5825 struct lpfc_nodelist *ndlp;
5826 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005827 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005828 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005829 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005830 list_add_tail(&piocb->dlist, &abort_list);
dea31012005-04-17 16:05:31 -05005831 }
James Smart2a9bf3d2010-06-07 15:24:45 -04005832 spin_lock_irq(&phba->hbalock);
5833 list_splice(&txcmplq_completions, &pring->txcmplq);
James Smart2e0fef82007-06-17 19:56:36 -05005834 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005835
James Smart2a9bf3d2010-06-07 15:24:45 -04005836 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5837 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5838 "0127 ELS timeout Data: x%x x%x x%x "
5839 "x%x\n", els_command,
5840 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5841 spin_lock_irq(&phba->hbalock);
5842 list_del_init(&piocb->dlist);
5843 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5844 spin_unlock_irq(&phba->hbalock);
5845 }
5846
James Smart2e0fef82007-06-17 19:56:36 -05005847 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5848 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005849}
5850
James Smarte59058c2008-08-24 21:49:00 -04005851/**
James Smart3621a712009-04-06 18:47:14 -04005852 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005853 * @vport: pointer to a host virtual N_Port data structure.
5854 *
5855 * This routine is used to clean up all the outstanding ELS commands on a
5856 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5857 * routine. After that, it walks the ELS transmit queue to remove all the
5858 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5859 * the IOCBs with a non-NULL completion callback function, the callback
5860 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5861 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5862 * callback function, the IOCB will simply be released. Finally, it walks
5863 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5864 * completion queue IOCB that is associated with the @vport and is not
5865 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5866 * part of the discovery state machine) out to HBA by invoking the
5867 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5868 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5869 * the IOCBs are aborted when this function returns.
5870 **/
dea31012005-04-17 16:05:31 -05005871void
James Smart2e0fef82007-06-17 19:56:36 -05005872lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005873{
James Smart2534ba72007-04-25 09:52:20 -04005874 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005875 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005876 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005877 struct lpfc_iocbq *tmp_iocb, *piocb;
5878 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005879
5880 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005881
James Smart2e0fef82007-06-17 19:56:36 -05005882 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005883 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5884 cmd = &piocb->iocb;
5885
5886 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5887 continue;
5888 }
5889
5890 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005891 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5892 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5893 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5894 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005895 continue;
dea31012005-04-17 16:05:31 -05005896
James Smart2e0fef82007-06-17 19:56:36 -05005897 if (piocb->vport != vport)
5898 continue;
5899
James Smart2534ba72007-04-25 09:52:20 -04005900 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005901 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005902 }
5903
5904 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005905 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5906 continue;
5907 }
dea31012005-04-17 16:05:31 -05005908
James Smart2e0fef82007-06-17 19:56:36 -05005909 if (piocb->vport != vport)
5910 continue;
5911
James Smart07951072007-04-25 09:51:38 -04005912 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005913 }
James Smart2e0fef82007-06-17 19:56:36 -05005914 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005915
James Smarta257bf92009-04-06 18:48:10 -04005916 /* Cancell all the IOCBs from the completions list */
5917 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5918 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005919
dea31012005-04-17 16:05:31 -05005920 return;
5921}
5922
James Smarte59058c2008-08-24 21:49:00 -04005923/**
James Smart3621a712009-04-06 18:47:14 -04005924 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005925 * @phba: pointer to lpfc hba data structure.
5926 *
5927 * This routine is used to clean up all the outstanding ELS commands on a
5928 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5929 * routine. After that, it walks the ELS transmit queue to remove all the
5930 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5931 * the IOCBs with the completion callback function associated, the callback
5932 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5933 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5934 * callback function associated, the IOCB will simply be released. Finally,
5935 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5936 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5937 * management plane IOCBs that are not part of the discovery state machine)
5938 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5939 **/
James Smart549e55c2007-08-02 11:09:51 -04005940void
5941lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5942{
5943 LIST_HEAD(completions);
5944 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5945 struct lpfc_iocbq *tmp_iocb, *piocb;
5946 IOCB_t *cmd = NULL;
5947
5948 lpfc_fabric_abort_hba(phba);
5949 spin_lock_irq(&phba->hbalock);
5950 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5951 cmd = &piocb->iocb;
5952 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5953 continue;
5954 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5955 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5956 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5957 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5958 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5959 continue;
5960 list_move_tail(&piocb->list, &completions);
5961 pring->txq_cnt--;
5962 }
5963 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5964 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5965 continue;
5966 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5967 }
5968 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005969
5970 /* Cancel all the IOCBs from the completions list */
5971 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5972 IOERR_SLI_ABORTED);
5973
James Smart549e55c2007-08-02 11:09:51 -04005974 return;
5975}
5976
James Smarte59058c2008-08-24 21:49:00 -04005977/**
James Smart3621a712009-04-06 18:47:14 -04005978 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005979 * @phba: Pointer to hba context object.
5980 * @cmdiocbp: Pointer to command iocb which reported error.
5981 * @rspiocbp: Pointer to response iocb which reported error.
5982 *
5983 * This function sends an event when there is an ELS command
5984 * failure.
5985 **/
5986void
5987lpfc_send_els_failure_event(struct lpfc_hba *phba,
5988 struct lpfc_iocbq *cmdiocbp,
5989 struct lpfc_iocbq *rspiocbp)
5990{
5991 struct lpfc_vport *vport = cmdiocbp->vport;
5992 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5993 struct lpfc_lsrjt_event lsrjt_event;
5994 struct lpfc_fabric_event_header fabric_event;
5995 struct ls_rjt stat;
5996 struct lpfc_nodelist *ndlp;
5997 uint32_t *pcmd;
5998
5999 ndlp = cmdiocbp->context1;
6000 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6001 return;
6002
6003 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6004 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6005 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6006 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6007 sizeof(struct lpfc_name));
6008 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6009 sizeof(struct lpfc_name));
6010 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6011 cmdiocbp->context2)->virt);
James Smart49198b32010-04-06 15:04:33 -04006012 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
James Smartea2151b2008-09-07 11:52:10 -04006013 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6014 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6015 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6016 fc_host_post_vendor_event(shost,
6017 fc_get_event_number(),
6018 sizeof(lsrjt_event),
6019 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05006020 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006021 return;
6022 }
6023 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6024 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6025 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6026 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6027 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6028 else
6029 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6030 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6031 sizeof(struct lpfc_name));
6032 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6033 sizeof(struct lpfc_name));
6034 fc_host_post_vendor_event(shost,
6035 fc_get_event_number(),
6036 sizeof(fabric_event),
6037 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05006038 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04006039 return;
6040 }
6041
6042}
6043
6044/**
James Smart3621a712009-04-06 18:47:14 -04006045 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04006046 * @vport: Pointer to vport object.
6047 * @ndlp: Pointer FC node object.
6048 * @cmd: ELS command code.
6049 *
6050 * This function posts an event when there is an incoming
6051 * unsolicited ELS command.
6052 **/
6053static void
6054lpfc_send_els_event(struct lpfc_vport *vport,
6055 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05006056 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04006057{
James Smartddcc50f2008-12-04 22:38:46 -05006058 struct lpfc_els_event_header *els_data = NULL;
6059 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04006060 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6061
James Smartddcc50f2008-12-04 22:38:46 -05006062 if (*payload == ELS_CMD_LOGO) {
6063 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6064 if (!logo_data) {
6065 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6066 "0148 Failed to allocate memory "
6067 "for LOGO event\n");
6068 return;
6069 }
6070 els_data = &logo_data->header;
6071 } else {
6072 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6073 GFP_KERNEL);
6074 if (!els_data) {
6075 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6076 "0149 Failed to allocate memory "
6077 "for ELS event\n");
6078 return;
6079 }
6080 }
6081 els_data->event_type = FC_REG_ELS_EVENT;
6082 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04006083 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05006084 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006085 break;
6086 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05006087 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04006088 break;
6089 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05006090 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6091 break;
6092 case ELS_CMD_LOGO:
6093 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6094 /* Copy the WWPN in the LOGO payload */
6095 memcpy(logo_data->logo_wwpn, &payload[2],
6096 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04006097 break;
6098 default:
Julia Lawalle9161412009-02-08 22:43:19 +01006099 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04006100 return;
6101 }
James Smartddcc50f2008-12-04 22:38:46 -05006102 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6103 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6104 if (*payload == ELS_CMD_LOGO) {
6105 fc_host_post_vendor_event(shost,
6106 fc_get_event_number(),
6107 sizeof(struct lpfc_logo_event),
6108 (char *)logo_data,
6109 LPFC_NL_VENDOR_ID);
6110 kfree(logo_data);
6111 } else {
6112 fc_host_post_vendor_event(shost,
6113 fc_get_event_number(),
6114 sizeof(struct lpfc_els_event_header),
6115 (char *)els_data,
6116 LPFC_NL_VENDOR_ID);
6117 kfree(els_data);
6118 }
James Smartea2151b2008-09-07 11:52:10 -04006119
6120 return;
6121}
6122
6123
6124/**
James Smart3621a712009-04-06 18:47:14 -04006125 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04006126 * @phba: pointer to lpfc hba data structure.
6127 * @pring: pointer to a SLI ring.
6128 * @vport: pointer to a host virtual N_Port data structure.
6129 * @elsiocb: pointer to lpfc els command iocb data structure.
6130 *
6131 * This routine is used for processing the IOCB associated with a unsolicited
6132 * event. It first determines whether there is an existing ndlp that matches
6133 * the DID from the unsolicited IOCB. If not, it will create a new one with
6134 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6135 * IOCB is then used to invoke the proper routine and to set up proper state
6136 * of the discovery state machine.
6137 **/
James Smarted957682007-06-17 19:56:37 -05006138static void
6139lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05006140 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05006141{
James Smart87af33f2007-10-27 13:37:43 -04006142 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05006143 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05006144 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05006145 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05006146 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05006147 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05006148
James Smarte47c9092008-02-08 18:49:26 -05006149 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05006150 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05006151
dea31012005-04-17 16:05:31 -05006152 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05006153 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6154 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05006155 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04006156 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05006157
James Smart858c9f62007-06-17 19:56:39 -05006158 did = icmd->un.rcvels.remoteID;
6159 if (icmd->ulpStatus) {
6160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6161 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6162 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05006163 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05006164 }
dea31012005-04-17 16:05:31 -05006165
6166 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05006167 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05006168 goto dropit;
dea31012005-04-17 16:05:31 -05006169
James Smartc8685952009-11-18 15:39:16 -05006170 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05006171 if (vport->load_flag & FC_UNLOADING)
6172 goto dropit;
6173
James Smart2e0fef82007-06-17 19:56:36 -05006174 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006175 if (!ndlp) {
dea31012005-04-17 16:05:31 -05006176 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05006177 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05006178 if (!ndlp)
dea31012005-04-17 16:05:31 -05006179 goto dropit;
dea31012005-04-17 16:05:31 -05006180
James Smart2e0fef82007-06-17 19:56:36 -05006181 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04006182 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05006183 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05006184 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05006185 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04006186 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6187 ndlp = lpfc_enable_node(vport, ndlp,
6188 NLP_STE_UNUSED_NODE);
6189 if (!ndlp)
6190 goto dropit;
6191 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6192 newnode = 1;
6193 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6194 ndlp->nlp_type |= NLP_FABRIC;
6195 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6196 /* This is similar to the new node path */
6197 ndlp = lpfc_nlp_get(ndlp);
6198 if (!ndlp)
6199 goto dropit;
6200 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6201 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04006202 }
dea31012005-04-17 16:05:31 -05006203
6204 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05006205
James Smart329f9bc2007-04-25 09:53:01 -04006206 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05006207 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05006208
6209 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6210 cmd &= ELS_CMD_MASK;
6211 }
6212 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006213 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6214 "0112 ELS command x%x received from NPORT x%x "
6215 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05006216 switch (cmd) {
6217 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006218 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6219 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6220 did, vport->port_state, ndlp->nlp_flag);
6221
dea31012005-04-17 16:05:31 -05006222 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05006223 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6224
James Smartddcc50f2008-12-04 22:38:46 -05006225 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05006226 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05006227 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6228 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6229 rjt_err = LSRJT_UNABLE_TPC;
6230 break;
6231 }
6232 /* We get here, and drop thru, if we are PT2PT with
6233 * another NPort and the other side has initiated
6234 * the PLOGI before responding to our FLOGI.
6235 */
dea31012005-04-17 16:05:31 -05006236 }
James Smart87af33f2007-10-27 13:37:43 -04006237
6238 shost = lpfc_shost_from_vport(vport);
6239 spin_lock_irq(shost->host_lock);
6240 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6241 spin_unlock_irq(shost->host_lock);
6242
James Smart2e0fef82007-06-17 19:56:36 -05006243 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6244 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05006245
dea31012005-04-17 16:05:31 -05006246 break;
6247 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05006248 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6249 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6250 did, vport->port_state, ndlp->nlp_flag);
6251
dea31012005-04-17 16:05:31 -05006252 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04006253 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006254 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006255 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006256 break;
6257 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05006258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6259 "RCV LOGO: 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.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05006263 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006264 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006265 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006266 break;
6267 }
James Smart2e0fef82007-06-17 19:56:36 -05006268 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05006269 break;
6270 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05006271 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6272 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6273 did, vport->port_state, ndlp->nlp_flag);
6274
dea31012005-04-17 16:05:31 -05006275 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05006276 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05006277 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006278 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006279 break;
6280 }
James Smart2e0fef82007-06-17 19:56:36 -05006281 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05006282 break;
6283 case ELS_CMD_RSCN:
6284 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04006285 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006286 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006287 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006288 break;
6289 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05006290 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6291 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6292 did, vport->port_state, ndlp->nlp_flag);
6293
James Smartddcc50f2008-12-04 22:38:46 -05006294 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05006295 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006296 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006297 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006298 break;
6299 }
James Smart2e0fef82007-06-17 19:56:36 -05006300 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6301 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05006302 break;
6303 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05006304 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6305 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6306 did, vport->port_state, ndlp->nlp_flag);
6307
dea31012005-04-17 16:05:31 -05006308 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05006309 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006310 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006311 break;
6312 }
James Smart2e0fef82007-06-17 19:56:36 -05006313 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6314 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05006315 break;
6316 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05006317 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6318 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6319 did, vport->port_state, ndlp->nlp_flag);
6320
dea31012005-04-17 16:05:31 -05006321 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05006322 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006323 break;
6324 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05006325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6326 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6327 did, vport->port_state, ndlp->nlp_flag);
6328
dea31012005-04-17 16:05:31 -05006329 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05006330 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006331 break;
6332 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05006333 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6334 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6335 did, vport->port_state, ndlp->nlp_flag);
6336
dea31012005-04-17 16:05:31 -05006337 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05006338 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05006339 break;
dea31012005-04-17 16:05:31 -05006340 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05006341 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6342 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6343 did, vport->port_state, ndlp->nlp_flag);
6344
dea31012005-04-17 16:05:31 -05006345 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05006346 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05006347 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05006348 break;
6349 }
James Smart2e0fef82007-06-17 19:56:36 -05006350 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05006351 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006352 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05006353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6354 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6355 did, vport->port_state, ndlp->nlp_flag);
6356
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006357 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05006358 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006359 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006360 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006361 break;
James Smart12265f62010-10-22 11:05:53 -04006362 case ELS_CMD_RLS:
6363 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6364 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6365 did, vport->port_state, ndlp->nlp_flag);
6366
6367 phba->fc_stat.elsRcvRLS++;
6368 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6369 if (newnode)
6370 lpfc_nlp_put(ndlp);
6371 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006372 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05006373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6374 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6375 did, vport->port_state, ndlp->nlp_flag);
6376
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006377 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05006378 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04006379 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006380 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05006381 break;
6382 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05006383 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6384 "RCV RPL: 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.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05006388 lpfc_els_rcv_rpl(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;
dea31012005-04-17 16:05:31 -05006392 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05006393 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6394 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6395 did, vport->port_state, ndlp->nlp_flag);
6396
dea31012005-04-17 16:05:31 -05006397 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05006398 lpfc_els_rcv_rnid(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);
dea31012005-04-17 16:05:31 -05006401 break;
James Smart12265f62010-10-22 11:05:53 -04006402 case ELS_CMD_RTV:
6403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6404 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6405 did, vport->port_state, ndlp->nlp_flag);
6406 phba->fc_stat.elsRcvRTV++;
6407 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6408 if (newnode)
6409 lpfc_nlp_put(ndlp);
6410 break;
James Smart5ffc2662009-11-18 15:39:44 -05006411 case ELS_CMD_RRQ:
6412 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6413 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6414 did, vport->port_state, ndlp->nlp_flag);
6415
6416 phba->fc_stat.elsRcvRRQ++;
6417 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6418 if (newnode)
6419 lpfc_nlp_put(ndlp);
6420 break;
James Smart12265f62010-10-22 11:05:53 -04006421 case ELS_CMD_ECHO:
6422 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6423 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6424 did, vport->port_state, ndlp->nlp_flag);
6425
6426 phba->fc_stat.elsRcvECHO++;
6427 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6428 if (newnode)
6429 lpfc_nlp_put(ndlp);
6430 break;
dea31012005-04-17 16:05:31 -05006431 default:
James Smart858c9f62007-06-17 19:56:39 -05006432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6433 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6434 cmd, did, vport->port_state);
6435
dea31012005-04-17 16:05:31 -05006436 /* Unsupported ELS command, reject */
James Smart63e801c2010-11-20 23:14:19 -05006437 rjt_err = LSRJT_CMD_UNSUPPORTED;
dea31012005-04-17 16:05:31 -05006438
6439 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04006440 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6441 "0115 Unknown ELS command x%x "
6442 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04006443 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04006444 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05006445 break;
6446 }
6447
6448 /* check if need to LS_RJT received ELS cmd */
6449 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05006450 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05006451 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04006452 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05006453 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6454 NULL);
dea31012005-04-17 16:05:31 -05006455 }
6456
James Smartd7c255b2008-08-24 21:50:00 -04006457 lpfc_nlp_put(elsiocb->context1);
6458 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05006459 return;
6460
6461dropit:
James Smart98c9ea52007-10-27 13:37:33 -04006462 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04006463 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6464 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05006465 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04006466 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05006467 phba->fc_stat.elsRcvDrop++;
6468}
6469
James Smarte59058c2008-08-24 21:49:00 -04006470/**
James Smart3621a712009-04-06 18:47:14 -04006471 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04006472 * @phba: pointer to lpfc hba data structure.
6473 * @vpi: host virtual N_Port identifier.
6474 *
6475 * This routine finds a vport on a HBA (referred by @phba) through a
6476 * @vpi. The function walks the HBA's vport list and returns the address
6477 * of the vport with the matching @vpi.
6478 *
6479 * Return code
6480 * NULL - No vport with the matching @vpi found
6481 * Otherwise - Address to the vport with the matching @vpi.
6482 **/
James Smart6669f9b2009-10-02 15:16:45 -04006483struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05006484lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6485{
6486 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04006487 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05006488
James Smart549e55c2007-08-02 11:09:51 -04006489 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006490 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04006491 if (vport->vpi == vpi) {
6492 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006493 return vport;
James Smart549e55c2007-08-02 11:09:51 -04006494 }
James Smart92d7f7b2007-06-17 19:56:38 -05006495 }
James Smart549e55c2007-08-02 11:09:51 -04006496 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05006497 return NULL;
6498}
James Smarted957682007-06-17 19:56:37 -05006499
James Smarte59058c2008-08-24 21:49:00 -04006500/**
James Smart3621a712009-04-06 18:47:14 -04006501 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04006502 * @phba: pointer to lpfc hba data structure.
6503 * @pring: pointer to a SLI ring.
6504 * @elsiocb: pointer to lpfc els iocb data structure.
6505 *
6506 * This routine is used to process an unsolicited event received from a SLI
6507 * (Service Level Interface) ring. The actual processing of the data buffer
6508 * associated with the unsolicited event is done by invoking the routine
6509 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6510 * SLI ring on which the unsolicited event was received.
6511 **/
James Smarted957682007-06-17 19:56:37 -05006512void
6513lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6514 struct lpfc_iocbq *elsiocb)
6515{
6516 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05006517 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05006518 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05006519 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6520 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05006521
James Smartd7c255b2008-08-24 21:50:00 -04006522 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05006523 elsiocb->context2 = NULL;
6524 elsiocb->context3 = NULL;
6525
6526 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6527 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6528 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6529 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05006530 phba->fc_stat.NoRcvBuf++;
6531 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05006532 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04006533 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05006534 return;
6535 }
6536
James Smart92d7f7b2007-06-17 19:56:38 -05006537 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6538 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6539 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6540 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6541 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04006542 else
6543 vport = lpfc_find_vport_by_vpid(phba,
6544 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05006545 }
James Smart7f5f3d02008-02-08 18:50:14 -05006546 /* If there are no BDEs associated
6547 * with this IOCB, there is nothing to do.
6548 */
James Smarted957682007-06-17 19:56:37 -05006549 if (icmd->ulpBdeCount == 0)
6550 return;
6551
James Smart7f5f3d02008-02-08 18:50:14 -05006552 /* type of ELS cmd is first 32bit word
6553 * in packet
6554 */
James Smarted957682007-06-17 19:56:37 -05006555 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05006556 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05006557 } else {
6558 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6559 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05006560 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6561 paddr);
James Smarted957682007-06-17 19:56:37 -05006562 }
6563
James Smart92d7f7b2007-06-17 19:56:38 -05006564 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6565 /*
6566 * The different unsolicited event handlers would tell us
6567 * if they are done with "mp" by setting context2 to NULL.
6568 */
dea31012005-04-17 16:05:31 -05006569 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006570 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6571 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05006572 }
James Smarted957682007-06-17 19:56:37 -05006573
6574 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05006575 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05006576 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006577 elsiocb->context2 = bdeBuf2;
6578 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05006579 /* free mp if we are done with it */
6580 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05006581 lpfc_in_buf_free(phba, elsiocb->context2);
6582 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05006583 }
dea31012005-04-17 16:05:31 -05006584 }
dea31012005-04-17 16:05:31 -05006585}
James Smart92d7f7b2007-06-17 19:56:38 -05006586
James Smarte59058c2008-08-24 21:49:00 -04006587/**
James Smart3621a712009-04-06 18:47:14 -04006588 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04006589 * @phba: pointer to lpfc hba data structure.
6590 * @vport: pointer to a virtual N_Port data structure.
6591 *
6592 * This routine issues a Port Login (PLOGI) to the Name Server with
6593 * State Change Request (SCR) for a @vport. This routine will create an
6594 * ndlp for the Name Server associated to the @vport if such node does
6595 * not already exist. The PLOGI to Name Server is issued by invoking the
6596 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6597 * (FDMI) is configured to the @vport, a FDMI node will be created and
6598 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6599 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006600void
6601lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6602{
6603 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6604
6605 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6606 if (!ndlp) {
6607 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6608 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006609 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05006610 lpfc_disc_start(vport);
6611 return;
6612 }
6613 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006614 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6615 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006616 return;
6617 }
6618 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05006619 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6620 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6621 if (!ndlp) {
James Smart76a95d72010-11-20 23:11:48 -05006622 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smarte47c9092008-02-08 18:49:26 -05006623 lpfc_disc_start(vport);
6624 return;
6625 }
6626 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6627 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6628 "0348 NameServer login: node freed\n");
6629 return;
6630 }
James Smart92d7f7b2007-06-17 19:56:38 -05006631 }
James Smart58da1ff2008-04-07 10:15:56 -04006632 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05006633
6634 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6635
6636 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6637 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006638 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6639 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006640 return;
6641 }
6642
James Smart3de2a652007-08-02 11:09:59 -04006643 if (vport->cfg_fdmi_on) {
James Smart63e801c2010-11-20 23:14:19 -05006644 /* If this is the first time, allocate an ndlp and initialize
6645 * it. Otherwise, make sure the node is enabled and then do the
6646 * login.
6647 */
6648 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6649 if (!ndlp_fdmi) {
6650 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6651 GFP_KERNEL);
6652 if (ndlp_fdmi) {
6653 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6654 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6655 } else
6656 return;
6657 }
6658 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6659 ndlp_fdmi = lpfc_enable_node(vport,
6660 ndlp_fdmi,
6661 NLP_STE_NPR_NODE);
6662
James Smart92d7f7b2007-06-17 19:56:38 -05006663 if (ndlp_fdmi) {
James Smart58da1ff2008-04-07 10:15:56 -04006664 lpfc_nlp_set_state(vport, ndlp_fdmi,
James Smart63e801c2010-11-20 23:14:19 -05006665 NLP_STE_PLOGI_ISSUE);
6666 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006667 }
6668 }
James Smart92d7f7b2007-06-17 19:56:38 -05006669}
6670
James Smarte59058c2008-08-24 21:49:00 -04006671/**
James Smart3621a712009-04-06 18:47:14 -04006672 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04006673 * @phba: pointer to lpfc hba data structure.
6674 * @pmb: pointer to the driver internal queue element for mailbox command.
6675 *
6676 * This routine is the completion callback function to register new vport
6677 * mailbox command. If the new vport mailbox command completes successfully,
6678 * the fabric registration login shall be performed on physical port (the
6679 * new vport created is actually a physical port, with VPI 0) or the port
6680 * login to Name Server for State Change Request (SCR) will be performed
6681 * on virtual port (real virtual port, with VPI greater than 0).
6682 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006683static void
6684lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6685{
6686 struct lpfc_vport *vport = pmb->vport;
6687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6688 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04006689 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05006690 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006691
James Smart09372822008-01-11 01:52:54 -05006692 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006693 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006694 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006695
6696 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04006697 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
James Smart38b92ef2010-08-04 16:11:39 -04006698 "0915 Register VPI failed : Status: x%x"
6699 " upd bit: x%x \n", mb->mbxStatus,
6700 mb->un.varRegVpi.upd);
6701 if (phba->sli_rev == LPFC_SLI_REV4 &&
6702 mb->un.varRegVpi.upd)
6703 goto mbox_err_exit ;
James Smart92d7f7b2007-06-17 19:56:38 -05006704
6705 switch (mb->mbxStatus) {
6706 case 0x11: /* unsupported feature */
6707 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05006708 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05006709 /* giving up on vport registration */
6710 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6711 spin_lock_irq(shost->host_lock);
6712 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6713 spin_unlock_irq(shost->host_lock);
6714 lpfc_can_disctmo(vport);
6715 break;
James Smart695a8142010-01-26 23:08:03 -05006716 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6717 case 0x20:
6718 spin_lock_irq(shost->host_lock);
6719 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6720 spin_unlock_irq(shost->host_lock);
6721 lpfc_init_vpi(phba, pmb, vport->vpi);
6722 pmb->vport = vport;
6723 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6724 rc = lpfc_sli_issue_mbox(phba, pmb,
6725 MBX_NOWAIT);
6726 if (rc == MBX_NOT_FINISHED) {
6727 lpfc_printf_vlog(vport,
6728 KERN_ERR, LOG_MBOX,
6729 "2732 Failed to issue INIT_VPI"
6730 " mailbox command\n");
6731 } else {
6732 lpfc_nlp_put(ndlp);
6733 return;
6734 }
6735
James Smart92d7f7b2007-06-17 19:56:38 -05006736 default:
6737 /* Try to recover from this error */
James Smart5af5eee2010-10-22 11:06:38 -04006738 if (phba->sli_rev == LPFC_SLI_REV4)
6739 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006740 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05006741 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006742 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05006743 spin_unlock_irq(shost->host_lock);
James Smart4b40c592010-03-15 11:25:44 -04006744 if (vport->port_type == LPFC_PHYSICAL_PORT
6745 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
James Smart76a95d72010-11-20 23:11:48 -05006746 lpfc_issue_init_vfi(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05006747 else
6748 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006749 break;
6750 }
James Smart92d7f7b2007-06-17 19:56:38 -05006751 } else {
James Smart695a8142010-01-26 23:08:03 -05006752 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05006753 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05006754 spin_unlock_irq(shost->host_lock);
6755 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04006756 if (phba->sli_rev < LPFC_SLI_REV4)
6757 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05006758 else {
James Smartfc2b9892010-02-26 14:15:29 -05006759 /*
6760 * If the physical port is instantiated using
6761 * FDISC, do not start vport discovery.
6762 */
6763 if (vport->port_state != LPFC_FDISC)
6764 lpfc_start_fdiscs(phba);
James Smart695a8142010-01-26 23:08:03 -05006765 lpfc_do_scr_ns_plogi(phba, vport);
6766 }
6767 } else
James Smart92d7f7b2007-06-17 19:56:38 -05006768 lpfc_do_scr_ns_plogi(phba, vport);
6769 }
James Smart38b92ef2010-08-04 16:11:39 -04006770mbox_err_exit:
James Smartfa4066b2008-01-11 01:53:27 -05006771 /* Now, we decrement the ndlp reference count held for this
6772 * callback function
6773 */
6774 lpfc_nlp_put(ndlp);
6775
James Smart92d7f7b2007-06-17 19:56:38 -05006776 mempool_free(pmb, phba->mbox_mem_pool);
6777 return;
6778}
6779
James Smarte59058c2008-08-24 21:49:00 -04006780/**
James Smart3621a712009-04-06 18:47:14 -04006781 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006782 * @phba: pointer to lpfc hba data structure.
6783 * @vport: pointer to a host virtual N_Port data structure.
6784 * @ndlp: pointer to a node-list data structure.
6785 *
6786 * This routine registers the @vport as a new virtual port with a HBA.
6787 * It is done through a registering vpi mailbox command.
6788 **/
James Smart695a8142010-01-26 23:08:03 -05006789void
James Smart92d7f7b2007-06-17 19:56:38 -05006790lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6791 struct lpfc_nodelist *ndlp)
6792{
James Smart09372822008-01-11 01:52:54 -05006793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006794 LPFC_MBOXQ_t *mbox;
6795
6796 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6797 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006798 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006799 mbox->vport = vport;
6800 mbox->context2 = lpfc_nlp_get(ndlp);
6801 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006802 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006803 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006804 /* mailbox command not success, decrement ndlp
6805 * reference count for this command
6806 */
6807 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006808 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006809
James Smarte8b62012007-08-02 11:10:09 -04006810 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6811 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006812 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006813 }
6814 } else {
James Smarte8b62012007-08-02 11:10:09 -04006815 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6816 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006817 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006818 }
James Smartfa4066b2008-01-11 01:53:27 -05006819 return;
6820
6821mbox_err_exit:
6822 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6823 spin_lock_irq(shost->host_lock);
6824 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6825 spin_unlock_irq(shost->host_lock);
6826 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006827}
6828
James Smarte59058c2008-08-24 21:49:00 -04006829/**
James Smart0c9ab6f2010-02-26 14:15:57 -05006830 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
James Smart695a8142010-01-26 23:08:03 -05006831 * @phba: pointer to lpfc hba data structure.
6832 *
James Smart0c9ab6f2010-02-26 14:15:57 -05006833 * This routine cancels the retry delay timers to all the vports.
James Smart695a8142010-01-26 23:08:03 -05006834 **/
6835void
James Smart0c9ab6f2010-02-26 14:15:57 -05006836lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
James Smart695a8142010-01-26 23:08:03 -05006837{
6838 struct lpfc_vport **vports;
6839 struct lpfc_nodelist *ndlp;
James Smart695a8142010-01-26 23:08:03 -05006840 uint32_t link_state;
James Smart0c9ab6f2010-02-26 14:15:57 -05006841 int i;
James Smart695a8142010-01-26 23:08:03 -05006842
6843 /* Treat this failure as linkdown for all vports */
6844 link_state = phba->link_state;
6845 lpfc_linkdown(phba);
6846 phba->link_state = link_state;
6847
6848 vports = lpfc_create_vport_work_array(phba);
6849
6850 if (vports) {
6851 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6852 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6853 if (ndlp)
6854 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6855 lpfc_els_flush_cmd(vports[i]);
6856 }
6857 lpfc_destroy_vport_work_array(phba, vports);
6858 }
James Smart0c9ab6f2010-02-26 14:15:57 -05006859}
6860
6861/**
6862 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6863 * @phba: pointer to lpfc hba data structure.
6864 *
6865 * This routine abort all pending discovery commands and
6866 * start a timer to retry FLOGI for the physical port
6867 * discovery.
6868 **/
6869void
6870lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6871{
6872 struct lpfc_nodelist *ndlp;
6873 struct Scsi_Host *shost;
6874
6875 /* Cancel the all vports retry delay retry timers */
6876 lpfc_cancel_all_vport_retry_delay_timer(phba);
James Smart695a8142010-01-26 23:08:03 -05006877
6878 /* If fabric require FLOGI, then re-instantiate physical login */
6879 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6880 if (!ndlp)
6881 return;
6882
James Smart695a8142010-01-26 23:08:03 -05006883 shost = lpfc_shost_from_vport(phba->pport);
6884 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6885 spin_lock_irq(shost->host_lock);
6886 ndlp->nlp_flag |= NLP_DELAY_TMO;
6887 spin_unlock_irq(shost->host_lock);
6888 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6889 phba->pport->port_state = LPFC_FLOGI;
6890 return;
6891}
6892
6893/**
6894 * lpfc_fabric_login_reqd - Check if FLOGI required.
6895 * @phba: pointer to lpfc hba data structure.
6896 * @cmdiocb: pointer to FDISC command iocb.
6897 * @rspiocb: pointer to FDISC response iocb.
6898 *
6899 * This routine checks if a FLOGI is reguired for FDISC
6900 * to succeed.
6901 **/
6902static int
6903lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6904 struct lpfc_iocbq *cmdiocb,
6905 struct lpfc_iocbq *rspiocb)
6906{
6907
6908 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6909 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6910 return 0;
6911 else
6912 return 1;
6913}
6914
6915/**
James Smart3621a712009-04-06 18:47:14 -04006916 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006917 * @phba: pointer to lpfc hba data structure.
6918 * @cmdiocb: pointer to lpfc command iocb data structure.
6919 * @rspiocb: pointer to lpfc response iocb data structure.
6920 *
6921 * This routine is the completion callback function to a Fabric Discover
6922 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6923 * single threaded, each FDISC completion callback function will reset
6924 * the discovery timer for all vports such that the timers will not get
6925 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6926 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6927 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6928 * assigned to the vport has been changed with the completion of the FDISC
6929 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6930 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6931 * routine is invoked to register new vport with the HBA. Otherwise, the
6932 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6933 * Server for State Change Request (SCR).
6934 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006935static void
6936lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6937 struct lpfc_iocbq *rspiocb)
6938{
6939 struct lpfc_vport *vport = cmdiocb->vport;
6940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6941 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6942 struct lpfc_nodelist *np;
6943 struct lpfc_nodelist *next_np;
6944 IOCB_t *irsp = &rspiocb->iocb;
6945 struct lpfc_iocbq *piocb;
6946
James Smarte8b62012007-08-02 11:10:09 -04006947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6948 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6949 irsp->ulpStatus, irsp->un.ulpWord[4],
6950 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006951 /* Since all FDISCs are being single threaded, we
6952 * must reset the discovery timer for ALL vports
6953 * waiting to send FDISC when one completes.
6954 */
6955 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6956 lpfc_set_disctmo(piocb->vport);
6957 }
6958
James Smart858c9f62007-06-17 19:56:39 -05006959 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6960 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6961 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6962
James Smart92d7f7b2007-06-17 19:56:38 -05006963 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006964
6965 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6966 lpfc_retry_pport_discovery(phba);
6967 goto out;
6968 }
6969
James Smart92d7f7b2007-06-17 19:56:38 -05006970 /* Check for retry */
6971 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6972 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006973 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006974 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006975 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006976 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006977 goto fdisc_failed;
6978 }
James Smartd7c255b2008-08-24 21:50:00 -04006979 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006980 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smart4b40c592010-03-15 11:25:44 -04006981 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006982 vport->fc_flag |= FC_FABRIC;
James Smart76a95d72010-11-20 23:11:48 -05006983 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
James Smartd7c255b2008-08-24 21:50:00 -04006984 vport->fc_flag |= FC_PUBLIC_LOOP;
6985 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006986
James Smartd7c255b2008-08-24 21:50:00 -04006987 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6988 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6989 if ((vport->fc_prevDID != vport->fc_myDID) &&
6990 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6991 /* If our NportID changed, we need to ensure all
6992 * remaining NPORTs get unreg_login'ed so we can
6993 * issue unreg_vpi.
6994 */
6995 list_for_each_entry_safe(np, next_np,
6996 &vport->fc_nodes, nlp_listp) {
6997 if (!NLP_CHK_NODE_ACT(ndlp) ||
6998 (np->nlp_state != NLP_STE_NPR_NODE) ||
6999 !(np->nlp_flag & NLP_NPR_ADISC))
7000 continue;
James Smart09372822008-01-11 01:52:54 -05007001 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007002 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05007003 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04007004 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05007005 }
James Smart78730cf2010-04-06 15:06:30 -04007006 lpfc_cleanup_pending_mbox(vport);
James Smart5af5eee2010-10-22 11:06:38 -04007007
7008 if (phba->sli_rev == LPFC_SLI_REV4)
7009 lpfc_sli4_unreg_all_rpis(vport);
7010
James Smartd7c255b2008-08-24 21:50:00 -04007011 lpfc_mbx_unreg_vpi(vport);
7012 spin_lock_irq(shost->host_lock);
7013 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart0f65ff62010-02-26 14:14:23 -05007014 if (phba->sli_rev == LPFC_SLI_REV4)
7015 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smart4b40c592010-03-15 11:25:44 -04007016 else
7017 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
James Smartd7c255b2008-08-24 21:50:00 -04007018 spin_unlock_irq(shost->host_lock);
James Smart38b92ef2010-08-04 16:11:39 -04007019 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7020 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7021 /*
7022 * Driver needs to re-reg VPI in order for f/w
7023 * to update the MAC address.
7024 */
7025 lpfc_register_new_vport(phba, vport, ndlp);
James Smart5ac6b302010-10-22 11:05:36 -04007026 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05007027 }
7028
James Smartecfd03c2010-02-12 14:41:27 -05007029 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7030 lpfc_issue_init_vpi(vport);
7031 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04007032 lpfc_register_new_vport(phba, vport, ndlp);
7033 else
7034 lpfc_do_scr_ns_plogi(phba, vport);
7035 goto out;
7036fdisc_failed:
7037 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7038 /* Cancel discovery timer */
7039 lpfc_can_disctmo(vport);
7040 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007041out:
7042 lpfc_els_free_iocb(phba, cmdiocb);
7043}
7044
James Smarte59058c2008-08-24 21:49:00 -04007045/**
James Smart3621a712009-04-06 18:47:14 -04007046 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04007047 * @vport: pointer to a virtual N_Port data structure.
7048 * @ndlp: pointer to a node-list data structure.
7049 * @retry: number of retries to the command IOCB.
7050 *
7051 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7052 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7053 * routine to issue the IOCB, which makes sure only one outstanding fabric
7054 * IOCB will be sent off HBA at any given time.
7055 *
7056 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7057 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7058 * will be stored into the context1 field of the IOCB for the completion
7059 * callback function to the FDISC ELS command.
7060 *
7061 * Return code
7062 * 0 - Successfully issued fdisc iocb command
7063 * 1 - Failed to issue fdisc iocb command
7064 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007065static int
James Smart92d7f7b2007-06-17 19:56:38 -05007066lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7067 uint8_t retry)
7068{
7069 struct lpfc_hba *phba = vport->phba;
7070 IOCB_t *icmd;
7071 struct lpfc_iocbq *elsiocb;
7072 struct serv_parm *sp;
7073 uint8_t *pcmd;
7074 uint16_t cmdsize;
7075 int did = ndlp->nlp_DID;
7076 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05007077
James Smart5ffc2662009-11-18 15:39:44 -05007078 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05007079 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7080 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7081 ELS_CMD_FDISC);
7082 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05007083 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007084 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7085 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007086 return 1;
7087 }
7088
7089 icmd = &elsiocb->iocb;
7090 icmd->un.elsreq64.myID = 0;
7091 icmd->un.elsreq64.fl = 1;
7092
James Smartf1126682009-06-10 17:22:44 -04007093 if (phba->sli_rev == LPFC_SLI_REV4) {
7094 /* FDISC needs to be 1 for WQE VPI */
7095 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7096 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7097 /* Set the ulpContext to the vpi */
7098 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
7099 } else {
7100 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7101 icmd->ulpCt_h = 1;
7102 icmd->ulpCt_l = 0;
7103 }
James Smart92d7f7b2007-06-17 19:56:38 -05007104
7105 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7106 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7107 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7108 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7109 sp = (struct serv_parm *) pcmd;
7110 /* Setup CSPs accordingly for Fabric */
7111 sp->cmn.e_d_tov = 0;
7112 sp->cmn.w2.r_a_tov = 0;
7113 sp->cls1.classValid = 0;
7114 sp->cls2.seqDelivery = 1;
7115 sp->cls3.seqDelivery = 1;
7116
7117 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7118 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7119 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7120 pcmd += sizeof(uint32_t); /* Port Name */
7121 memcpy(pcmd, &vport->fc_portname, 8);
7122 pcmd += sizeof(uint32_t); /* Node Name */
7123 pcmd += sizeof(uint32_t); /* Node Name */
7124 memcpy(pcmd, &vport->fc_nodename, 8);
7125
7126 lpfc_set_disctmo(vport);
7127
7128 phba->fc_stat.elsXmitFDISC++;
7129 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7130
James Smart858c9f62007-06-17 19:56:39 -05007131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7132 "Issue FDISC: did:x%x",
7133 did, 0, 0);
7134
James Smart92d7f7b2007-06-17 19:56:38 -05007135 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7136 if (rc == IOCB_ERROR) {
7137 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05007138 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04007139 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7140 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05007141 return 1;
7142 }
7143 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05007144 return 0;
7145}
7146
James Smarte59058c2008-08-24 21:49:00 -04007147/**
James Smart3621a712009-04-06 18:47:14 -04007148 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04007149 * @phba: pointer to lpfc hba data structure.
7150 * @cmdiocb: pointer to lpfc command iocb data structure.
7151 * @rspiocb: pointer to lpfc response iocb data structure.
7152 *
7153 * This routine is the completion callback function to the issuing of a LOGO
7154 * ELS command off a vport. It frees the command IOCB and then decrement the
7155 * reference count held on ndlp for this completion function, indicating that
7156 * the reference to the ndlp is no long needed. Note that the
7157 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7158 * callback function and an additional explicit ndlp reference decrementation
7159 * will trigger the actual release of the ndlp.
7160 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007161static void
7162lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7163 struct lpfc_iocbq *rspiocb)
7164{
7165 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05007166 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05007167 struct lpfc_nodelist *ndlp;
7168 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05007169
7170 irsp = &rspiocb->iocb;
7171 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7172 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7173 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05007174
7175 lpfc_els_free_iocb(phba, cmdiocb);
7176 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05007177
7178 /* Trigger the release of the ndlp after logo */
7179 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05007180}
7181
James Smarte59058c2008-08-24 21:49:00 -04007182/**
James Smart3621a712009-04-06 18:47:14 -04007183 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04007184 * @vport: pointer to a virtual N_Port data structure.
7185 * @ndlp: pointer to a node-list data structure.
7186 *
7187 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7188 *
7189 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7190 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7191 * will be stored into the context1 field of the IOCB for the completion
7192 * callback function to the LOGO ELS command.
7193 *
7194 * Return codes
7195 * 0 - Successfully issued logo off the @vport
7196 * 1 - Failed to issue logo off the @vport
7197 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007198int
7199lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7200{
7201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7202 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007203 IOCB_t *icmd;
7204 struct lpfc_iocbq *elsiocb;
7205 uint8_t *pcmd;
7206 uint16_t cmdsize;
7207
7208 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7209 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7210 ELS_CMD_LOGO);
7211 if (!elsiocb)
7212 return 1;
7213
7214 icmd = &elsiocb->iocb;
7215 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7216 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7217 pcmd += sizeof(uint32_t);
7218
7219 /* Fill in LOGO payload */
7220 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7221 pcmd += sizeof(uint32_t);
7222 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7223
James Smart858c9f62007-06-17 19:56:39 -05007224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7225 "Issue LOGO npiv did:x%x flg:x%x",
7226 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7227
James Smart92d7f7b2007-06-17 19:56:38 -05007228 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7229 spin_lock_irq(shost->host_lock);
7230 ndlp->nlp_flag |= NLP_LOGO_SND;
7231 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04007232 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7233 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05007234 spin_lock_irq(shost->host_lock);
7235 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7236 spin_unlock_irq(shost->host_lock);
7237 lpfc_els_free_iocb(phba, elsiocb);
7238 return 1;
7239 }
7240 return 0;
7241}
7242
James Smarte59058c2008-08-24 21:49:00 -04007243/**
James Smart3621a712009-04-06 18:47:14 -04007244 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04007245 * @ptr: holder for the timer function associated data.
7246 *
7247 * This routine is invoked by the fabric iocb block timer after
7248 * timeout. It posts the fabric iocb block timeout event by setting the
7249 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7250 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7251 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7252 * posted event WORKER_FABRIC_BLOCK_TMO.
7253 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007254void
7255lpfc_fabric_block_timeout(unsigned long ptr)
7256{
7257 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7258 unsigned long iflags;
7259 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04007260
James Smart92d7f7b2007-06-17 19:56:38 -05007261 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7262 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7263 if (!tmo_posted)
7264 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7265 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7266
James Smart5e9d9b82008-06-14 22:52:53 -04007267 if (!tmo_posted)
7268 lpfc_worker_wake_up(phba);
7269 return;
James Smart92d7f7b2007-06-17 19:56:38 -05007270}
7271
James Smarte59058c2008-08-24 21:49:00 -04007272/**
James Smart3621a712009-04-06 18:47:14 -04007273 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04007274 * @phba: pointer to lpfc hba data structure.
7275 *
7276 * This routine issues one fabric iocb from the driver internal list to
7277 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7278 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7279 * remove one pending fabric iocb from the driver internal list and invokes
7280 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7281 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007282static void
7283lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7284{
7285 struct lpfc_iocbq *iocb;
7286 unsigned long iflags;
7287 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05007288 IOCB_t *cmd;
7289
7290repeat:
7291 iocb = NULL;
7292 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05007293 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05007294 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7295 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7296 list);
7297 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05007298 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05007299 atomic_inc(&phba->fabric_iocb_count);
7300 }
7301 spin_unlock_irqrestore(&phba->hbalock, iflags);
7302 if (iocb) {
7303 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7304 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7305 iocb->iocb_flag |= LPFC_IO_FABRIC;
7306
James Smart858c9f62007-06-17 19:56:39 -05007307 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7308 "Fabric sched1: ste:x%x",
7309 iocb->vport->port_state, 0, 0);
7310
James Smart3772a992009-05-22 14:50:54 -04007311 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007312
7313 if (ret == IOCB_ERROR) {
7314 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7315 iocb->fabric_iocb_cmpl = NULL;
7316 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7317 cmd = &iocb->iocb;
7318 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7319 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7320 iocb->iocb_cmpl(phba, iocb, iocb);
7321
7322 atomic_dec(&phba->fabric_iocb_count);
7323 goto repeat;
7324 }
7325 }
7326
7327 return;
7328}
7329
James Smarte59058c2008-08-24 21:49:00 -04007330/**
James Smart3621a712009-04-06 18:47:14 -04007331 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007332 * @phba: pointer to lpfc hba data structure.
7333 *
7334 * This routine unblocks the issuing fabric iocb command. The function
7335 * will clear the fabric iocb block bit and then invoke the routine
7336 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7337 * from the driver internal fabric iocb list.
7338 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007339void
7340lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7341{
7342 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7343
7344 lpfc_resume_fabric_iocbs(phba);
7345 return;
7346}
7347
James Smarte59058c2008-08-24 21:49:00 -04007348/**
James Smart3621a712009-04-06 18:47:14 -04007349 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007350 * @phba: pointer to lpfc hba data structure.
7351 *
7352 * This routine blocks the issuing fabric iocb for a specified amount of
7353 * time (currently 100 ms). This is done by set the fabric iocb block bit
7354 * and set up a timeout timer for 100ms. When the block bit is set, no more
7355 * fabric iocb will be issued out of the HBA.
7356 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007357static void
7358lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7359{
7360 int blocked;
7361
7362 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05007363 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05007364 if (!blocked)
7365 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7366
7367 return;
7368}
7369
James Smarte59058c2008-08-24 21:49:00 -04007370/**
James Smart3621a712009-04-06 18:47:14 -04007371 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04007372 * @phba: pointer to lpfc hba data structure.
7373 * @cmdiocb: pointer to lpfc command iocb data structure.
7374 * @rspiocb: pointer to lpfc response iocb data structure.
7375 *
7376 * This routine is the callback function that is put to the fabric iocb's
7377 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7378 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7379 * function first restores and invokes the original iocb's callback function
7380 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7381 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7382 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007383static void
7384lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7385 struct lpfc_iocbq *rspiocb)
7386{
7387 struct ls_rjt stat;
7388
7389 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7390 BUG();
7391
7392 switch (rspiocb->iocb.ulpStatus) {
7393 case IOSTAT_NPORT_RJT:
7394 case IOSTAT_FABRIC_RJT:
7395 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7396 lpfc_block_fabric_iocbs(phba);
7397 }
7398 break;
7399
7400 case IOSTAT_NPORT_BSY:
7401 case IOSTAT_FABRIC_BSY:
7402 lpfc_block_fabric_iocbs(phba);
7403 break;
7404
7405 case IOSTAT_LS_RJT:
7406 stat.un.lsRjtError =
7407 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7408 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7409 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7410 lpfc_block_fabric_iocbs(phba);
7411 break;
7412 }
7413
7414 if (atomic_read(&phba->fabric_iocb_count) == 0)
7415 BUG();
7416
7417 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7418 cmdiocb->fabric_iocb_cmpl = NULL;
7419 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7420 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7421
7422 atomic_dec(&phba->fabric_iocb_count);
7423 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05007424 /* Post any pending iocbs to HBA */
7425 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05007426 }
7427}
7428
James Smarte59058c2008-08-24 21:49:00 -04007429/**
James Smart3621a712009-04-06 18:47:14 -04007430 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04007431 * @phba: pointer to lpfc hba data structure.
7432 * @iocb: pointer to lpfc command iocb data structure.
7433 *
7434 * This routine is used as the top-level API for issuing a fabric iocb command
7435 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7436 * function makes sure that only one fabric bound iocb will be outstanding at
7437 * any given time. As such, this function will first check to see whether there
7438 * is already an outstanding fabric iocb on the wire. If so, it will put the
7439 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7440 * issued later. Otherwise, it will issue the iocb on the wire and update the
7441 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7442 *
7443 * Note, this implementation has a potential sending out fabric IOCBs out of
7444 * order. The problem is caused by the construction of the "ready" boolen does
7445 * not include the condition that the internal fabric IOCB list is empty. As
7446 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7447 * ahead of the fabric IOCBs in the internal list.
7448 *
7449 * Return code
7450 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7451 * IOCB_ERROR - failed to issue fabric iocb
7452 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007453static int
James Smart92d7f7b2007-06-17 19:56:38 -05007454lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7455{
7456 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05007457 int ready;
7458 int ret;
7459
7460 if (atomic_read(&phba->fabric_iocb_count) > 1)
7461 BUG();
7462
7463 spin_lock_irqsave(&phba->hbalock, iflags);
7464 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7465 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7466
James Smart7f5f3d02008-02-08 18:50:14 -05007467 if (ready)
7468 /* Increment fabric iocb count to hold the position */
7469 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05007470 spin_unlock_irqrestore(&phba->hbalock, iflags);
7471 if (ready) {
7472 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7473 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7474 iocb->iocb_flag |= LPFC_IO_FABRIC;
7475
James Smart858c9f62007-06-17 19:56:39 -05007476 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7477 "Fabric sched2: ste:x%x",
7478 iocb->vport->port_state, 0, 0);
7479
James Smart3772a992009-05-22 14:50:54 -04007480 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05007481
7482 if (ret == IOCB_ERROR) {
7483 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7484 iocb->fabric_iocb_cmpl = NULL;
7485 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7486 atomic_dec(&phba->fabric_iocb_count);
7487 }
7488 } else {
7489 spin_lock_irqsave(&phba->hbalock, iflags);
7490 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7491 spin_unlock_irqrestore(&phba->hbalock, iflags);
7492 ret = IOCB_SUCCESS;
7493 }
7494 return ret;
7495}
7496
James Smarte59058c2008-08-24 21:49:00 -04007497/**
James Smart3621a712009-04-06 18:47:14 -04007498 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007499 * @vport: pointer to a virtual N_Port data structure.
7500 *
7501 * This routine aborts all the IOCBs associated with a @vport from the
7502 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7503 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7504 * list, removes each IOCB associated with the @vport off the list, set the
7505 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7506 * associated with the IOCB.
7507 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01007508static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05007509{
7510 LIST_HEAD(completions);
7511 struct lpfc_hba *phba = vport->phba;
7512 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05007513
7514 spin_lock_irq(&phba->hbalock);
7515 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7516 list) {
7517
7518 if (piocb->vport != vport)
7519 continue;
7520
7521 list_move_tail(&piocb->list, &completions);
7522 }
7523 spin_unlock_irq(&phba->hbalock);
7524
James Smarta257bf92009-04-06 18:48:10 -04007525 /* Cancel all the IOCBs from the completions list */
7526 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7527 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007528}
7529
James Smarte59058c2008-08-24 21:49:00 -04007530/**
James Smart3621a712009-04-06 18:47:14 -04007531 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007532 * @ndlp: pointer to a node-list data structure.
7533 *
7534 * This routine aborts all the IOCBs associated with an @ndlp from the
7535 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7536 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7537 * list, removes each IOCB associated with the @ndlp off the list, set the
7538 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7539 * associated with the IOCB.
7540 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007541void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7542{
7543 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04007544 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05007545 struct lpfc_iocbq *tmp_iocb, *piocb;
7546 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05007547
7548 spin_lock_irq(&phba->hbalock);
7549 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7550 list) {
7551 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7552
7553 list_move_tail(&piocb->list, &completions);
7554 }
7555 }
7556 spin_unlock_irq(&phba->hbalock);
7557
James Smarta257bf92009-04-06 18:48:10 -04007558 /* Cancel all the IOCBs from the completions list */
7559 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7560 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007561}
7562
James Smarte59058c2008-08-24 21:49:00 -04007563/**
James Smart3621a712009-04-06 18:47:14 -04007564 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04007565 * @phba: pointer to lpfc hba data structure.
7566 *
7567 * This routine aborts all the IOCBs currently on the driver internal
7568 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7569 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7570 * list, removes IOCBs off the list, set the status feild to
7571 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7572 * the IOCB.
7573 **/
James Smart92d7f7b2007-06-17 19:56:38 -05007574void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7575{
7576 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05007577
7578 spin_lock_irq(&phba->hbalock);
7579 list_splice_init(&phba->fabric_iocb_list, &completions);
7580 spin_unlock_irq(&phba->hbalock);
7581
James Smarta257bf92009-04-06 18:48:10 -04007582 /* Cancel all the IOCBs from the completions list */
7583 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7584 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05007585}
James Smart6fb120a2009-05-22 14:52:59 -04007586
7587/**
7588 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7589 * @phba: pointer to lpfc hba data structure.
7590 * @axri: pointer to the els xri abort wcqe structure.
7591 *
7592 * This routine is invoked by the worker thread to process a SLI4 slow-path
7593 * ELS aborted xri.
7594 **/
7595void
7596lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7597 struct sli4_wcqe_xri_aborted *axri)
7598{
7599 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
James Smart19ca7602010-11-20 23:11:55 -05007600 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7601
James Smart6fb120a2009-05-22 14:52:59 -04007602 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7603 unsigned long iflag = 0;
James Smart19ca7602010-11-20 23:11:55 -05007604 struct lpfc_nodelist *ndlp;
James Smart589a52d2010-07-14 15:30:54 -04007605 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart6fb120a2009-05-22 14:52:59 -04007606
James Smart0f65ff62010-02-26 14:14:23 -05007607 spin_lock_irqsave(&phba->hbalock, iflag);
7608 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007609 list_for_each_entry_safe(sglq_entry, sglq_next,
7610 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7611 if (sglq_entry->sli4_xritag == xri) {
7612 list_del(&sglq_entry->list);
James Smart19ca7602010-11-20 23:11:55 -05007613 ndlp = sglq_entry->ndlp;
7614 sglq_entry->ndlp = NULL;
James Smart6fb120a2009-05-22 14:52:59 -04007615 list_add_tail(&sglq_entry->list,
7616 &phba->sli4_hba.lpfc_sgl_list);
James Smart0f65ff62010-02-26 14:14:23 -05007617 sglq_entry->state = SGL_FREED;
7618 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
James Smart6fb120a2009-05-22 14:52:59 -04007619 spin_unlock_irqrestore(&phba->hbalock, iflag);
James Smart19ca7602010-11-20 23:11:55 -05007620 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
James Smart589a52d2010-07-14 15:30:54 -04007621
7622 /* Check if TXQ queue needs to be serviced */
7623 if (pring->txq_cnt)
7624 lpfc_worker_wake_up(phba);
James Smart6fb120a2009-05-22 14:52:59 -04007625 return;
7626 }
7627 }
James Smart0f65ff62010-02-26 14:14:23 -05007628 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7629 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7630 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7631 spin_unlock_irqrestore(&phba->hbalock, iflag);
7632 return;
7633 }
7634 sglq_entry->state = SGL_XRI_ABORTED;
7635 spin_unlock_irqrestore(&phba->hbalock, iflag);
7636 return;
James Smart6fb120a2009-05-22 14:52:59 -04007637}